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中文網其他相關文章!