List of usage examples for org.apache.commons.httpclient.params HttpConnectionManagerParams setDefaultMaxConnectionsPerHost
public void setDefaultMaxConnectionsPerHost(int paramInt)
From source file:com.marvelution.hudson.plugins.apiv2.client.connectors.HttpClient3Connector.java
/** * Create the {@link HttpClient} object//from w w w. ja v a 2s . c o m */ private void createClient() { HttpConnectionManagerParams params = new HttpConnectionManagerParams(); params.setConnectionTimeout(TIMEOUT_MS); params.setDefaultMaxConnectionsPerHost(MAX_HOST_CONNECTIONS); params.setMaxTotalConnections(MAX_TOTAL_CONNECTIONS); MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); connectionManager.setParams(params); httpClient = new HttpClient(connectionManager); configureCredentials(); if (StringUtils.isNotBlank(System.getProperty("http.proxyHost"))) { log.debug("A HTTP Proxy is configured"); System.setProperty("java.net.useSystemProxies", "true"); Proxy proxy = chooseProxy(); if (proxy.type() == Type.HTTP && proxy.address() instanceof InetSocketAddress) { // convert the socket address to an ProxyHost final InetSocketAddress isa = (InetSocketAddress) proxy.address(); // assume default scheme (http) ProxyHost proxyHost = new ProxyHost(getHost(isa), isa.getPort()); httpClient.getHostConfiguration().setProxyHost(proxyHost); if (StringUtils.isNotBlank(System.getProperty("http.proxyUser"))) { String user = System.getProperty("http.proxyUser"); String password = System.getProperty("http.proxyPassword"); httpClient.getState().setProxyCredentials(new AuthScope(getHost(isa), isa.getPort()), new UsernamePasswordCredentials(user, password)); } } } }
From source file:edu.utah.further.core.ws.HttpClientTemplate.java
/** * Private {@link HttpClient} initialization. *///ww w . jav a 2 s. co m @PostConstruct private final void afterPropertiesSet() { // Client is higher in the hierarchy than manager so set the parameters here final HttpClientParams clientParams = new HttpClientParams(); clientParams.setConnectionManagerClass(connectionManager.getClass()); clientParams.setConnectionManagerTimeout(connectionTimeout); clientParams.setSoTimeout(readTimeout); clientParams.setParameter("http.connection.timeout", new Integer(connectionTimeout)); // A retry handler for when a connection fails clientParams.setParameter(HttpMethodParams.RETRY_HANDLER, new HttpMethodRetryHandler() { @Override public boolean retryMethod(final HttpMethod method, final IOException exception, final int executionCount) { if (executionCount >= retryCount) { // Do not retry if over max retry count return false; } if (instanceOf(exception, NoHttpResponseException.class)) { // Retry if the server dropped connection on us return true; } if (instanceOf(exception, SocketException.class)) { // Retry if the server reset connection on us return true; } if (instanceOf(exception, SocketTimeoutException.class)) { // Retry if the read timed out return true; } if (!method.isRequestSent()) { // Retry if the request has not been sent fully or // if it's OK to retry methods that have been sent return true; } // otherwise do not retry return false; } }); httpClient.setParams(clientParams); final HttpConnectionManagerParams connectionManagerParams = connectionManager.getParams(); connectionManagerParams.setDefaultMaxConnectionsPerHost(maxConnectionsPerHost); connectionManager.setParams(connectionManagerParams); }
From source file:com.clarkparsia.sbol.editor.sparql.StardogEndpoint.java
public StardogEndpoint(String url, String username, String passwd) { this.url = url; HttpConnectionManager manager = new MultiThreadedHttpConnectionManager(); HttpConnectionManagerParams params = new HttpConnectionManagerParams(); params.setDefaultMaxConnectionsPerHost(20); params.setStaleCheckingEnabled(false); manager.setParams(params);/* w ww. ja v a 2 s .c o m*/ HttpClientParams clientParams = new HttpClientParams(); client = new HttpClient(clientParams, manager); setCredentials(username, passwd); }
From source file:fr.aliasource.webmail.server.proxy.client.http.ProxyClient.java
private HttpClient createHttpClient() { mtConMan = new MultiThreadedHttpConnectionManager(); HttpClient ret = new HttpClient(mtConMan); HttpConnectionManagerParams mp = ret.getHttpConnectionManager().getParams(); mp.setDefaultMaxConnectionsPerHost(4); mp.setMaxTotalConnections(8);/*from ww w.j a v a2s . co m*/ return ret; }
From source file:com.sa.npopa.samples.hbase.rest.client.Client.java
private void initialize(Cluster cluster, boolean sslEnabled) { this.cluster = cluster; this.sslEnabled = sslEnabled; MultiThreadedHttpConnectionManager manager = new MultiThreadedHttpConnectionManager(); HttpConnectionManagerParams managerParams = manager.getParams(); managerParams.setConnectionTimeout(2000); // 2 s managerParams.setDefaultMaxConnectionsPerHost(10); managerParams.setMaxTotalConnections(100); extraHeaders = new ConcurrentHashMap<String, String>(); this.httpClient = new HttpClient(manager); HttpClientParams clientParams = httpClient.getParams(); clientParams.setVersion(HttpVersion.HTTP_1_1); }
From source file:com.iflytek.spider.protocol.httpclient.Http.java
/** * Configures the HTTP client/*from w w w. j av a 2 s . c o m*/ */ private void configureClient() { // Set up an HTTPS socket factory that accepts self-signed certs. Protocol https = new Protocol("https", new DummySSLProtocolSocketFactory(), 443); Protocol.registerProtocol("https", https); HttpConnectionManagerParams params = connectionManager.getParams(); params.setConnectionTimeout(timeout); params.setSoTimeout(timeout); params.setSendBufferSize(BUFFER_SIZE); params.setReceiveBufferSize(BUFFER_SIZE); params.setMaxTotalConnections(maxThreadsTotal); params.setDefaultMaxConnectionsPerHost(maxThreadsTotal); // executeMethod(HttpMethod) seems to ignore the connection timeout on // the connection manager. // set it explicitly on the HttpClient. client.getParams().setConnectionManagerTimeout(timeout); HostConfiguration hostConf = client.getHostConfiguration(); ArrayList headers = new ArrayList(); // Set the User Agent in the header headers.add(new Header("User-Agent", userAgent)); // prefer English headers.add(new Header("Accept-Language", acceptLanguage)); // prefer UTF-8 headers.add(new Header("Accept-Charset", "utf-8,ISO-8859-1;q=0.7,*;q=0.7")); // prefer understandable formats headers.add(new Header("Accept", "text/html,application/xml;q=0.9,application/xhtml+xml,text/xml;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5")); // accept gzipped content headers.add(new Header("Accept-Encoding", "x-gzip, gzip, deflate")); hostConf.getParams().setParameter("http.default-headers", headers); // HTTP proxy server details if (useProxy) { hostConf.setProxy(proxyHost, proxyPort); if (proxyUsername.length() > 0) { AuthScope proxyAuthScope = getAuthScope(this.proxyHost, this.proxyPort, this.proxyRealm); NTCredentials proxyCredentials = new NTCredentials(this.proxyUsername, this.proxyPassword, this.agentHost, this.proxyRealm); client.getState().setProxyCredentials(proxyAuthScope, proxyCredentials); } } }
From source file:com.iflytek.spider.protocol.httpclient.HttpSimply.java
/** * Configures the HTTP client//from w w w .j a v a 2 s.c o m */ private void configureClient() { // Set up an HTTPS socket factory that accepts self-signed certs. Protocol https = new Protocol("https", new DummySSLProtocolSocketFactory(), 443); Protocol.registerProtocol("https", https); HttpConnectionManagerParams params = connectionManager.getParams(); params.setConnectionTimeout(timeout); //params.setSoTimeout(timeout); timeouttimeout params.setSendBufferSize(BUFFER_SIZE); params.setReceiveBufferSize(BUFFER_SIZE); params.setMaxTotalConnections(maxThreadsTotal); params.setDefaultMaxConnectionsPerHost(maxThreadsTotal); // executeMethod(HttpMethod) seems to ignore the connection timeout on // the connection manager. // set it explicitly on the HttpClient. client.getParams().setConnectionManagerTimeout(timeout); HostConfiguration hostConf = client.getHostConfiguration(); ArrayList headers = new ArrayList(); // Set the User Agent in the header headers.add(new Header("User-Agent", userAgent)); // prefer English headers.add(new Header("Accept-Language", acceptLanguage)); // prefer UTF-8 headers.add(new Header("Accept-Charset", "utf-8,ISO-8859-1;q=0.7,*;q=0.7")); // prefer understandable formats headers.add(new Header("Accept", "text/html,application/xml;q=0.9,application/xhtml+xml,text/xml;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5")); // accept gzipped content headers.add(new Header("Accept-Encoding", "x-gzip, gzip, deflate")); hostConf.getParams().setParameter("http.default-headers", headers); // HTTP proxy server details if (useProxy) { hostConf.setProxy(proxyHost, proxyPort); if (proxyUsername.length() > 0) { AuthScope proxyAuthScope = getAuthScope(this.proxyHost, this.proxyPort, this.proxyRealm); NTCredentials proxyCredentials = new NTCredentials(this.proxyUsername, this.proxyPassword, this.agentHost, this.proxyRealm); client.getState().setProxyCredentials(proxyAuthScope, proxyCredentials); } } }
From source file:it.geosolutions.httpproxy.service.impl.ProxyServiceImpl.java
/** * Load proxy configuration when proxy config has changed *///from ww w . j av a 2 s . c om private void loadProxyConfig() { connectionManager = new MultiThreadedHttpConnectionManager(); HttpConnectionManagerParams params = new HttpConnectionManagerParams(); params.setSoTimeout(proxyConfig.getSoTimeout()); params.setConnectionTimeout(proxyConfig.getConnectionTimeout()); params.setMaxTotalConnections(proxyConfig.getMaxTotalConnections()); params.setDefaultMaxConnectionsPerHost(proxyConfig.getDefaultMaxConnectionsPerHost()); connectionManager.setParams(params); httpClient = new HttpClient(connectionManager); configureCallbacks(); }
From source file:it.geosolutions.httpproxy.HTTPProxy.java
/** * Initialize the <code>ProxyServlet</code> * //from www . j av a2 s. c o m * @param servletConfig The Servlet configuration passed in by the servlet conatiner */ public void init(ServletConfig servletConfig) throws ServletException { super.init(servletConfig); ServletContext context = getServletContext(); String proxyPropPath = context.getInitParameter("proxyPropPath"); proxyConfig = new ProxyConfig(getServletContext(), proxyPropPath); connectionManager = new MultiThreadedHttpConnectionManager(); HttpConnectionManagerParams params = new HttpConnectionManagerParams(); params.setSoTimeout(proxyConfig.getSoTimeout()); params.setConnectionTimeout(proxyConfig.getConnectionTimeout()); params.setMaxTotalConnections(proxyConfig.getMaxTotalConnections()); params.setDefaultMaxConnectionsPerHost(proxyConfig.getDefaultMaxConnectionsPerHost()); //setSystemProxy(params); connectionManager.setParams(params); httpClient = new HttpClient(connectionManager); // // Check for system proxy usage // try { String proxyHost = System.getProperty("http.proxyHost"); int proxyPort = 80; if (proxyHost != null && !proxyHost.isEmpty()) { try { proxyPort = (System.getProperty("http.proxyPort") != null ? Integer.parseInt(System.getProperty("http.proxyPort")) : proxyPort); httpClient.getHostConfiguration().setProxy(proxyHost, proxyPort); } catch (Exception ex) { LOGGER.warning("No proxy port found"); } } } catch (Exception ex) { LOGGER.warning("Exception while setting the system proxy: " + ex.getLocalizedMessage()); } // ////////////////////////////////////////// // Setup the callbacks (in the future this // will be a pluggable lookup). // ////////////////////////////////////////// callbacks = new ArrayList<ProxyCallback>(); callbacks.add(new MimeTypeChecker(proxyConfig)); callbacks.add(new HostNameChecker(proxyConfig)); callbacks.add(new RequestTypeChecker(proxyConfig)); callbacks.add(new MethodsChecker(proxyConfig)); callbacks.add(new HostChecker(proxyConfig)); }
From source file:eionet.cr.harvest.PullHarvest.java
/** * * @return/*from www. j a v a2s . c o m*/ */ private EndpointHttpClient prepareEndpointHttpClient() { HttpConnectionManagerParams managerParams = new HttpConnectionManagerParams(); managerParams.setDefaultMaxConnectionsPerHost(20); managerParams.setStaleCheckingEnabled(false); int httpTimeout = GeneralConfig.getIntProperty(GeneralConfig.HARVESTER_HTTP_TIMEOUT, getTimeout()); managerParams.setConnectionTimeout(httpTimeout); managerParams.setSoTimeout(httpTimeout); HttpConnectionManager manager = new MultiThreadedHttpConnectionManager(); manager.setParams(managerParams); HttpClientParams clientParams = new HttpClientParams(); clientParams.setParameter("http.useragent", URLUtil.userAgentHeader()); clientParams.setParameter("http.protocol.max-redirects", MAX_REDIRECTIONS); HashMap<String, String> headers = new HashMap<String, String>(); headers.put("Connection", "close"); clientParams.setParameter("additionalHTTPHeaders", headers); return new EndpointHttpClient(clientParams, manager); }