title: HttpClient timeout
body: <p>I have a client server app using spring HttpInvokers.  I am struggling with the timeouts.  I see other threads regarding this but no clear answers.</p>
  
  <p>As far as I know the readTimeout is supposed to control the length of a transaction after it has already connected.  I have made this very long because some processes such as report requests take time to run.  This has worked fine for a long period of time now.</p>
  
  <p>Now the problem is that sometimes the internet connection fails or blips out at the moment a request is made and the connection is never made.  Instead of erroring out I have instituted a retry procedure which intercepts a failed connection and retries it.  I want these failures to happen quickly so I set the HttpClient parameters <strong>soTimeout</strong> and <strong>connectionManagerTimeout</strong> to 2 seconds.  </p>
  
  <p>This seemed to work for the most part.  Occasionally it takes longer than 2 seconds to catch the problem but that is ok.  The issue is that the soTimeout seems to apply to or override the readTimout as well.  So now all my longer running requests get the retry function even though they have connected just fine and are simply waiting for the reply to complete.  The connectionManagerTimeout setting seems to do nothing at all.  Nothing seems to affect the time it takes to actually acquire the initial connection.</p>
  
  <p>Is there another timeout parameter I should be setting?  </p>
  
  <pre><code> &lt;bean id="myServiceInterceptor"
            class="org.springframework.remoting.httpinvoker.HttpInvokerClientInterceptor"&gt;
          &lt;property name="serviceUrl"&gt;
              &lt;value&gt;https://myhost/myservices/myMgrService&lt;/value&gt;
          &lt;/property&gt;
          &lt;property name="remoteInvocationFactory" ref="remoteInvocationFactory"/&gt;
          &lt;property name="httpInvokerRequestExecutor"&gt;
   &lt;bean class="org.springframework.remoting.httpinvoker.CommonsHttpInvokerRequestExecutor"&gt;
                  &lt;!--read time out is how long we will wait for a reply.  This is large in case we are waiting on a long server process--&gt;
                  &lt;property name="readTimeout" value="2000000"/&gt;
                  &lt;!--                we manually set this so we can control the parameter timeout values--&gt;
                  &lt;property name="httpClient"&gt;
                      &lt;bean class="org.apache.commons.httpclient.HttpClient"&gt;
                          &lt;constructor-arg index="0"&gt;
                              &lt;!--we want multi threaded if we want to ever connect in background threads, this is default if not set anyways in CommonsHttpInvokerRequestExecutor but since we are overriding we have to manually set it or we get the simple one--&gt;
                              &lt;bean class="org.apache.commons.httpclient.MultiThreadedHttpConnectionManager"&gt;&lt;/bean&gt;
                          &lt;/constructor-arg&gt;
                          &lt;property name="params"&gt;
                              &lt;bean class="org.apache.commons.httpclient.params.HttpClientParams"&gt;
                                  &lt;!--Here we set the socket time out and connection manager time out which is how long we wait for the socket to connect before showing bad feedback.
               The default is 60 seconds which makes the client just hang.  Now we get immediate response from our RetryConnection--&gt;
                                  &lt;property name="soTimeout" value="2000"/&gt;
                                  &lt;property name="connectionManagerTimeout" value="2000"/&gt;
                              &lt;/bean&gt;
                          &lt;/property&gt;
                      &lt;/bean&gt;
                  &lt;/property&gt;
              &lt;/bean&gt;        &lt;/property&gt;
      &lt;/bean&gt;
      &lt;bean id="myServiceMgr" class="org.springframework.aop.framework.ProxyFactoryBean"&gt;
          &lt;property name="interceptorNames"&gt;
              &lt;list&gt;
  
                  &lt;value&gt;clientExceptionAdvisor&lt;/value&gt;
                  &lt;value&gt;retryConnection&lt;/value&gt;
                  &lt;value&gt;myServiceInterceptor&lt;/value&gt;
              &lt;/list&gt;
          &lt;/property&gt;
          &lt;property name="proxyInterfaces"&gt;
              &lt;value&gt;ServiceIF&lt;/value&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  </code></pre>
  
  <p><em><strong></em>*</strong>*UPDATE SOLUTION
  Looks like soTimout is read timeout also.  There is a way to set connection timeout it is just a pain.  Here is the spring xml i used:</p>
  
  <pre><code>&lt;bean class="org.springframework.remoting.httpinvoker.CommonsHttpInvokerRequestExecutor"&gt;
                  &lt;!--read time out is how long we will wait for a reply.  This is large in case we are waiting on a long server process--&gt;
                  &lt;property name="readTimeout" value="2000000"/&gt;
                  &lt;!--                we manually set this so we can control the parameter timeout values--&gt;
                  &lt;property name="httpClient"&gt;
                      &lt;bean class="org.apache.commons.httpclient.HttpClient"&gt;
                          &lt;constructor-arg index="0"&gt;
                              &lt;bean class="org.apache.commons.httpclient.params.HttpClientParams"&gt;
                                  &lt;!--Here we set the connection manager time out which is supposed to be how long we wait for the established connection to be returned from the connection manager. This shortness allows us to catch it and enable the retry function.--&gt;
                                  &lt;property name="connectionManagerTimeout" value="2500"/&gt;
                              &lt;/bean&gt;
                          &lt;/constructor-arg&gt;
                          &lt;constructor-arg index="1"&gt;
                              &lt;!--we want multi threaded if we want to ever connect in background threads, this is default if not set anyways in CommonsHttpInvokerRequestExecutor but since we are overriding we have to manually set it or we get the simple one--&gt;
                              &lt;bean class="org.apache.commons.httpclient.MultiThreadedHttpConnectionManager"&gt;
                                  &lt;property name="params"&gt;
                                      &lt;bean class="org.apache.commons.httpclient.params.HttpConnectionManagerParams"&gt;
                                          &lt;!--Here we set the socket time out which is essentially the same thing as the readTimeout.  It is the time we wait for a response--&gt;
                                          &lt;property name="soTimeout" value="2000000"/&gt;
                                          &lt;!--Here we set the connection time out which is supposed to be how long we wait for the connect to be established. This shortness allows us to catch it and enable the retry function.  The default is 60 seconds which makes the client just hang.  --&gt;
                                          **&lt;property name="connectionTimeout" value="2500"/&gt;**
                                      &lt;/bean&gt;
                                  &lt;/property&gt;
                              &lt;/bean&gt;
                          &lt;/constructor-arg&gt;
                          &lt;property name="params"&gt;
                              &lt;bean class="org.apache.commons.httpclient.params.HttpClientParams"&gt;
                                  &lt;!--Here we set the socket time out which is essentially the same thing as the readTimeout.  It is the time we wait for a response--&gt;
                                  &lt;property name="soTimeout" value="2000000"/&gt;
                                  &lt;!--Here we set the connection manager time out which is how long we wait to get an established connection returned from the connection manager.
               The default is 60 seconds which makes the client just hang.  Now we get more immediate response from our RetryConnection.  But it isn't totally reliable cause of underlying tcp/ip--&gt;
                                  **&lt;property name="connectionManagerTimeout" value="2500"/&gt;**
                              &lt;/bean&gt;
                          &lt;/property&gt;
                      &lt;/bean&gt;
                  &lt;/property&gt;
              &lt;/bean&gt;
  </code></pre>