users@jersey.java.net

Re: [Jersey] jersey-apache-client connection pool configuration

From: Alex Sherwin <alex.sherwin_at_acadiasoft.com>
Date: Mon, 07 Jun 2010 12:48:58 -0400

How are you configuring your client? I'm using the ApacheHttpClient
wrapper from the Jersey libs, and setting up the
MultiTHreadedHttpConnectionManager directly, like so:

       connectionManager = new MultiThreadedHttpConnectionManager();
       
connectionManager.getParams().setDefaultMaxConnectionsPerHost(MAX_CONNECTIONS_PER_HOST);
       
connectionManager.getParams().setMaxTotalConnections(MAX_TOTAL_CONNECTIONS);

       clientConfig = new DefaultApacheHttpClientConfig();
       
clientConfig.getProperties().put(DefaultApacheHttpClientConfig.PROPERTY_PREEMPTIVE_AUTHENTICATION,
Boolean.TRUE);

       httpClient = new ApacheHttpClient(new ApacheHttpClientHandler(new
HttpClient(connectionManager)), clientConfig);

It sounds like this is what you want to do, I believe

Then, to use,

ClientResponse response =
httpClient.resource("/some/uri").accept(..).get(ClientResponse.class);
if (response.getStatus() <= 201) {
   String entity = response.getEntity(String.class);
}

Etc


On 6/7/2010 12:08 PM, Mike Boyers wrote:
> I'm beginning work on a RESTful api that, in order to fulfill requests, will need to reach out to other apis (some RESTful themselves, some HTTP but not RESTful).
>
> My main requirements for any HTTP requests (both RESTful and non-RESTful) made to other services are:
> -Support keep-alives
> -Support connection pooling
> -Support maximum configurable sizes for connection pools
> -Support fail-fast "connection pool timeouts" when a particular pool has reached its maximum configured size
> -If a pool grows under load, it needs to shrink again as load decreases
> -Both RESTful and non-RESTful request should share the same connection pools
> -Ability to query for pool sizes and other statistics to expose via JMX
>
> When using Apache's HttpClient in the raw, I know I can accomplish all of these goals. But that won't get me the jersey-client features I'd like to have, so I'd like to consider using the jersey-apache-client for all HTTP requests and just get the non-RESTful responses as Strings.
>
> However, I'm not sure how I can configure the underlying MultiThreadedHttpConnectionManager to behave the way I want. Some of the methods I'm used to calling are:
>
> setDefaultMaxConnectionsPerHost()
> setConnectionTimeout() -- I know this is already supported and know how to configure it
> closeIdleConnections()
> deleteConnections()
>
> And also HttpClientParameter's setConnectionManagerTimeout() method.
>
> Any ideas?
>
> Thanks,
> Mike Boyers
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>
>
>
>