Example usage for org.apache.http.conn.routing HttpRoute HttpRoute

List of usage examples for org.apache.http.conn.routing HttpRoute HttpRoute

Introduction

In this page you can find the example usage for org.apache.http.conn.routing HttpRoute HttpRoute.

Prototype

public HttpRoute(final HttpHost target, final InetAddress local, final HttpHost proxy, final boolean secure,
        final TunnelType tunnelled, final LayerType layered) 

Source Link

Document

Creates a new route with at most one proxy.

Usage

From source file:com.jkoolcloud.jesl.net.http.HttpClient.java

/**
 * {@inheritDoc}/*from w  w w.j a  va 2s  .  c  o  m*/
 */
@Override
public synchronized void connect() throws IOException {
    try {
        if (secure) {
            SSLSocketFactory ssf = null;
            if (!StringUtils.isEmpty(sslKeystore)) {
                SSLContextFactory scf = new SSLContextFactory(sslKeystore, sslKeystorePwd, sslKeystorePwd);
                ssf = new SSLSocketFactory(scf.getSslContext(true));
            } else {
                ssf = new SSLSocketFactory(SSLContext.getDefault());
            }
            Scheme secureScheme = new Scheme("https", port, ssf);
            schemeReg = new SchemeRegistry();
            schemeReg.register(secureScheme);
        }
        route = new HttpRoute(httpHost, null, httpProxy, secure, RouteInfo.TunnelType.PLAIN,
                RouteInfo.LayerType.PLAIN);
        if (schemeReg != null) {
            connMgr = new BasicClientConnectionManager(schemeReg);
        } else {
            connMgr = new BasicClientConnectionManager();
        }
        connReq = connMgr.requestConnection(route, null);
        connection = connReq.getConnection(0, null);
        connection.open(route, new BasicHttpContext(), new BasicHttpParams());
        logger.log(OpLevel.DEBUG, "Connected to {0}{1}", uri,
                (httpProxy != null ? " via proxy " + httpProxy : ""));
    } catch (Throwable e) {
        close();
        throw new IOException("Failed to connect to uri=" + uri + ", reason=" + e.getMessage(), e);
    }
}

From source file:com.allstate.client.core.SoapClient.java

private void configureProxy() {
    if (proxyUri == null) {
        return;/*from www .  j a va 2 s.  co m*/
    }
    if (proxyTlsEnabled) {
        final HttpHost proxy = new HttpHost(proxyUri.getHost(), proxyUri.getPort(), HTTPS);
        // https://issues.apache.org/jira/browse/HTTPCLIENT-1318
        // http://stackoverflow.com/questions/15048102/httprouteplanner-how-does-it-work-with-an-https-proxy
        // To make the HttpClient talk to a HTTP End-site through an HTTPS Proxy, the route should be secure,
        //  but there should not be any Tunnelling or Layering.
        if (!endpointTlsEnabled) {
            client.setRoutePlanner(new HttpRoutePlanner() {
                @Override
                public HttpRoute determineRoute(HttpHost target, HttpRequest request, HttpContext context) {
                    return new HttpRoute(target, null, proxy, true, RouteInfo.TunnelType.PLAIN,
                            RouteInfo.LayerType.PLAIN);
                }
            });
        }
        client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
    } else {
        HttpHost proxy = new HttpHost(proxyUri.getHost(), proxyUri.getPort());
        client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
    }
}