You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by Gary Gregory <ga...@gmail.com> on 2012/10/01 16:49:46 UTC

Dealing with a deprecated ContentEncodingHttpClient

 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:

?

Gary


-- 
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

Re: Dealing with a deprecated ContentEncodingHttpClient

Posted by Gary Gregory <ga...@gmail.com>.
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 <ol...@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

Re: Dealing with a deprecated ContentEncodingHttpClient

Posted by Oleg Kalnichevski <ol...@apache.org>.
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