hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gary Gregory <garydgreg...@gmail.com>
Subject Re: Dealing with a deprecated ContentEncodingHttpClient
Date Mon, 01 Oct 2012 19:00:40 GMT
Thank you for the feedback, I'll have to see how to apply this to our code
base.

Gary

On Mon, Oct 1, 2012 at 11:53 AM, Oleg Kalnichevski <olegk@apache.org> wrote:

> On Mon, 2012-10-01 at 10:49 -0400, Gary Gregory wrote:
> > Hi All:
> >
> > I have 4.2.1 client code like this:
> >
> >    private DefaultHttpClient httpClient;
> >    ...
> >    this.httpClient = new *ContentEncodingHttpClient*(new
> > PoolingClientConnectionManager(this.schemeRegistry), params);
> >
> > According to the Javadoc I should use a DecompressingHttpClient instead,
> so
> > I code:
> >
> >    this.httpClient = new DecompressingHttpClient(new
> > DecompressingHttpClient (new
> > PoolingClientConnectionManager(this.schemeRegistry), params));
> >
> > Which means I have to retype DefaultHttpClient as a
> DecompressingHttpClient.
> >
> > I do not use the HttpClient interface because I need to call
> > org.apache.http.impl.client.AbstractHttpClient.getCredentialsProvider()
> >
> > But there is no way to get from a DecompressingHttpClient (which
> implements
> > HttpClient) to its DefaultHttpClient so I can call
> getCredentialsProvider().
> >
> > In order to do what I need would need to save both
> DecompressingHttpClient
> > and its DecompressingHttpClient in ivars which smells wrong to me.
> >
> > Option 1:
> >
> > Add "public HttpClient getBackend()" to DecompressingHttpClient, which I
> > can call and cast to a DefaultHttpClient.
> >
> > Option 2:
> >
>
> You can always override CredentialsProvider set at the client level by
> setting a different one in the local HttpContext instance
>
> ---
> CredentialsProvider credsProvider = new BasicCredentialsProvider();
> HttpContext localContext = new BasicHttpContext();
> localContext.setAttribute(ClientContext.CREDS_PROVIDER, credsProvider);
> HttpResponse response = httpclient.execute(httpget, localContext);
> ---
>
> Besides, this should work as well
>
> private CredentialsProvider credsProvider;
> private HttpClient httpClient;
>
> ---
> this.credsProvider = new BasicCredentialsProvider();
> DefaultHttpClient dc = new DefaultHttpClient();
> dc.setCredentialsProvier(this.credsProvider);
> this.httpClient = new DecompressingHttpClient(dc);
> ---
>
> Oleg
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
> For additional commands, e-mail: dev-help@hc.apache.org
>
>


-- 
E-Mail: garydgregory@gmail.com | ggregory@apache.org
JUnit in Action, 2nd Ed: <http://goog_1249600977>http://bit.ly/ECvg0
Spring Batch in Action: <http://s.apache.org/HOq>http://bit.ly/bqpbCK
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message