Apache Commons HTTPClient 3.x Keeping Connections Open

I am using HttpClient to execute a PostMethod for a remote servlet and for some reason a lot of my connections open and call all my connections to the server.
Here's more information about architecture
GWT client calls GWT service GWT
service instantiates HttpClient, creates PostMethod and client executes method
it then receives input stream by calling .getResponseBodyAsStream () method and writes it to byte array
it then closes input stream and flushes output stream array of bytes, executes a few more lines of code, and then calls the .releaseConnection () method

There must be something obvious, I forget what is causing it. If I do a GET in the browser for the same service, the connections are closed immediately, but something about the HTTPClient causes them to hang.

+1


source to share


1 answer


You need to call HttpMethodBase # releaseConnection (). If you return an InputStream that will be used later, an easy way is to wrap it with an anonymous filterInputStream overwriting close ():



final HttpMethodBase method = ...;
return new FilterInputStream(method.getResponseBodyAsStream())
{
  public void close() throws IOException
  {
    try {
      super.close();
    } finally {
      method.releaseConnection();
    }
  }
};

      

+2


source







All Articles