WebService / java.net.SocketTimeoutException: Read timed out

…衆ロ難τιáo~ 提交于 2020-01-01 05:16:11

问题


I am facing an issue in WebService, in details :

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

When I try to send a request to the target service, it takes 30-60 seconds and than the exception above is thrown. I am using Tomcat 5,and I would like to ask is there any way of increasing the timeout value ? Also the WSDL and WebService which I want to access is running and available.

I greatly appreciate any help in this,

Kind regards, P.


回答1:


You need to set "ReceiveTimeout" for this request.

This page has details on adding this property to request context:

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




回答2:


I'm a bit late to this party, but I tried the other solutions, and they didn't work, but this did.

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



回答3:


Right before you make your Web Service call (i.e. port.someAction(....)), you need to set the Request Timeout to a larger amount in the 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));

Or, if you are using 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));

Here is a post that really helped me:

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



来源:https://stackoverflow.com/questions/5270981/webservice-java-net-sockettimeoutexception-read-timed-out

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!