You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by Sinead Whelan <si...@aib.ie> on 2003/02/11 21:44:14 UTC

Pooling HttpClient

Hi

I wish to use HttpClient in a servlet based application. The HttpClient will be used to communicate with another internal server (always the same server). This communications will be in HTTP over SSL and I would like to be able to reuse connections to the server without having to do an expensive SSL handshake all the time. I would intend to have a long timeout on the HTTP connection (~15 minutes).

Currently in my servlet I have code similar to below,

class MyServlet extends HttpServlet {

   static HttpConnectionManager httpConnectionManager = new MultiThreadedHttpConnectionManager();
   static HttpClient httpClient = new HttpClient(httpConnectionManager);

    public void init() {
        httpConnectionManager.setMaxConnectionsPerHost(150);
    }


    public void doPost(Req req, Response resp) {
        PostMethod post = new PostMethod(url.getPath());
        post.setRequestContentLength(PostMethod.CONTENT_LENGTH_CHUNKED);
       post.addParameter("TestReq", "Hello");
    
        int result = httpClient.executeMethod(post);

        post.releaseConnection();
    }
    
}

This does not appear to work when a few users/threads are accessing the servlet at the same time. I get the following error message on the executeMethod():

Recoverable exception caught when reading response - couldn't find valid http header. (or something like that!)

Do you think that this is the correct way to use it if you want to pool connection to same server (should I use static HttpClient)?

Any help would be greatly appreciated.

Cheers

Sinead


**********************************************************************
This document is strictly confidential and is intended for use by
 the addressee unless otherwise indicated.

Allied Irish Banks
**********************************************************************


Re: Pooling HttpClient

Posted by Michael Becke <be...@u.washington.edu>.
I believe this is a bug that was recently fixed.  I would recommend 
using the most recent code from CVS until the next release (alpha 3 or 
beta 1) comes out.

Mike

Sinead Whelan wrote:
> Hi
> 
> I wish to use HttpClient in a servlet based application. The HttpClient will be used to communicate with another internal server (always the same server). This communications will be in HTTP over SSL and I would like to be able to reuse connections to the server without having to do an expensive SSL handshake all the time. I would intend to have a long timeout on the HTTP connection (~15 minutes).
> 
> Currently in my servlet I have code similar to below,
> 
> class MyServlet extends HttpServlet {
> 
>    static HttpConnectionManager httpConnectionManager = new MultiThreadedHttpConnectionManager();
>    static HttpClient httpClient = new HttpClient(httpConnectionManager);
> 
>     public void init() {
>         httpConnectionManager.setMaxConnectionsPerHost(150);
>     }
> 
> 
>     public void doPost(Req req, Response resp) {
>         PostMethod post = new PostMethod(url.getPath());
>         post.setRequestContentLength(PostMethod.CONTENT_LENGTH_CHUNKED);
>        post.addParameter("TestReq", "Hello");
>     
>         int result = httpClient.executeMethod(post);
> 
>         post.releaseConnection();
>     }
>     
> }
> 
> This does not appear to work when a few users/threads are accessing the servlet at the same time. I get the following error message on the executeMethod():
> 
> Recoverable exception caught when reading response - couldn't find valid http header. (or something like that!)
> 
> Do you think that this is the correct way to use it if you want to pool connection to same server (should I use static HttpClient)?
> 
> Any help would be greatly appreciated.
> 
> Cheers
> 
> Sinead
> 
> 
> **********************************************************************
> This document is strictly confidential and is intended for use by
>  the addressee unless otherwise indicated.
> 
> Allied Irish Banks
> **********************************************************************
> 
>