In Apache HTTP Client (4.x, the successor to commons http 3.x), on HttpClient the method:
HttpClient.execute(HttpUriRequest request)
States in the JavaDocs:
“Executes a request using the default context.”
- What is the default context (referring to an
HttpContextobject)? - How can I configure the default context so I don’t need to pass it on each call to
execute()? (I don’t control the call to execute(), but I control creating the HttpClient)
The default context is configured by the
HttpClientimplementation that you are using. For implementations based onAbstractHttpClient, the work is done by thecreateHttpContext()method. Note that a new default context is created for eachexecutecall.One way to configure the default context yourself would be to extend one of the existing
HttpClientimplementation classes and override the method.Another way is to set the various parameters that the method uses; e.g. the connection manager’s scheme registry, the authScheme registry, the cookieSpecs registry, the cookie store or the credentials provider.
For the record, here’s what the
DefaultHttpClient.createHttpContext()does: