Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trying to access a WS server with Spring-WS - "Connection timed out", but the server respond when tested with SOAP UI

The problem

I am taking over the development of a java web service client and in order to test an evolution I have to request a method from a distant web service server (which is embedded in an Apache Axis2 running in a tomcat instance).

In the first place, I requested the method through SOAP UI, using the WSDL provided by the server. It works fine.

Now I try to request the method through my Java web service client, but I cannot connect to the server even though the test with SOAP UI proves that everything is fine about it.

The java web service client relies on Spring-WS.


Calling the web service from the client

// Setting the kycScoreRequest
...

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

The resulting error

[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

Hypothesis 1 : Do I use the right web service URL ?

I'm kinda sure Spring is given the right URL, because it is the same as before I took over the code and nothing changed about the wsdl nor the server (and our client never complained, it was working for him, but never on our machines at work. So don't ask me how the developer before me tested it although it was not working, because idk) :

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

I have the following in the 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>

I also tried the EPR instead as the url, but it doens't change anything :

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

Hypothesis 2 : Is it the proxy I'm behind ?

Then, I thought that the error must have been caused because of the proxy which I'm behind. Indeed, when I tried to write a little piece of code to connect to the wsdl url, at first I couldn't and got a "connection timed out". To resolve this I set the proxy as java System properties, allowing me to now access the wsdl from the web service client.

Setting the proxy

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

Connecting to the 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

Unfortunately, when I try to call the web service server with my proxy set, I still have the exact same error as mentioned above. Now I am already out of idea. How is it possible that my Java client can access the web service WSDL but not its methods ?


(edit) Hypothesis 3 : Is it the http header ?

I intercepted the HTTP msg from SOAP UI and the WS client thanks to membrane interceptor. See the headers :

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 client (the destination URL is a SOAP UI mock server, because obviously if I use the URL I really try to connect to there is nothing sent and thus nothing to intercept)

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)

I don't really know anything about http headers, but the main difference seems to be SOAPAction. I set the SOAPAction attribute of my ws client message to the same value as SOAP UI, but it didn't change anything.

public Object marshalWithSoapActionHeader(KycScore o) {

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

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

Otherwise, is it possible that the java version we can see in the User-Agent attribute is important ? (edit) I don't think so because I tried to use a 1.6 jre and the version does change in the User-Agent attribute but I still have the same error.

like image 618
Flyout91 Avatar asked Jan 31 '18 10:01

Flyout91


2 Answers

Summarizing troubleshooting tips to try that summarize longwinded discussions in comments:

  1. Try checking whether or not you are missing any required headers.
  2. Try accessing a simple-to-connect-to health check or ping endpoint of the service.
  3. Try reducing your connection timeout if you keep getting a connection timeout.
  4. Check for Firewall rules if you can't connect.
  5. When using custom client libraries that were developed in house, try to reach out to devs who know that library for help.
  6. When using custom client libraries, attach sources to debug.
  7. Try copying a template like myKong's SOAP Web Service example if you can get away with it.
like image 53
entpnerd Avatar answered Nov 18 '22 13:11

entpnerd


Please check the proxy settings in your Internet explorer

like image 1
DevEmani Avatar answered Nov 18 '22 15:11

DevEmani