/** * Obtains the tracked route. * If a route has been tracked, it is {@link #isConnected connected}. * If not connected, nothing has been tracked so far. * * @return the tracked route, or * <code>null</code> if nothing has been tracked so far */ public final HttpRoute toRoute() { return !this.connected ? null : new HttpRoute(this.targetHost, this.localAddress, this.proxyChain, this.secure, this.tunnelled, this.layered); }
private HttpContext getContext( URI uri ) { HttpClientContext httpClientContext = HttpClientContext.create(); //used by httpclient version >= 4.3 httpClientContext .setAttribute( HttpClientContext.HTTP_ROUTE, new HttpRoute( new HttpHost( uri.getHost(), uri.getPort() ) ) ); //used by httpclient version 4.2 httpClientContext .setAttribute( HttpClientContext.HTTP_TARGET_HOST, new HttpHost( uri.getHost(), uri.getPort() ) ); return httpClientContext; }
@Override public HttpRoute determineRoute(HttpHost host, HttpRequest request, HttpContext context) throws HttpException { Args.notNull(host, "Target host"); Args.notNull(request, "Request"); final HttpClientContext clientContext = HttpClientContext.adapt(context); final RequestConfig config = clientContext.getRequestConfig(); final InetAddress local = config.getLocalAddress(); HttpHost proxy = config.getProxy(); final HttpHost target; if (host.getPort() > 0 && (host.getSchemeName().equalsIgnoreCase("http") && host.getPort() == 80 || host.getSchemeName().equalsIgnoreCase("https") && host.getPort() == 443)) { target = new HttpHost(host.getHostName(), -1, host.getSchemeName()); } else { target = host; } final boolean secure = target.getSchemeName().equalsIgnoreCase("https"); if (proxy == null) { return new HttpRoute(target, local, secure); } else { return new HttpRoute(target, local, proxy, secure); } }
/** * Obtains the tracked route. * If a route has been tracked, it is {@link #isConnected connected}. * If not connected, nothing has been tracked so far. * * @return the tracked route, or * <code>null</code> if nothing has been tracked so far */ public final HttpRoute toRoute() { return !this.connected ? null : new HttpRoute(this.targetHost, this.localAddress, this.proxyChain, this.secure, this.tunnelled, this.layered); }
/** * Obtains the tracked route. * If a route has been tracked, it is {@link #isConnected connected}. * If not connected, nothing has been tracked so far. * * @return the tracked route, or * {@code null} if nothing has been tracked so far */ public final HttpRoute toRoute() { return !this.connected ? null : new HttpRoute(this.targetHost, this.localAddress, this.proxyChain, this.secure, this.tunnelled, this.layered); }
/** * Obtains the tracked route. * If a route has been tracked, it is {@link #isConnected connected}. * If not connected, nothing has been tracked so far. * * @return the tracked route, or * {@code null} if nothing has been tracked so far */ public final HttpRoute toRoute() { return !this.connected ? null : new HttpRoute(this.targetHost, this.localAddress, this.proxyChain, this.secure, this.tunnelled, this.layered); }
/** * Obtains the tracked route. * If a route has been tracked, it is {@link #isConnected connected}. * If not connected, nothing has been tracked so far. * * @return the tracked route, or * <code>null</code> if nothing has been tracked so far */ public final HttpRoute toRoute() { return !this.connected ? null : new HttpRoute(this.targetHost, this.localAddress, this.proxyChain, this.secure, this.tunnelled, this.layered); }
/** * Obtains the tracked route. * If a route has been tracked, it is {@link #isConnected connected}. * If not connected, nothing has been tracked so far. * * @return the tracked route, or * {@code null} if nothing has been tracked so far */ public final HttpRoute toRoute() { return !this.connected ? null : new HttpRoute(this.targetHost, this.localAddress, this.proxyChain, this.secure, this.tunnelled, this.layered); }
/** * @param host the host * @param port the port number * @param max number connections */ public static void setHostLimit(final String host, final int port, final int max) { HttpHost hostPort = new HttpHost(host, port); connManager.setMaxPerRoute(new HttpRoute(hostPort), max); }
/** * @param host the host * @param port the port number * @param max number connections */ public static void setHostLimit(final String host, final int port, final int max) { final HttpHost hostPort = new HttpHost(host, port); connManager.setMaxPerRoute(new HttpRoute(hostPort), max); }
@Override public HttpRoute determineRoute(final HttpHost host, final HttpRequest request, final HttpContext context) throws HttpException { String hostname = (host != null ? host.getHostName() : null); if ((hosts != null) && (hostname != null)) { for (String h : hosts) { if (hostname.equalsIgnoreCase(h)) { // bypass proxy for that hostname return new HttpRoute(host); } } } return super.determineRoute(host, request, context); } };
@Override public HttpRoute determineRoute(HttpHost target, HttpRequest request, HttpContext context) throws HttpException { String hostname = target.getHostName(); for (String nonProxyHost : nonProxyHosts) { if (isNonProxyHost(hostname, nonProxyHost)) { // Return direct route return new HttpRoute(target); } } return super.determineRoute(target, request, context); }
/** * For each route we explicitly set max Connections. * @param host * @param port * @param maxConnsPerRout */ public DruidNodeAccessor(String host, int port, int maxConnsPerRout) { proxyInit(); if (host != null) { HttpHost targetHost = new HttpHost(host, port); pool.setMaxPerRoute(new HttpRoute(targetHost), maxConnsPerRout); } }
/** * For each route we explicitly set max Connections. * @param host * @param port * @param maxConnsPerRout */ public DruidNodeAccessor(String host, int port, int maxConnsPerRout) { proxyInit(); if (host != null) { HttpHost targetHost = new HttpHost(host, port); pool.setMaxPerRoute(new HttpRoute(targetHost), maxConnsPerRout); } }
protected NFHttpClient(String host, int port){ super(new ThreadSafeClientConnManager()); this.name = "UNNAMED_" + numNonNamedHttpClients.incrementAndGet(); httpHost = new HttpHost(host, port); httpRoute = new HttpRoute(httpHost); init(DefaultClientConfigImpl.getClientConfigWithDefaultValues(), false); }
protected ClientConnectionManager newInstance() { final ThreadSafeClientConnManager cm = new ThreadSafeClientConnManager( newSchemeRegistry()); // 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 to 50 final HttpHost localhost = new HttpHost("locahost"); cm.setMaxForRoute(new HttpRoute(localhost), 50); return cm; }
protected ClientConnectionManager newInstance() { final ThreadSafeClientConnManager cm = new ThreadSafeClientConnManager( newSchemeRegistry()); // 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 to 50 final HttpHost localhost = new HttpHost("locahost"); cm.setMaxForRoute(new HttpRoute(localhost), 50); return cm; }