WebService / java.net.SocketTimeoutException: Read timed out 网络服务/ java.net.SocketTimeoutException:读取超时

7
我在Web服务中遇到了问题,具体如下:
Caused by: org.apache.cxf.interceptor.Fault: Could not send Message.
at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:64)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:220)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:276)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:222)
at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:73)
at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:171)
... 26 more
Caused by: java.net.SocketTimeoutException: Read timed out
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:129)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
at java.io.BufferedInputStream.read1(BufferedInputStream.java:258)
at java.io.BufferedInputStream.read(BufferedInputStream.java:317)
at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:687)
at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:632)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1000)
at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:373)
at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponse(HTTPConduit.java:1900)
at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1828)
at org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:66)
at org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:590)
at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:62)
... 31 more

当我尝试向目标服务发送请求时,需要30-60秒的时间,然后会抛出上述异常。我正在使用Tomcat 5,并且想知道是否有增加超时值的方法? 同时,我想要访问的WSDL和WebService正在运行并可用。
非常感谢您的帮助,
敬礼, P.
3个回答

3
我有点晚来到这个派对,但我尝试了其他解决方案,它们都没有起作用,但是这个起作用了。
MyWebService service = new MyWebService();
MyWebServicePortType client = service.MyWebServicePort();

Client cl = ClientProxy.getClient(client);

HTTPConduit http = (HTTPConduit) cl.getConduit();

HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
httpClientPolicy.setConnectionTimeout(0);
httpClientPolicy.setReceiveTimeout(0);

http.setClient(httpClientPolicy);

client.doSomething(...);

这个答案应该被接受为解决方案,这里是唯一有效的答案。 - saidfagan

3

-1

在进行Web服务调用之前(即port.someAction(....)),您需要在请求上下文中将请求超时设置为更长的时间:

    // Set request context property.
    java.util.Map<String, Object> requestContext =
      ((javax.xml.ws.BindingProvider) port).getRequestContext();

    requestContext.put("com.sun.xml.ws.request.timeout", new Long(600000));

或者,如果您正在使用JAX-WS:

    // Set request context property.
    java.util.Map<String, Object> requestContext =
      ((javax.xml.ws.BindingProvider) port).getRequestContext();

    requestContext.put("com.sun.xml.internal.ws.request.timeout", new Long(600000));

这是一篇真正帮助我的文章:

如何为JAX-WS Web服务客户端设置超时时间?


我认为放置上下文变量并不是一个坏主意,但你无法确定每个JRE上都可用com.sun.xml.internal.*的包。 - froginvasion

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接