Announcement Announcement Module
Collapse
No announcement yet.
HttpClient timeout Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • HttpClient timeout

    I cannot for the life of me get HttpClient not to timeout, which makes debugging a real pain. Below is my configuration and the exception I see. Any help would be much appreciated.

    Code:
        private WebServiceTemplate createHtpClientWebServiceTemplate() {
            WebServiceTemplate template = new WebServiceTemplate();
            template.setDefaultUri(protocol + "://" + host + ":" + port + "/" + context);
            template.setMarshaller(marshaller());
            template.setUnmarshaller(marshaller());
            CommonsHttpMessageSender messageSender = new CommonsHttpMessageSender();
            DefaultHttpMethodRetryHandler retryHandler = new DefaultHttpMethodRetryHandler(0, false);
            messageSender.getHttpClient().getParams().setParameter(HttpMethodParams.RETRY_HANDLER, retryHandler);
            messageSender.getHttpClient().getParams().setParameter(HttpMethodParams.HEAD_BODY_CHECK_TIMEOUT, -1);
            messageSender.getHttpClient().getParams().setSoTimeout(0);
            messageSender.getHttpClient().getHostConfiguration().getParams().setParameter(HttpMethodParams.RETRY_HANDLER, retryHandler);
            messageSender.getHttpClient().getHostConfiguration().getParams().setParameter(HttpMethodParams.HEAD_BODY_CHECK_TIMEOUT, -1);
            messageSender.getHttpClient().getHttpConnectionManager().getParams().setParameter(HttpMethodParams.RETRY_HANDLER, retryHandler);
            messageSender.getHttpClient().getHttpConnectionManager().getParams().setParameter(HttpMethodParams.HEAD_BODY_CHECK_TIMEOUT, -1);
            messageSender.getHttpClient().getHttpConnectionManager().getParams().setSoTimeout(0);
    
            template.setMessageSender(messageSender);
            return template;
        }
    Code:
    org.springframework.ws.client.WebServiceIOException: I/O error: The server localhost failed to respond; nested exception is org.apache.commons.httpclient.NoHttpResponseException: The server localhost failed to respond
    Caused by: org.apache.commons.httpclient.NoHttpResponseException: The server localhost failed to respond
    	at org.apache.commons.httpclient.HttpMethodBase.readStatusLine(HttpMethodBase.java:1835)
    	at org.apache.commons.httpclient.HttpMethodBase.readResponse(HttpMethodBase.java:1590)
    	at org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java:995)
    	at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:397)
    	at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:170)
    	at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:396)
    	at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:324)
    	at org.springframework.ws.transport.http.CommonsHttpConnection.onSendAfterWrite(CommonsHttpConnection.java:83)
    	at org.springframework.ws.transport.AbstractWebServiceConnection.send(AbstractWebServiceConnection.java:41)
    	at org.springframework.ws.client.core.WebServiceTemplate.sendRequest(WebServiceTemplate.java:400)
    	at org.springframework.ws.client.core.WebServiceTemplate.sendAndReceive(WebServiceTemplate.java:358)
    	at org.springframework.ws.client.core.WebServiceTemplate.marshalSendAndReceive(WebServiceTemplate.java:215)
    	at org.springframework.ws.client.core.WebServiceTemplate.marshalSendAndReceive(WebServiceTemplate.java:203)
    	at com.foliofn.ws.AbstractWebServiceServerTest.marshalSecureSendAndReceive(AbstractWebServiceServerTest.java:200)
    	at com.foliofn.ws.endpoint.HoldingEndpointCrudServerTest.createAndQueryHoldingForSingleMember(HoldingEndpointCrudServerTest.java:43)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    	at java.lang.reflect.Method.invoke(Method.java:597)
    	at org.junit.internal.runners.TestMethodRunner.executeMethodBody(TestMethodRunner.java:99)
    	at org.junit.internal.runners.TestMethodRunner.runUnprotected(TestMethodRunner.java:81)
    	at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
    	at org.junit.internal.runners.TestMethodRunner.runMethod(TestMethodRunner.java:75)
    	at org.junit.internal.runners.TestMethodRunner.run(TestMethodRunner.java:45)
    	at org.junit.internal.runners.TestClassMethodsRunner.invokeTestMethod(TestClassMethodsRunner.java:75)
    	at org.junit.internal.runners.TestClassMethodsRunner.run(TestClassMethodsRunner.java:36)
    	at org.junit.internal.runners.TestClassRunner$1.runUnprotected(TestClassRunner.java:42)
    	at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
    	at org.junit.internal.runners.TestClassRunner.run(TestClassRunner.java:52)
    	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
    	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)

  • #2
    I am not sure whether the HttpClient params returned by Commons HTTP Client are mutable. What you can try is to create a new HttpClient, set up the parameters, and inject that into the CommonsHttpMessageSender constructor.

    Comment


    • #3
      Good idea. I changed to the below, but still get a timeout in about 30 seconds...

      Code:
              DefaultHttpMethodRetryHandler retryHandler = new DefaultHttpMethodRetryHandler(0, false);
              HttpClientParams clientParams = new HttpClientParams();
              clientParams.setParameter(HttpMethodParams.RETRY_HANDLER, retryHandler);
              clientParams.setParameter(HttpMethodParams.HEAD_BODY_CHECK_TIMEOUT, 600000);
              clientParams.setSoTimeout(600000);
              clientParams.setConnectionManagerTimeout(600000);
              HttpClient client = new HttpClient(clientParams);
              CommonsHttpMessageSender messageSender = new CommonsHttpMessageSender(client);

      Comment


      • #5
        Yes, weird, but as a famous philosopher once said ~"There are no contradictions in reality. If you think you see a contradiction, look to your assumptions. One of them is wrong."

        My assumption was that httpclient was timing out, where in reality it was the eclipse tcp monitor/interceptor plugin that was timing out and returning a bogus status. Once I took that out of the loop for the tests, timeouts in httpclient works as specified. FYI all eclipse tcp monitor plugin users...

        -barry

        Comment


        • #6
          How do i take out the tcp monitor/interceptor plugin from eclipse

          Comment

          Working...
          X