title: HttpClient: Connection reset after 5 minutes idle, keep-alive possible?
body: <p>I'm using a <code>HttpClient</code> to send a <code>SOAP</code> request to an webservice to query some data. For some webservice parameters the execution of the webservice takes longer than 5 minutes and after 5 minutes I get an <code>java.net.SocketException: Connection reset</code>.</p>
  
  <p>I think that the error occures because the connection idles for more than 5 minutes and then a firewall caps the connection.</p>
  
  <p><strong>Is there a way to send a keep-alive package for a http post request or something to keep the connection alive?</strong> (I need a client-side solution if possible)</p>
  
  <p>If you google for <code>HttpClient keep-alive</code> you find a lot of topics regarding reusing a connection. In my case I only want to keep the connection alive until I get a response.</p>
  
  <p>Method to execute the SOAP request:</p>
  
  <pre><code>def executeSOAPRequest(String url, String content, String soapAction, Integer timeout) {
      def retVal = new SoapResponse();
  
      PostMethod post = new PostMethod(url);
  
      RequestEntity entity = new StringRequestEntity(content,"ISO-8859-1","ISO-8859-1");
  
      post.setRequestEntity(entity);
      post.setRequestHeader("SOAPAction", soapAction);
  
      HttpClient httpclient = new HttpClient()
      httpclient.setTimeout(timeout)
  
      try {
          retVal.httpResponse = httpclient.executeMethod(post);
          retVal.httpResponseBody = post.getResponseBodyAsString();
      } catch(Exception e){
          ... exception handling ...
      } finally {
          ... finally stuff ...
      }
  
      return retVal;
  }
  </code></pre>
  
  <p>Currently the HttpClient v3.1 is used.</p>