hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mark A. Claassen" <MClaas...@ocie.net>
Subject Proxy Failover
Date Thu, 23 Apr 2015 16:45:27 GMT
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;
		}



Disclaimer:
The opinions provided herein do not necessarily state or reflect those of Donnell Systems,
Inc.(DSI). DSI makes no warranty for and assumes no legal liability or responsibility for
the posting.



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