Example usage for org.apache.http.conn ManagedHttpClientConnection getSocket

List of usage examples for org.apache.http.conn ManagedHttpClientConnection getSocket

Introduction

In this page you can find the example usage for org.apache.http.conn ManagedHttpClientConnection getSocket.

Prototype

Socket getSocket();

Source Link

Document

Returns the underlying socket.

Usage

From source file:org.artifactory.util.HttpUtils.java

public static String resolveResponseRemoteAddress(CloseableHttpResponse response) {
    try {/*from w  w  w .j  a  v  a  2  s.  co  m*/
        Field connHolderField = response.getClass().getDeclaredField("connHolder");
        connHolderField.setAccessible(true);
        Object connHolder = connHolderField.get(response);

        Field managedConnField = connHolder.getClass().getDeclaredField("managedConn");
        managedConnField.setAccessible(true);
        ManagedHttpClientConnection managedConn = (ManagedHttpClientConnection) managedConnField
                .get(connHolder);
        String hostAddress = managedConn.getSocket().getInetAddress().getHostAddress();
        return hostAddress == null ? StringUtils.EMPTY : hostAddress;
    } catch (Throwable throwable) {
        return StringUtils.EMPTY;
    }
}

From source file:com.ksc.http.protocol.SdkHttpRequestExecutor.java

@Override
protected HttpResponse doSendRequest(final HttpRequest request, final HttpClientConnection conn,
        final HttpContext context) throws IOException, HttpException {
    KscRequestMetrics awsRequestMetrics = (KscRequestMetrics) context
            .getAttribute(KscRequestMetrics.class.getSimpleName());

    if (awsRequestMetrics == null) {
        return super.doSendRequest(request, conn, context);
    }/*from   ww w . j  ava2s  .  c  om*/
    if (conn instanceof ManagedHttpClientConnection) {
        ManagedHttpClientConnection managedConn = (ManagedHttpClientConnection) conn;
        Socket sock = managedConn.getSocket();
        if (sock instanceof SdkMetricsSocket) {
            SdkMetricsSocket sdkMetricsSocket = (SdkMetricsSocket) sock;
            sdkMetricsSocket.setMetrics(awsRequestMetrics);
        } else if (sock instanceof SdkSSLMetricsSocket) {
            SdkSSLMetricsSocket sdkSSLMetricsSocket = (SdkSSLMetricsSocket) sock;
            sdkSSLMetricsSocket.setMetrics(awsRequestMetrics);
        }
    }
    awsRequestMetrics.startEvent(Field.HttpClientSendRequestTime);
    try {
        return super.doSendRequest(request, conn, context);
    } finally {
        awsRequestMetrics.endEvent(Field.HttpClientSendRequestTime);
    }
}

From source file:org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.java

@Override
public void upgrade(final ManagedHttpClientConnection conn, final HttpHost host, final HttpContext context)
        throws IOException {
    final HttpClientContext clientContext = HttpClientContext.adapt(context);
    final Lookup<ConnectionSocketFactory> registry = getSocketFactoryRegistry(clientContext);
    final ConnectionSocketFactory sf = registry.lookup(host.getSchemeName());
    if (sf == null) {
        throw new UnsupportedSchemeException(host.getSchemeName() + " protocol is not supported");
    }/*from  w  ww. j a va2  s.co m*/
    if (!(sf instanceof LayeredConnectionSocketFactory)) {
        throw new UnsupportedSchemeException(
                host.getSchemeName() + " protocol does not support connection upgrade");
    }
    final LayeredConnectionSocketFactory lsf = (LayeredConnectionSocketFactory) sf;
    Socket sock = conn.getSocket();
    final int port = this.schemePortResolver.resolve(host);
    sock = lsf.createLayeredSocket(sock, host.getHostName(), port, context);
    conn.bind(sock);
}

From source file:org.apache.http.impl.conn.HttpClientConnectionOperator.java

public void upgrade(final ManagedHttpClientConnection conn, final HttpHost host, final HttpContext context)
        throws IOException {
    final HttpClientContext clientContext = HttpClientContext.adapt(context);
    final Lookup<ConnectionSocketFactory> registry = getSocketFactoryRegistry(clientContext);
    final ConnectionSocketFactory sf = registry.lookup(host.getSchemeName());
    if (sf == null) {
        throw new UnsupportedSchemeException(host.getSchemeName() + " protocol is not supported");
    }//from   www .jav a 2s .co m
    if (!(sf instanceof LayeredConnectionSocketFactory)) {
        throw new UnsupportedSchemeException(
                host.getSchemeName() + " protocol does not support connection upgrade");
    }
    final LayeredConnectionSocketFactory lsf = (LayeredConnectionSocketFactory) sf;
    Socket sock = conn.getSocket();
    final int port = this.schemePortResolver.resolve(host);
    sock = lsf.createLayeredSocket(sock, host.getHostName(), port, context);
    conn.bind(sock);
}