Java Code Examples for org.apache.http.conn.ManagedHttpClientConnection#getSocket()

The following examples show how to use org.apache.http.conn.ManagedHttpClientConnection#getSocket() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExtendedConnectionOperator.java    From lavaplayer with Apache License 2.0 6 votes vote down vote up
@Override
public void upgrade(ManagedHttpClientConnection connection, HttpHost host, HttpContext context) throws IOException {
  ConnectionSocketFactory socketFactory = getSocketFactory(host, HttpClientContext.adapt(context));

  if (!(socketFactory instanceof LayeredConnectionSocketFactory)) {
    throw new UnsupportedSchemeException(host.getSchemeName() +
        " protocol does not support connection upgrade");
  }

  LayeredConnectionSocketFactory layeredFactory = (LayeredConnectionSocketFactory) socketFactory;

  Socket socket = connection.getSocket();
  int port = this.schemePortResolver.resolve(host);
  socket = layeredFactory.createLayeredSocket(socket, host.getHostName(), port, context);

  connection.bind(socket);
}
 
Example 2
Source File: SdkHttpRequestExecutor.java    From ibm-cos-sdk-java with Apache License 2.0 5 votes vote down vote up
@Override
protected HttpResponse doSendRequest(
        final HttpRequest request,
        final HttpClientConnection conn,
        final HttpContext context)
            throws IOException, HttpException {
    AWSRequestMetrics awsRequestMetrics = (AWSRequestMetrics) context
            .getAttribute(AWSRequestMetrics.class.getSimpleName());

    if (awsRequestMetrics == null) {
        return super.doSendRequest(request, conn, context);
    }
    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);
    }
}