On Mon, 2013-04-08 at 21:25 +0200, Simone Tripodi wrote:
> Hi again Oleg,
> 
> please apologise for the silly question, but... could you provide me please
> a sample of how to use the RoutePlanner in the way I described?
> 
> Sorry, but I haven't figured out how to... many thanks in advance!
> 
> best,
> -Simo
> 
> 

Something like that should probably suffice.

Hope this helps

Oleg

---
public HttpRoute determineRoute(
        final HttpHost host,
        final HttpRequest request,
        final HttpContext context) throws HttpException {
    final HttpClientContext clientContext =
HttpClientContext.adapt(context);
    RequestConfig config = clientContext.getRequestConfig();
    InetAddress local = config.getLocalAddress();
    HttpHost proxy = config.getProxy();
    
    // bypass proxy for localhost
    if (host.getHostName().equalsIgnoreCase("localhost") 
     || host.getHostName().equals("127.0.0.1")) {
        proxy = null;
    }
    HttpHost target;
    if (host.getPort() <= 0) {
        target = new HttpHost(
                host.getHostName(),
                this.schemePortResolver.resolve(host),
                host.getSchemeName());
    } else {
        target = host;
    }
    boolean secure = target.getSchemeName().equalsIgnoreCase("https");
    if (proxy == null) {
        return new HttpRoute(target, local, secure);
    } else {
        return new HttpRoute(target, local, proxy, secure);
    }
}




> http://people.apache.org/~simonetripodi/
> http://simonetripodi.livejournal.com/
> http://twitter.com/simonetripodi
> http://www.99soft.org/
> 
> 
> On Mon, Apr 8, 2013 at 8:34 PM, Simone Tripodi 
> <[email protected]>wrote:
> 
> > Thanks Oleg, it does indeed!
> >
> > All the best,
> > -Simo
> >
> > http://people.apache.org/~simonetripodi/
> > http://simonetripodi.livejournal.com/
> > http://twitter.com/simonetripodi
> > http://www.99soft.org/
> >
> >
> > On Mon, Apr 8, 2013 at 7:06 PM, Oleg Kalnichevski <[email protected]>wrote:
> >
> >> On Mon, 2013-04-08 at 17:30 +0200, Simone Tripodi wrote:
> >> > Hi all mates,
> >> >
> >> > is there any way to setup exception for proxy, in HttpClient instances?
> >> >
> >> > I mean, domains such as "localhost" or "127.0.0.1" should be skipped by
> >> > proxy resolution, as well as more domains which could be configured by
> >> > users - is there any API to achieve it?
> >> >
> >> > Many thanks in advance, all the best!
> >> > -Simo
> >> >
> >>
> >> This is what HttpRoutePlanner is for. One can selectively construct
> >> different routes based on request properties, target host or contextual
> >> attributes.
> >>
> >> Hope this helps
> >>
> >> Oleg
> >>
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: [email protected]
> >> For additional commands, e-mail: [email protected]
> >>
> >>
> >



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to