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: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to