Refine search
/** * Construct a sitestream controller using a DefaultHttpClient */ public SitestreamController(Hosts hosts, Authentication auth) { this.client = new DefaultHttpClient(new PoolingClientConnectionManager()); this.hosts = Preconditions.checkNotNull(hosts); this.auth = Preconditions.checkNotNull(auth); }
SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme(CouchDBConstants.PROTOCOL, Integer.parseInt(defaultPort), ssf)); PoolingClientConnectionManager ccm = new PoolingClientConnectionManager(schemeRegistry); httpClient = new DefaultHttpClient(ccm); httpHost = new HttpHost(contactNode, Integer.parseInt(defaultPort), CouchDBConstants.PROTOCOL); httpClient.getParams().setParameter(CoreProtocolPNames.HTTP_CONTENT_CHARSET, "UTF-8"); ccm.setMaxTotal(Integer.parseInt(maxConnections)); ccm.setDefaultMaxPerRoute(Integer.parseInt(maxConnections)); ((DefaultHttpClient) httpClient).addRequestInterceptor(new HttpRequestInterceptor() ((DefaultHttpClient) httpClient).addResponseInterceptor(new HttpResponseInterceptor()
@Override public void stop() { if (log.isLoggable(Level.FINE)) log.fine("Shutting down HTTP client connection manager/pool"); clientConnectionManager.shutdown(); }
private void init(String host, int port, String userName, String password) { this.host = host; this.port = port; this.userName = userName; this.password = password; this.baseUrl = SCHEME_HTTP + host + ":" + port + KYLIN_API_PATH; final HttpParams httpParams = new BasicHttpParams(); HttpConnectionParams.setSoTimeout(httpParams, httpSocketTimeoutMs); HttpConnectionParams.setConnectionTimeout(httpParams, httpConnectionTimeoutMs); final PoolingClientConnectionManager cm = new PoolingClientConnectionManager(); KylinConfig config = KylinConfig.getInstanceFromEnv(); cm.setDefaultMaxPerRoute(config.getRestClientDefaultMaxPerRoute()); cm.setMaxTotal(config.getRestClientMaxTotal()); client = new DefaultHttpClient(cm, httpParams); if (userName != null && password != null) { CredentialsProvider provider = new BasicCredentialsProvider(); UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(userName, password); provider.setCredentials(AuthScope.ANY, credentials); client.setCredentialsProvider(provider); } }
PoolingClientConnectionManager connectionManager = new PoolingClientConnectionManager(); connectionManager.setMaxTotal(poolSize);
PoolingClientConnectionManager cxMgr = new PoolingClientConnectionManager( SchemeRegistryFactory.createDefault()); cxMgr.setMaxTotal(100); cxMgr.setDefaultMaxPerRoute(20);
public StreamClientImpl(StreamClientConfigurationImpl configuration) throws InitializationException { this.configuration = configuration; HttpProtocolParams.setContentCharset(globalParams, getConfiguration().getContentCharset()); HttpProtocolParams.setUseExpectContinue(globalParams, false); // These are some safety settings, we should never run into these timeouts as we // do our own expiration checking HttpConnectionParams.setConnectionTimeout(globalParams, (getConfiguration().getTimeoutSeconds()+5) * 1000); HttpConnectionParams.setSoTimeout(globalParams, (getConfiguration().getTimeoutSeconds()+5) * 1000); HttpConnectionParams.setStaleCheckingEnabled(globalParams, getConfiguration().getStaleCheckingEnabled()); if (getConfiguration().getSocketBufferSize() != -1) HttpConnectionParams.setSocketBufferSize(globalParams, getConfiguration().getSocketBufferSize()); // Only register 80, not 443 and SSL SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); clientConnectionManager = new PoolingClientConnectionManager(registry); clientConnectionManager.setMaxTotal(getConfiguration().getMaxTotalConnections()); clientConnectionManager.setDefaultMaxPerRoute(getConfiguration().getMaxTotalPerRoute()); httpClient = new DefaultHttpClient(clientConnectionManager, globalParams); if (getConfiguration().getRequestRetryCount() != -1) { httpClient.setHttpRequestRetryHandler( new DefaultHttpRequestRetryHandler(getConfiguration().getRequestRetryCount(), false) ); } }
SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", Integer.parseInt(port), ssf)); PoolingClientConnectionManager ccm = new PoolingClientConnectionManager(schemeRegistry); httpClient = new DefaultHttpClient(ccm); httpHost = new HttpHost(hosts[0], Integer.parseInt(port), "http"); ((DefaultHttpClient) httpClient).addRequestInterceptor(new HttpRequestInterceptor() ((DefaultHttpClient) httpClient).addResponseInterceptor(new HttpResponseInterceptor()
httpParams.setIntParameter(ClientPNames.MAX_REDIRECTS, 3); SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory())); schemeRegistry.register(new Scheme("https", 443, SSLSocketFactory.getSocketFactory())); PoolingClientConnectionManager cm = new PoolingClientConnectionManager(schemeRegistry); cm.setMaxTotal(configurationService.getIntConfiguration(CoreOptions.HTTP_MAX_CONNECTIONS, 20)); cm.setDefaultMaxPerRoute(configurationService.getIntConfiguration(CoreOptions.HTTP_MAX_CONNECTIONS_PER_ROUTE, 10)); final DefaultHttpClient hc = new DefaultHttpClient(cm, httpParams); hc.setRedirectStrategy(new LMFRedirectStrategy()); hc.setHttpRequestRetryHandler(new LMFHttpRequestRetryHandler()); hc.removeRequestInterceptorByClass(org.apache.http.protocol.RequestUserAgent.class); hc.addRequestInterceptor(new LMFRequestUserAgent(userAgentString));
return null; PoolingClientConnectionManager connManager = new PoolingClientConnectionManager( SchemeRegistryFactory.createDefault()); connManager.setMaxTotal(100); connManager.setDefaultMaxPerRoute(30); DefaultHttpClient client = new DefaultHttpClient(connManager); client.getConnectionManager().getSchemeRegistry().register(Utils.getMockedScheme()); HttpHost proxy = new HttpHost(ph, Integer.parseInt(pp)); client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); if (pu != null && pw != null) { client.getCredentialsProvider().setCredentials(new AuthScope(proxy),
SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", data.getPort(), PlainSocketFactory.getSocketFactory())); PoolingClientConnectionManager cm = new PoolingClientConnectionManager(schemeRegistry); cm.setMaxTotal(200); cm.setDefaultMaxPerRoute(20); DefaultHttpClient newHttpClient = new DefaultHttpClient(cm); HttpParams params = newHttpClient.getParams(); DefaultHttpClient newHttpClient = new DefaultHttpClient(); HttpParams params = newHttpClient.getParams(); registry.register(scheme);
SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme(targetServer.getProtocol(), getPortOrDefault(targetServer.getPort()), PlainSocketFactory .getSocketFactory())); BasicHttpParams httpParams = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParams, config.getConnectionTimeout()); HttpConnectionParams.setSoTimeout(httpParams, config.getSocketTimeout()); PoolingClientConnectionManager cm = new PoolingClientConnectionManager(schemeRegistry); cm.setDefaultMaxPerRoute(config.getMaxConnections()); cm.setMaxTotal(config.getMaxConnections()); DefaultHttpClient httpClient = new DefaultHttpClient(cm, httpParams); httpClient.removeResponseInterceptorByClass(ResponseProcessCookies.class); httpClient.removeRequestInterceptorByClass(RequestAddCookies.class);
/** * 默认httpclient * * @see <a * href="https://issues.apache.org/jira/browse/HTTPCLIENT-1193">HTTPCLIENT-1193</a> * @param clientConnectionManager */ public HttpComponent4_1Factory() { PoolingClientConnectionManager clientConnectionManager = new PoolingClientConnectionManager(); clientConnectionManager.setMaxTotal(30); clientConnectionManager.setDefaultMaxPerRoute(clientConnectionManager .getMaxTotal()); httpClient = new DefaultHttpClient(clientConnectionManager); httpClient.getParams().setParameter( CoreProtocolPNames.HTTP_CONTENT_CHARSET, Consts.UTF_8); httpClient.getParams().setParameter( CoreProtocolPNames.HTTP_ELEMENT_CHARSET, Consts.UTF_8.name()); httpClient.getParams().setParameter( CoreProtocolPNames.STRICT_TRANSFER_ENCODING, Consts.UTF_8); httpClient.getParams().setParameter(HttpHeaders.CONTENT_ENCODING, Consts.UTF_8); httpClient.getParams().setParameter(HttpHeaders.ACCEPT_CHARSET, Consts.UTF_8); SSLSocketFactory socketFactory = new SSLSocketFactory( HttpClientFactory.allowSSLContext()); socketFactory .setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); Scheme scheme = new Scheme("https", socketFactory, 443); httpClient.getConnectionManager().getSchemeRegistry().register(scheme); }
private DefaultHttpClient createClient() { try { DefaultHttpClient client = new DefaultHttpClient(new PoolingClientConnectionManager()); SSLSocketFactory socketFactory = TrustedSSLSocketFactory.create(); Scheme sch = new Scheme("https", 443, socketFactory); client.getConnectionManager().getSchemeRegistry().register(sch); return client; } catch (GeneralSecurityException e) { throw new IllegalStateException(MessageFormat.format( "Failed to initialize SSL socket factory: {0}", baseUri), e); } }
/** * Create a new instance of the {@code HttpClientMessageSender} with a default {@link HttpClient} that uses a * default {@link org.apache.http.impl.conn.PoolingClientConnectionManager}. */ public HttpComponentsMessageSender() { org.apache.http.impl.client.DefaultHttpClient defaultClient = new org.apache.http.impl.client.DefaultHttpClient(new org.apache.http.impl.conn.PoolingClientConnectionManager()); defaultClient.addRequestInterceptor(new RemoveSoapHeadersInterceptor(), 0); this.httpClient = defaultClient; setConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT_MILLISECONDS); setReadTimeout(DEFAULT_READ_TIMEOUT_MILLISECONDS); }
private SolrServer getSolr(final String url) { PoolingClientConnectionManager mgr = new PoolingClientConnectionManager(); mgr.setDefaultMaxPerRoute(20); mgr.setDefaultMaxPerRoute(100); DefaultHttpClient client = new DefaultHttpClient(mgr); HttpParams params = client.getParams(); HttpConnectionParams.setStaleCheckingEnabled(params, true); HttpConnectionParams.setSoTimeout(params, TIMEOUT_MILLISECONDS); client.setHttpRequestRetryHandler(new StandardHttpRequestRetryHandler(3, true)); return new HttpSolrServer(url, client); }
/** * 默认构造函数 */ public HttpUtil() { this.charset = "UTF-8"; PoolingClientConnectionManager pccm = new PoolingClientConnectionManager(); pccm.setMaxTotal(100); //设置整个连接池最大链接数 httpClient = new DefaultHttpClient(pccm); httpClient.getParams().setParameter(ClientPNames.COOKIE_POLICY,CookiePolicy.BROWSER_COMPATIBILITY); httpClient.getConnectionManager().closeIdleConnections(30,TimeUnit.SECONDS); }
public ApacheHttpClient(HttpClientConfig config, Set<? extends HttpRequestFilter> requestFilters) { Preconditions.checkNotNull(config, "config is null"); Preconditions.checkNotNull(requestFilters, "requestFilters is null"); PoolingClientConnectionManager connectionManager = new PoolingClientConnectionManager(); connectionManager.setMaxTotal(config.getMaxConnections()); connectionManager.setDefaultMaxPerRoute(config.getMaxConnectionsPerServer()); BasicHttpParams httpParams = new BasicHttpParams(); httpParams.setParameter(CoreConnectionPNames.SO_TIMEOUT, (int) config.getReadTimeout().toMillis()); httpParams.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, (int) config.getConnectTimeout().toMillis()); httpParams.setParameter(CoreConnectionPNames.SO_LINGER, 0); // do we need this? DefaultHttpClient defaultHttpClient = new DefaultHttpClient(connectionManager, httpParams); defaultHttpClient.setKeepAliveStrategy(new FixedIntervalKeepAliveStrategy(config.getKeepAliveInterval())); defaultHttpClient.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(0, false)); this.httpClient = defaultHttpClient; this.requestFilters = ImmutableList.copyOf(requestFilters); }
private DefaultHttpClient getHttpClientByConfig(ProxyConfig proxyConfig) { DefaultHttpClient client = new DefaultHttpClient(new PoolingClientConnectionManager()); client.getParams().setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 30000); if (proxyConfig == null) { return client; } HttpHost proxyHost = new HttpHost(proxyConfig.getHost(), proxyConfig.getPort()); client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxyHost); // if (!StringUtils.isEmpty(proxyConfig.getUserName())) { // client.getState().setProxyCredentials( // new AuthScope(proxyConfig.getHost(), proxyConfig.getPort()), // new UsernamePasswordCredentials(proxyConfig.getUserName(), proxyConfig.getPassword())); // } return client; }
private static PoolingClientConnectionManager buildConnectionManager() { PoolingClientConnectionManager cManager = new PoolingClientConnectionManager(); // set the maximum connections total and per host cManager.setDefaultMaxPerRoute(MAX_CONNECTIONS_PER_HOST); cManager.setMaxTotal(MAX_TOTAL_CONNECTIONS); return cManager; }