I have developed a soap application and am sending requests to the required service. The problem is that after some time an exception is thrown:
Stacktrace:
Servlet.service() for servlet [dispatcherServlet] in context with path [/api] threw exception [Request processing failed: org.springframework.ws.client.WebServiceTransportException: Unauthorized [401]] with root cause
org.springframework.ws.client.WebServiceTransportException: Unauthorized [401]
at org.springframework.ws.client.core.WebServiceTemplate.handleError(WebServiceTemplate.java:665) ~[spring-ws-core-4.0.2.jar!/:na]
at org.springframework.ws.client.core.WebServiceTemplate.doSendAndReceive(WebServiceTemplate.java:587) ~[spring-ws-core-4.0.2.jar!/:na]
at org.springframework.ws.client.core.WebServiceTemplate.sendAndReceive(WebServiceTemplate.java:538) ~[spring-ws-core-4.0.2.jar!/:na]
at
The functionality works in Windows, but in Linux (Rocky Linux) it stops working after some time (5-10 minutes).
Here is my configuration (some info are changed like URLs):
@Configuration
@RequiredArgsConstructor
public class CustomerPaymentClientConfig {
@Bean
public Jaxb2Marshaller marshaller() {
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setContextPath("com.example.wsdl");
return marshaller;
}
@Bean
public WebServiceTemplate webServiceTemplate(WebServiceTemplateBuilder builder, Jaxb2Marshaller marshaller) throws Exception {
return builder
.setDefaultUri("https://service.example.com/WebPortalVC/PaymentWS")
.setMarshaller(marshaller)
.setUnmarshaller(marshaller)
.build();
}
}
Here is my client
@Service
@RequiredArgsConstructor
public class GPPPaymentClient extends WebServiceGatewaySupport {
private final WebServiceTemplate webServiceTemplate;
private final Jaxb2Marshaller marshaller;
public InitiatePaymentResponse InitiatePayment(MessageHeader messageHeader, InitiatePayment InitiationRequest) {
JAXBElement<InitiatePaymentResponse> object = (JAXBElement<InitiatePaymentResponse>) webServiceTemplate.marshalSendAndReceive(InitiationRequest, webServiceMessage -> {
try {
String namespaceSer = "http://services.ws.payment.example.net/";
SoapMessage soapMessage = (SoapMessage) webServiceMessage;
SoapHeader header = soapMessage.getSoapHeader();
header.addNamespaceDeclaration("ser", namespaceSer);
ObjectFactory objectFactory = new ObjectFactory();
MessageHeader soapHeader = objectFactory.createMessageHeader();
soapHeader.setUserID(messageHeader.getUserID());
soapHeader.setReceiverID(messageHeader.getReceiverID());
soapHeader.setTransactionID(messageHeader.getTransactionID());
soapHeader.setMessageDateTime(messageHeader.getMessageDateTime());
JAXBElement<MessageHeader> headerElement = new JAXBElement<>(new QName("http://services.ws.payment.example.net/", "messageHeader"), MessageHeader.class, null, soapHeader);
marshaller.marshal(headerElement, header.getResult());
JAXBElement<InitiatePayment> bodyElement = new JAXBElement<>(new QName("http://test.ws.payment.example.net/", "InitiatePayment"), InitiatePayment.class, null, InitiationRequest);
marshaller.marshal(bodyElement, soapMessage.getPayloadResult());
} catch (Exception e) {
log.info(e.toString());
}
});
return object.getValue();
}
}
Here I'm adding properties to trust ssl certificates from truststore
@Bean
public void addProperties() {
System.setProperty("javax.net.ssl.keyStore", keyStoreLocation);
System.setProperty("javax.net.ssl.keyStorePassword", keyStorePassword);
System.setProperty("javax.net.ssl.trustStore", cacertLocation);
System.setProperty("javax.net.ssl.trustStorePassword", cacertPassword);
}
A couple of years ago I encountered such a problem. The problem, as I understood it, was the JDK version. I changed JDK to another version (Amazon Coretto) and everything worked.