The default context is configured using the HttpClient implementation that you use. For implementations based on AbstractHttpClient , work is done using the createHttpContext() method. Note that for each execute call, a new default context is created.
One way to set the default context is to extend one of the existing HttpClient implementation HttpClient and override the method.
Another way is to set various parameters that the method uses; for example, the connection manager schema registry, authScheme registry, cookieSpecs registry, cookie storage, or credential provider.
For the record here, what DefaultHttpClient.createHttpContext() does:
@Override protected HttpContext createHttpContext() { HttpContext context = new BasicHttpContext(); context.setAttribute( ClientContext.SCHEME_REGISTRY, getConnectionManager().getSchemeRegistry()); context.setAttribute( ClientContext.AUTHSCHEME_REGISTRY, getAuthSchemes()); context.setAttribute( ClientContext.COOKIESPEC_REGISTRY, getCookieSpecs()); context.setAttribute( ClientContext.COOKIE_STORE, getCookieStore()); context.setAttribute( ClientContext.CREDS_PROVIDER, getCredentialsProvider()); return context; }
source share