Java 类org.apache.http.conn.routing.HttpRoute 实例源码

项目:ts-benchmark    文件:HttpTest.java   
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();  
    }
项目:lams    文件:BasicClientConnectionManager.java   
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);
        }

    };
}
项目:lams    文件:SingleClientConnManager.java   
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);
        }

    };
}
项目:lams    文件:PoolingClientConnectionManager.java   
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);
        }

    };

}
项目:lams    文件:ConnPoolByRoute.java   
/**
 * 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;
}
项目:lams    文件:ConnPoolByRoute.java   
/**
 * 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();
    }
}
项目:lams    文件:ConnPoolByRoute.java   
@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();
    }
}
项目:fastcrawler    文件:SniPoolingHttpClientConnectionManager.java   
@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;
        }
    }
}
项目:vscrawler    文件:ProxyFeedBackClientExecChain.java   
@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;
    }
}
项目:wechat-api-java    文件:HttpRequestUtil.java   
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;
}
项目:Open-DM    文件:HCAPAdapter.java   
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);
}
项目:lams    文件:RequestClientConnControl.java   
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);
        }
    }
}
项目:lams    文件:RequestProxyAuthentication.java   
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);
}
项目:lams    文件:DefaultRequestDirector.java   
protected void rewriteRequestURI(
        final RequestWrapper request,
        final HttpRoute route) throws ProtocolException {
    try {

        URI uri = request.getURI();
        if (route.getProxyHost() != null && !route.isTunnelled()) {
            // Make sure the request URI is absolute
            if (!uri.isAbsolute()) {
                HttpHost target = route.getTargetHost();
                uri = URIUtils.rewriteURI(uri, target, true);
            } else {
                uri = URIUtils.rewriteURI(uri);
            }
        } else {
            // Make sure the request URI is relative
            if (uri.isAbsolute()) {
                uri = URIUtils.rewriteURI(uri, null);
            } else {
                uri = URIUtils.rewriteURI(uri);
            }
        }
        request.setURI(uri);

    } catch (URISyntaxException ex) {
        throw new ProtocolException("Invalid URI: " +
                request.getRequestLine().getUri(), ex);
    }
}
项目:lams    文件:DefaultRequestDirector.java   
/**
 * Establish connection either directly or through a tunnel and retry in case of
 * a recoverable I/O failure
 */
private void tryConnect(
        final RoutedRequest req, final HttpContext context) throws HttpException, IOException {
    HttpRoute route = req.getRoute();
    HttpRequest wrapper = req.getRequest();

    int connectCount = 0;
    for (;;) {
        context.setAttribute(ExecutionContext.HTTP_REQUEST, wrapper);
        // Increment connect count
        connectCount++;
        try {
            if (!managedConn.isOpen()) {
                managedConn.open(route, context, params);
            } else {
                managedConn.setSocketTimeout(HttpConnectionParams.getSoTimeout(params));
            }
            establishRoute(route, context);
            break;
        } catch (IOException ex) {
            try {
                managedConn.close();
            } catch (IOException ignore) {
            }
            if (retryHandler.retryRequest(ex, connectCount, context)) {
                if (this.log.isInfoEnabled()) {
                    this.log.info("I/O exception ("+ ex.getClass().getName() +
                            ") caught when connecting to the target host: "
                            + ex.getMessage());
                    if (this.log.isDebugEnabled()) {
                        this.log.debug(ex.getMessage(), ex);
                    }
                    this.log.info("Retrying connect");
                }
            } else {
                throw ex;
            }
        }
    }
}
项目:lams    文件:DefaultRequestDirector.java   
/**
 * Creates the CONNECT request for tunnelling.
 * Called by {@link #createTunnelToTarget createTunnelToTarget}.
 *
 * @param route     the route to establish
 * @param context   the context for request execution
 *
 * @return  the CONNECT request for tunnelling
 */
protected HttpRequest createConnectRequest(HttpRoute route,
                                           HttpContext context) {
    // see RFC 2817, section 5.2 and
    // INTERNET-DRAFT: Tunneling TCP based protocols through
    // Web proxy servers

    HttpHost target = route.getTargetHost();

    String host = target.getHostName();
    int port = target.getPort();
    if (port < 0) {
        Scheme scheme = connManager.getSchemeRegistry().
            getScheme(target.getSchemeName());
        port = scheme.getDefaultPort();
    }

    StringBuilder buffer = new StringBuilder(host.length() + 6);
    buffer.append(host);
    buffer.append(':');
    buffer.append(Integer.toString(port));

    String authority = buffer.toString();
    ProtocolVersion ver = HttpProtocolParams.getVersion(params);
    HttpRequest req = new BasicHttpRequest
        ("CONNECT", authority, ver);

    return req;
}
项目:lams    文件:AIMDBackoffManager.java   
public void backOff(HttpRoute route) {
    synchronized(connPerRoute) {
        int curr = connPerRoute.getMaxPerRoute(route);
        Long lastUpdate = getLastUpdate(lastRouteBackoffs, route);
        long now = clock.getCurrentTime();
        if (now - lastUpdate.longValue() < coolDown) return;
        connPerRoute.setMaxPerRoute(route, getBackedOffPoolSize(curr));
        lastRouteBackoffs.put(route, Long.valueOf(now));
    }
}
项目:lams    文件:AIMDBackoffManager.java   
public void probe(HttpRoute route) {
    synchronized(connPerRoute) {
        int curr = connPerRoute.getMaxPerRoute(route);
        int max = (curr >= cap) ? cap : curr + 1;
        Long lastProbe = getLastUpdate(lastRouteProbes, route);
        Long lastBackoff = getLastUpdate(lastRouteBackoffs, route);
        long now = clock.getCurrentTime();
        if (now - lastProbe.longValue() < coolDown || now - lastBackoff.longValue() < coolDown)
            return;
        connPerRoute.setMaxPerRoute(route, max);
        lastRouteProbes.put(route, Long.valueOf(now));
    }
}
项目:lams    文件:PoolingClientConnectionManager.java   
private String format(final HttpRoute route, final Object state) {
    StringBuilder buf = new StringBuilder();
    buf.append("[route: ").append(route).append("]");
    if (state != null) {
        buf.append("[state: ").append(state).append("]");
    }
    return buf.toString();
}
项目:lams    文件:PoolingClientConnectionManager.java   
private String formatStats(final HttpRoute route) {
    StringBuilder buf = new StringBuilder();
    PoolStats totals = this.pool.getTotalStats();
    PoolStats stats = this.pool.getStats(route);
    buf.append("[total kept alive: ").append(totals.getAvailable()).append("; ");
    buf.append("route allocated: ").append(stats.getLeased() + stats.getAvailable());
    buf.append(" of ").append(stats.getMax()).append("; ");
    buf.append("total allocated: ").append(totals.getLeased() + totals.getAvailable());
    buf.append(" of ").append(totals.getMax()).append("]");
    return buf.toString();
}
项目:lams    文件:ConnPoolByRoute.java   
public int getConnectionsInPool(HttpRoute route) {
    poolLock.lock();
    try {
        // don't allow a pool to be created here!
        RouteSpecificPool rospl = getRoutePool(route, false);
        return (rospl != null) ? rospl.getEntryCount() : 0;

    } finally {
        poolLock.unlock();
    }
}
项目:lams    文件:ConnPoolByRoute.java   
@Override
public PoolEntryRequest requestPoolEntry(
        final HttpRoute route,
        final Object state) {

    final WaitingThreadAborter aborter = new WaitingThreadAborter();

    return new PoolEntryRequest() {

        public void abortRequest() {
            poolLock.lock();
            try {
                aborter.abort();
            } finally {
                poolLock.unlock();
            }
        }

        public BasicPoolEntry getPoolEntry(
                long timeout,
                TimeUnit tunit)
                    throws InterruptedException, ConnectionPoolTimeoutException {
            return getEntryBlocking(route, state, timeout, tunit, aborter);
        }

    };
}
项目:lams    文件:RouteSpecificPool.java   
/**
 * Creates a new route-specific pool.
 *
 * @param route the route for which to pool
 * @param connPerRoute the connections per route configuration
 */
public RouteSpecificPool(HttpRoute route, ConnPerRoute connPerRoute) {
    this.route = route;
    this.connPerRoute = connPerRoute;
    this.maxEntries = connPerRoute.getMaxForRoute(route);
    this.freeEntries = new LinkedList<BasicPoolEntry>();
    this.waitingThreads = new LinkedList<WaitingThread>();
    this.numEntries = 0;
}
项目:lams    文件:ThreadSafeClientConnManager.java   
public ClientConnectionRequest requestConnection(
        final HttpRoute route,
        final Object state) {

    final PoolEntryRequest poolRequest = pool.requestPoolEntry(
            route, state);

    return new ClientConnectionRequest() {

        public void abortRequest() {
            poolRequest.abortRequest();
        }

        public ManagedClientConnection getConnection(
                long timeout, TimeUnit tunit) throws InterruptedException,
                ConnectionPoolTimeoutException {
            if (route == null) {
                throw new IllegalArgumentException("Route may not be null.");
            }

            if (log.isDebugEnabled()) {
                log.debug("Get connection: " + route + ", timeout = " + timeout);
            }

            BasicPoolEntry entry = poolRequest.getPoolEntry(timeout, tunit);
            return new BasicPooledConnAdapter(ThreadSafeClientConnManager.this, entry);
        }

    };

}
项目:lams    文件:BasicPoolEntry.java   
public BasicPoolEntry(ClientConnectionOperator op,
                      HttpRoute route,
                      ReferenceQueue<Object> queue) {
    super(op, route);
    if (route == null) {
        throw new IllegalArgumentException("HTTP route may not be null");
    }
    this.created = System.currentTimeMillis();
    this.validUntil = Long.MAX_VALUE;
    this.expiry = this.validUntil;
}
项目:lams    文件:BasicPoolEntry.java   
/**
 * Creates a new pool entry with a specified maximum lifetime.
 *
 * @param op        the connection operator
 * @param route     the planned route for the connection
 * @param connTTL   maximum lifetime of this entry, <=0 implies "infinity"
 * @param timeunit  TimeUnit of connTTL
 *
 * @since 4.1
 */
public BasicPoolEntry(ClientConnectionOperator op,
                      HttpRoute route, long connTTL, TimeUnit timeunit) {
    super(op, route);
    if (route == null) {
        throw new IllegalArgumentException("HTTP route may not be null");
    }
    this.created = System.currentTimeMillis();
    if (connTTL > 0) {
        this.validUntil = this.created + timeunit.toMillis(connTTL);
    } else {
        this.validUntil = Long.MAX_VALUE;
    }
    this.expiry = this.validUntil;
}
项目:lams    文件:AbstractPooledConnAdapter.java   
public void open(HttpRoute route,
                 HttpContext context, HttpParams params)
    throws IOException {
    AbstractPoolEntry entry = getPoolEntry();
    assertValid(entry);
    entry.open(route, context, params);
}
项目:lams    文件:HttpPoolEntry.java   
public HttpPoolEntry(
        final Log log,
        final String id,
        final HttpRoute route,
        final OperatedClientConnection conn,
        final long timeToLive, final TimeUnit tunit) {
    super(id, route, conn, timeToLive, tunit);
    this.log = log;
    this.tracker = new RouteTracker(route);
}
项目:lams    文件:AbstractPoolEntry.java   
/**
 * Creates a new pool entry.
 *
 * @param connOperator     the Connection Operator for this entry
 * @param route   the planned route for the connection,
 *                or <code>null</code>
 */
protected AbstractPoolEntry(ClientConnectionOperator connOperator,
                            HttpRoute route) {
    super();
    if (connOperator == null) {
        throw new IllegalArgumentException("Connection operator may not be null");
    }
    this.connOperator = connOperator;
    this.connection = connOperator.createConnection();
    this.route = route;
    this.tracker = null;
}
项目:lams    文件:ConnPerRouteBean.java   
public void setMaxForRoute(final HttpRoute route, int max) {
    if (route == null) {
        throw new IllegalArgumentException
            ("HTTP route may not be null.");
    }
    if (max < 1) {
        throw new IllegalArgumentException
            ("The maximum must be greater than 0.");
    }
    this.maxPerHostMap.put(route, Integer.valueOf(max));
}
项目:lams    文件:ConnPerRouteBean.java   
public int getMaxForRoute(final HttpRoute route) {
    if (route == null) {
        throw new IllegalArgumentException
            ("HTTP route may not be null.");
    }
    Integer max = this.maxPerHostMap.get(route);
    if (max != null) {
        return max.intValue();
    } else {
        return this.defaultMax;
    }
}
项目:lams    文件:ConnPerRouteBean.java   
public void setMaxForRoutes(final Map<HttpRoute, Integer> map) {
    if (map == null) {
        return;
    }
    this.maxPerHostMap.clear();
    this.maxPerHostMap.putAll(map);
}
项目:lams    文件:ConnRouteParams.java   
/**
 * Obtains the {@link ConnRoutePNames#FORCED_ROUTE FORCED_ROUTE}
 * parameter value.
 * {@link #NO_ROUTE} will be mapped to <code>null</code>,
 * to allow unsetting in a hierarchy.
 *
 * @param params    the parameters in which to look up
 *
 * @return  the forced route set in the argument parameters, or
 *          <code>null</code> if not set
 */
public static HttpRoute getForcedRoute(HttpParams params) {
    if (params == null) {
        throw new IllegalArgumentException("Parameters must not be null.");
    }
    HttpRoute route = (HttpRoute)
        params.getParameter(FORCED_ROUTE);
    if ((route != null) && NO_ROUTE.equals(route)) {
        // value is explicitly unset
        route = null;
    }
    return route;
}
项目:java-apache-httpclient    文件:TracingClientExec.java   
@Override
public CloseableHttpResponse execute(
    HttpRoute route,
    HttpRequestWrapper request,
    HttpClientContext clientContext,
    HttpExecutionAware execAware) throws IOException, HttpException {

  ActiveSpan localSpan = clientContext.getAttribute(ACTIVE_SPAN, ActiveSpan.class);
  CloseableHttpResponse response = null;
  try {
    if (localSpan == null) {
      localSpan = handleLocalSpan(request, clientContext);
    }

    return (response = handleNetworkProcessing(localSpan, route, request, clientContext, execAware));
  } catch (Exception e) {
    localSpan.deactivate();
    throw e;
  } finally {
    if (response != null) {
      /**
       * This exec runs after {@link org.apache.http.impl.execchain.RedirectExec} which loops
       * until there is no redirect or reaches max redirect count.
       * {@link RedirectStrategy} is used to decide whether localSpan should be finished or not.
       * If there is a redirect localSpan is not finished and redirect is logged.
       */
      Integer redirectCount = clientContext.getAttribute(REDIRECT_COUNT, Integer.class);
      if (!redirectHandlingDisabled &&
          clientContext.getRequestConfig().isRedirectsEnabled() &&
          redirectStrategy.isRedirected(request, response, clientContext) &&
          ++redirectCount < clientContext.getRequestConfig().getMaxRedirects()) {

        clientContext.setAttribute(REDIRECT_COUNT, redirectCount);
      } else {
        localSpan.deactivate();
      }
    }
  }
}
项目:springboot-shiro-cas-mybatis    文件:SimpleHttpClientFactoryBean.java   
/**
 * 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);
    }
}
项目:springboot-shiro-cas-mybatis    文件:SimpleHttpClientFactoryBean.java   
/**
 * 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);

        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)
                .setStaleConnectionCheckEnabled(true)
                .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);
    }
}
项目:cas-5.1.0    文件:SimpleHttpClientFactoryBean.java   
/**
 * 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);
    }
}
项目:cas-server-4.2.1    文件:SimpleHttpClientFactoryBean.java   
/**
 * 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);
    }
}
项目:lams    文件:ProxyClient.java   
ProxyConnection(final HttpRoute route) {
    super();
    this.route = route;
}
项目:lams    文件:ProxyClient.java   
public HttpRoute getRoute() {
    return this.route;
}