List of usage examples for org.apache.commons.httpclient MultiThreadedHttpConnectionManager MultiThreadedHttpConnectionManager
public MultiThreadedHttpConnectionManager()
From source file:org.wso2.carbon.device.mgt.iot.output.adapter.ui.authentication.oauth.OAuthTokenValidaterStubFactory.java
/** * This created httpclient pool that can be used to connect to external entity. This connection can be configured * via broker.xml by setting up the required http connection parameters. * * @return an instance of HttpClient that is configured with MultiThreadedHttpConnectionManager *//*from w w w . j av a2 s .c o m*/ private HttpClient createHttpClient() { HttpConnectionManagerParams params = new HttpConnectionManagerParams(); params.setDefaultMaxConnectionsPerHost(Integer.parseInt( tokenValidationProperties.getProperty(WebsocketConstants.MAXIMUM_HTTP_CONNECTION_PER_HOST))); params.setMaxTotalConnections(Integer .parseInt(tokenValidationProperties.getProperty(WebsocketConstants.MAXIMUM_TOTAL_HTTP_CONNECTION))); HttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); connectionManager.setParams(params); return new HttpClient(connectionManager); }
From source file:org.wso2.carbon.device.mgt.mobile.windows.api.common.authenticator.OAuthTokenValidationStubFactory.java
/** * Creates an instance of MultiThreadedHttpConnectionManager using HttpClient 3.x APIs * * @param properties Properties to configure MultiThreadedHttpConnectionManager * @return An instance of properly configured MultiThreadedHttpConnectionManager */// www .j a v a 2 s. co m private HttpConnectionManager createConnectionManager(Properties properties) { HttpConnectionManagerParams params = new HttpConnectionManagerParams(); if (properties == null || properties.isEmpty()) { throw new IllegalArgumentException("Parameters required to initialize HttpClient instances " + "associated with OAuth token validation service stub are not provided"); } String maxConnectionsPerHostParam = properties .getProperty(PluginConstants.AuthenticatorProperties.MAX_CONNECTION_PER_HOST); if (maxConnectionsPerHostParam == null || maxConnectionsPerHostParam.isEmpty()) { if (log.isDebugEnabled()) { log.debug("MaxConnectionsPerHost parameter is not explicitly defined. Therefore, the default, " + "which is 2, will be used"); } } else { params.setDefaultMaxConnectionsPerHost(Integer.parseInt(maxConnectionsPerHostParam)); } String maxTotalConnectionsParam = properties .getProperty(PluginConstants.AuthenticatorProperties.MAX_TOTAL_CONNECTIONS); if (maxTotalConnectionsParam == null || maxTotalConnectionsParam.isEmpty()) { if (log.isDebugEnabled()) { log.debug("MaxTotalConnections parameter is not explicitly defined. Therefore, the default, " + "which is 10, will be used"); } } else { params.setMaxTotalConnections(Integer.parseInt(maxTotalConnectionsParam)); } HttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); connectionManager.setParams(params); return connectionManager; }
From source file:org.wso2.carbon.device.mgt.output.adapter.http.HTTPEventAdapter.java
@Override public void init() throws OutputEventAdapterException { tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); //ExecutorService will be assigned if it is null if (executorService == null) { int minThread; int maxThread; long defaultKeepAliveTime; int jobQueSize; //If global properties are available those will be assigned else constant values will be assigned if (globalProperties.get(HTTPEventAdapterConstants.ADAPTER_MIN_THREAD_POOL_SIZE_NAME) != null) { minThread = Integer.parseInt( globalProperties.get(HTTPEventAdapterConstants.ADAPTER_MIN_THREAD_POOL_SIZE_NAME)); } else {// ww w .j ava 2 s.c om minThread = HTTPEventAdapterConstants.ADAPTER_MIN_THREAD_POOL_SIZE; } if (globalProperties.get(HTTPEventAdapterConstants.ADAPTER_MAX_THREAD_POOL_SIZE_NAME) != null) { maxThread = Integer.parseInt( globalProperties.get(HTTPEventAdapterConstants.ADAPTER_MAX_THREAD_POOL_SIZE_NAME)); } else { maxThread = HTTPEventAdapterConstants.ADAPTER_MAX_THREAD_POOL_SIZE; } if (globalProperties.get(HTTPEventAdapterConstants.ADAPTER_KEEP_ALIVE_TIME_NAME) != null) { defaultKeepAliveTime = Integer .parseInt(globalProperties.get(HTTPEventAdapterConstants.ADAPTER_KEEP_ALIVE_TIME_NAME)); } else { defaultKeepAliveTime = HTTPEventAdapterConstants.DEFAULT_KEEP_ALIVE_TIME_IN_MILLIS; } if (globalProperties.get(HTTPEventAdapterConstants.ADAPTER_EXECUTOR_JOB_QUEUE_SIZE_NAME) != null) { jobQueSize = Integer.parseInt( globalProperties.get(HTTPEventAdapterConstants.ADAPTER_EXECUTOR_JOB_QUEUE_SIZE_NAME)); } else { jobQueSize = HTTPEventAdapterConstants.ADAPTER_EXECUTOR_JOB_QUEUE_SIZE; } executorService = new ThreadPoolExecutor(minThread, maxThread, defaultKeepAliveTime, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(jobQueSize)); //configurations for the httpConnectionManager which will be shared by every http adapter int defaultMaxConnectionsPerHost; int maxTotalConnections; if (globalProperties.get(HTTPEventAdapterConstants.DEFAULT_MAX_CONNECTIONS_PER_HOST) != null) { defaultMaxConnectionsPerHost = Integer .parseInt(globalProperties.get(HTTPEventAdapterConstants.DEFAULT_MAX_CONNECTIONS_PER_HOST)); } else { defaultMaxConnectionsPerHost = HTTPEventAdapterConstants.DEFAULT_DEFAULT_MAX_CONNECTIONS_PER_HOST; } if (globalProperties.get(HTTPEventAdapterConstants.MAX_TOTAL_CONNECTIONS) != null) { maxTotalConnections = Integer .parseInt(globalProperties.get(HTTPEventAdapterConstants.MAX_TOTAL_CONNECTIONS)); } else { maxTotalConnections = HTTPEventAdapterConstants.DEFAULT_MAX_TOTAL_CONNECTIONS; } connectionManager = new MultiThreadedHttpConnectionManager(); connectionManager.getParams().setDefaultMaxConnectionsPerHost(defaultMaxConnectionsPerHost); connectionManager.getParams().setMaxTotalConnections(maxTotalConnections); } }
From source file:org.wso2.carbon.device.mgt.output.adapter.websocket.authentication.oauth.OAuthTokenValidaterStubFactory.java
/** * This created httpclient pool that can be used to connect to external entity. This connection can be configured * via broker.xml by setting up the required http connection parameters. * * @return an instance of HttpClient that is configured with MultiThreadedHttpConnectionManager *///from w w w . j a v a 2 s.c o m private HttpClient createHttpClient() { HttpConnectionManagerParams params = new HttpConnectionManagerParams(); params.setDefaultMaxConnectionsPerHost(Integer .parseInt(tokenValidationProperties.get(WebsocketConstants.MAXIMUM_HTTP_CONNECTION_PER_HOST))); params.setMaxTotalConnections( Integer.parseInt(tokenValidationProperties.get(WebsocketConstants.MAXIMUM_TOTAL_HTTP_CONNECTION))); HttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); connectionManager.setParams(params); return new HttpClient(connectionManager); }
From source file:org.wso2.carbon.event.output.adapter.http.HTTPEventAdapter.java
@Override public void init() throws OutputEventAdapterException { tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); //ExecutorService will be assigned if it is null if (executorService == null) { int minThread; int maxThread; long defaultKeepAliveTime; int jobQueSize; //If global properties are available those will be assigned else constant values will be assigned if (globalProperties.get(HTTPEventAdapterConstants.ADAPTER_MIN_THREAD_POOL_SIZE_NAME) != null) { minThread = Integer.parseInt( globalProperties.get(HTTPEventAdapterConstants.ADAPTER_MIN_THREAD_POOL_SIZE_NAME)); } else {/*w w w . j a va 2 s. c o m*/ minThread = HTTPEventAdapterConstants.ADAPTER_MIN_THREAD_POOL_SIZE; } if (globalProperties.get(HTTPEventAdapterConstants.ADAPTER_MAX_THREAD_POOL_SIZE_NAME) != null) { maxThread = Integer.parseInt( globalProperties.get(HTTPEventAdapterConstants.ADAPTER_MAX_THREAD_POOL_SIZE_NAME)); } else { maxThread = HTTPEventAdapterConstants.ADAPTER_MAX_THREAD_POOL_SIZE; } if (globalProperties.get(HTTPEventAdapterConstants.ADAPTER_KEEP_ALIVE_TIME_NAME) != null) { defaultKeepAliveTime = Integer .parseInt(globalProperties.get(HTTPEventAdapterConstants.ADAPTER_KEEP_ALIVE_TIME_NAME)); } else { defaultKeepAliveTime = HTTPEventAdapterConstants.DEFAULT_KEEP_ALIVE_TIME_IN_MILLIS; } if (globalProperties.get(HTTPEventAdapterConstants.ADAPTER_EXECUTOR_JOB_QUEUE_SIZE_NAME) != null) { jobQueSize = Integer.parseInt( globalProperties.get(HTTPEventAdapterConstants.ADAPTER_EXECUTOR_JOB_QUEUE_SIZE_NAME)); } else { jobQueSize = HTTPEventAdapterConstants.ADAPTER_EXECUTOR_JOB_QUEUE_SIZE; } executorService = new ThreadPoolExecutor(minThread, maxThread, defaultKeepAliveTime, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(jobQueSize)); //configurations for the httpConnectionManager which will be shared by every http adapter int defaultMaxConnectionsPerHost; int maxTotalConnections; if (globalProperties.get(HTTPEventAdapterConstants.DEFAULT_MAX_CONNECTIONS_PER_HOST) != null) { defaultMaxConnectionsPerHost = Integer .parseInt(globalProperties.get(HTTPEventAdapterConstants.DEFAULT_MAX_CONNECTIONS_PER_HOST)); } else { defaultMaxConnectionsPerHost = HTTPEventAdapterConstants.DEFAULT_DEFAULT_MAX_CONNECTIONS_PER_HOST; } if (globalProperties.get(HTTPEventAdapterConstants.MAX_TOTAL_CONNECTIONS) != null) { maxTotalConnections = Integer .parseInt(globalProperties.get(HTTPEventAdapterConstants.MAX_TOTAL_CONNECTIONS)); } else { maxTotalConnections = HTTPEventAdapterConstants.DEFAULT_MAX_TOTAL_CONNECTIONS; } connectionManager = new MultiThreadedHttpConnectionManager(); connectionManager.getParams().setDefaultMaxConnectionsPerHost(defaultMaxConnectionsPerHost); connectionManager.getParams().setMaxTotalConnections(maxTotalConnections); } }
From source file:org.wso2.carbon.event.output.adapter.soap.SoapEventAdapter.java
private HttpClient createMultiThreadedHttpConnectionManager(int connectionTimeOut, int maxConnectionPerHost) { HttpConnectionManagerParams params = new HttpConnectionManagerParams(); params.setDefaultMaxConnectionsPerHost(maxConnectionPerHost); params.setConnectionTimeout(connectionTimeOut); MultiThreadedHttpConnectionManager httpConnectionManager = new MultiThreadedHttpConnectionManager(); httpConnectionManager.setParams(params); return new HttpClient(httpConnectionManager); }
From source file:org.wso2.carbon.identity.entitlement.policy.publisher.CarbonBasicPolicyPublisherModule.java
private void doSend(String body) throws EntitlementException { if (serverUrl != null) { serverUrl = serverUrl.trim();/*from w ww . ja v a 2s . co m*/ if (!serverUrl.endsWith("/")) { serverUrl += "/"; } } String serverEndPoint = serverUrl + "EntitlementPolicyAdminService"; ServiceClient client = null; try { MultiThreadedHttpConnectionManager httpConnectionManager = new MultiThreadedHttpConnectionManager(); HttpClient httpClient = new HttpClient(httpConnectionManager); client = new ServiceClient(configCtx, null); Options option = client.getOptions(); option.setManageSession(true); HttpTransportProperties.Authenticator authenticator = new HttpTransportProperties.Authenticator(); authenticator.setUsername(serverUserName); authenticator.setPassword(serverPassword); authenticator.setPreemptiveAuthentication(true); option.setProperty(org.apache.axis2.transport.http.HTTPConstants.AUTHENTICATE, authenticator); option.setProperty(Constants.Configuration.TRANSPORT_URL, serverEndPoint); option.setProperty(HTTPConstants.REUSE_HTTP_CLIENT, Constants.VALUE_TRUE); option.setProperty(HTTPConstants.CACHED_HTTP_CLIENT, httpClient); client.sendRobust(AXIOMUtil.stringToOM(body)); } catch (AxisFault axisFault) { log.error("Policy publish fails due : " + axisFault.getMessage(), axisFault); throw new EntitlementException("Policy publish fails due : " + axisFault.getMessage()); } catch (XMLStreamException e) { log.error("Policy publish fails due : " + e.getMessage(), e); throw new EntitlementException("Policy publish fails due : " + e.getMessage()); } finally { if (client != null) { try { client.cleanupTransport(); client.cleanup(); } catch (AxisFault axisFault) { log.error("Error while cleaning HTTP client", axisFault); } } } }
From source file:org.wso2.carbon.identity.entitlement.proxy.soap.basicAuth.BasicAuthEntitlementServiceClient.java
private void initConfigurationContext() throws Exception { HttpConnectionManager multiThreadedHttpConnectionManager = new MultiThreadedHttpConnectionManager(); HttpClient httpClient = new HttpClient(multiThreadedHttpConnectionManager); File configFile = new File(DEFAULT_AXIS2_XML); if (!configFile.exists()) { configurationContext = ConfigurationContextFactory.createDefaultConfigurationContext(); configurationContext.setProperty(HTTPConstants.DEFAULT_MAX_CONNECTIONS_PER_HOST, MAX_CONNECTIONS_PER_HOST); } else {//from w w w.ja v a 2 s. co m configurationContext = ConfigurationContextFactory .createConfigurationContextFromFileSystem(DEFAULT_CLIENT_REPO, DEFAULT_AXIS2_XML); } configurationContext.setProperty(HTTPConstants.CACHED_HTTP_CLIENT, httpClient); configurationContext.setProperty(HTTPConstants.REUSE_HTTP_CLIENT, Constants.VALUE_TRUE); Map<String, TransportOutDescription> transportsOut = configurationContext.getAxisConfiguration() .getTransportsOut(); for (TransportOutDescription transportOutDescription : transportsOut.values()) { if (Constants.TRANSPORT_HTTP.equals(transportOutDescription.getName()) || Constants.TRANSPORT_HTTPS.equals(transportOutDescription.getName())) { transportOutDescription.getSender().init(configurationContext, transportOutDescription); } } }
From source file:org.wso2.carbon.identity.samples.entitlement.kmarket.trading.WSO2IdentityAgent.java
private void initConfigurationContext() throws AxisFault { MultiThreadedHttpConnectionManager multiThreadedHttpConnectionManager = new MultiThreadedHttpConnectionManager(); HttpClient httpClient = new HttpClient(multiThreadedHttpConnectionManager); configurationContext = ConfigurationContextFactory.createConfigurationContextFromFileSystem(null, null); configurationContext.setProperty(HTTPConstants.CACHED_HTTP_CLIENT, httpClient); configurationContext.setProperty(HTTPConstants.REUSE_HTTP_CLIENT, org.apache.axis2.Constants.VALUE_TRUE); HashMap<String, TransportOutDescription> transportsOut = configurationContext.getAxisConfiguration() .getTransportsOut();/* ww w.j a v a2 s . c o m*/ for (TransportOutDescription transportOutDescription : transportsOut.values()) { transportOutDescription.getSender().init(configurationContext, transportOutDescription); } }
From source file:org.wso2.carbon.mashup.javascript.hostobjects.pooledhttpclient.PooledHttpClientHostObject.java
public PooledHttpClientHostObject() { MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); HttpConnectionManagerParams params = connectionManager.getParams(); params.setDefaultMaxConnectionsPerHost(CONN_POOL_THREAD_MAX); params.setMaxTotalConnections(CONN_POOL_GLOBAL_MAX); this.httpClient = new HttpClient(connectionManager); }