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

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

Introduction

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

Prototype

public final HttpHost getTargetHost() 

Source Link

Usage

From source file:com.navercorp.pinpoint.plugin.httpclient4.EndPointUtils.java

public static String getHostAndPort(HttpRoute route) {
    final HttpHost proxyHost = route.getProxyHost();
    if (proxyHost != null) {
        final String hostName = proxyHost.getHostName();
        final int port = HostAndPort.getPortOrNoPort(proxyHost.getPort());
        return HostAndPort.toHostAndPortString(hostName, port);
    } else {//from   ww  w. java 2  s. com
        final HttpHost targetHost = route.getTargetHost();
        if (targetHost != null) {
            final String hostName = targetHost.getHostName();
            final int port = HostAndPort.getPortOrNoPort(targetHost.getPort());
            return HostAndPort.toHostAndPortString(hostName, port);
        }
    }
    return "";
}

From source file:org.callimachusproject.client.ProxyClientExecDecorator.java

public ClientExecChain decorateMainExec(final ClientExecChain mainExec) {
    return new ClientExecChain() {
        public CloseableHttpResponse execute(HttpRoute route, HttpRequestWrapper request,
                HttpClientContext context, HttpExecutionAware execAware) throws IOException, HttpException {
            HttpHost host = route.getTargetHost();
            if (host != null) {
                ClientExecChain proxy = proxies.get(host);
                if (proxy != null) {
                    ClientExecChain execChain = new AuthenticationClientExecChain(proxy);
                    return execChain.execute(route, request, context, execAware);
                }//from  w ww. java2  s  . c om
            }
            return mainExec.execute(route, request, context, execAware);
        }
    };
}

From source file:org.apache.synapse.transport.nhttp.ConnectionPool.java

/**
 * Returns SSL Connections List for the given list host:port combinations
 *
 * @param hostList String List in Host:Port format
 * @return List of NHttpClientConnection
 *///from   www .  ja  va  2 s . c om
public List<NHttpClientConnection> getSslConnectionsList(Set<String> hostList) {
    List<NHttpClientConnection> selectedConnections = new ArrayList<NHttpClientConnection>();

    for (String host : hostList) {
        try {
            String[] params = host.split(":");

            for (HttpRoute httpRoute : connMap.keySet()) {
                if (params.length > 1 && params[0].equalsIgnoreCase(httpRoute.getTargetHost().getHostName())
                        && (Integer.valueOf(params[1]) == (httpRoute.getTargetHost().getPort()))
                        && httpRoute.getTargetHost().getSchemeName().equalsIgnoreCase(SSL_SCHEMA_NAME)) {

                    List<NHttpClientConnection> clientConnections = connMap.get(httpRoute);

                    if (clientConnections != null) {
                        int count = 0;
                        for (NHttpClientConnection nHttpClientConnection : clientConnections) {
                            selectedConnections.add(clientConnections.get(count));
                            count++;
                        }
                    }
                }
            }
        } catch (NumberFormatException e) {
            if (log.isWarnEnabled()) {
                log.warn("Error in port number in host:port - " + host + " discard connection loading ", e);
            }
        }
    }

    return selectedConnections;
}

From source file:org.callimachusproject.client.UnavailableRequestDirector.java

@Override
public CloseableHttpResponse execute(HttpRoute route, HttpRequestWrapper request,
        HttpClientContext clientContext, HttpExecutionAware execAware) throws IOException, HttpException {
    BasicHttpResponse _503 = new BasicHttpResponse(HttpVersion.HTTP_1_1, 503, "Service Disconnected");
    HttpHost target = route.getTargetHost();
    try {/* w  ww.j  a  va  2  s. c om*/
        URI root = new URI(target.getSchemeName(), null, target.getHostName(), target.getPort(), "/", null,
                null);
        return new HttpUriResponse(root.resolve(request.getURI()).toASCIIString(), _503);
    } catch (URISyntaxException e) {
        return new HttpUriResponse(request.getURI().toASCIIString(), _503);
    }
}

From source file:org.apache.synapse.transport.passthru.connections.TargetConnections.java

/**
 * Shutdown the connections of the given host:port list. This will allow to create new connection
 * at the next request happens.//  w  w  w.ja  va 2 s.  co  m
 *
 * @param hostList Set of String which contains entries in hots:port format
 */
public void resetConnectionPool(Set<String> hostList) {

    for (String host : hostList) {
        String[] params = host.split(":");

        for (Map.Entry<HttpRoute, HostConnections> connectionsEntry : poolMap.entrySet()) {
            HttpRoute httpRoute = connectionsEntry.getKey();

            if (params.length > 1 && params[0].equalsIgnoreCase(httpRoute.getTargetHost().getHostName())
                    && (Integer.valueOf(params[1]) == (httpRoute.getTargetHost().getPort()))
                    && httpRoute.getTargetHost().getSchemeName().equalsIgnoreCase(sslSchemaName)) {

                try {
                    NHttpClientConnection connection = connectionsEntry.getValue().getConnection();
                    if (connection != null && connection.getContext() != null) {

                        shutdownConnection(connectionsEntry.getValue().getConnection());
                        log.info("Connection " + httpRoute.getTargetHost().getHostName() + ":"
                                + httpRoute.getTargetHost().getPort() + " Successful");

                    } else {
                        log.debug("Error shutdown connection for " + httpRoute.getTargetHost().getHostName()
                                + " " + httpRoute.getTargetHost().getPort() + " - Connection not available");
                    }
                } catch (Exception e) {
                    log.warn("Error shutdown connection for " + httpRoute.getTargetHost().getHostName() + " "
                            + httpRoute.getTargetHost().getPort() + " ", e);
                }

            }

        }
    }
}

From source file:com.navercorp.pinpoint.plugin.httpclient4.interceptor.HttpClientConnectionManagerConnectMethodInterceptor.java

@Override
protected void doInBeforeTrace(SpanEventRecorder recorder, Object target, Object[] args) {
    if (args != null && args.length >= 2 && args[1] != null && args[1] instanceof HttpRoute) {
        final HttpRoute route = (HttpRoute) args[1];
        final StringBuilder sb = new StringBuilder();
        if (route.getProxyHost() != null) {
            sb.append(route.getProxyHost().getHostName());
            if (route.getProxyHost().getPort() > 0) {
                sb.append(":").append(route.getProxyHost().getPort());
            }/*from w  w w. ja v  a  2 s.  c o m*/
        } else {
            if (route.getTargetHost() != null) {
                sb.append(route.getTargetHost().getHostName());
                if (route.getTargetHost().getPort() > 0) {
                    sb.append(":").append(route.getTargetHost().getPort());
                }
            }
        }
        recorder.recordAttribute(AnnotationKey.HTTP_INTERNAL_DISPLAY, sb.toString());
    }
    recorder.recordApi(methodDescriptor);
    recorder.recordServiceType(HttpClient4Constants.HTTP_CLIENT_4_INTERNAL);
}

From source file:com.navercorp.pinpoint.plugin.httpclient4.interceptor.ManagedClientConnectionOpenMethodInterceptor.java

@Override
protected void doInBeforeTrace(SpanEventRecorder recorder, Object target, Object[] args) {
    if (args != null && args.length >= 1 && args[0] != null && args[0] instanceof HttpRoute) {
        final HttpRoute route = (HttpRoute) args[0];
        final StringBuilder sb = new StringBuilder();
        if (route.getProxyHost() != null) {
            sb.append(route.getProxyHost().getHostName());
            if (route.getProxyHost().getPort() > 0) {
                sb.append(":").append(route.getProxyHost().getPort());
            }/* w w w  .  j av a 2  s.  c  om*/
        } else {
            if (route.getTargetHost() != null) {
                sb.append(route.getTargetHost().getHostName());
                if (route.getTargetHost().getPort() > 0) {
                    sb.append(":").append(route.getTargetHost().getPort());
                }
            }
        }
        recorder.recordAttribute(AnnotationKey.HTTP_INTERNAL_DISPLAY, sb.toString());
    }
    recorder.recordApi(methodDescriptor);
    recorder.recordServiceType(HttpClient4Constants.HTTP_CLIENT_4_INTERNAL);
}

From source file:org.opendatakit.http.conn.GaeManagedClientConnection.java

GaeManagedClientConnection(HttpRoute route, Object state) {
    this.route = route;
    if (route != null) {
        this.targetHost = route.getTargetHost();
    } else {/*from   w  w  w . j  a v a  2s .c om*/
        this.targetHost = null;
    }
    this.state = state;
}

From source file:com.serphacker.serposcope.scraper.http.extensions.CloseableBasicHttpClientConnectionManager.java

@Override
public void upgrade(final HttpClientConnection conn, final HttpRoute route, final HttpContext context)
        throws IOException {
    Args.notNull(conn, "Connection");
    Args.notNull(route, "HTTP route");
    Asserts.check(conn == this.conn, "Connection not obtained from this manager");
    this.connectionOperator.upgrade(this.conn, route.getTargetHost(), context);
}