WebService / java.net.SocketTimeoutException:读取超时

时间:2011-03-11 09:12:43

标签: java web-services tomcat cxf

我在WebService中面临一个问题,详情如下:

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 个答案:

答案 0 :(得分:3)

您需要为此请求设置“ReceiveTimeout”。

此页面详细说明了如何将此属性添加到请求上下文中:

http://cxf.apache.org/docs/developing-a-consumer.html

答案 1 :(得分:2)

我参加这个派对有点晚了,但是我尝试了其他解决方案,但他们没有工作,但是this做了。

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(...);

答案 2 :(得分:-1)

在您进行Web服务调用之前(即port.someAction(....)),您需要在requestContext中将请求超时设置为更大的数量:

    // 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));

这是一篇真正帮助我的帖子:

How do I set the timeout for a JAX-WS webservice client?