Example usage for org.apache.http.impl.nio.conn CPoolProxy newProxy

List of usage examples for org.apache.http.impl.nio.conn CPoolProxy newProxy

Introduction

In this page you can find the example usage for org.apache.http.impl.nio.conn CPoolProxy newProxy.

Prototype

public static NHttpClientConnection newProxy(final CPoolEntry poolEntry) 

Source Link

Usage

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

@Test
public void testConnectionInitialize() throws Exception {
    final HttpHost target = new HttpHost("somehost", -1, "http");
    final HttpRoute route = new HttpRoute(target);
    final HttpContext context = new BasicHttpContext();

    final Log log = Mockito.mock(Log.class);
    final CPoolEntry poolentry = new CPoolEntry(log, "some-id", route, conn, -1, TimeUnit.MILLISECONDS);
    final NHttpClientConnection managedConn = CPoolProxy.newProxy(poolentry);

    Mockito.when(conn.getIOSession()).thenReturn(iosession);
    Mockito.when(sslStrategy.upgrade(target, iosession)).thenReturn(iosession);

    connman.startRoute(managedConn, route, context);

    Mockito.verify(noopStrategy, Mockito.never()).upgrade(target, iosession);
    Mockito.verify(conn, Mockito.never()).bind(iosession);

    Assert.assertFalse(connman.isRouteComplete(managedConn));
}

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

@Test
public void testConnectionInitializeHttps() throws Exception {
    final HttpHost target = new HttpHost("somehost", 443, "https");
    final HttpRoute route = new HttpRoute(target, null, true);
    final HttpContext context = new BasicHttpContext();

    final Log log = Mockito.mock(Log.class);
    final CPoolEntry poolentry = new CPoolEntry(log, "some-id", route, conn, -1, TimeUnit.MILLISECONDS);
    poolentry.markRouteComplete();/*  www .j av a 2s  . c  om*/
    final NHttpClientConnection managedConn = CPoolProxy.newProxy(poolentry);

    Mockito.when(conn.getIOSession()).thenReturn(iosession);
    Mockito.when(sslStrategy.upgrade(target, iosession)).thenReturn(iosession);

    connman.startRoute(managedConn, route, context);

    Mockito.verify(sslStrategy).upgrade(target, iosession);
    Mockito.verify(conn).bind(iosession);
}

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

@Test
public void testConnectionInitializeContextSpecific() throws Exception {
    final HttpHost target = new HttpHost("somehost", 80, "http11");
    final HttpRoute route = new HttpRoute(target);
    final HttpContext context = new BasicHttpContext();

    final Registry<SchemeIOSessionStrategy> reg = RegistryBuilder.<SchemeIOSessionStrategy>create()
            .register("http11", noopStrategy).build();
    context.setAttribute(PoolingNHttpClientConnectionManager.IOSESSION_FACTORY_REGISTRY, reg);

    final Log log = Mockito.mock(Log.class);
    final CPoolEntry poolentry = new CPoolEntry(log, "some-id", route, conn, -1, TimeUnit.MILLISECONDS);
    final NHttpClientConnection managedConn = CPoolProxy.newProxy(poolentry);

    Mockito.when(conn.getIOSession()).thenReturn(iosession);
    Mockito.when(sslStrategy.upgrade(target, iosession)).thenReturn(iosession);

    connman.startRoute(managedConn, route, context);

    Mockito.verify(noopStrategy, Mockito.never()).upgrade(target, iosession);
    Mockito.verify(conn, Mockito.never()).bind(iosession);

    Assert.assertFalse(connman.isRouteComplete(managedConn));
}

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

@Test(expected = UnsupportedSchemeException.class)
public void testConnectionInitializeUnknownScheme() throws Exception {
    final HttpHost target = new HttpHost("somehost", -1, "whatever");
    final HttpRoute route = new HttpRoute(target, null, true);
    final HttpContext context = new BasicHttpContext();

    final Log log = Mockito.mock(Log.class);
    final CPoolEntry poolentry = new CPoolEntry(log, "some-id", route, conn, -1, TimeUnit.MILLISECONDS);
    poolentry.markRouteComplete();/*  w  w w  . j av a2s  . c om*/
    final NHttpClientConnection managedConn = CPoolProxy.newProxy(poolentry);

    Mockito.when(conn.getIOSession()).thenReturn(iosession);
    Mockito.when(sslStrategy.upgrade(target, iosession)).thenReturn(iosession);

    connman.startRoute(managedConn, route, context);
}

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

@Test
public void testConnectionUpgrade() throws Exception {
    final HttpHost target = new HttpHost("somehost", 443, "https");
    final HttpRoute route = new HttpRoute(target);
    final HttpContext context = new BasicHttpContext();

    final Log log = Mockito.mock(Log.class);
    final CPoolEntry poolentry = new CPoolEntry(log, "some-id", route, conn, -1, TimeUnit.MILLISECONDS);
    poolentry.markRouteComplete();//from   w  w  w.  jav a  2  s . com
    final NHttpClientConnection managedConn = CPoolProxy.newProxy(poolentry);

    Mockito.when(conn.getIOSession()).thenReturn(iosession);
    Mockito.when(sslStrategy.upgrade(target, iosession)).thenReturn(iosession);

    connman.upgrade(managedConn, route, context);

    Mockito.verify(sslStrategy).upgrade(target, iosession);
    Mockito.verify(conn).bind(iosession);
}

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

@Test(expected = UnsupportedSchemeException.class)
public void testConnectionUpgradeUnknownScheme() throws Exception {
    final HttpHost target = new HttpHost("somehost", -1, "whatever");
    final HttpRoute route = new HttpRoute(target);
    final HttpContext context = new BasicHttpContext();

    final Log log = Mockito.mock(Log.class);
    final CPoolEntry poolentry = new CPoolEntry(log, "some-id", route, conn, -1, TimeUnit.MILLISECONDS);
    poolentry.markRouteComplete();/*from w  w w . j  a  v  a 2 s.c o m*/
    final NHttpClientConnection managedConn = CPoolProxy.newProxy(poolentry);

    Mockito.when(conn.getIOSession()).thenReturn(iosession);
    Mockito.when(sslStrategy.upgrade(target, iosession)).thenReturn(iosession);

    connman.upgrade(managedConn, route, context);
}

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

@Test(expected = UnsupportedSchemeException.class)
public void testConnectionUpgradeIllegalScheme() throws Exception {
    final HttpHost target = new HttpHost("somehost", 80, "http");
    final HttpRoute route = new HttpRoute(target);
    final HttpContext context = new BasicHttpContext();

    final Log log = Mockito.mock(Log.class);
    final CPoolEntry poolentry = new CPoolEntry(log, "some-id", route, conn, -1, TimeUnit.MILLISECONDS);
    poolentry.markRouteComplete();//ww  w . ja  va  2s.c  o  m
    final NHttpClientConnection managedConn = CPoolProxy.newProxy(poolentry);

    Mockito.when(conn.getIOSession()).thenReturn(iosession);
    Mockito.when(sslStrategy.upgrade(target, iosession)).thenReturn(iosession);

    connman.upgrade(managedConn, route, context);
}

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

@Test
public void testConnectionRouteComplete() throws Exception {
    final HttpHost target = new HttpHost("somehost", 80, "http");
    final HttpRoute route = new HttpRoute(target);
    final HttpContext context = new BasicHttpContext();

    final Log log = Mockito.mock(Log.class);
    final CPoolEntry poolentry = new CPoolEntry(log, "some-id", route, conn, -1, TimeUnit.MILLISECONDS);
    poolentry.markRouteComplete();//from  www. j a  v a 2  s  . co m
    final NHttpClientConnection managedConn = CPoolProxy.newProxy(poolentry);

    Mockito.when(conn.getIOSession()).thenReturn(iosession);
    Mockito.when(sslStrategy.upgrade(target, iosession)).thenReturn(iosession);

    connman.startRoute(managedConn, route, context);
    connman.routeComplete(managedConn, route, context);

    Assert.assertTrue(connman.isRouteComplete(managedConn));
}