Soap Connection timed out in Java client but not i

2019-07-09 05:34发布

问题:

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?

回答1:

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.



回答2:

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.