php小编草莓在这里为大家解答一个常见问题:为什么在Linux操作系统上使用SOAP服务(jax-ws)时,在一段时间后会停止并抛出WebServiceTransportException: Unauthorized异常?这个问题可能是由于权限问题引起的。在Linux上,SOAP服务可能需要访问某些文件或目录,但是没有足够的权限进行访问,导致服务停止。解决这个问题的方法是确保SOAP服务有足够的权限来访问所需的文件和目录。可以通过更改文件和目录的权限或确保SOAP服务使用具有足够权限的用户来解决这个问题。
我开发了一个肥皂应用程序,并向所需的服务发送请求。问题是一段时间后抛出异常:
堆栈跟踪:
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
该功能在 windows 中有效,但在 linux (rocky linux) 中,它会在一段时间(5-10 分钟)后停止工作。
这是我的配置(一些信息已更改,例如 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(); } }
这是我的客户
@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(); } }
在这里,我添加属性以信任来自信任库的 ssl 证书
@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); }
几年前我就遇到过这样的问题。据我了解,问题出在 JDK 版本上。我将 JDK 更改为另一个版本 (Amazon Coretto),一切正常。
以上是为什么 SOAP 服务 (jax-ws) 在 Linux 操作系统上在一段时间后停止并抛出 WebServiceTransportException: Unauthorized ]?的详细内容。更多信息请关注PHP中文网其他相关文章!