簡體   English   中英

嘗試使用Spring-WS訪問WS服務器 - “連接超時”,但服務器在使用SOAP UI進行測試時會響應

[英]Trying to access a WS server with Spring-WS - “Connection timed out”, but the server respond when tested with SOAP UI

問題

我正在接管java Web服務客戶端的開發,為了測試進化,我必須從遠程Web服務服務器(嵌入在tomcat實例中運行的Apache Axis2中)中請求一個方法。

首先,我使用服務器提供的WSDL通過SOAP UI請求了該方法。 它工作正常。

現在我嘗試通過我的Java Web服務客戶端請求該方法,但我無法連接到服務器,即使使用SOAP UI測試證明一切都很好。

java Web服務客戶端依賴於Spring-WS。


從客戶端調用Web服務

// Setting the kycScoreRequest
...

// Trying to connect and to get the kycScoreResponse 
KycScoreResponse kycScoreResponse = (KycScoreResponse) getWebServiceTemplate().marshalSendAndReceive(kycScoreRequest);

產生的錯誤

[main] DEBUG com.foo.AbstractMain - org.springframework.ws.client.WebServiceIOException: I/O error: Connection timed out: connect; nested exception is java.net.ConnectException: Connection timed out: connect
    at org.springframework.ws.client.core.WebServiceTemplate.sendAndReceive(WebServiceTemplate.java:545)
    at org.springframework.ws.client.core.WebServiceTemplate.marshalSendAndReceive(WebServiceTemplate.java:386)
    at org.springframework.ws.client.core.WebServiceTemplate.marshalSendAndReceive(WebServiceTemplate.java:380)
    at org.springframework.ws.client.core.WebServiceTemplate.marshalSendAndReceive(WebServiceTemplate.java:372)
    at com.foo.MainKycScore.getReturn(MainKycScore.java:37)
    at com.foo.MainKycScore.main(MainKycScore.java:244)
Caused by: java.net.ConnectException: Connection timed out: connect
    at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
    at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
    at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
    at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
    at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
    at java.net.PlainSocketImpl.connect(Unknown Source)
    at java.net.SocksSocketImpl.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:121)
    at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:180)
    at org.apache.http.impl.conn.ManagedClientConnectionImpl.open(ManagedClientConnectionImpl.java:326)
    at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:610)
    at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:445)
    at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:835)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:108)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:56)
    at org.springframework.ws.transport.http.HttpComponentsConnection.onSendAfterWrite(HttpComponentsConnection.java:119)
    at org.springframework.ws.transport.AbstractWebServiceConnection.send(AbstractWebServiceConnection.java:47)
    at org.springframework.ws.client.core.WebServiceTemplate.sendRequest(WebServiceTemplate.java:624)
    at org.springframework.ws.client.core.WebServiceTemplate.doSendAndReceive(WebServiceTemplate.java:587)
    at org.springframework.ws.client.core.WebServiceTemplate.sendAndReceive(WebServiceTemplate.java:539)
    ... 5 more

假設1:我使用正確的Web服務URL嗎?

我確信Spring給了正確的URL,因為它與我接手代碼之前是一樣的,並沒有改變wsdl和服務器( 我們的客戶從不抱怨,它對他有用,但從來沒有在我們的工作中的機器 。所以不要問我之前的開發人員如何測試它,雖然它不起作用,因為idk):

WebServiceGatewaySupport.setDefaultUri("http://82.36.138.182:8080/axis2/services/KYCService01.KYCService01HttpSoap11Endpoint/")

我在WSDL中有以下內容:

<wsdl:service name="KYCService01">
    <wsdl:port name="KYCService01HttpSoap11Endpoint" binding="ns:KYCService01Soap11Binding">
        <soap:address location="http://82.36.138.182:8080/axis2/services/KYCService01.KYCService01HttpSoap11Endpoint/"/>
    </wsdl:port>
</wsdl:service>

我也嘗試將EPR作為網址,但它並沒有改變任何東西:

WebServiceGatewaySupport.setDefaultUri("http://82.36.138.182:8080/axis2/services/KYCService01")

假設2:這是我落后的代理嗎?

然后,我認為錯誤肯定是由於我所支持的代理引起的。 實際上,當我嘗試編寫一小段代碼來連接到wsdl url時,起初我無法得到“連接超時”。 為了解決這個問題,我將代理設置為java System屬性,允許我現在從Web服務客戶端訪問wsdl。

設置代理

System.setProperty("http.proxyHost", "<my_proxy_hostname>");
System.setProperty("http.proxyPort", "<my_proxy_port>");

連接到WSDL URL

URL wsdlAddress = null;
HttpURLConnection connection = null;

wsdlAdress = new URL("<wsdl_url>");
connection = (HttpURLConnection) wsdlAdress.openConnection();
connection.connect(); // It works if the proxy is set as System properties

不幸的是,當我嘗試使用我的代理集調用Web服務服務器時,我仍然有與上面提到的完全相同的錯誤。 現在我已經不在乎了。 我的Java客戶端如何可以訪問Web服務WSDL而不是其方法?


(編輯)假設3:這是http標題嗎?

由於膜攔截器,我從SOAP UI和WS客戶端攔截了HTTP msg。 查看標題:

SOAP UI

POST http://82.36.138.182:8080/axis2/services/KYCService01.KYCService01HttpSoap11Endpoint/ HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: text/xml;charset=UTF-8
SOAPAction: "urn:kycScore"
Content-Length: 1301
Host: 84.37.138.182:8080
Proxy-Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)

WS客戶端(目標URL是SOAP UI模擬服務器,因為很明顯,如果我使用URL我真的嘗試連接到沒有發送任何內容,因此沒有任何內容可以攔截)

POST /mock HTTP/1.1
Accept-Encoding: gzip
Accept: text/xml, text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
SOAPAction: ""
Content-Type: text/xml; charset=utf-8
Content-Length: 1032
Host: localhost:8088
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.5.3 (Java/1.8.0_101)

我對http頭文件一無所知,但主要區別似乎是SOAPAction。 我將我的ws客戶端消息的SOAPAction屬性設置為與SOAP UI相同的值,但它沒有改變任何東西。

public Object marshalWithSoapActionHeader(KycScore o) {

        return getWebServiceTemplate().marshalSendAndReceive(o, new WebServiceMessageCallback() {

            public void doWithMessage(WebServiceMessage message) {
                ((SoapMessage) message).setSoapAction("urn:kycScore");
            }
        });
    }

否則,我們可以在User-Agent屬性中看到的java版本是否重要? (編輯)我不這么認為,因為我試圖使用1.6 jre並且版本確實在User-Agent屬性中更改但我仍然有相同的錯誤。

總結疑難解答提示,嘗試總結評論中的長篇討論:

  1. 嘗試檢查是否缺少任何必需的標題。
  2. 嘗試訪問服務的簡單連接到運行狀況檢查或ping端點。
  3. 如果持續連接超時,請嘗試減少連接超時。
  4. 如果無法連接,請檢查防火牆規則。
  5. 使用內部開發的自定義客戶端庫時,請嘗試聯系知道該庫以獲取幫助的開發人員。
  6. 使用自定義客戶端庫時,請將源附加到調試。
  7. 如果你能逃脫它,請嘗試復制像myKong的SOAP Web服務示例這樣的模板。

請檢查Internet Explorer中的代理設置

可能的解決方案1.請嘗試從瀏覽器2訪問WSDL。請查看SOAP UI中是否已配置任何授權標頭或代理設置

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM