List of usage examples for org.apache.commons.httpclient.params HttpConnectionManagerParams setDefaultMaxConnectionsPerHost
public void setDefaultMaxConnectionsPerHost(int paramInt)
From source file:org.mapfish.print.config.Config.java
private synchronized MultiThreadedHttpConnectionManager getConnectionManager() { if (connectionManager == null) { connectionManager = new MultiThreadedHttpConnectionManager(); final HttpConnectionManagerParams params = connectionManager.getParams(); params.setDefaultMaxConnectionsPerHost(perHostParallelFetches); params.setMaxTotalConnections(globalParallelFetches); params.setSoTimeout(socketTimeout); params.setConnectionTimeout(connectionTimeout); }/*from w w w.j a v a 2 s . c o m*/ return connectionManager; }
From source file:org.mule.transport.http.HttpConnector.java
@Override protected void doInitialise() throws InitialisationException { super.doInitialise(); if (clientConnectionManager == null) { clientConnectionManager = new MultiThreadedHttpConnectionManager(); String prop = System.getProperty("mule.http.disableCleanupThread"); disableCleanupThread = prop != null && prop.equals("true"); if (!disableCleanupThread) { connectionCleaner = new IdleConnectionTimeoutThread(); connectionCleaner.setName("HttpClient-connection-cleaner-" + getName()); connectionCleaner.addConnectionManager(clientConnectionManager); connectionCleaner.start();//from w w w .j a v a 2s . c om } HttpConnectionManagerParams params = new HttpConnectionManagerParams(); if (getSendBufferSize() != INT_VALUE_NOT_SET) { params.setSendBufferSize(getSendBufferSize()); } if (getReceiveBufferSize() != INT_VALUE_NOT_SET) { params.setReceiveBufferSize(getReceiveBufferSize()); } if (getClientSoTimeout() != INT_VALUE_NOT_SET) { params.setSoTimeout(getClientSoTimeout()); } if (getSocketSoLinger() != INT_VALUE_NOT_SET) { params.setLinger(getSocketSoLinger()); } params.setTcpNoDelay(isSendTcpNoDelay()); params.setMaxTotalConnections(dispatchers.getMaxTotal()); params.setDefaultMaxConnectionsPerHost(dispatchers.getMaxTotal()); clientConnectionManager.setParams(params); } //connection manager must be created during initialization due that devkit requires the connection manager before start phase. //That's why it not manager only during stop/start phases and must be created also here. if (connectionManager == null) { try { connectionManager = new org.mule.transport.http.HttpConnectionManager(this, getReceiverWorkManager()); } catch (MuleException e) { throw new InitialisationException( CoreMessages.createStaticMessage("failed creating http connection manager"), this); } } }
From source file:org.obm.caldav.client.AbstractPushTest.java
private HttpClient createHttpClient() { HttpClient ret = new HttpClient(new MultiThreadedHttpConnectionManager()); HttpConnectionManagerParams mp = ret.getHttpConnectionManager().getParams(); mp.setDefaultMaxConnectionsPerHost(4); mp.setMaxTotalConnections(8);/*from w w w . j av a2 s.co m*/ return ret; }
From source file:org.obm.caldav.obmsync.service.impl.ObmSyncProviderFactory.java
protected ObmSyncProviderFactory() { MultiThreadedHttpConnectionManager mtConMan = new MultiThreadedHttpConnectionManager(); HttpClient ret = new HttpClient(mtConMan); HttpConnectionManagerParams mp = ret.getHttpConnectionManager().getParams(); mp.setDefaultMaxConnectionsPerHost(10); mp.setMaxTotalConnections(20);/*from w w w . j ava 2 s . c o m*/ this.hc = ret; }
From source file:org.openrdf.http.client.HTTPClient.java
public HTTPClient() { valueFactory = ValueFactoryImpl.getInstance(); // Use MultiThreadedHttpConnectionManager to allow concurrent access on // HttpClient manager = new MultiThreadedHttpConnectionManager(); // Allow 20 concurrent connections to the same host (default is 2) HttpConnectionManagerParams params = new HttpConnectionManagerParams(); params.setDefaultMaxConnectionsPerHost(20); manager.setParams(params);/*ww w.ja v a2s.c o m*/ httpClient = new HttpClient(manager); configureProxySettings(httpClient); }
From source file:org.openrdf.repository.sparql.SPARQLConnection.java
public SPARQLConnection(SPARQLRepository repository, String queryEndpointUrl, String updateEndpointUrl) { super(repository); this.queryEndpointUrl = queryEndpointUrl; this.updateEndpointUrl = updateEndpointUrl; // Use MultiThreadedHttpConnectionManager to allow concurrent access on // HttpClient HttpConnectionManager manager = new MultiThreadedHttpConnectionManager(); // Allow 20 concurrent connections to the same host (default is 2) HttpConnectionManagerParams params = new HttpConnectionManagerParams(); params.setDefaultMaxConnectionsPerHost(20); params.setStaleCheckingEnabled(false); manager.setParams(params);/*w w w. j av a 2s.c o m*/ HttpClientParams clientParams = new HttpClientParams(); clientParams.setParameter(HttpMethodParams.USER_AGENT, APP_NAME + "/" + VERSION + " " + clientParams.getParameter(HttpMethodParams.USER_AGENT)); // set additional HTTP headers, if desired by the user if (repository.getAdditionalHttpHeaders() != null) clientParams.setParameter(ADDITIONAL_HEADER_NAME, repository.getAdditionalHttpHeaders()); client = new HttpClient(clientParams, manager); }
From source file:org.opensaml.ws.soap.client.http.HttpClientBuilder.java
/** * Builds an HTTP client with the given settings. Settings are NOT reset to their default values after a client has * been created./*from w ww .j a v a2 s .c o m*/ * * @return the created client. */ public HttpClient buildClient() { if (httpsProtocolSocketFactory != null) { Protocol.registerProtocol("https", new Protocol("https", httpsProtocolSocketFactory, 443)); } HttpClientParams clientParams = new HttpClientParams(); clientParams.setAuthenticationPreemptive(isPreemptiveAuthentication()); clientParams.setContentCharset(getContentCharSet()); clientParams.setParameter(HttpClientParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(connectionRetryAttempts, false)); HttpConnectionManagerParams connMgrParams = new HttpConnectionManagerParams(); connMgrParams.setConnectionTimeout(getConnectionTimeout()); connMgrParams.setDefaultMaxConnectionsPerHost(getMaxConnectionsPerHost()); connMgrParams.setMaxTotalConnections(getMaxTotalConnections()); connMgrParams.setReceiveBufferSize(getReceiveBufferSize()); connMgrParams.setSendBufferSize(getSendBufferSize()); connMgrParams.setTcpNoDelay(isTcpNoDelay()); MultiThreadedHttpConnectionManager connMgr = new MultiThreadedHttpConnectionManager(); connMgr.setParams(connMgrParams); HttpClient httpClient = new HttpClient(clientParams, connMgr); if (proxyHost != null) { HostConfiguration hostConfig = new HostConfiguration(); hostConfig.setProxy(proxyHost, proxyPort); httpClient.setHostConfiguration(hostConfig); if (proxyUsername != null) { AuthScope proxyAuthScope = new AuthScope(proxyHost, proxyPort); UsernamePasswordCredentials proxyCredentials = new UsernamePasswordCredentials(proxyUsername, proxyPassword); httpClient.getState().setProxyCredentials(proxyAuthScope, proxyCredentials); } } return httpClient; }
From source file:org.paxle.crawler.http.impl.HttpCrawler.java
@Modified public synchronized void modified(Map<String, Object> configuration) { /*/* w w w . java2 s.c o m*/ * Cleanup old config */ this.cleanup(); /* * Init with changed configuration */ this.connectionManager = new MultiThreadedHttpConnectionManager(); final HttpConnectionManagerParams connectionManagerParams = connectionManager.getParams(); // configure connections per host final Integer maxConnections = (Integer) configuration.get(PROP_MAXCONNECTIONS_PER_HOST); if (maxConnections != null) { connectionManagerParams.setDefaultMaxConnectionsPerHost(maxConnections.intValue()); } // configuring timeouts final Integer connectionTimeout = (Integer) configuration.get(PROP_CONNECTION_TIMEOUT); if (connectionTimeout != null) { connectionManagerParams.setConnectionTimeout(connectionTimeout.intValue()); } final Integer socketTimeout = (Integer) configuration.get(PROP_SOCKET_TIMEOUT); if (socketTimeout != null) { connectionManagerParams.setSoTimeout(socketTimeout.intValue()); } // set new http client this.httpClient = new HttpClient(connectionManager); // the crawler should request and accept content-encoded data final Boolean acceptEncoding = (Boolean) configuration.get(PROP_ACCEPT_ENCODING); if (acceptEncoding != null) { this.acceptEncoding = acceptEncoding.booleanValue(); } // specifies if the crawler should skipp unsupported-mime-types final Boolean skipUnsupportedMimeTypes = (Boolean) configuration.get(PROP_SKIP_UNSUPPORTED_MIMETYPES); if (skipUnsupportedMimeTypes != null) { this.skipUnsupportedMimeTypes = skipUnsupportedMimeTypes.booleanValue(); } // the cookie policy to use for crawling final String propCookiePolicy = (String) configuration.get(PROP_COOKIE_POLICY); this.cookiePolicy = (propCookiePolicy == null || propCookiePolicy.length() == 0) ? CookiePolicy.BROWSER_COMPATIBILITY : propCookiePolicy; // the http-user-agent string that should be used final String userAgent = (String) configuration.get(PROP_USER_AGENT); if (userAgent != null) { StringBuffer buf = new StringBuffer(); Pattern pattern = Pattern.compile("\\$\\{[^\\}]*}"); Matcher matcher = pattern.matcher(userAgent); // replacing property placeholders with system-properties while (matcher.find()) { String placeHolder = matcher.group(); String propName = placeHolder.substring(2, placeHolder.length() - 1); String propValue = System.getProperty(propName); if (propValue != null) matcher.appendReplacement(buf, propValue); } matcher.appendTail(buf); this.userAgent = buf.toString(); } else { // Fallback this.userAgent = "PaxleFramework"; } // download limit in bytes final Integer maxDownloadSize = (Integer) configuration.get(PROP_MAXDOWNLOAD_SIZE); if (maxDownloadSize != null) { this.maxDownloadSize = maxDownloadSize.intValue(); } // limit data transfer rate final Integer transferLimit = (Integer) configuration.get(PROP_TRANSFER_LIMIT); int limitKBps = 0; if (transferLimit != null) limitKBps = transferLimit.intValue(); this.logger.debug("transfer rate limit: " + limitKBps + " kb/s"); // TODO: lrc = (limitKBps > 0) ? new CrawlerTools.LimitedRateCopier(limitKBps) : null; // proxy configuration final Boolean useProxyVal = (Boolean) configuration.get(PROP_PROXY_USE); final String host = (String) configuration.get(PROP_PROXY_HOST); final Integer portVal = (Integer) configuration.get(PROP_PROXY_PORT); if (useProxyVal != null && useProxyVal.booleanValue() && host != null && host.length() > 0 && portVal != null) { this.logger.info(String.format("Proxy is enabled: %s:%d", host, portVal)); final int port = portVal.intValue(); final ProxyHost proxyHost = new ProxyHost(host, port); this.httpClient.getHostConfiguration().setProxyHost(proxyHost); final String user = (String) configuration.get(PROP_PROXY_HOST); final String pwd = (String) configuration.get(PROP_PROXY_PASSWORD); if (user != null && user.length() > 0 && pwd != null && pwd.length() > 0) this.httpClient.getState().setProxyCredentials(new AuthScope(host, port), new UsernamePasswordCredentials(user, pwd)); } else { this.logger.info("Proxy is disabled"); this.httpClient.getHostConfiguration().setProxyHost(null); this.httpClient.getState().clearCredentials(); } }
From source file:org.paxle.tools.icon.impl.IconTool.java
protected void activate(Map<String, Object> props) { /*/*from ww w.j ava 2 s .c o m*/ * Initialize the icon-map and load the default icons */ // configure connection manager HttpConnectionManagerParams cmParams = this.connectionManager.getParams(); cmParams.setDefaultMaxConnectionsPerHost(10); cmParams.setConnectionTimeout(15000); cmParams.setSoTimeout(15000); // create the http-client this.httpClient = new HttpClient(this.connectionManager); /* configure mime-type to resource-file map */ InputStream mapStream = null; try { mapStream = IconTool.class.getResourceAsStream("/resources/iconmap.properties"); this.iconMap.load(mapStream); mapStream.close(); // load the default icon byte[] data = readFileIconPng("unknown"); if (data != null) this.defaultIcon = new IconData(data); data = readFileIconPng("text/html"); if (data != null) this.defaultHtmlIcon = new IconData(data); } catch (Exception e) { e.printStackTrace(); } finally { if (mapStream != null) try { mapStream.close(); } catch (Exception e) { /* ignore this */} } }
From source file:org.sonar.wsclient.connectors.HttpClient3Connector.java
private void createClient() { final HttpConnectionManagerParams params = new HttpConnectionManagerParams(); params.setConnectionTimeout(AbstractQuery.DEFAULT_TIMEOUT_MILLISECONDS); params.setSoTimeout(AbstractQuery.DEFAULT_TIMEOUT_MILLISECONDS); params.setDefaultMaxConnectionsPerHost(MAX_HOST_CONNECTIONS); params.setMaxTotalConnections(MAX_TOTAL_CONNECTIONS); final MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); connectionManager.setParams(params); this.httpClient = new HttpClient(connectionManager); configureCredentials();// www. ja v a 2s. co m }