无法使用Java代码访问Web服务,但可以从Chrome中正常查看其wsdl

时间:2014-08-01 13:17:15

标签: java web-services soap netbeans wsdl

大家!

我遇到了一个非常奇怪的问题。我在Netbeans中编写了一个Web服务示例。在Netbeans IDE中,Web服务客户端和Web服务运行流畅,如果有点慢。但是在部署到Tomcat 7.0之后,客户端无法正常评估Web服务。

wsdl的网址为http://221.207.220.12:7001/InterWebService/InterService.wsdl?wsdl,可以通过Chrome看到。

以下是例外信息:

Exception in thread "main" com.sun.xml.internal.ws.client.ClientTransportException:      HTTP transport error: java.net.ConnectException: Connection timed out: connect
       at com.sun.xml.internal.ws.transport.http.client.HttpClientTransport.getOutput(HttpClientTransport.java:117)
       at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.process(HttpTransportPipe.java:208)
       at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.processRequest(HttpTransportPipe.java:130)
       at com.sun.xml.internal.ws.transport.DeferredTransportPipe.processRequest(DeferredTransportPipe.java:95)
       at com.sun.xml.internal.ws.api.pipe.Fiber.__doRun(Fiber.java:1121)
       at com.sun.xml.internal.ws.api.pipe.Fiber._doRun(Fiber.java:1035)
       at com.sun.xml.internal.ws.api.pipe.Fiber.doRun(Fiber.java:1004)
       at com.sun.xml.internal.ws.api.pipe.Fiber.runSync(Fiber.java:862)
       at com.sun.xml.internal.ws.client.Stub.process(Stub.java:448)
       at com.sun.xml.internal.ws.client.sei.SEIStub.doProcess(SEIStub.java:178)
       at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:93)
       at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:77)
       at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(SEIStub.java:147)
       at com.sun.proxy.$Proxy32.news(Unknown Source)
       at Main.news(Main.java:19)
       at Main.main(Main.java:13)
Caused by: java.net.ConnectException: Connection timed out: connect
       at java.net.DualStackPlainSocketImpl.connect0(Native Method)
       at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)
       at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:345)
       at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
       at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
       at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
       at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
       at java.net.Socket.connect(Socket.java:589)
       at java.net.Socket.connect(Socket.java:538)
       at sun.net.NetworkClient.doConnect(NetworkClient.java:180)
       at sun.net.www.http.HttpClient.openServer(HttpClient.java:432)
       at sun.net.www.http.HttpClient.openServer(HttpClient.java:527)
       at sun.net.www.http.HttpClient.<init>(HttpClient.java:211)
       at sun.net.www.http.HttpClient.New(HttpClient.java:308)
       at sun.net.www.http.HttpClient.New(HttpClient.java:326)
       at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:1167)
       at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1146)
       at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:997)
       at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:931)
       at sun.net.www.protocol.http.HttpURLConnection.getOutputStream0(HttpURLConnection.java:1281)
       at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1256)
       at com.sun.xml.internal.ws.transport.http.client.HttpClientTransport.getOutput(HttpClientTransport.java:104)
       ... 15 more
Java Result: 1
BUILD SUCCESSFUL (total time: 23 seconds)*

寻找别人的帮助!并提前感谢。

2 个答案:

答案 0 :(得分:2)

我也遇到了类似的问题并找到了根本原因,如下所示:

在调查问题的根本原因时,发现WSDL文件中“wsdl:port”元素的“soap:address”是指与调用Web服务的url不匹配的url。基于SOAP规范,这是不正确的。

在我们的环境中,“soap:address”在wsdl文件中引用'reverse proxy'url(即“xxx.com:9040/service.asmx”),这不是我们尝试访问Ace服务的实际url (即“xxx.com/service.asmx”)

答案 1 :(得分:1)

听起来您需要将代理配置到Java客户端代码中。你可以用类似的东西来做到这一点

String proxyHost = "192.168.2.2";
String proxyPort = "3128";
System.out.println("Setting up with proxy: " + proxyHost + ":" + proxyPort);
System.setProperty("http.proxyHost", proxyHost);
System.setProperty("http.proxyPort", proxyPort);
System.setProperty("http.nonProxyHosts", "localhost|127.0.0.1");

假设您的代理服务器位于“192.168.2.2:3128”。您需要在启动时执行此操作,我相信在您访问任何HTTP连接之前。