Scrivio Interview library
ScenarioIntermediate7 min read · updated 12 November 2026

A Spring Boot service must call a partner's SOAP API that uses WS-Security signatures, while exposing a REST API to your own clients. How would you structure the integration and test it?

We keep the SOAP integration inside one adapter module: classes generated from the partner's WSDL, a WebServiceTemplate or CXF client with WS-Security interceptors that sign and timestamp each message with a key from the secret manager, and code that turns SOAP faults into our own domain exceptions. Our REST API only ever sees those domain types and returns problem details, never partner XML. We test the adapter with mocked SOAP responses, check against the partner's sandbox with a contract test, and set timeouts and retries knowing that most SOAP operations are not idempotent.

Why this question is asked

Many Spring Boot services sit between a modern world of JSON clients and an older world of partner SOAP services: a bank's payment gateway, an insurer's quote engine, a tax authority's filing service. Done badly, partner XML and security details leak through the whole codebase. Interviewers ask this scenario to see whether we can isolate an awkward dependency, configure message-level security, and test something we do not control. In this answer, we will look at the structure first, then generate the client, configure WS-Security, map faults to our REST errors, test the adapter, and finish with timeouts and retries.

1Structuring the Integration Around an Adapter

The rule is that SOAP is a detail of one module. Our REST controllers call an application service, the application service talks to an interface we define in our own terms, such as QuotePort with a method quote(QuoteRequest), and only the adapter that implements QuotePort knows about WSDLs, XML and signatures. This is the ports and adapters idea: the core of the application depends on an interface, and the outside world plugs into it. So when the partner releases a new WSDL, or replaces SOAP with REST, only the adapter changes.

Step throughWhere each concern lives
  1. REST controllerour JSON contract, problem details on errors
  2. Application servicebusiness rules, uses QuotePort
  3. QuotePort interfaceour own request, response and exception types
  4. SOAP adaptermaps types, calls WebServiceTemplate, maps faults
  5. WS-Security interceptorsigns, timestamps, validates replies
  6. Generated JAXB classesfrom the partner WSDL, never used outside the adapter

6 layers, from the top down. Step through them one at a time.

2Generating the Client Classes From the WSDL

We never write the XML classes by hand. A Maven plugin reads the partner's WSDL, which we store in the repository so builds are reproducible, and generates Java classes into target/generated-sources. With Apache CXF 4.x, the generated classes use the jakarta namespace, which current Spring versions require.

XML
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>${cxf.version}</version> <!-- a 4.x version for jakarta -->
<executions>
<execution>
<id>partner-wsdl</id>
<phase>generate-sources</phase>
<goals><goal>wsdl2java</goal></goals>
<configuration>
<wsdlOptions>
<wsdlOption>
<wsdl>${project.basedir}/src/main/resources/wsdl/partner-quote.wsdl</wsdl>
<extraargs><extraarg>-p</extraarg><extraarg>com.acme.partner.generated</extraarg></extraargs>
</wsdlOption>
</wsdlOptions>
</configuration>
</execution>
</executions>
</plugin>

If we use Spring Web Services instead of a CXF client, we only need the JAXB classes for the message payloads, which a JAXB Maven plugin can generate from the WSDL's schema; check that the plugin version targets the jakarta namespace. Either way, the generated package is used only inside the adapter.

3Signing and Timestamping With WS-Security

WS-Security adds a security header to each SOAP message. The partner usually asks for two actions: a Timestamp, which says when the message was created and when it expires so it cannot be replayed later, and a Signature, which signs the body and the timestamp with our private key. With Spring Web Services, Wss4jSecurityInterceptor does both, using the WSS4J library underneath. With a CXF client, the equivalent is the WSS4JOutInterceptor.

Java
@Bean
Wss4jSecurityInterceptor partnerSecurity(PartnerProperties p, KeyStore signingKeys, KeyStore partnerTrust) {
Merlin ours = new Merlin(); ours.setKeyStore(signingKeys); // keystore bytes from the secret manager
Merlin theirs = new Merlin(); theirs.setTrustStore(partnerTrust);
Wss4jSecurityInterceptor sec = new Wss4jSecurityInterceptor();
sec.setSecurementActions("Timestamp Signature"); // what we add to outgoing messages
sec.setSecurementUsername(p.keyAlias()); // alias of our signing key
sec.setSecurementPassword(p.keyPassword());
sec.setSecurementSignatureCrypto(ours);
sec.setSecurementTimeToLive(300); // timestamp valid for 5 minutes
sec.setValidationActions("Timestamp Signature"); // what we require on replies
sec.setValidationSignatureCrypto(theirs);
return sec;
}
@Bean
WebServiceTemplate partnerTemplate(Jaxb2Marshaller marshaller, Wss4jSecurityInterceptor sec, PartnerProperties p) {
WebServiceTemplate t = new WebServiceTemplate(marshaller);
t.setDefaultUri(p.url());
t.setInterceptors(new ClientInterceptor[] { sec });
HttpUrlConnectionMessageSender sender = new HttpUrlConnectionMessageSender();
sender.setConnectionTimeout(Duration.ofSeconds(3));
sender.setReadTimeout(Duration.ofSeconds(20));
t.setMessageSender(sender);
return t;
}

Notice where the key comes from. The private key and its password are loaded from the secret manager at startup into a KeyStore object, so they are never in the repository or the image. The exact class names for the WSS4J crypto and the available message senders depend on the Spring WS version, so check your version.

4Mapping Faults Without Leaking Partner XML

When the partner rejects a request, Spring WS throws SoapFaultClientException, which holds the fault. The adapter reads the fault code and detail, and turns it into one of our own exceptions. The controller advice then turns that into a problem details response.

Java
public Quote quote(QuoteRequest request) {
try {
GetQuoteResponse r = (GetQuoteResponse) template.marshalSendAndReceive(toSoap(request));
return fromSoap(r);
} catch (SoapFaultClientException e) {
String code = partnerErrorCode(e.getSoapFault()); // reads <detail><errorCode>
if ("POLICY_NOT_FOUND".equals(code)) throw new PolicyNotFoundException(request.policyId());
throw new PartnerRejectedException(code); // no XML, no partner message text
} catch (WebServiceIOException e) {
throw new PartnerUnavailableException(e); // timeout or connection problem
}
}
@ExceptionHandler(PartnerUnavailableException.class)
ProblemDetail unavailable() {
return ProblemDetail.forStatusAndDetail(HttpStatus.SERVICE_UNAVAILABLE, "Quote service is temporarily unavailable");
}
// GET /quotes/7 while the partner is down -> 503 application/problem+json

Our clients never see a fault string, a namespace or a stack trace from the partner. Partner messages can reveal internal details, and our REST contract must not change when the partner changes its wording.

5Testing the Adapter and the Partner Contract

Most tests should not call the partner at all. Spring WS ships MockWebServiceServer, which replaces the message sender of a WebServiceTemplate, checks the request payload and returns a canned response or fault. We point it at a template built without the security interceptor, so the test focuses on mapping. WireMock, at the HTTP level, is handy for timeouts and malformed responses.

Java
MockWebServiceServer server = MockWebServiceServer.createServer(templateWithoutSecurity);
server.expect(payload(new StringSource("<q:getQuote xmlns:q='urn:partner'><q:policyId>7</q:policyId></q:getQuote>")))
.andRespond(withPayload(new StringSource("<q:getQuoteResponse xmlns:q='urn:partner'><q:premium>412.50</q:premium></q:getQuoteResponse>")));
Quote quote = adapter.quote(new QuoteRequest("7"));
assertThat(quote.premium()).isEqualByComparingTo("412.50"); // passes
server.verify();

The signing itself gets its own test with a test keystore: we sign a message and validate it with the matching trust store. Then a small contract test runs against the partner's sandbox, in a scheduled pipeline rather than every build, because sandboxes are slow and sometimes down. That test proves that our signature, timestamp and payload are accepted by the real partner, which is the one thing mocks cannot prove.

6Timeouts and Retries

Every call needs a connect timeout and a read timeout, as in the template above, otherwise a stalled partner holds our request threads. Retries need more thought. A getQuote call is a read, so one retry after a timeout is safe. A submitPayment call usually is not: if the timeout happened after the partner processed it, a retry pays twice.

So we retry only operations we know are safe, or ones where the partner offers an idempotency reference such as our own transaction id. For the rest, after a timeout we call the partner's status operation, if it has one, before deciding to resubmit, and we put a circuit breaker around the adapter so a partner outage fails fast instead of piling up waiting threads.

7Follow-up questions

Why not call the SOAP service directly from the controller?

Because then the generated classes, the fault handling and the security setup spread into the web layer, and every partner change touches our REST code. The adapter keeps all of that in one place with one interface we own and can mock.

How do you debug a signature the partner rejects?

We log the outgoing SOAP message after signing at debug level in a non-production environment, compare it with the partner's example, and check the usual causes: wrong key alias, a certificate the partner has not registered, clock skew that makes the timestamp look expired, or signing different parts than the partner expects. The partner's error detail, read in the adapter, usually names which of these it is.

8Conclusion

In this answer, we put a partner SOAP integration with WS-Security behind an adapter: generated jakarta classes from the stored WSDL, a WebServiceTemplate with a WSS4J interceptor that signs and timestamps with keys from the secret manager, faults mapped to domain exceptions and problem details, mocked tests plus a sandbox contract test, and timeouts with careful retries.

What to say in the interviewAbout 90 seconds aloud

Open with

I would isolate the partner in an adapter module behind an interface in our own terms, say QuotePort, so the REST controllers and the domain never see SOAP.

Then, if they want more

In that module I generate the client classes from the partner's WSDL, stored in the repo, with the CXF codegen plugin or a JAXB plugin, using a version that generates the jakarta namespace.

For the calls I use Spring Web Services' WebServiceTemplate, or a CXF client, with a WS-Security interceptor based on WSS4J that adds a timestamp and signs the body with our private key, and validates the signature on replies against the partner's certificate. The keystore and passwords come from the secret manager at startup, never from the repo.

In the adapter I catch SoapFaultClientException, read the error code from the fault detail and throw our own exceptions, which the controller advice turns into problem details, so no partner XML or wording leaks to our clients.

For testing I use MockWebServiceServer or WireMock with recorded responses for the mapping, a separate test for signing with a test keystore, and a scheduled contract test against the partner sandbox to prove the real signature is accepted.

Finally, explicit connect and read timeouts, a circuit breaker, and retries only for reads or operations with an idempotency reference, because a retried payment can be paid twice.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "A Spring Boot service must call a partner's SOAP API that uses WS-Security signatures...": https://scrivio-interview-library.netlify.app/spring-boot/rest-api-design/3288b81fc1/