Example usage for org.apache.http.nio.conn SchemeIOSessionStrategy upgrade

List of usage examples for org.apache.http.nio.conn SchemeIOSessionStrategy upgrade

Introduction

In this page you can find the example usage for org.apache.http.nio.conn SchemeIOSessionStrategy upgrade.

Prototype

IOSession upgrade(HttpHost host, IOSession iosession) throws IOException;

Source Link

Document

Decorates the original IOSession with a transport level security protocol implementation.

Usage

From source file:org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager.java

@Override
public void startRoute(final NHttpClientConnection managedConn, final HttpRoute route,
        final HttpContext context) throws IOException {
    Args.notNull(managedConn, "Managed connection");
    Args.notNull(route, "HTTP route");
    final HttpHost host;
    if (route.getProxyHost() != null) {
        host = route.getProxyHost();/*from   w  ww.  jav a2 s  .c  o m*/
    } else {
        host = route.getTargetHost();
    }
    final Lookup<SchemeIOSessionStrategy> reg = getIOSessionFactoryRegistry(context);
    final SchemeIOSessionStrategy sf = reg.lookup(host.getSchemeName());
    if (sf == null) {
        throw new UnsupportedSchemeException(host.getSchemeName() + " protocol is not supported");
    }
    if (sf.isLayeringRequired()) {
        synchronized (managedConn) {
            final CPoolEntry entry = CPoolProxy.getPoolEntry(managedConn);
            final ManagedNHttpClientConnection conn = entry.getConnection();
            final IOSession ioSession = conn.getIOSession();
            final IOSession currentSession = sf.upgrade(host, ioSession);
            conn.bind(currentSession);
        }
    }
}

From source file:org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager.java

@Override
public void upgrade(final NHttpClientConnection managedConn, final HttpRoute route, final HttpContext context)
        throws IOException {
    Args.notNull(managedConn, "Managed connection");
    Args.notNull(route, "HTTP route");
    final HttpHost host = route.getTargetHost();
    final Lookup<SchemeIOSessionStrategy> reg = getIOSessionFactoryRegistry(context);
    final SchemeIOSessionStrategy sf = reg.lookup(host.getSchemeName());
    if (sf == null) {
        throw new UnsupportedSchemeException(host.getSchemeName() + " protocol is not supported");
    }//from  w  ww  .jav  a 2 s. com
    if (!sf.isLayeringRequired()) {
        throw new UnsupportedSchemeException(
                host.getSchemeName() + " protocol does not support connection upgrade");
    }
    synchronized (managedConn) {
        final CPoolEntry entry = CPoolProxy.getPoolEntry(managedConn);
        final ManagedNHttpClientConnection conn = entry.getConnection();
        final IOSession currentSession = sf.upgrade(host, conn.getIOSession());
        conn.bind(currentSession);
    }
}