hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Imre Fazekas <Faze...@connexis.com>
Subject HttpClient instance management
Date Wed, 24 Jun 2009 13:45:51 GMT
Dear All,


i'm just wondering when the DefaultHttpClient class should be  
instantiated.
I have a class providing basic HTTP services like sending JSON  
message, sending a get and parsing the response, etc. So this class  
has static methods.
I defined these members with these initializations:
private static HttpParams                  defaultParameters;
private static  SchemeRegistry              supportedSchemes;
private static  ClientConnectionManager     clcm;
static{
         setup();
         clcm = createManager();
     }

     private static final void setup() {
         supportedSchemes = new SchemeRegistry();
         SocketFactory sf = PlainSocketFactory.getSocketFactory();
         supportedSchemes.register(new Scheme("http", sf, 80));

         HttpParams params = new BasicHttpParams( );
         HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
         HttpProtocolParams.setUseExpectContinue(params, false);

         defaultParameters = params;

         context = new BasicHttpContext( );
     }

     private static final ClientConnectionManager createManager() {
         return new ThreadSafeClientConnManager( defaultParameters,  
supportedSchemes );
     }


May i define the HttpClient as a static field or i should define  
always a new instance when a service method is called? Like this:
public static Response get(String uri) {
         DefaultHttpClient httpClient = getHttpClient();
         HttpGet get = new HttpGet( serverURI + uri );
	...
}



Thank you in advance!

Regards,

Imre





---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Mime
View raw message