在Web服务中获取连接超时异常

时间:2014-01-07 08:47:41

标签: java web-services exception wsdl

当我尝试通过webservice提交请求时,我收到以下异常。

堆栈跟踪如下:

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:194)
    at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.processRequest(HttpTransportPipe.java:122)
    at com.sun.xml.internal.ws.transport.DeferredTransportPipe.processRequest(DeferredTransportPipe.java:95)
    at com.sun.xml.internal.ws.api.pipe.Fiber.__doRun(Fiber.java:626)
    at com.sun.xml.internal.ws.api.pipe.Fiber._doRun(Fiber.java:585)
    at com.sun.xml.internal.ws.api.pipe.Fiber.doRun(Fiber.java:570)
    at com.sun.xml.internal.ws.api.pipe.Fiber.runSync(Fiber.java:467)
    at com.sun.xml.internal.ws.client.Stub.process(Stub.java:308)
    at com.sun.xml.internal.ws.client.sei.SEIStub.doProcess(SEIStub.java:146)
    at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:98)
    at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:78)
    at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(SEIStub.java:129)
    at $Proxy40.externalSearchPerson(Unknown Source)
    at com.igniteibroker.Main.personSearch(Main.java:52)
    at com.igniteibroker.Main.main(Main.java:64)
Caused by: java.net.ConnectException: Connection timed out: connect
    at java.net.DualStackPlainSocketImpl.connect0(Native Method)
    at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:69)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:157)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391)
    at java.net.Socket.connect(Socket.java:579)
    at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:618)
    at sun.security.ssl.BaseSSLSocketImpl.connect(BaseSSLSocketImpl.java:160)
    at sun.net.NetworkClient.doConnect(NetworkClient.java:180)
    at sun.net.www.http.HttpClient.openServer(HttpClient.java:378)
    at sun.net.www.http.HttpClient.openServer(HttpClient.java:473)
    at sun.net.www.protocol.https.HttpsClient.<init>(HttpsClient.java:270)
    at sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:327)
    at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:191)
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:974)
    at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:177)
    at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1090)
    at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:250)
    at com.sun.xml.internal.ws.transport.http.client.HttpClientTransport.getOutput(HttpClientTransport.java:105)
    ... 15 more

如果您发现问题,请帮我解决此问题。提前致谢

2 个答案:

答案 0 :(得分:0)

如果您使用的是jersey.api

import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.api.client.config.ClientConfig;
import com.sun.jersey.api.client.config.DefaultClientConfig;
import com.sun.jersey.api.representation.Form;


ClientResponse response = null;
ClientConfig config = new DefaultClientConfig();
Client client = Client.create(config);
/*client.setReadTimeout(30);*/
/*client.setConnectTimeout(interval)*/
WebResource service = client.resource(getBaseURI());

在Client类中有方法client.setConnectTimeout(interval)如果你没有设置这个方法,那么它会尝试连接无限时间。

答案 1 :(得分:0)

我尝试在WSDL中加载SoapUI文件。

令人惊讶的是它给了我“java.lang.Exception: Failed to load url;

我认为您正在使用https wsdl url加载此webservice

它将受密码保护。在您的计算机上本地保存您的wsdl文件,并尝试在soap ui中加载wsdl文件而不是网址。

在h ttps endpoint发送请求时,您需要提供用户名和密码。
soapui中,您可以在左下角的请求属性中填写用户名和密码。