Java Code Examples for org.apache.commons.httpclient.MultiThreadedHttpConnectionManager#setParams()
The following examples show how to use
org.apache.commons.httpclient.MultiThreadedHttpConnectionManager#setParams() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultDiamondSubscriber.java From diamond with Apache License 2.0 | 6 votes |
protected void initHttpClient() { if (MockServer.isTestMode()) { return; } HostConfiguration hostConfiguration = new HostConfiguration(); hostConfiguration.setHost(diamondConfigure.getDomainNameList().get(this.domainNamePos.get()), diamondConfigure.getPort()); MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); connectionManager.closeIdleConnections(diamondConfigure.getPollingIntervalTime() * 4000); HttpConnectionManagerParams params = new HttpConnectionManagerParams(); params.setStaleCheckingEnabled(diamondConfigure.isConnectionStaleCheckingEnabled()); params.setMaxConnectionsPerHost(hostConfiguration, diamondConfigure.getMaxHostConnections()); params.setMaxTotalConnections(diamondConfigure.getMaxTotalConnections()); params.setConnectionTimeout(diamondConfigure.getConnectionTimeout()); // 设置读超时为1分钟, // [email protected] params.setSoTimeout(60 * 1000); connectionManager.setParams(params); httpClient = new HttpClient(connectionManager); httpClient.setHostConfiguration(hostConfiguration); }
Example 2
Source File: DefaultDiamondSubscriber.java From diamond with Apache License 2.0 | 6 votes |
protected void initHttpClient() { if (MockServer.isTestMode()) { return; } HostConfiguration hostConfiguration = new HostConfiguration(); hostConfiguration.setHost(diamondConfigure.getDomainNameList().get(this.domainNamePos.get()), diamondConfigure.getPort()); MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); connectionManager.closeIdleConnections(diamondConfigure.getPollingIntervalTime() * 4000); HttpConnectionManagerParams params = new HttpConnectionManagerParams(); params.setStaleCheckingEnabled(diamondConfigure.isConnectionStaleCheckingEnabled()); params.setMaxConnectionsPerHost(hostConfiguration, diamondConfigure.getMaxHostConnections()); params.setMaxTotalConnections(diamondConfigure.getMaxTotalConnections()); params.setConnectionTimeout(diamondConfigure.getConnectionTimeout()); // 设置读超时为1分钟, // [email protected] params.setSoTimeout(60 * 1000); connectionManager.setParams(params); httpClient = new HttpClient(connectionManager); httpClient.setHostConfiguration(hostConfiguration); }
Example 3
Source File: CoreServerInitializer.java From micro-integrator with Apache License 2.0 | 5 votes |
private ConfigurationContext getClientConfigurationContext() throws AxisFault { String clientRepositoryLocation = serverConfigurationService.getFirstProperty(CLIENT_REPOSITORY_LOCATION); String clientAxis2XmlLocationn = serverConfigurationService.getFirstProperty(CLIENT_AXIS2_XML_LOCATION); ConfigurationContext clientConfigContextToReturn = ConfigurationContextFactory .createConfigurationContextFromFileSystem(clientRepositoryLocation, clientAxis2XmlLocationn); MultiThreadedHttpConnectionManager httpConnectionManager = new MultiThreadedHttpConnectionManager(); HttpConnectionManagerParams params = new HttpConnectionManagerParams(); // Set the default max connections per host int defaultMaxConnPerHost = 500; Parameter defaultMaxConnPerHostParam = clientConfigContextToReturn.getAxisConfiguration() .getParameter("defaultMaxConnPerHost"); if (defaultMaxConnPerHostParam != null) { defaultMaxConnPerHost = Integer.parseInt((String) defaultMaxConnPerHostParam.getValue()); } params.setDefaultMaxConnectionsPerHost(defaultMaxConnPerHost); // Set the max total connections int maxTotalConnections = 15000; Parameter maxTotalConnectionsParam = clientConfigContextToReturn.getAxisConfiguration() .getParameter("maxTotalConnections"); if (maxTotalConnectionsParam != null) { maxTotalConnections = Integer.parseInt((String) maxTotalConnectionsParam.getValue()); } params.setMaxTotalConnections(maxTotalConnections); params.setSoTimeout(600000); params.setConnectionTimeout(600000); httpConnectionManager.setParams(params); clientConfigContextToReturn .setProperty(HTTPConstants.MULTITHREAD_HTTP_CONNECTION_MANAGER, httpConnectionManager); clientConfigContextToReturn.setProperty(MicroIntegratorBaseConstants.WORK_DIR, serverWorkDir); return clientConfigContextToReturn; }
Example 4
Source File: CFActivator.java From orion.server with Eclipse Public License 1.0 | 5 votes |
private HttpClient createHttpClient() { //see http://hc.apache.org/httpclient-3.x/threading.html MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); HttpConnectionManagerParams params = connectionManager.getParams(); params.setMaxConnectionsPerHost(HostConfiguration.ANY_HOST_CONFIGURATION, PreferenceHelper.getInt(ServerConstants.HTTP_MAX_CONN_HOST_CONF_KEY, 50)); params.setMaxTotalConnections(PreferenceHelper.getInt(ServerConstants.HTTP_MAX_CONN_TOTAL_CONF_KEY, 150)); params.setConnectionTimeout(PreferenceHelper.getInt(ServerConstants.HTTP_CONN_TIMEOUT_CONF_KEY, 15000)); //15s params.setSoTimeout(PreferenceHelper.getInt(ServerConstants.HTTP_SO_TIMEOUT_CONF_KEY, 30000)); //30s connectionManager.setParams(params); HttpClientParams clientParams = new HttpClientParams(); clientParams.setConnectionManagerTimeout(PreferenceHelper.getInt(ServerConstants.HTTP_CONN_MGR_TIMEOUT_CONF_KEY, 300000)); // 5 minutes return new HttpClient(clientParams, connectionManager); }
Example 5
Source File: HttpClientBuilder.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Builds an HTTP client with the given settings. Settings are NOT reset to their default values after a client has * been created. * * @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; }
Example 6
Source File: HTTPProxyAdapter.java From flex-blazeds with Apache License 2.0 | 5 votes |
/** * Sets <code>HTTPConnectionManagerSettings</code>. * * @param connectionManagerSettings The connection manager settings. */ public void setConnectionManagerSettings(HTTPConnectionManagerSettings connectionManagerSettings) { this.connectionManagerSettings = connectionManagerSettings; initHttpConnectionManagerParams(connectionManagerSettings); connectionManager = new MultiThreadedHttpConnectionManager(); connectionManager.setParams(connectionParams); }
Example 7
Source File: AutoscalerCloudControllerClient.java From attic-stratos with Apache License 2.0 | 5 votes |
private AutoscalerCloudControllerClient() { MultiThreadedHttpConnectionManager multiThreadedHttpConnectionManager = new MultiThreadedHttpConnectionManager(); HttpConnectionManagerParams params = new HttpConnectionManagerParams(); params.setDefaultMaxConnectionsPerHost(AS_CC_CLIENT_MAX_CONNECTIONS_PER_HOST); params.setMaxTotalConnections(AS_CC_CLIENT_MAX_TOTAL_CONNECTIONS); multiThreadedHttpConnectionManager.setParams(params); HttpClient httpClient = new HttpClient(multiThreadedHttpConnectionManager); try { ConfigurationContext ctx = ConfigurationContextFactory.createConfigurationContextFromFileSystem(null, null); ctx.setProperty(HTTPConstants.CACHED_HTTP_CLIENT, httpClient); XMLConfiguration conf = ConfUtil.getInstance(null).getConfiguration(); int port = conf.getInt("autoscaler.cloudController.port", AutoscalerConstants .CLOUD_CONTROLLER_DEFAULT_PORT); String hostname = conf.getString("autoscaler.cloudController.hostname", "localhost"); String epr = "https://" + hostname + ":" + port + "/" + AutoscalerConstants.CLOUD_CONTROLLER_SERVICE_SFX; int cloudControllerClientTimeout = conf.getInt("autoscaler.cloudController.clientTimeout", 180000); stub = new CloudControllerServiceStub(ctx, epr); stub._getServiceClient().getOptions().setProperty(HTTPConstants.SO_TIMEOUT, cloudControllerClientTimeout); stub._getServiceClient().getOptions().setProperty(HTTPConstants.CONNECTION_TIMEOUT, cloudControllerClientTimeout); stub._getServiceClient().getOptions().setProperty(HTTPConstants.CHUNKED, Constants.VALUE_FALSE); stub._getServiceClient().getOptions().setProperty(Constants.Configuration.DISABLE_SOAP_ACTION, Boolean .TRUE); } catch (Exception e) { log.error("Could not initialize cloud controller client", e); } }
Example 8
Source File: CloudControllerServiceClient.java From attic-stratos with Apache License 2.0 | 5 votes |
private CloudControllerServiceClient(String epr) throws AxisFault { MultiThreadedHttpConnectionManager multiThreadedHttpConnectionManager = new MultiThreadedHttpConnectionManager(); HttpConnectionManagerParams params = new HttpConnectionManagerParams(); params.setDefaultMaxConnectionsPerHost(StratosConstants.CLOUD_CONTROLLER_CLIENT_MAX_CONNECTIONS_PER_HOST); params.setMaxTotalConnections(StratosConstants.CLOUD_CONTROLLER_CLIENT_MAX_TOTAL_CONNECTIONS); multiThreadedHttpConnectionManager.setParams(params); HttpClient httpClient = new HttpClient(multiThreadedHttpConnectionManager); ConfigurationContext ctx = ConfigurationContextFactory.createConfigurationContextFromFileSystem(null, null); ctx.setProperty(HTTPConstants.CACHED_HTTP_CLIENT, httpClient); String ccSocketTimeout = System.getProperty(StratosConstants.CLOUD_CONTROLLER_CLIENT_SOCKET_TIMEOUT) == null ? StratosConstants.DEFAULT_CLIENT_SOCKET_TIMEOUT : System.getProperty(StratosConstants.CLOUD_CONTROLLER_CLIENT_SOCKET_TIMEOUT); String ccConnectionTimeout = System.getProperty(StratosConstants.CLOUD_CONTROLLER_CLIENT_CONNECTION_TIMEOUT) == null ? StratosConstants.DEFAULT_CLIENT_CONNECTION_TIMEOUT : System.getProperty(StratosConstants.CLOUD_CONTROLLER_CLIENT_CONNECTION_TIMEOUT); try { stub = new CloudControllerServiceStub(ctx, epr); stub._getServiceClient().getOptions() .setProperty(HTTPConstants.SO_TIMEOUT, Integer.valueOf(ccSocketTimeout)); stub._getServiceClient().getOptions() .setProperty(HTTPConstants.CONNECTION_TIMEOUT, new Integer(ccConnectionTimeout)); stub._getServiceClient().getOptions().setProperty(HTTPConstants.CHUNKED, Constants.VALUE_FALSE); stub._getServiceClient().getOptions().setProperty(Constants.Configuration.DISABLE_SOAP_ACTION, Boolean .TRUE); } catch (AxisFault axisFault) { String msg = "Could not initialize cloud controller service client"; log.error(msg, axisFault); throw new AxisFault(msg, axisFault); } }
Example 9
Source File: AutoscalerServiceClient.java From attic-stratos with Apache License 2.0 | 5 votes |
private AutoscalerServiceClient(String epr) throws AxisFault { MultiThreadedHttpConnectionManager multiThreadedHttpConnectionManager = new MultiThreadedHttpConnectionManager(); HttpConnectionManagerParams params = new HttpConnectionManagerParams(); params.setDefaultMaxConnectionsPerHost(StratosConstants.AUTOSCALER_CLIENT_MAX_CONNECTIONS_PER_HOST); params.setMaxTotalConnections(StratosConstants.AUTOSCALER_CLIENT_MAX_TOTAL_CONNECTIONS); multiThreadedHttpConnectionManager.setParams(params); HttpClient httpClient = new HttpClient(multiThreadedHttpConnectionManager); ConfigurationContext ctx = ConfigurationContextFactory.createConfigurationContextFromFileSystem(null, null); ctx.setProperty(HTTPConstants.CACHED_HTTP_CLIENT, httpClient); String autosclaerSocketTimeout = System.getProperty(StratosConstants.AUTOSCALER_CLIENT_SOCKET_TIMEOUT) == null ? StratosConstants.DEFAULT_CLIENT_SOCKET_TIMEOUT : System.getProperty(StratosConstants.AUTOSCALER_CLIENT_SOCKET_TIMEOUT); String autosclaerConnectionTimeout = System.getProperty(StratosConstants.AUTOSCALER_CLIENT_CONNECTION_TIMEOUT) == null ? StratosConstants.DEFAULT_CLIENT_CONNECTION_TIMEOUT : System.getProperty(StratosConstants.AUTOSCALER_CLIENT_CONNECTION_TIMEOUT); try { stub = new AutoscalerServiceStub(ctx, epr); stub._getServiceClient().getOptions().setProperty(HTTPConstants.SO_TIMEOUT, Integer.valueOf(autosclaerSocketTimeout)); stub._getServiceClient().getOptions().setProperty(HTTPConstants.CONNECTION_TIMEOUT, Integer.valueOf(autosclaerConnectionTimeout)); stub._getServiceClient().getOptions().setProperty(HTTPConstants.CHUNKED, Constants.VALUE_FALSE); stub._getServiceClient().getOptions().setProperty(Constants.Configuration.DISABLE_SOAP_ACTION, Boolean .TRUE); } catch (AxisFault axisFault) { String msg = "Could not initialize autoscaler service client"; log.error(msg, axisFault); throw new AxisFault(msg, axisFault); } }
Example 10
Source File: StratosManagerServiceClient.java From attic-stratos with Apache License 2.0 | 5 votes |
private StratosManagerServiceClient(String epr) throws AxisFault { MultiThreadedHttpConnectionManager multiThreadedHttpConnectionManager = new MultiThreadedHttpConnectionManager(); HttpConnectionManagerParams params = new HttpConnectionManagerParams(); params.setDefaultMaxConnectionsPerHost(StratosConstants.STRATOS_MANAGER_CLIENT_MAX_CONNECTIONS_PER_HOST); params.setMaxTotalConnections(StratosConstants.STRATOS_MANAGER_CLIENT_MAX_TOTAL_CONNECTIONS); multiThreadedHttpConnectionManager.setParams(params); HttpClient httpClient = new HttpClient(multiThreadedHttpConnectionManager); ConfigurationContext ctx = ConfigurationContextFactory.createConfigurationContextFromFileSystem(null, null); ctx.setProperty(HTTPConstants.CACHED_HTTP_CLIENT, httpClient); String ccSocketTimeout = System.getProperty(StratosConstants.STRATOS_MANAGER_CLIENT_SOCKET_TIMEOUT) == null ? StratosConstants.DEFAULT_CLIENT_SOCKET_TIMEOUT : System.getProperty(StratosConstants.STRATOS_MANAGER_CLIENT_SOCKET_TIMEOUT); String ccConnectionTimeout = System.getProperty(StratosConstants.STRATOS_MANAGER_CLIENT_CONNECTION_TIMEOUT) == null ? StratosConstants.DEFAULT_CLIENT_CONNECTION_TIMEOUT : System.getProperty(StratosConstants.STRATOS_MANAGER_CLIENT_CONNECTION_TIMEOUT); try { stub = new StratosManagerServiceStub(ctx, epr); stub._getServiceClient().getOptions().setProperty(HTTPConstants.SO_TIMEOUT, Integer.valueOf (ccSocketTimeout)); stub._getServiceClient().getOptions().setProperty(HTTPConstants.CONNECTION_TIMEOUT, Integer.valueOf (ccConnectionTimeout)); stub._getServiceClient().getOptions().setProperty(HTTPConstants.CHUNKED, Constants.VALUE_FALSE); stub._getServiceClient().getOptions().setProperty(Constants.Configuration.DISABLE_SOAP_ACTION, Boolean .TRUE); } catch (AxisFault axisFault) { String msg = "Could not initialize stratos manager service client"; log.error(msg, axisFault); throw new AxisFault(msg, axisFault); } }