加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

java – 尝试使用Spring-WS访问WS服务器 – “连接超时”,但服

发布时间:2020-12-15 01:34:47 所属栏目:大数据 来源:网络整理
导读:问题 我正在接管java Web服务客户端的开发,为了测试进化,我必须从远程Web服务服务器(嵌入在tomcat实例中运行的Apache Axis2中)中请求一个方法. 首先,我使用服务器提供的WSDL通过SOAP UI请求了该方法.它工作正常. 现在我尝试通过我的Java Web服务客户端请求该

问题

我正在接管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中有以下内容:

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

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

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

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

设置代理

System.setProperty("http.proxyHost","

连接到WSDL URL

URL wsdlAddress = null;
HttpURLConnection connection = null;

wsdlAdress = new URL("

不幸的是,当我尝试使用我的代理集调用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属性中更改但我仍然有相同的错误.

最佳答案
总结疑难解答提示,尝试总结评论中的长篇讨论:

>尝试检查是否缺少任何必需的标题.
>尝试访问服务的简单连接到运行状况检查或ping端点.
>如果持续连接超时,请尝试减少连接超时.
>如果无法连接,请检查防火墙规则.
>使用内部开发的自定义客户端库时,请尝试联系知道该库的开发人员以获取帮助.
>使用自定义客户端库时,将源附加到调试.
>尝试复制像myKong’s SOAP Web Service example这样的模板,如果你能逃脱它.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读