Example usage for org.apache.http.conn.scheme Scheme isLayered

List of usage examples for org.apache.http.conn.scheme Scheme isLayered

Introduction

In this page you can find the example usage for org.apache.http.conn.scheme Scheme isLayered.

Prototype

public final boolean isLayered() 

Source Link

Document

Indicates whether this scheme allows for layered connections.

Usage

From source file:org.eclipse.thym.core.internal.util.HttpUtil.java

/**
 * Set the proxy settings from ProxyService.
 * This method sets a {@link HttpRoutePlanner} to the client
 * //from   w  w w  .j  a v  a2s . c o m
 * @param client
 */
public static void setupProxy(final DefaultHttpClient client) {
    client.setRoutePlanner(new HttpRoutePlanner() {

        @Override
        public HttpRoute determineRoute(HttpHost target, HttpRequest request, HttpContext context)
                throws HttpException {

            //use forced route if one exists
            HttpRoute route = ConnRouteParams.getForcedRoute(request.getParams());
            if (route != null)
                return route;

            // if layered, is it secure?
            final Scheme scheme = client.getConnectionManager().getSchemeRegistry().getScheme(target);
            final boolean secure = scheme.isLayered();

            HttpHost host = null;
            try {
                IProxyData[] proxyDatas = getEclipseProxyData(new URI(target.toURI()));
                for (IProxyData data : proxyDatas) {
                    if (data.getType().equals(IProxyData.HTTP_PROXY_TYPE)) {
                        host = new HttpHost(data.getHost(), data.getPort());
                        break;
                    }
                }
            } catch (URISyntaxException e) {
                HybridCore.log(IStatus.ERROR, "Incorrect URI", e);
            }
            if (host == null) {
                return new HttpRoute(target, null, secure);
            }
            return new HttpRoute(target, null, host, secure);
        }
    });

}

From source file:org.jboss.tools.feedhenry.ui.model.HttpUtil.java

/**
 * Set the proxy settings from ProxyService.
 * This method sets a {@link HttpRoutePlanner} to the client
 * /*from  www  .  j  av  a2s .c om*/
 * @param client
 */
static void setupProxy(final DefaultHttpClient client) {
    client.setRoutePlanner(new HttpRoutePlanner() {

        /* (non-Javadoc)
         * @see org.apache.http.conn.routing.HttpRoutePlanner#determineRoute(org.apache.http.HttpHost, org.apache.http.HttpRequest, org.apache.http.protocol.HttpContext)
         */
        @Override
        public HttpRoute determineRoute(HttpHost target, HttpRequest request, HttpContext context)
                throws HttpException {

            //use forced route if one exists
            HttpRoute route = ConnRouteParams.getForcedRoute(request.getParams());
            if (route != null)
                return route;

            // if layered, is it secure?
            final Scheme scheme = client.getConnectionManager().getSchemeRegistry().getScheme(target);
            final boolean secure = scheme.isLayered();

            final IProxyService proxy = FHPlugin.getDefault().getProxyService();
            HttpHost host = null;
            if (proxy != null) {
                try {
                    IProxyData[] proxyDatas = proxy.select(new URI(target.toURI()));
                    for (IProxyData data : proxyDatas) {
                        if (data.getType().equals(IProxyData.HTTP_PROXY_TYPE)) {
                            host = new HttpHost(data.getHost(), data.getPort());
                            break;
                        }
                    }
                } catch (URISyntaxException e) {
                    FHPlugin.log(IStatus.ERROR, "Incorrect URI", e);
                }
            }
            if (host == null) {
                return new HttpRoute(target, null, secure);
            }
            return new HttpRoute(target, null, host, secure);
        }
    });

}

From source file:com.puppetlabs.geppetto.injectable.eclipse.impl.ProxiedRoutePlanner.java

@Override
public HttpRoute determineRoute(HttpHost target, HttpRequest request, HttpContext context)
        throws HttpException {
    if (request == null) {
        throw new IllegalStateException("Request must not be null.");
    }//from  ww  w.  j  ava 2s. c  o  m

    // If we have a forced route, we can do without a target.
    HttpRoute route = ConnRouteParams.getForcedRoute(request.getParams());
    if (route != null)
        return route;

    // If we get here, there is no forced route.
    // So we need a target to compute a route.

    if (target == null) {
        throw new IllegalStateException("Target host must not be null.");
    }

    final InetAddress local = ConnRouteParams.getLocalAddress(request.getParams());
    final HttpHost proxy = ConnRouteParams.getDefaultProxy(request.getParams());

    final Scheme schm;
    try {
        schm = schemeRegistry.getScheme(target.getSchemeName());
    } catch (IllegalStateException ex) {
        throw new HttpException(ex.getMessage());
    }
    // as it is typically used for TLS/SSL, we assume that
    // a layered scheme implies a secure connection
    final boolean secure = schm.isLayered();

    if (proxy != null)
        return new HttpRoute(target, local, proxy, secure);

    IProxyData[] select = Activator.getInstance().getProxyService().select(URI.create(target.toURI()));
    for (IProxyData proxyData : select)
        if (proxyData.getType().equals(IProxyData.HTTP_PROXY_TYPE)) {
            HttpHost proxyHost = new HttpHost(proxyData.getHost(), proxyData.getPort());
            return new HttpRoute(target, null, proxyHost, secure);
        }

    return new HttpRoute(target, local, secure);
}