On Tue, Oct 11, 2005 at 11:42:33AM +0200, Keesjan van Bunningen wrote:
> How can I explicitly pass the HttpState when executing a method?
>
> The only way I could find (and the one used in the authentication examples)
> is:
>
> client.getState().setCredentials(
> new AuthScope("www.verisign.com", 443, "realm"),
> new UsernamePasswordCredentials("username", "password")
> );
>
> But this will set the state on the client level, not the method level IMO.
>
> This still suggests that I require different HttpClient objects.
>
> Or am I still missing something?!
>
HttpClient#executeMethod(HostConfiguration, HttpMethod, HttpState) is
what you want
Oleg
>
> Keesjan
>
> ________________________________
>
> From: Roland Weber [mailto:[EMAIL PROTECTED]
> Sent: Tue 10/11/2005 11:07 AM
> To: HttpClient User Discussion
> Subject: Re: Use a single or multiple client instances?
>
>
>
> Hello Keesjan,
>
> you should keep a separate HttpState for each user of MyClass.
> Authentication credentials and cookies are set in the HttpState,
> and the HttpClient provides only a default HttpState. There is
> no need to have different HttpClient objects if you pass the
> HttpState explicitly when executing a method.
>
> A static attribute should do just fine for either 1 or 2.
>
> 3 will have to be answered by somebody else.
>
> cheers,
> Roland
>
>
>
>
> "Keesjan van Bunningen" <[EMAIL PROTECTED]>
> 11.10.2005 10:52
> Please respond to
> "HttpClient User Discussion"
>
>
> To
> <[email protected]>
> cc
>
> Subject
> Use a single or multiple client instances?
>
>
>
>
>
>
> For each request to a remote server I create a new instance of MyClass
> that uses/wraps HttpClient.
>
> 1. Can I use a single instance of the HttpClient (as a static field)
> inside MyClass or do I need to instantiate a new one for each new instance
> of MyClass?
> Because I use authentication and the credentials are set on the client, I
> presume I require a new instance for each request.
>
> 2. If I require a new instance of HttpClient for each instance of MyClass,
> how do I share the multi-threaded connection manager? Can I include the
> MultiThreadedHttpConnectionManager as a static field in MyClass and pass
> this as the parameter in the constructor of HttpClient?
>
> 3. If I want to apply new connection settings on-the-fly, is it
> possible/wise to update these settings in the existing connection manager?
> For instance, what happens if the MaxTotalConnections is currently set to
> 10 and the connection manager has 10 connections open, but I change the
> MaxTotalConnections value to 6?
>
> class MyClass {
> private static final HttpConnectionManager manager = new
> MultiThreadedHttpConnectionManager();
> private HttpClient client;
>
> public MyClass() {
> init();
> }
>
> private void init() {
> int maxConnections = (...) // loaded on-the-fly and may change over
> time
>
> this.client = new HttpClient(manager);
> // set/update settings
>
> this.client.getHttpConnectionManager().getParams().setMaxTotalConnections(maxConnections);
> }
>
> (...)
> }
>
>
> Kind regards,
>
> Keesjan van Bunningen
>
> Finalist IT Group - The Netherlands
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]