Search in sources :

Example 21 with MultiThreadedHttpConnectionManager

use of org.apache.commons.httpclient.MultiThreadedHttpConnectionManager in project carbon-apimgt by wso2.

the class ExtendedHTTPEventAdapter method init.

@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(ExtendedHTTPEventAdapterConstants.ADAPTER_MIN_THREAD_POOL_SIZE_NAME) != null) {
            minThread = Integer.parseInt(globalProperties.get(ExtendedHTTPEventAdapterConstants.ADAPTER_MIN_THREAD_POOL_SIZE_NAME));
        } else {
            minThread = ExtendedHTTPEventAdapterConstants.ADAPTER_MIN_THREAD_POOL_SIZE;
        }
        if (globalProperties.get(ExtendedHTTPEventAdapterConstants.ADAPTER_MAX_THREAD_POOL_SIZE_NAME) != null) {
            maxThread = Integer.parseInt(globalProperties.get(ExtendedHTTPEventAdapterConstants.ADAPTER_MAX_THREAD_POOL_SIZE_NAME));
        } else {
            maxThread = ExtendedHTTPEventAdapterConstants.ADAPTER_MAX_THREAD_POOL_SIZE;
        }
        if (globalProperties.get(ExtendedHTTPEventAdapterConstants.ADAPTER_KEEP_ALIVE_TIME_NAME) != null) {
            defaultKeepAliveTime = Integer.parseInt(globalProperties.get(ExtendedHTTPEventAdapterConstants.ADAPTER_KEEP_ALIVE_TIME_NAME));
        } else {
            defaultKeepAliveTime = ExtendedHTTPEventAdapterConstants.DEFAULT_KEEP_ALIVE_TIME_IN_MILLIS;
        }
        if (globalProperties.get(ExtendedHTTPEventAdapterConstants.ADAPTER_EXECUTOR_JOB_QUEUE_SIZE_NAME) != null) {
            jobQueSize = Integer.parseInt(globalProperties.get(ExtendedHTTPEventAdapterConstants.ADAPTER_EXECUTOR_JOB_QUEUE_SIZE_NAME));
        } else {
            jobQueSize = ExtendedHTTPEventAdapterConstants.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(ExtendedHTTPEventAdapterConstants.DEFAULT_MAX_CONNECTIONS_PER_HOST) != null) {
            defaultMaxConnectionsPerHost = Integer.parseInt(globalProperties.get(ExtendedHTTPEventAdapterConstants.DEFAULT_MAX_CONNECTIONS_PER_HOST));
        } else {
            defaultMaxConnectionsPerHost = ExtendedHTTPEventAdapterConstants.DEFAULT_DEFAULT_MAX_CONNECTIONS_PER_HOST;
        }
        if (globalProperties.get(ExtendedHTTPEventAdapterConstants.MAX_TOTAL_CONNECTIONS) != null) {
            maxTotalConnections = Integer.parseInt(globalProperties.get(ExtendedHTTPEventAdapterConstants.MAX_TOTAL_CONNECTIONS));
        } else {
            maxTotalConnections = ExtendedHTTPEventAdapterConstants.DEFAULT_MAX_TOTAL_CONNECTIONS;
        }
        connectionManager = new MultiThreadedHttpConnectionManager();
        connectionManager.getParams().setDefaultMaxConnectionsPerHost(defaultMaxConnectionsPerHost);
        connectionManager.getParams().setMaxTotalConnections(maxTotalConnections);
        Map<String, String> staticProperties = eventAdapterConfiguration.getStaticProperties();
        if (staticProperties.get(ExtendedHTTPEventAdapterConstants.ADAPTER_OAUTH_CONSUMER_KEY) != null) {
            accessTokenGenerator = new AccessTokenGenerator(staticProperties.get(ExtendedHTTPEventAdapterConstants.ADAPTER_OAUTH_URL), staticProperties.get(ExtendedHTTPEventAdapterConstants.ADAPTER_OAUTH_CONSUMER_KEY), staticProperties.get(ExtendedHTTPEventAdapterConstants.ADAPTER_OAUTH_CONSUMER_SECRET));
            this.oauthURL = staticProperties.get(ExtendedHTTPEventAdapterConstants.ADAPTER_OAUTH_URL);
        }
    }
}
Also used : AccessTokenGenerator(org.wso2.carbon.apimgt.impl.recommendationmgt.AccessTokenGenerator) MultiThreadedHttpConnectionManager(org.apache.commons.httpclient.MultiThreadedHttpConnectionManager) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue)

Example 22 with MultiThreadedHttpConnectionManager

use of org.apache.commons.httpclient.MultiThreadedHttpConnectionManager in project coprhd-controller by CoprHD.

the class HP3PARApiFactory method init.

/**
 * Initialize HTTP client
 */
public void init() {
    _log.info("3PARDriver:HP3PARApiFactory init enter");
    _clientMap = new ConcurrentHashMap<String, HP3PARApi>();
    HttpConnectionManagerParams params = new HttpConnectionManagerParams();
    params.setDefaultMaxConnectionsPerHost(_maxConnPerHost);
    params.setMaxTotalConnections(_maxConn);
    params.setTcpNoDelay(true);
    params.setConnectionTimeout(_connTimeout);
    params.setSoTimeout(_socketConnTimeout);
    _connectionManager = new MultiThreadedHttpConnectionManager();
    _connectionManager.setParams(params);
    // close idle connections immediately
    _connectionManager.closeIdleConnections(0);
    HttpClient client = new HttpClient(_connectionManager);
    client.getParams().setConnectionManagerTimeout(connManagerTimeout);
    client.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new HttpMethodRetryHandler() {

        @Override
        public boolean retryMethod(HttpMethod httpMethod, IOException e, int i) {
            return false;
        }
    });
    Protocol.registerProtocol("https", new Protocol("https", new NonValidatingSocketFactory(), 8080));
}
Also used : IOException(java.io.IOException) HttpMethodRetryHandler(org.apache.commons.httpclient.HttpMethodRetryHandler) HttpConnectionManagerParams(org.apache.commons.httpclient.params.HttpConnectionManagerParams) ApacheHttpClient(com.sun.jersey.client.apache.ApacheHttpClient) HttpClient(org.apache.commons.httpclient.HttpClient) MultiThreadedHttpConnectionManager(org.apache.commons.httpclient.MultiThreadedHttpConnectionManager) HP3PARApi(com.emc.storageos.hp3par.impl.HP3PARApi) Protocol(org.apache.commons.httpclient.protocol.Protocol) HttpMethod(org.apache.commons.httpclient.HttpMethod)

Example 23 with MultiThreadedHttpConnectionManager

use of org.apache.commons.httpclient.MultiThreadedHttpConnectionManager in project coprhd-controller by CoprHD.

the class VPlexApiFactory method init.

/**
 * Initialize HTTP client
 */
private void init() {
    // Create the VPlex API client map.
    _clientMap = new ConcurrentHashMap<String, VPlexApiClient>();
    // Setup the connection parameters.
    HttpConnectionManagerParams params = new HttpConnectionManagerParams();
    params.setMaxTotalConnections(_maxConn);
    params.setDefaultMaxConnectionsPerHost(_maxConnPerHost);
    params.setConnectionTimeout(_connTimeoutMs);
    params.setSoTimeout(_socketTimeoutMs);
    params.setTcpNoDelay(true);
    // Create the HTTP connection manager for managing the set of HTTP
    // connections and set the configuration parameters. Also, make sure
    // idle connections are closed immediately to prevent a buildup of
    // connections in the CLOSE_WAIT state.
    MultiThreadedHttpConnectionManager mgr = new MultiThreadedHttpConnectionManager();
    mgr.setParams(params);
    mgr.closeIdleConnections(0);
    // Create the HTTP client and set the handler for determining if an
    // HttpMethod should be retried after a recoverable exception during
    // execution.
    HttpClient client = new HttpClient(mgr);
    client.getParams().setConnectionManagerTimeout(connManagerTimeout);
    client.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new HttpMethodRetryHandler() {

        @Override
        public boolean retryMethod(HttpMethod httpMethod, IOException e, int i) {
            return false;
        }
    });
    // Create the client handler.
    _clientHandler = new ApacheHttpClientHandler(client);
    // Register the specific for the HTTPS protocol.
    Protocol.registerProtocol("https", new Protocol("https", new NonValidatingSocketFactory(), 443));
}
Also used : IOException(java.io.IOException) HttpMethodRetryHandler(org.apache.commons.httpclient.HttpMethodRetryHandler) HttpConnectionManagerParams(org.apache.commons.httpclient.params.HttpConnectionManagerParams) ApacheHttpClient(com.sun.jersey.client.apache.ApacheHttpClient) HttpClient(org.apache.commons.httpclient.HttpClient) MultiThreadedHttpConnectionManager(org.apache.commons.httpclient.MultiThreadedHttpConnectionManager) ApacheHttpClientHandler(com.sun.jersey.client.apache.ApacheHttpClientHandler) Protocol(org.apache.commons.httpclient.protocol.Protocol) HttpMethod(org.apache.commons.httpclient.HttpMethod)

Example 24 with MultiThreadedHttpConnectionManager

use of org.apache.commons.httpclient.MultiThreadedHttpConnectionManager in project coprhd-controller by CoprHD.

the class HDSApiFactory method init.

/**
 * Initialize HTTP client
 */
public void init() {
    // Create the VPlex API client map.
    _clientMap = new ConcurrentHashMap<String, HDSApiClient>();
    // Setup the connection parameters.
    HttpConnectionManagerParams params = new HttpConnectionManagerParams();
    params.setMaxTotalConnections(_maxConn);
    params.setDefaultMaxConnectionsPerHost(_maxConnPerHost);
    params.setConnectionTimeout(_connTimeoutMs);
    params.setSoTimeout(socketConnectionTimeoutMs);
    params.setTcpNoDelay(true);
    // Create the HTTP connection manager for managing the set of HTTP
    // connections.
    MultiThreadedHttpConnectionManager mgr = new MultiThreadedHttpConnectionManager();
    mgr.setParams(params);
    // close idle connections immediately
    mgr.closeIdleConnections(0);
    // Create the HTTP client and set the handler for determining if an
    // HttpMethod should be retried after a recoverable exception during
    // execution.
    HttpClient client = new HttpClient(mgr);
    client.getParams().setConnectionManagerTimeout(connManagerTimeout);
    client.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new HttpMethodRetryHandler() {

        @Override
        public boolean retryMethod(HttpMethod httpMethod, IOException e, int i) {
            return false;
        }
    });
    // Create the client handler.
    _clientHandler = new ApacheHttpClientHandler(client);
    // Register the specific for the HTTPS protocol.
    Protocol.registerProtocol("https", new Protocol("https", new NonValidatingSocketFactory(), 443));
}
Also used : IOException(java.io.IOException) HttpMethodRetryHandler(org.apache.commons.httpclient.HttpMethodRetryHandler) HttpConnectionManagerParams(org.apache.commons.httpclient.params.HttpConnectionManagerParams) ApacheHttpClient(com.sun.jersey.client.apache.ApacheHttpClient) HttpClient(org.apache.commons.httpclient.HttpClient) MultiThreadedHttpConnectionManager(org.apache.commons.httpclient.MultiThreadedHttpConnectionManager) ApacheHttpClientHandler(com.sun.jersey.client.apache.ApacheHttpClientHandler) Protocol(org.apache.commons.httpclient.protocol.Protocol) HttpMethod(org.apache.commons.httpclient.HttpMethod)

Example 25 with MultiThreadedHttpConnectionManager

use of org.apache.commons.httpclient.MultiThreadedHttpConnectionManager in project application by collectionspace.

the class ServicesConnection method initClient.

private void initClient() {
    if (manager != null)
        return;
    synchronized (getClass()) {
        if (manager != null)
            return;
        // We're only connecting to one host, so set the max connections per host to be
        // the same as the max total connections.
        HttpConnectionManagerParams params = new HttpConnectionManagerParams();
        params.setMaxTotalConnections(MAX_SERVICES_CONNECTIONS);
        params.setDefaultMaxConnectionsPerHost(MAX_SERVICES_CONNECTIONS);
        manager = new MultiThreadedHttpConnectionManager();
        manager.setParams(params);
    }
}
Also used : HttpConnectionManagerParams(org.apache.commons.httpclient.params.HttpConnectionManagerParams) MultiThreadedHttpConnectionManager(org.apache.commons.httpclient.MultiThreadedHttpConnectionManager)

Aggregations

MultiThreadedHttpConnectionManager (org.apache.commons.httpclient.MultiThreadedHttpConnectionManager)34 HttpClient (org.apache.commons.httpclient.HttpClient)26 HttpConnectionManagerParams (org.apache.commons.httpclient.params.HttpConnectionManagerParams)13 IOException (java.io.IOException)11 HttpConnectionManager (org.apache.commons.httpclient.HttpConnectionManager)7 HttpMethodRetryHandler (org.apache.commons.httpclient.HttpMethodRetryHandler)7 ApacheHttpClient (com.sun.jersey.client.apache.ApacheHttpClient)6 HttpMethod (org.apache.commons.httpclient.HttpMethod)6 GetMethod (org.apache.commons.httpclient.methods.GetMethod)6 Protocol (org.apache.commons.httpclient.protocol.Protocol)6 ApacheHttpClientHandler (com.sun.jersey.client.apache.ApacheHttpClientHandler)5 HttpClientParams (org.apache.commons.httpclient.params.HttpClientParams)5 Credentials (org.apache.commons.httpclient.Credentials)3 UsernamePasswordCredentials (org.apache.commons.httpclient.UsernamePasswordCredentials)3 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)2 AdvancedGeoCoder (com.google.code.geocoder.AdvancedGeoCoder)2 SocketTimeoutException (java.net.SocketTimeoutException)2 URISyntaxException (java.net.URISyntaxException)2 UnknownHostException (java.net.UnknownHostException)2 HttpException (org.apache.commons.httpclient.HttpException)2