3

I created a soap client with wsimport and a given wsdl. I also used SoapUI to test the service. Using SoapUI I had no problem but when using my Java client I get

java.net.ConnectException: Connection timed out: connect

The default values I have in the requestContext are as follows

com.sun.xml.internal.ws.connect.timeout=100000
javax.xml.ws.service.endpoint.address=[fully qualified domain name endpoint]
com.sun.xml.internal.ws.request.timeout=100000
javax.xml.ws.soap.http.soapaction.use=null
com.sun.xml.internal.ws.client.ContentNegotiation=none
javax.xml.ws.soap.http.soapaction.uri=null

I've tried increasing the timeout but it still doesn't connect.

Has anyone else had a similar problem?

Shubham Kadlag
  • 2,248
  • 1
  • 13
  • 32
geco17
  • 5,152
  • 3
  • 21
  • 38
  • 1
    Connection timeout is a very generic error. You should tell more specifics. Also try using HttpURLConnection class as it is very easy to troubleshoot and then you can get back to wsimport. Is your soapui using any proxy as this can also cause problems in java code? Are you using any certificates in soap ui? – Shubham Kadlag May 29 '18 at 09:25
  • 1
    Timeout config aside, have you compared what SoapUI is actually sending to the service against what Java is sending? In SoapUI, on the left there is the panel(s) you use to create the request, but once you send the request, the 'raw' request tab is populated. I have used this many times to compare what SoapUI is sending against my Java or Node apps. It's been invaluable to me in highlighting what I have missed in the app. E.g. small typo in URL; request type, GET, PUSH, etc. the method to call; some missing attribute in the payload; incorrect headers; certificates; credentials.. – Chris Adams May 29 '18 at 09:42

2 Answers2

0

The problem was I was behind a proxy. I did different tests and found that using a web browser (or SoapUI) I was able to access the resource but from the command line it wasn't working.

After much searching, it was a simple fix: either passing the property as a jvm argument or manually setting it in the code with System.setProperty("java.net.useSystemProxies", "true"). The JVM wasn't using the proxy on its own.

EDIT

As I used wsimport I have a jax-ws client. It's important that proxy settings be configured prior to instantiantion.

ANOTHER EDIT

If by chance you're having problems and you're using an application server to make the soap request through the proxy, you may have to specify java.net.useSystemProxies=true (or similar) in the server's configuration--for example catalina.properties if using tomcat.

geco17
  • 5,152
  • 3
  • 21
  • 38
0

As you mentioned the problem is of proxy, it has been answered in below links.

How to use an HTTP proxy in java

Proxy settings in a java program

If you are using proxy with authentication then you have set authenticator along with the proxy. This is answered here.

Authenticated HTTP proxy with Java

EDIT:

As correctly mentioned by William Burnham, you have set to set the properties before calling them. Morever, I recommend you to clear the property soon after getting response using System.clearProperty(key) as the property is set for complete instance of jvm till it is restarted and hence can cause problems for other outgoing connections.

Shubham Kadlag
  • 2,248
  • 1
  • 13
  • 32
  • thank you for the information. I had already seen these links by the time I wrote my own answer but they are definitely useful. If using jax-ws (as in my case) an additional detail is the proxy settings must be configured before initializing the jax-ws client. I will update my answer accordingly. – geco17 May 29 '18 at 15:44