org.apache.http.conn.ConnectionRequest Java Examples

The following examples show how to use org.apache.http.conn.ConnectionRequest. 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: HttpClientConnectionManagementLiveTest.java    From tutorials with MIT License 6 votes vote down vote up
@Test
// @Ignore
// 2.2 IN ARTICLE
public final void whenOpeningLowLevelConnectionWithSocketTimeout_thenNoExceptions() throws InterruptedException, ExecutionException, IOException, HttpException {
    basicConnManager = new BasicHttpClientConnectionManager();
    context = HttpClientContext.create();
    final ConnectionRequest connRequest = basicConnManager.requestConnection(route, null);
    conn = connRequest.get(1000, TimeUnit.SECONDS);
    if (!conn.isOpen()) {
        basicConnManager.connect(conn, route, 1000, context);
    }
    conn.setSocketTimeout(30000);

    assertTrue(conn.getSocketTimeout() == 30000);
    assertTrue(conn.isOpen());
}
 
Example #2
Source File: SimpleHttpClientConnectionManager.java    From lavaplayer with Apache License 2.0 6 votes vote down vote up
@Override
public ConnectionRequest requestConnection(HttpRoute route, Object state) {
  return new ConnectionRequest() {

    @Override
    public boolean cancel() {
      // Nothing to do.
      return false;
    }

    @Override
    public HttpClientConnection get(final long timeout, final TimeUnit timeUnit) {
      return connectionFactory.create(route, connectionConfig);
    }
  };
}
 
Example #3
Source File: ClientConnectionManagerFactory.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    try {
        Object ret = method.invoke(orig, args);
        return ret instanceof ConnectionRequest
                ? ClientConnectionRequestFactory.wrap((ConnectionRequest) ret)
                : ret
                ;
    } catch (InvocationTargetException e) {
        log.debug("", e);
        throw e.getCause();
    }
}
 
Example #4
Source File: HttpClientConnectionManagementLiveTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
// 2.1 IN ARTCLE
public final void whenLowLevelConnectionIsEstablished_thenNoExceptions() throws IOException, HttpException, InterruptedException, ExecutionException {
    basicConnManager = new BasicHttpClientConnectionManager();
    final ConnectionRequest connRequest = basicConnManager.requestConnection(route, null);
    assertTrue(connRequest.get(1000, TimeUnit.SECONDS) != null);
}
 
Example #5
Source File: ClientConnectionRequestFactory.java    From ibm-cos-sdk-java with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a wrapped instance of {@link ConnectionRequest}
 * to capture the necessary performance metrics.
 * @param orig the target instance to be wrapped
 */
static ConnectionRequest wrap(ConnectionRequest orig) {
    if (orig instanceof Wrapped)
        throw new IllegalArgumentException();
    return (ConnectionRequest) Proxy.newProxyInstance(
            // https://github.com/aws/aws-sdk-java/pull/48#issuecomment-29454423
            ClientConnectionRequestFactory.class.getClassLoader(),
            interfaces,
            new Handler(orig));
}
 
Example #6
Source File: ClientConnectionManagerFactory.java    From ibm-cos-sdk-java with Apache License 2.0 5 votes vote down vote up
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    try {
        Object ret = method.invoke(orig, args);
        return ret instanceof ConnectionRequest
                ? ClientConnectionRequestFactory.wrap((ConnectionRequest) ret)
                : ret
                ;
    } catch (InvocationTargetException e) {
        log.debug("", e);
        throw e.getCause();
    }
}
 
Example #7
Source File: AbstractHttpWriter.java    From incubator-gobblin with Apache License 2.0 5 votes vote down vote up
@Override
public ConnectionRequest requestConnection(HttpRoute route, Object state) {
  try {
    onConnect(new URI(route.getTargetHost().toURI()));
  } catch (IOException | URISyntaxException e) {
    throw new RuntimeException("onConnect() callback failure: " + e, e);
  }
  return super.requestConnection(route, state);
}
 
Example #8
Source File: ClientConnectionRequestFactory.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a wrapped instance of {@link ConnectionRequest}
 * to capture the necessary performance metrics.
 *
 * @param orig the target instance to be wrapped
 */
static ConnectionRequest wrap(ConnectionRequest orig) {
    if (orig instanceof Wrapped) {
        throw new IllegalArgumentException();
    }
    return (ConnectionRequest) Proxy.newProxyInstance(
            // https://github.com/aws/aws-sdk-java/pull/48#issuecomment-29454423
            ClientConnectionRequestFactory.class.getClassLoader(),
            INTERFACES,
            new Handler(orig));
}
 
Example #9
Source File: ClientConnectionRequestFactoryTest.java    From ibm-cos-sdk-java with Apache License 2.0 4 votes vote down vote up
@Test
public void wrapOnce() {
    ConnectionRequest wrapped = ClientConnectionRequestFactory
            .wrap(noop);
    assertTrue(wrapped instanceof Wrapped);
}
 
Example #10
Source File: DelegatingHttpClientConnectionManager.java    From incubator-gobblin with Apache License 2.0 4 votes vote down vote up
@Override
public ConnectionRequest requestConnection(HttpRoute route, Object state) {
  return this.fallbackConnManager.requestConnection(route, state);
}
 
Example #11
Source File: ConnectionReuseTest.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
public ConnectionRequest getClientConnectionRequest(HttpClient httpClient, HttpRoute route, PoolingHttpClientConnectionManager cm) {
  ConnectionRequest mConn = cm.requestConnection(route, HttpSolrClient.cacheKey);
  return mConn;
}
 
Example #12
Source File: ConnectionReuseTest.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
public HttpClientConnection getConn(ConnectionRequest mConn)
    throws InterruptedException, ConnectionPoolTimeoutException, ExecutionException {
  HttpClientConnection conn = mConn.get(30, TimeUnit.SECONDS);

  return conn;
}
 
Example #13
Source File: ClientConnectionRequestFactoryTest.java    From ibm-cos-sdk-java with Apache License 2.0 4 votes vote down vote up
@Test(expected = IllegalArgumentException.class)
public void wrapTwice() {
    ConnectionRequest wrapped = ClientConnectionRequestFactory.wrap(noop);
    ClientConnectionRequestFactory.wrap(wrapped);
}
 
Example #14
Source File: ClientConnectionManagerFactoryTest.java    From ibm-cos-sdk-java with Apache License 2.0 4 votes vote down vote up
@Override
public ConnectionRequest requestConnection(HttpRoute route,
                                           Object state) {
    return null;
}
 
Example #15
Source File: IdleConnectionReaperTest.java    From ibm-cos-sdk-java with Apache License 2.0 4 votes vote down vote up
@Override
public ConnectionRequest requestConnection(HttpRoute route, Object state) {
    return null;
}
 
Example #16
Source File: ClientConnectionRequestFactory.java    From ibm-cos-sdk-java with Apache License 2.0 4 votes vote down vote up
Handler(ConnectionRequest orig) {
    this.orig = orig;
}
 
Example #17
Source File: ClientConnectionManagerFactoryTest.java    From aws-sdk-java-v2 with Apache License 2.0 4 votes vote down vote up
@Override
public ConnectionRequest requestConnection(HttpRoute route,
                                           Object state) {
    return null;
}
 
Example #18
Source File: ClientConnectionRequestFactory.java    From aws-sdk-java-v2 with Apache License 2.0 4 votes vote down vote up
Handler(ConnectionRequest orig) {
    this.orig = orig;
}