当前位置: 首页>>代码示例>>Java>>正文


Java HttpRoute类代码示例

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


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

示例1: test

import org.apache.http.conn.routing.HttpRoute; //导入依赖的package包/类
public static void test(){
		PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
		// Increase max total connection to 200  
		cm.setMaxTotal(200);  
		// Increase default max connection per route to 20  
		cm.setDefaultMaxPerRoute(20);  
		// Increase max connections for localhost:80 to 50  
		HttpHost localhost = new HttpHost("http://cc.0071515.com", 80);  
		cm.setMaxPerRoute(new HttpRoute(localhost), 2);  
		  
//		CloseableHttpClient httpClient = HttpClients.custom()  
//		        .setConnectionManager(cm)  
//		        .build();  
		httpClient = HttpClients.custom()  
				.setConnectionManager(cm)  
				.build();  
	}
 
开发者ID:dbiir,项目名称:ts-benchmark,代码行数:18,代码来源:HttpTest.java

示例2: requestConnection

import org.apache.http.conn.routing.HttpRoute; //导入依赖的package包/类
public final ClientConnectionRequest requestConnection(
        final HttpRoute route,
        final Object state) {

    return new ClientConnectionRequest() {

        public void abortRequest() {
            // Nothing to abort, since requests are immediate.
        }

        public ManagedClientConnection getConnection(
                long timeout, TimeUnit tunit) {
            return BasicClientConnectionManager.this.getConnection(
                    route, state);
        }

    };
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:19,代码来源:BasicClientConnectionManager.java

示例3: requestConnection

import org.apache.http.conn.routing.HttpRoute; //导入依赖的package包/类
public final ClientConnectionRequest requestConnection(
        final HttpRoute route,
        final Object state) {

    return new ClientConnectionRequest() {

        public void abortRequest() {
            // Nothing to abort, since requests are immediate.
        }

        public ManagedClientConnection getConnection(
                long timeout, TimeUnit tunit) {
            return SingleClientConnManager.this.getConnection(
                    route, state);
        }

    };
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:19,代码来源:SingleClientConnManager.java

示例4: requestConnection

import org.apache.http.conn.routing.HttpRoute; //导入依赖的package包/类
public ClientConnectionRequest requestConnection(
        final HttpRoute route,
        final Object state) {
    if (route == null) {
        throw new IllegalArgumentException("HTTP route may not be null");
    }
    if (this.log.isDebugEnabled()) {
        this.log.debug("Connection request: " + format(route, state) + formatStats(route));
    }
    final Future<HttpPoolEntry> future = this.pool.lease(route, state);

    return new ClientConnectionRequest() {

        public void abortRequest() {
            future.cancel(true);
        }

        public ManagedClientConnection getConnection(
                final long timeout,
                final TimeUnit tunit) throws InterruptedException, ConnectionPoolTimeoutException {
            return leaseConnection(future, timeout, tunit);
        }

    };

}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:27,代码来源:PoolingClientConnectionManager.java

示例5: getRoutePool

import org.apache.http.conn.routing.HttpRoute; //导入依赖的package包/类
/**
 * Get a route-specific pool of available connections.
 *
 * @param route   the route
 * @param create    whether to create the pool if it doesn't exist
 *
 * @return  the pool for the argument route,
 *     never <code>null</code> if <code>create</code> is <code>true</code>
 */
protected RouteSpecificPool getRoutePool(HttpRoute route,
                                         boolean create) {
    RouteSpecificPool rospl = null;
    poolLock.lock();
    try {

        rospl = routeToPool.get(route);
        if ((rospl == null) && create) {
            // no pool for this route yet (or anymore)
            rospl = newRouteSpecificPool(route);
            routeToPool.put(route, rospl);
        }

    } finally {
        poolLock.unlock();
    }

    return rospl;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:29,代码来源:ConnPoolByRoute.java

示例6: deleteEntry

import org.apache.http.conn.routing.HttpRoute; //导入依赖的package包/类
/**
 * Deletes a given pool entry.
 * This closes the pooled connection and removes all references,
 * so that it can be GCed.
 *
 * <p><b>Note:</b> Does not remove the entry from the freeConnections list.
 * It is assumed that the caller has already handled this step.</p>
 * <!-- @@@ is that a good idea? or rather fix it? -->
 *
 * @param entry         the pool entry for the connection to delete
 */
protected void deleteEntry(BasicPoolEntry entry) {

    HttpRoute route = entry.getPlannedRoute();

    if (log.isDebugEnabled()) {
        log.debug("Deleting connection"
                + " [" + route + "][" + entry.getState() + "]");
    }

    poolLock.lock();
    try {

        closeConnection(entry);

        RouteSpecificPool rospl = getRoutePool(route, true);
        rospl.deleteEntry(entry);
        numConnections--;
        if (rospl.isUnused()) {
            routeToPool.remove(route);
        }

    } finally {
        poolLock.unlock();
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:37,代码来源:ConnPoolByRoute.java

示例7: handleLostEntry

import org.apache.http.conn.routing.HttpRoute; //导入依赖的package包/类
@Override
protected void handleLostEntry(HttpRoute route) {

    poolLock.lock();
    try {

        RouteSpecificPool rospl = getRoutePool(route, true);
        rospl.dropEntry();
        if (rospl.isUnused()) {
            routeToPool.remove(route);
        }

        numConnections--;
        notifyWaitingThread(rospl);

    } finally {
        poolLock.unlock();
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:20,代码来源:ConnPoolByRoute.java

示例8: connect

import org.apache.http.conn.routing.HttpRoute; //导入依赖的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

示例9: execute

import org.apache.http.conn.routing.HttpRoute; //导入依赖的package包/类
@Override
public CloseableHttpResponse execute(HttpRoute route, HttpRequestWrapper request, HttpClientContext clientContext,
        HttpExecutionAware execAware) throws IOException, HttpException {
    Proxy proxy = (Proxy) clientContext.getAttribute(VSCrawlerConstant.VSCRAWLER_AVPROXY_KEY);
    if (proxy != null) {
        proxy.recordUsage();
    }
    try {
        return delegate.execute(route, request, clientContext, execAware);
    } catch (IOException ioe) {
        if (proxy != null) {
            proxy.recordFailed();
        }
        throw ioe;
    }
}
 
开发者ID:virjar,项目名称:vscrawler,代码行数:17,代码来源:ProxyFeedBackClientExecChain.java

示例10: buildHttpClient

import org.apache.http.conn.routing.HttpRoute; //导入依赖的package包/类
/**
 * Build a HTTP client based on the current properties.
 *
 * @return the built HTTP client
 */
private CloseableHttpClient buildHttpClient() {
    try {

        final ConnectionSocketFactory plainsf = PlainConnectionSocketFactory.getSocketFactory();
        final LayeredConnectionSocketFactory sslsf = this.sslSocketFactory;

        final Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create()
                .register("http", plainsf)
                .register("https", sslsf)
                .build();

        final PoolingHttpClientConnectionManager connMgmr = new PoolingHttpClientConnectionManager(registry);
        connMgmr.setMaxTotal(this.maxPooledConnections);
        connMgmr.setDefaultMaxPerRoute(this.maxConnectionsPerRoute);
        connMgmr.setValidateAfterInactivity(DEFAULT_TIMEOUT);

        final HttpHost httpHost = new HttpHost(InetAddress.getLocalHost());
        final HttpRoute httpRoute = new HttpRoute(httpHost);
        connMgmr.setMaxPerRoute(httpRoute, MAX_CONNECTIONS_PER_ROUTE);

        final RequestConfig requestConfig = RequestConfig.custom()
                .setSocketTimeout(this.readTimeout)
                .setConnectTimeout(this.connectionTimeout)
                .setConnectionRequestTimeout(this.connectionTimeout)
                .setCircularRedirectsAllowed(this.circularRedirectsAllowed)
                .setRedirectsEnabled(this.redirectsEnabled)
                .setAuthenticationEnabled(this.authenticationEnabled)
                .build();


        final HttpClientBuilder builder = HttpClients.custom()
                .setConnectionManager(connMgmr)
                .setDefaultRequestConfig(requestConfig)
                .setSSLSocketFactory(sslsf)
                .setSSLHostnameVerifier(this.hostnameVerifier)
                .setRedirectStrategy(this.redirectionStrategy)
                .setDefaultCredentialsProvider(this.credentialsProvider)
                .setDefaultCookieStore(this.cookieStore)
                .setConnectionReuseStrategy(this.connectionReuseStrategy)
                .setConnectionBackoffStrategy(this.connectionBackoffStrategy)
                .setServiceUnavailableRetryStrategy(this.serviceUnavailableRetryStrategy)
                .setProxyAuthenticationStrategy(this.proxyAuthenticationStrategy)
                .setDefaultHeaders(this.defaultHeaders)
                .useSystemProperties();

        return builder.build();

    } catch (final Exception e) {
        LOGGER.error(e.getMessage(), e);
        throw new RuntimeException(e);
    }
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:58,代码来源:SimpleHttpClientFactoryBean.java

示例11: buildHttpClient

import org.apache.http.conn.routing.HttpRoute; //导入依赖的package包/类
/**
 * Build a HTTP client based on the current properties.
 *
 * @return the built HTTP client
 */
private CloseableHttpClient buildHttpClient() {
    try {

        final ConnectionSocketFactory plainsf = PlainConnectionSocketFactory.getSocketFactory();
        final LayeredConnectionSocketFactory sslsf = this.sslSocketFactory;

        final Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create()
                .register("http", plainsf)
                .register("https", sslsf)
                .build();

        final PoolingHttpClientConnectionManager connMgmr = new PoolingHttpClientConnectionManager(registry);
        connMgmr.setMaxTotal(this.maxPooledConnections);
        connMgmr.setDefaultMaxPerRoute(this.maxConnectionsPerRoute);
        connMgmr.setValidateAfterInactivity(DEFAULT_TIMEOUT);

        final HttpHost httpHost = new HttpHost(InetAddress.getLocalHost());
        final HttpRoute httpRoute = new HttpRoute(httpHost);
        connMgmr.setMaxPerRoute(httpRoute, MAX_CONNECTIONS_PER_ROUTE);

        final RequestConfig requestConfig = RequestConfig.custom()
                .setSocketTimeout(this.readTimeout)
                .setConnectTimeout(Long.valueOf(this.connectionTimeout).intValue())
                .setConnectionRequestTimeout(Long.valueOf(this.connectionTimeout).intValue())
                .setCircularRedirectsAllowed(this.circularRedirectsAllowed)
                .setRedirectsEnabled(this.redirectsEnabled)
                .setAuthenticationEnabled(this.authenticationEnabled)
                .build();


        final HttpClientBuilder builder = HttpClients.custom()
                .setConnectionManager(connMgmr)
                .setDefaultRequestConfig(requestConfig)
                .setSSLSocketFactory(sslsf)
                .setSSLHostnameVerifier(this.hostnameVerifier)
                .setRedirectStrategy(this.redirectionStrategy)
                .setDefaultCredentialsProvider(this.credentialsProvider)
                .setDefaultCookieStore(this.cookieStore)
                .setConnectionReuseStrategy(this.connectionReuseStrategy)
                .setConnectionBackoffStrategy(this.connectionBackoffStrategy)
                .setServiceUnavailableRetryStrategy(this.serviceUnavailableRetryStrategy)
                .setProxyAuthenticationStrategy(this.proxyAuthenticationStrategy)
                .setDefaultHeaders(this.defaultHeaders)
                .useSystemProperties();

        return builder.build();

    } catch (final Exception e) {
        LOGGER.error(e.getMessage(), e);
        throw Throwables.propagate(e);
    }
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:58,代码来源:SimpleHttpClientFactoryBean.java

示例12: createHttpClient

import org.apache.http.conn.routing.HttpRoute; //导入依赖的package包/类
private static CloseableHttpClient createHttpClient(int maxTotal, int maxPerRoute, int maxRoute, String hostname, int port) {
    ConnectionSocketFactory plainsf = PlainConnectionSocketFactory
            .getSocketFactory();
    LayeredConnectionSocketFactory sslsf = SSLConnectionSocketFactory
            .getSocketFactory();
    Registry<ConnectionSocketFactory> registry = RegistryBuilder
            .<ConnectionSocketFactory>create()
            .register("http", plainsf)
            .register("https", sslsf)
            .build();

    PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(
            registry);

    // 将最大连接数增加
    cm.setMaxTotal(maxTotal);
    // 将每个路由基础的连接增加
    cm.setDefaultMaxPerRoute(maxPerRoute);

    // 将目标主机的最大连接数增加
    HttpHost httpHost = new HttpHost(hostname, port);
    cm.setMaxPerRoute(new HttpRoute(httpHost), maxRoute);

    // 请求重试处理
    HttpRequestRetryHandler httpRequestRetryHandler = (exception, executionCount, context) -> {
        if (executionCount >= 5) {// 如果已经重试了5次,就放弃
            return false;
        }
        if (exception instanceof NoHttpResponseException) {// 如果服务器丢掉了连接,那么就重试
            return true;
        }
        if (exception instanceof SSLHandshakeException) {// 不要重试SSL握手异常
            return false;
        }
        if (exception instanceof InterruptedIOException) {// 超时
            return false;
        }
        if (exception instanceof UnknownHostException) {// 目标服务器不可达
            return false;
        }
        if (exception instanceof ConnectTimeoutException) {// 连接被拒绝
            return false;
        }
        if (exception instanceof SSLException) {// SSL握手异常
            return false;
        }

        HttpClientContext clientContext = HttpClientContext.adapt(context);
        HttpRequest request = clientContext.getRequest();
        // 如果请求是幂等的,就再次尝试
        if (!(request instanceof HttpEntityEnclosingRequest)) {
            return true;
        }
        return false;
    };

    CloseableHttpClient httpClient = HttpClients.custom()
            .setConnectionManager(cm)
            .setRetryHandler(httpRequestRetryHandler)
            .build();

    return httpClient;
}
 
开发者ID:Evan1120,项目名称:wechat-api-java,代码行数:64,代码来源:HttpRequestUtil.java

示例13: requestConnection

import org.apache.http.conn.routing.HttpRoute; //导入依赖的package包/类
public ClientConnectionRequest requestConnection(HttpRoute route, Object state) {
    if (count > MAX_COUNT) {
        LOG.log(Level.INFO, "****Getting connection in pool.  Current total max = "
                + getConnectionsInPool()
                + "   Current for route = " + getConnectionsInPool(route) + "  Route = "
                + route.getTargetHost());
        count = 0;
    }
    ++count;
    return super.requestConnection(route, state);
}
 
开发者ID:Hitachi-Data-Systems,项目名称:Open-DM,代码行数:12,代码来源:HCAPAdapter.java

示例14: process

import org.apache.http.conn.routing.HttpRoute; //导入依赖的package包/类
public void process(final HttpRequest request, final HttpContext context)
        throws HttpException, IOException {
    if (request == null) {
        throw new IllegalArgumentException("HTTP request may not be null");
    }

    String method = request.getRequestLine().getMethod();
    if (method.equalsIgnoreCase("CONNECT")) {
        request.setHeader(PROXY_CONN_DIRECTIVE, HTTP.CONN_KEEP_ALIVE);
        return;
    }

    // Obtain the client connection (required)
    HttpRoutedConnection conn = (HttpRoutedConnection) context.getAttribute(
            ExecutionContext.HTTP_CONNECTION);
    if (conn == null) {
        this.log.debug("HTTP connection not set in the context");
        return;
    }

    HttpRoute route = conn.getRoute();

    if (route.getHopCount() == 1 || route.isTunnelled()) {
        if (!request.containsHeader(HTTP.CONN_DIRECTIVE)) {
            request.addHeader(HTTP.CONN_DIRECTIVE, HTTP.CONN_KEEP_ALIVE);
        }
    }
    if (route.getHopCount() == 2 && !route.isTunnelled()) {
        if (!request.containsHeader(PROXY_CONN_DIRECTIVE)) {
            request.addHeader(PROXY_CONN_DIRECTIVE, HTTP.CONN_KEEP_ALIVE);
        }
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:34,代码来源:RequestClientConnControl.java

示例15: process

import org.apache.http.conn.routing.HttpRoute; //导入依赖的package包/类
public void process(final HttpRequest request, final HttpContext context)
        throws HttpException, IOException {
    if (request == null) {
        throw new IllegalArgumentException("HTTP request may not be null");
    }
    if (context == null) {
        throw new IllegalArgumentException("HTTP context may not be null");
    }

    if (request.containsHeader(AUTH.PROXY_AUTH_RESP)) {
        return;
    }

    HttpRoutedConnection conn = (HttpRoutedConnection) context.getAttribute(
            ExecutionContext.HTTP_CONNECTION);
    if (conn == null) {
        this.log.debug("HTTP connection not set in the context");
        return;
    }
    HttpRoute route = conn.getRoute();
    if (route.isTunnelled()) {
        return;
    }

    // Obtain authentication state
    AuthState authState = (AuthState) context.getAttribute(
            ClientContext.PROXY_AUTH_STATE);
    if (authState == null) {
        this.log.debug("Proxy auth state not set in the context");
        return;
    }
    if (this.log.isDebugEnabled()) {
        this.log.debug("Proxy auth state: " + authState.getState());
    }
    process(authState, request, context);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:37,代码来源:RequestProxyAuthentication.java


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