Example usage for org.apache.http.conn.params ConnRouteParams getLocalAddress

List of usage examples for org.apache.http.conn.params ConnRouteParams getLocalAddress

Introduction

In this page you can find the example usage for org.apache.http.conn.params ConnRouteParams getLocalAddress.

Prototype

public static InetAddress getLocalAddress(final HttpParams params) 

Source Link

Document

Obtains the ConnRoutePNames#LOCAL_ADDRESS LOCAL_ADDRESS parameter value.

Usage

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.");
    }/* www.jav a2s  .co  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);
}