當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。