hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oleg Kalnichevski <ol...@apache.org>
Subject Re: HTTP Client 4.0: proxy settings?
Date Wed, 18 Feb 2009 19:38:57 GMT
Subhash Chandran wrote:
> This is how I do it::
> 
> String proxyHost = ...;
> int proxyPort = ...;
> String proxyUsername = ...;
> String proxyPassword = ...;
> 
> final HttpHost hcProxyHost = new HttpHost(proxyHost, proxyPort, "http");
> httpclient.getCredentialsProvider().setCredentials(
>                         new AuthScope(proxyHost, proxyPort),
>                         new UsernamePasswordCredentials(proxyUsername,
> new String(proxyPassword)));
> httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, hcProxyHost);
> 
> Subhash.
> 
 >
> On Wed, Feb 18, 2009 at 11:25 PM, Florent Georges <lists@fgeorges.org> wrote:
>>  Hi,
>>
>>  I am evaluating the impact of migrating from HTTP Client 3.1
>> to 4.0, and this is going well so far.  But I couldn't find a
>> way to set proxy settings.  In 3.1 I do (error management left
>> for clarity):
>>
>>    String host = System.getProperty("http.proxyHost");
>>    String port = System.getProperty("http.proxyPort");
>>    client.getHostConfiguration()
>>      . setProxy(host, Integer.parseInt(port));
>>
>>  As an aside question, shouldn't the client take the system
>> properties http.proxy* and https.proxy* into account?
>>

It depends. Libraries that make use of system properties may have issues 
when running in a managed environment such as an EJB container.

If you want HttpClient to use proxy system properties, try out the route 
planner implementation based on java.net.ProxySelector

---
DefaultHttpClient httpclient = new DefaultHttpClient();

ProxySelectorRoutePlanner routePlanner = new ProxySelectorRoutePlanner(
     httpclient.getConnectionManager().getSchemeRegistry(),
     ProxySelector.getDefault());

httpclient.setRoutePlanner(routePlanner);
---

Oleg


>>  Regards,
>>
>> --
>> Florent Georges
>> http://www.fgeorges.org/
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
>> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>>
>>
> 
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Mime
View raw message