php editor Strawberry is here to answer a common question for everyone: Why does the SOAP service (jax-ws) stop after a period of time and throw a WebServiceTransportException: Unauthorized exception when using the Linux operating system? This issue may be caused by permission issues. On Linux, the SOAP service may need to access certain files or directories, but does not have sufficient permissions to access them, causing the service to stop. The solution to this problem is to ensure that the SOAP service has sufficient permissions to access the required files and directories. This problem can be solved by changing the permissions of the files and directories or ensuring that the SOAP service uses a user with sufficient permissions.
I have developed a soap application and send requests to the required services. The problem is that after some time an exception is thrown:
Stack trace:
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
This feature works in windows, but in linux (rocky linux) it stops working after some time (5-10 minutes).
This is my configuration (some information has been changed, such as the url):
@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(); } }
This 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) { jaxbelementobject = (jaxbelement ) 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 headerelement = new jaxbelement<>(new qname("http://services.ws.payment.example.net/", "messageheader"), messageheader.class, null, soapheader); marshaller.marshal(headerelement, header.getresult()); jaxbelement 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 add properties to trust the ssl certificate from the 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); }
I encountered this problem a few years ago. From what I understand, the problem is with the JDK version. I changed the JDK to another version (Amazon Coretto) and everything worked fine.
The above is the detailed content of Why does SOAP service (jax-ws) stop after some time and throw WebServiceTransportException: Unauthorized ] on Linux operating system?. For more information, please follow other related articles on the PHP Chinese website!