Apache HTTP Proxy Chain

A little confuse what is really possible here.

Can Java Proxy Apache HTTP Client (4.x) Proxy? Any tips on how?

I found documentation offering it , but the source is a bit complicated, and I found at least one class ( DefaultRequestDirector) that throws an exception;

    throw new HttpException("Proxy chains are not supported.")

Directly configure the client using a single proxy using

    httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);

but for me it’s not obvious how to set up a proxy chain. If I follow the hints in the documentation above, I do the following.

    httpClient.setRoutePlanner(new HttpRoutePlanner() {
        @Override
        public HttpRoute determineRoute(HttpHost target, HttpRequest request, HttpContext context) throws HttpException {
            return new HttpRoute(target, null, new HttpHost[]{proxy, new HttpHost("localhost", 8081)}, "https".equalsIgnoreCase(target.getSchemeName()), TunnelType.TUNNELLED, LayerType.PLAIN);
        }
    });

but this raises the exception mentioned above;

org.apache.http.client.ClientProtocolException
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:822)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:754)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:732)
    at Main.main(Main.java:70)
Caused by: org.apache.http.HttpException: Proxy chains are not supported.
    at org.apache.http.impl.client.DefaultRequestDirector.createTunnelToProxy(DefaultRequestDirector.java:957)
    at org.apache.http.impl.client.DefaultRequestDirector.establishRoute(DefaultRequestDirector.java:764)
    at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:579)
    at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:425)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:820)
    ... 8 more
+5
source share
1 answer

The documentation you refer to above says:

QUOTE 2,7. - HttpClient , HttpClient -, - . UNQUOTE

, , -.

-1

All Articles