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

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

Introduction

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

Prototype

boolean isLayeringRequired();

Source Link

Document

Determines whether or not protocol layering is required.

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();/*w  w w  .j  ava 2 s  .c om*/
    } 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");
    }// w ww.  j a va2 s. c  o m
    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);
    }
}