尝试使用Spring-WS访问WS服务器 - "连接超时",但服务器在使用SOAP UI进行测试时会响应

Fly*_*t91 6 java spring soap wsdl web-services

问题

我正在接管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);
Run Code Online (Sandbox Code Playgroud)

产生的错误

[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
Run Code Online (Sandbox Code Playgroud)

假设1:我使用正确的Web服务URL吗?

我确信Spring给了正确的URL,因为它与我接手代码之前是一样的,并没有改变wsdl和服务器(我们的客户从不抱怨,它对他有用,但从来没有在我们的工作中的机器.所以不要问我之前的开发人员如何测试它,虽然它不起作用,因为idk):

WebServiceGatewaySupport.setDefaultUri("http://82.36.138.182:8080/axis2/services/KYCService01.KYCService01HttpSoap11Endpoint/")
Run Code Online (Sandbox Code Playgroud)

我在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>
Run Code Online (Sandbox Code Playgroud)

我也尝试将EPR作为网址,但它并没有改变任何东西:

WebServiceGatewaySupport.setDefaultUri("http://82.36.138.182:8080/axis2/services/KYCService01")
Run Code Online (Sandbox Code Playgroud)

假设2:它是我落后的代理吗?

然后,我认为错误肯定是由于我所支持的代理引起的.实际上,当我尝试编写一小段代码来连接到wsdl url时,起初我无法得到"连接超时".为了解决这个问题,我将代理设置为java System属性,允许我现在从Web服务客户端访问wsdl.

设置代理

System.setProperty("http.proxyHost", "<my_proxy_hostname>");
System.setProperty("http.proxyPort", "<my_proxy_port>");
Run Code Online (Sandbox Code Playgroud)

连接到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
Run Code Online (Sandbox Code Playgroud)

不幸的是,当我尝试使用我的代理集调用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)
Run Code Online (Sandbox Code Playgroud)

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)
Run Code Online (Sandbox Code Playgroud)

我对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");
            }
        });
    }
Run Code Online (Sandbox Code Playgroud)

否则,我们可以在User-Agent属性中看到的java版本是否重要?(编辑)我不这么认为,因为我试图使用1.6 jre并且版本确实在User-Agent属性中更改但我仍然有相同的错误.

小智 0

可能的解决方案 1. 请尝试从浏览器访问 WSDL 2. 请查看 SOAP UI 中是否已配置任何授权标头或代理设置