Hi
On 19/05/12 13:50, Ganesan, Chandru wrote:
Hi

When I execute  a POST message (JSON) using WebClient the client fails with 
SocketTimeoutException (see exception below).
The same request works fine from Firefox REST client. I think there a problem 
with how I'm executing the POST from WebClient?

CXF client code times out after 60 secs or so by default, so it can be configured from Spring or code, example:
WebClient.getConfig(wc).getHttpConduit().getClient().setReceiveTimeout(6000000);

HTH, Sergey


Thanks for the help

Sample code:
==========

                ----------------------
         webClient.reset();
         webClient.path(serviceList.get(ASSET) + "/" + id);
         webClient.type(MediaType.APPLICATION_JSON);
         webClient.accept(MediaType.APPLICATION_JSON);

         Response response = null;
         try {
             ObjectMapper mapper = new ObjectMapper();
             String postMessage = mapper.writeValueAsString(properties);
             response = webClient.post(postMessage);
         } catch (Exception e) {
             throw new ValidationException(e);
         }

         if (response.getStatus() == Status.OK.getStatusCode()) {
             return true;
         }
         return retVal;
Here is the server exception:

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:243)
                 at 
org.apache.cxf.jaxrs.client.WebClient.doChainedInvocation(WebClient.java:595)
                 at 
org.apache.cxf.jaxrs.client.WebClient.doInvoke(WebClient.java:576)
                 at 
org.apache.cxf.jaxrs.client.WebClient.invoke(WebClient.java:240)
                 at 
org.apache.cxf.jaxrs.client.WebClient.post(WebClient.java:249)
Caused by: java.net.SocketTimeoutException: SocketTimeoutException invoking 
http://......................................................: Read timed out
                 at 
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
                 at 
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
                 at 
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
                 at 
java.lang.reflect.Constructor.newInstance(Constructor.java:513)
                 at 
org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.mapException(HTTPConduit.java:2058)
                 at 
org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:2043)
                 at 
org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:66)
                 at 
org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:639)
                 at 
org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:62)
                 ... 135 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:1195)
                 at 
java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:379)

Chandru



--
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/

Blog: http://sberyozkin.blogspot.com

Reply via email to