On Thu, 2015-04-23 at 16:45 +0000, Mark A. Claassen wrote:
> I found some information on proxy failover and HttpClient, but not much.  I 
> was wondering, though, if my approach is OK.  I realize there are 
> inefficiencies, but before I go there, I want to know if I am even on the 
> right track.
> 
> I extended DefautRoutePlanner and implemented the determineProxy method.
> In that method I get the list of potential proxies and then test them.  I 
> return the first one in the list that works. (Also, when I find one that 
> works, I remember it so I don't need to test it again.)
> 
> In my constructor for my route planner, I create a separate HttpClient 
> instance that just uses the DefaultRoutePlanner, which returns NULL for 
> determineProxy().
> 
> Has anyone done anything like this?
> 
> Thanks,
> Mark
> 
> 
> 
>       private boolean testProxy(URI targetURI, Proxy proxy) {
>                       boolean rval;
>                       if (proxy.type() != Proxy.Type.DIRECT) {
>                               InetSocketAddress address = (InetSocketAddress) 
> proxy.address();
>                               HttpHost host = new 
> HttpHost(address.getHostName(), address.getPort(), 
> ApacheNetworkImpl.SCHEME_HTTP);
> 
>                               try {
>                                       URI uri = new URI(host.toURI());
>                                       RequestBuilder rb = 
> RequestBuilder.get(uri);
>                                       HttpUriRequest request = rb.build();
>                                       try {
>                                               HttpResponse resp = 
> testClient.execute(request);
>                                               rval = true;
>                                       }
>                                       catch (IOException ex) {
>                                               rval = false;
>                                               connectFailed(targetURI, 
> address, ex);
>                                       }
>                                       finally {
>                                               request.abort();
>                                       }
>                               }
>                               catch (URISyntaxException ex) {
>                                       rval = false;
>                               }
>                       }
>                       else
>                               rval = true;
>                       return rval;
>               }
> 

Mark,

There is a JIRA for similar feature request

https://issues.apache.org/jira/browse/HTTPCLIENT-1176

It should be possible to come with a more efficient solution by using a
custom HttpRequestRetryHandler in additional to a custom RoutePlanner.

Hope this helps

Oleg



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

Reply via email to