• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java HttpClientConnection类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.apache.http.HttpClientConnection的典型用法代码示例。如果您正苦于以下问题:Java HttpClientConnection类的具体用法?Java HttpClientConnection怎么用?Java HttpClientConnection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



HttpClientConnection类属于org.apache.http包,在下文中一共展示了HttpClientConnection类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: doSendRequest

import org.apache.http.HttpClientConnection; //导入依赖的package包/类
@Override
protected HttpResponse doSendRequest(final HttpRequest request, final HttpClientConnection conn, final HttpContext context) throws IOException, HttpException {
    synchronized(listener) {
        listener.log(TranscriptListener.Type.request, request.getRequestLine().toString());
        for(Header header : request.getAllHeaders()) {
            switch(header.getName()) {
                case HttpHeaders.AUTHORIZATION:
                case "X-Auth-Key":
                case "X-Auth-Token":
                    listener.log(TranscriptListener.Type.request, String.format("%s: %s", header.getName(),
                            StringUtils.repeat("*", Integer.min(8, StringUtils.length(header.getValue())))));
                    break;
                default:
                    listener.log(TranscriptListener.Type.request, header.toString());
                    break;
            }
        }
    }
    return super.doSendRequest(request, conn, context);
}
 
开发者ID:iterate-ch,项目名称:cyberduck,代码行数:21,代码来源:LoggingHttpRequestExecutor.java


示例2: connect

import org.apache.http.HttpClientConnection; //导入依赖的package包/类
@Override
public void connect(final HttpClientConnection conn, final HttpRoute route,
                    final int connectTimeout, final HttpContext context) throws IOException {
    try {
        super.connect(conn, route, connectTimeout, context);
    } catch (SSLProtocolException e) {
        Boolean enableSniValue =
            (Boolean) context.getAttribute(SniSSLConnectionSocketFactory.ENABLE_SNI);
        boolean enableSni = enableSniValue == null || enableSniValue;
        if (enableSni && e.getMessage() != null &&
            e.getMessage().equals("handshake alert:  unrecognized_name")) {
            logger.warn("Server saw wrong SNI host, retrying without SNI");
            context.setAttribute(SniSSLConnectionSocketFactory.ENABLE_SNI, false);
            super.connect(conn, route, connectTimeout, context);
        } else {
            throw e;
        }
    }
}
 
开发者ID:doubleview,项目名称:fastcrawler,代码行数:20,代码来源:SniPoolingHttpClientConnectionManager.java


示例3: doReceiveResponse

import org.apache.http.HttpClientConnection; //导入依赖的package包/类
@Override
protected HttpResponse doReceiveResponse(
        final HttpRequest          request,
        final HttpClientConnection conn,
        final HttpContext          context)
            throws HttpException, IOException {
    AWSRequestMetrics awsRequestMetrics = (AWSRequestMetrics) context
            .getAttribute(AWSRequestMetrics.class.getSimpleName());
    if (awsRequestMetrics == null) {
        return super.doReceiveResponse(request, conn, context);
    }
    awsRequestMetrics.startEvent(Field.HttpClientReceiveResponseTime);
    try {
        return super.doReceiveResponse(request, conn, context);
    } finally {
        awsRequestMetrics.endEvent(Field.HttpClientReceiveResponseTime);
    }
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:19,代码来源:SdkHttpRequestExecutor.java


示例4: requestConnection

import org.apache.http.HttpClientConnection; //导入依赖的package包/类
public final ConnectionRequest requestConnection(
        final HttpRoute route,
        final Object state) {
    Args.notNull(route, "Route");
    return new ConnectionRequest() {

        public boolean cancel() {
            // Nothing to abort, since requests are immediate.
            return false;
        }

        public HttpClientConnection get(final long timeout, final TimeUnit tunit) {
            return BasicHttpClientConnectionManager.this.getConnection(
                    route, state);
        }

    };
}
 
开发者ID:xxonehjh,项目名称:remote-files-sync,代码行数:19,代码来源:BasicHttpClientConnectionManager.java


示例5: getConnection

import org.apache.http.HttpClientConnection; //导入依赖的package包/类
synchronized HttpClientConnection getConnection(final HttpRoute route, final Object state) {
    Asserts.check(!this.isShutdown.get(), "Connection manager has been shut down");
    if (Log.isLoggable(TAG, Log.DEBUG)) {
        Log.d(TAG, "Get connection for route " + route);
    }
    Asserts.check(!this.leased, "Connection is still allocated");
    if (!LangUtils.equals(this.route, route) || !LangUtils.equals(this.state, state)) {
        closeConnection();
    }
    this.route = route;
    this.state = state;
    checkExpiry();
    if (this.conn == null) {
        this.conn = this.connFactory.create(route, this.connConfig);
    }
    this.leased = true;
    return this.conn;
}
 
开发者ID:xxonehjh,项目名称:remote-files-sync,代码行数:19,代码来源:BasicHttpClientConnectionManager.java


示例6: connect

import org.apache.http.HttpClientConnection; //导入依赖的package包/类
public void connect(
        final HttpClientConnection conn,
        final HttpRoute route,
        final int connectTimeout,
        final HttpContext context) throws IOException {
    Args.notNull(conn, "Connection");
    Args.notNull(route, "HTTP route");
    Asserts.check(conn == this.conn, "Connection not obtained from this manager");
    final HttpHost host;
    if (route.getProxyHost() != null) {
        host = route.getProxyHost();
    } else {
        host = route.getTargetHost();
    }
    final InetSocketAddress localAddress = route.getLocalAddress() != null ? new InetSocketAddress(route.getLocalAddress(), 0) : null;;
    this.connectionOperator.connect(this.conn, host, localAddress,
            connectTimeout, this.socketConfig, context);
}
 
开发者ID:xxonehjh,项目名称:remote-files-sync,代码行数:19,代码来源:BasicHttpClientConnectionManager.java


示例7: requestConnection

import org.apache.http.HttpClientConnection; //导入依赖的package包/类
public ConnectionRequest requestConnection(
        final HttpRoute route,
        final Object state) {
    Args.notNull(route, "HTTP route");
    if (Log.isLoggable(TAG, Log.DEBUG)) {
        Log.d(TAG, "Connection request: " + format(route, state) + formatStats(route));
    }
    final Future<CPoolEntry> future = this.pool.lease(route, state, null);
    return new ConnectionRequest() {

        public boolean cancel() {
            return future.cancel(true);
        }

        public HttpClientConnection get(
                final long timeout,
                final TimeUnit tunit) throws InterruptedException, ExecutionException, ConnectionPoolTimeoutException {
            return leaseConnection(future, timeout, tunit);
        }

    };

}
 
开发者ID:xxonehjh,项目名称:remote-files-sync,代码行数:24,代码来源:PoolingHttpClientConnectionManager.java


示例8: leaseConnection

import org.apache.http.HttpClientConnection; //导入依赖的package包/类
protected HttpClientConnection leaseConnection(
        final Future<CPoolEntry> future,
        final long timeout,
        final TimeUnit tunit) throws InterruptedException, ExecutionException, ConnectionPoolTimeoutException {
    final CPoolEntry entry;
    try {
        entry = future.get(timeout, tunit);
        if (entry == null || future.isCancelled()) {
            throw new InterruptedException();
        }
        Asserts.check(entry.getConnection() != null, "Pool entry with no connection");
        if (Log.isLoggable(TAG, Log.DEBUG)) {
            Log.d(TAG, "Connection leased: " + format(entry) + formatStats(entry.getRoute()));
        }
        return CPoolProxy.newProxy(entry);
    } catch (final TimeoutException ex) {
        throw new ConnectionPoolTimeoutException("Timeout waiting for connection from pool");
    }
}
 
开发者ID:xxonehjh,项目名称:remote-files-sync,代码行数:20,代码来源:PoolingHttpClientConnectionManager.java


示例9: testLeaseReleaseNonReusable

import org.apache.http.HttpClientConnection; //导入依赖的package包/类
@Test
public void testLeaseReleaseNonReusable() throws Exception {
    final HttpHost target = new HttpHost("localhost", 80);
    final HttpRoute route = new HttpRoute(target);

    Mockito.when(connFactory.create(
            Mockito.eq(route), Mockito.<ConnectionConfig>any())).thenReturn(conn);

    final ConnectionRequest connRequest1 = mgr.requestConnection(route, null);
    final HttpClientConnection conn1 = connRequest1.get(0, TimeUnit.MILLISECONDS);
    Assert.assertNotNull(conn1);
    Assert.assertFalse(conn1.isOpen());

    mgr.releaseConnection(conn1, null, 100, TimeUnit.MILLISECONDS);

    Assert.assertNull(mgr.getRoute());
    Assert.assertNull(mgr.getState());

    final ConnectionRequest connRequest2 = mgr.requestConnection(route, null);
    final HttpClientConnection conn2 = connRequest2.get(0, TimeUnit.MILLISECONDS);
    Assert.assertNotNull(conn2);
    Assert.assertFalse(conn2.isOpen());

    Mockito.verify(connFactory, Mockito.times(2)).create(
            Mockito.eq(route), Mockito.<ConnectionConfig>any());
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:27,代码来源:TestBasicHttpClientConnectionManager.java


示例10: makeRequest

import org.apache.http.HttpClientConnection; //导入依赖的package包/类
private void makeRequest(HttpClientConnection conn, String body, Map<String, String> headers)
    throws IOException, HttpException {
  HttpEntityEnclosingRequest req = new HttpPost("/");
  req.setHeaders(
      new Header[] {
        new BasicHeader(HeaderMapper.SERVICE, SERVICE),
        new BasicHeader(HeaderMapper.PROCEDURE, ECHO_PROCEDURE),
        new BasicHeader(HeaderMapper.CALLER, CLIENT),
        new BasicHeader(HeaderMapper.ENCODING, RawEncoding.ENCODING),
        new BasicHeader(HttpHeaders.CONTENT_LENGTH, String.valueOf(body.length()))
      });
  headers.forEach(req::setHeader);
  req.setEntity(new ByteArrayEntity(body.getBytes(Charsets.UTF_8)));
  conn.sendRequestHeader(req);
  conn.sendRequestEntity(req);
  conn.flush();

  HttpResponse res = conn.receiveResponseHeader();
  assertEquals(HttpStatus.SC_OK, res.getStatusLine().getStatusCode());

  conn.receiveResponseEntity(res);
  String echo = EntityUtils.toString(res.getEntity(), Charsets.UTF_8);
  assertEquals(body, echo);
}
 
开发者ID:yarpc,项目名称:yarpc-java,代码行数:25,代码来源:HttpConnectionReuseTest.java


示例11: testReleaseReusable

import org.apache.http.HttpClientConnection; //导入依赖的package包/类
@Test
public void testReleaseReusable() throws Exception {
    final HttpHost target = new HttpHost("localhost", 80);
    final HttpRoute route = new HttpRoute(target);

    final CPoolEntry entry = Mockito.spy(new CPoolEntry(LogFactory.getLog(getClass()), "id", route, conn,
            -1, TimeUnit.MILLISECONDS));
    entry.markRouteComplete();

    Mockito.when(future.isCancelled()).thenReturn(Boolean.FALSE);
    Mockito.when(future.get(1, TimeUnit.SECONDS)).thenReturn(entry);
    Mockito.when(pool.lease(route, null, null)).thenReturn(future);
    Mockito.when(conn.isOpen()).thenReturn(Boolean.TRUE);

    final ConnectionRequest connRequest1 = mgr.requestConnection(route, null);
    final HttpClientConnection conn1 = connRequest1.get(1, TimeUnit.SECONDS);
    Assert.assertNotNull(conn1);
    Assert.assertTrue(conn1.isOpen());

    mgr.releaseConnection(conn1, "some state", 0, TimeUnit.MILLISECONDS);

    Mockito.verify(pool).release(entry, true);
    Mockito.verify(entry).setState("some state");
    Mockito.verify(entry).updateExpiry(Mockito.anyLong(), Mockito.eq(TimeUnit.MILLISECONDS));
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:26,代码来源:TestPoolingHttpClientConnectionManager.java


示例12: requestConnection

import org.apache.http.HttpClientConnection; //导入依赖的package包/类
@Override
public final ConnectionRequest requestConnection(
        final HttpRoute route,
        final Object state) {
    Args.notNull(route, "Route");
    return new ConnectionRequest() {

        @Override
        public boolean cancel() {
            // Nothing to abort, since requests are immediate.
            return false;
        }

        @Override
        public HttpClientConnection get(final long timeout, final TimeUnit tunit) {
            return BasicHttpClientConnectionManager.this.getConnection(
                    route, state);
        }

    };
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:22,代码来源:BasicHttpClientConnectionManager.java


示例13: getConnection

import org.apache.http.HttpClientConnection; //导入依赖的package包/类
synchronized HttpClientConnection getConnection(final HttpRoute route, final Object state) {
    Asserts.check(!this.isShutdown.get(), "Connection manager has been shut down");
    if (this.log.isDebugEnabled()) {
        this.log.debug("Get connection for route " + route);
    }
    Asserts.check(!this.leased, "Connection is still allocated");
    if (!LangUtils.equals(this.route, route) || !LangUtils.equals(this.state, state)) {
        closeConnection();
    }
    this.route = route;
    this.state = state;
    checkExpiry();
    if (this.conn == null) {
        this.conn = this.connFactory.create(route, this.connConfig);
    }
    this.leased = true;
    return this.conn;
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:19,代码来源:BasicHttpClientConnectionManager.java


示例14: requestConnection

import org.apache.http.HttpClientConnection; //导入依赖的package包/类
@Override
public ConnectionRequest requestConnection(
        final HttpRoute route,
        final Object state) {
    Args.notNull(route, "HTTP route");
    if (this.log.isDebugEnabled()) {
        this.log.debug("Connection request: " + format(route, state) + formatStats(route));
    }
    final Future<CPoolEntry> future = this.pool.lease(route, state, null);
    return new ConnectionRequest() {

        @Override
        public boolean cancel() {
            return future.cancel(true);
        }

        @Override
        public HttpClientConnection get(
                final long timeout,
                final TimeUnit tunit) throws InterruptedException, ExecutionException, ConnectionPoolTimeoutException {
            return leaseConnection(future, timeout, tunit);
        }

    };

}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:27,代码来源:PoolingHttpClientConnectionManager.java


示例15: testSocketTimeoutExistingConnection

import org.apache.http.HttpClientConnection; //导入依赖的package包/类
@Test
public void testSocketTimeoutExistingConnection() throws Exception {
    final HttpRoute route = new HttpRoute(target);
    final HttpClientContext context = new HttpClientContext();
    final RequestConfig config = RequestConfig.custom().setSocketTimeout(3000).build();
    final HttpRequestWrapper request = HttpRequestWrapper.wrap(new HttpGet("http://bar/test"));
    context.setRequestConfig(config);
    final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");
    Mockito.when(managedConn.isOpen()).thenReturn(true);
    Mockito.when(requestExecutor.execute(
            Mockito.same(request),
            Mockito.<HttpClientConnection>any(),
            Mockito.<HttpClientContext>any())).thenReturn(response);

    mainClientExec.execute(route, request, context, execAware);
    Mockito.verify(managedConn).setSocketTimeout(3000);
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:18,代码来源:TestMainClientExec.java


示例16: testExecAbortedPriorToRequestExecution

import org.apache.http.HttpClientConnection; //导入依赖的package包/类
@Test(expected=RequestAbortedException.class)
public void testExecAbortedPriorToRequestExecution() throws Exception {
    final HttpRoute route = new HttpRoute(target);
    final HttpClientContext context = new HttpClientContext();
    final HttpRequestWrapper request = HttpRequestWrapper.wrap(new HttpGet("http://bar/test"));

    Mockito.when(managedConn.isOpen()).thenReturn(Boolean.FALSE);
    Mockito.when(execAware.isAborted()).thenReturn(Boolean.FALSE, Boolean.FALSE, Boolean.TRUE);
    try {
        mainClientExec.execute(route, request, context, execAware);
    } catch (final IOException ex) {
        Mockito.verify(connRequest, Mockito.times(1)).get(0, TimeUnit.MILLISECONDS);
        Mockito.verify(connManager, Mockito.times(1)).connect(managedConn, route, 0, context);
        Mockito.verify(requestExecutor, Mockito.never()).execute(
                Mockito.same(request),
                Mockito.<HttpClientConnection>any(),
                Mockito.<HttpClientContext>any());
        throw ex;
    }
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:21,代码来源:TestMainClientExec.java


示例17: testExecRuntimeException

import org.apache.http.HttpClientConnection; //导入依赖的package包/类
@Test(expected=RuntimeException.class)
public void testExecRuntimeException() throws Exception {
    final HttpRoute route = new HttpRoute(target);
    final HttpClientContext context = new HttpClientContext();
    final HttpRequestWrapper request = HttpRequestWrapper.wrap(new HttpGet("http://bar/test"));

    Mockito.when(requestExecutor.execute(
            Mockito.<HttpRequest>any(),
            Mockito.<HttpClientConnection>any(),
            Mockito.<HttpClientContext>any())).thenThrow(new RuntimeException("Ka-boom"));

    try {
        mainClientExec.execute(route, request, context, execAware);
    } catch (final Exception ex) {
        Mockito.verify(connManager).releaseConnection(managedConn, null, 0, TimeUnit.MILLISECONDS);

        throw ex;
    }
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:20,代码来源:TestMainClientExec.java


示例18: testExecIOException

import org.apache.http.HttpClientConnection; //导入依赖的package包/类
@Test(expected=IOException.class)
public void testExecIOException() throws Exception {
    final HttpRoute route = new HttpRoute(target);
    final HttpClientContext context = new HttpClientContext();
    final HttpRequestWrapper request = HttpRequestWrapper.wrap(new HttpGet("http://bar/test"));

    Mockito.when(requestExecutor.execute(
            Mockito.<HttpRequest>any(),
            Mockito.<HttpClientConnection>any(),
            Mockito.<HttpClientContext>any())).thenThrow(new IOException("Ka-boom"));

    try {
        mainClientExec.execute(route, request, context, execAware);
    } catch (final Exception ex) {
        Mockito.verify(connManager).releaseConnection(managedConn, null, 0, TimeUnit.MILLISECONDS);

        throw ex;
    }
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:20,代码来源:TestMainClientExec.java


示例19: testReleaseNonReusable

import org.apache.http.HttpClientConnection; //导入依赖的package包/类
@Test
public void testReleaseNonReusable() throws Exception {
    final HttpHost target = new HttpHost("localhost", 80);
    final HttpRoute route = new HttpRoute(target);

    final CPoolEntry entry = Mockito.spy(new CPoolEntry(LogFactory.getLog(getClass()), "id", route, conn,
            -1, TimeUnit.MILLISECONDS));
    entry.markRouteComplete();

    Mockito.when(future.isCancelled()).thenReturn(Boolean.FALSE);
    Mockito.when(future.get(1, TimeUnit.SECONDS)).thenReturn(entry);
    Mockito.when(pool.lease(route, null, null)).thenReturn(future);
    Mockito.when(conn.isOpen()).thenReturn(Boolean.FALSE);

    final ConnectionRequest connRequest1 = mgr.requestConnection(route, null);
    final HttpClientConnection conn1 = connRequest1.get(1, TimeUnit.SECONDS);
    Assert.assertNotNull(conn1);
    Assert.assertFalse(conn1.isOpen());

    mgr.releaseConnection(conn1, "some state", 0, TimeUnit.MILLISECONDS);

    Mockito.verify(pool).release(entry, false);
    Mockito.verify(entry, Mockito.never()).setState(Mockito.anyObject());
    Mockito.verify(entry, Mockito.never()).updateExpiry(Mockito.anyLong(), Mockito.eq(TimeUnit.MILLISECONDS));
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:26,代码来源:TestPoolingHttpClientConnectionManager.java


示例20: testReleaseConnectionReusable

import org.apache.http.HttpClientConnection; //导入依赖的package包/类
@Test
public void testReleaseConnectionReusable() throws Exception {
    connHolder.setState("some state");
    connHolder.setValidFor(100, TimeUnit.SECONDS);
    connHolder.markReusable();

    connHolder.releaseConnection();

    Assert.assertTrue(connHolder.isReleased());

    Mockito.verify(conn, Mockito.never()).close();
    Mockito.verify(mgr).releaseConnection(conn, "some state", 100, TimeUnit.SECONDS);

    connHolder.releaseConnection();

    Mockito.verify(mgr, Mockito.times(1)).releaseConnection(
            Mockito.<HttpClientConnection>any(),
            Mockito.anyObject(),
            Mockito.anyLong(),
            Mockito.<TimeUnit>any());
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:22,代码来源:TestConnectionHolder.java



注:本文中的org.apache.http.HttpClientConnection类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java PathShape类代码示例发布时间:2022-05-21
下一篇:
Java OWLAnnotationPropertyDomainAxiom类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap