Example usage for org.apache.commons.httpclient MultiThreadedHttpConnectionManager MultiThreadedHttpConnectionManager

List of usage examples for org.apache.commons.httpclient MultiThreadedHttpConnectionManager MultiThreadedHttpConnectionManager

Introduction

In this page you can find the example usage for org.apache.commons.httpclient MultiThreadedHttpConnectionManager MultiThreadedHttpConnectionManager.

Prototype

public MultiThreadedHttpConnectionManager() 

Source Link

Usage

From source file:org.wso2.carbon.appfactory.s4.integration.utils.CloudUtils.java

/**
 * Get the current date from the Amazon Route 53 server
 * // ww w .  ja va  2 s .c o m
 * @return
 * @throws AppFactoryException
 */
public static String getGMTTime() throws AppFactoryException {

    HttpClient httpClient = new HttpClient(new MultiThreadedHttpConnectionManager());
    GetMethod getMethod = new GetMethod("https://" + AWS_HOST + "/date");
    try {
        httpClient.executeMethod(getMethod);
    } catch (IOException e) {
        String msg = "Error occured while retriving the current date from the Amazon Route 53 server";
        log.error(msg, e);
        throw new AppFactoryException(msg, e);
    } finally {
        getMethod.releaseConnection();
    }
    String date = getMethod.getResponseHeader("Date").getValue();
    return date;

}

From source file:org.wso2.carbon.appfactory.s4.integration.utils.DomainMappingUtils.java

/**
 * Send rest POST request to Stratos SM.
 *
 * @param stage                         the stage of the Stratos SM
 * @param body                          message body
 * @param addSubscriptionDomainEndPoint end point to send the message
 * @throws AppFactoryException// ww  w. j a  v a  2  s.co  m
 */
public static DomainMappingResponse sendPostRequest(String stage, String body,
        String addSubscriptionDomainEndPoint) throws AppFactoryException {
    HttpClient httpClient = new HttpClient(new MultiThreadedHttpConnectionManager());
    String endPointUrl = getSMUrl(stage) + addSubscriptionDomainEndPoint;
    PostMethod postMethod = new PostMethod(endPointUrl);

    // password as garbage value since we authenticate with mutual ssl
    postMethod.setRequestHeader(AUTHORIZATION_HEADER, getAuthHeaderValue());
    StringRequestEntity requestEntity;
    try {
        requestEntity = new StringRequestEntity(body, "application/json", "UTF-8");
    } catch (UnsupportedEncodingException e) {
        String msg = "Error while setting parameters";
        log.error(msg, e);
        throw new AppFactoryException(msg, e);
    }
    postMethod.setRequestEntity(requestEntity);
    return send(httpClient, postMethod);
}

From source file:org.wso2.carbon.appfactory.s4.integration.utils.DomainMappingUtils.java

/**
 * Send REST DELETE request to stratos SM.
 *
 * @param stage                            the stage of the Stratos SM
 * @param removeSubscriptionDomainEndPoint end point to send the message
 * @throws AppFactoryException/*from w ww  . ja  v  a 2 s. c o m*/
 */
public static DomainMappingResponse sendDeleteRequest(String stage, String removeSubscriptionDomainEndPoint)
        throws AppFactoryException {
    HttpClient httpClient = new HttpClient(new MultiThreadedHttpConnectionManager());
    String endPointUrl = getSMUrl(stage) + removeSubscriptionDomainEndPoint;
    DeleteMethod deleteMethod = new DeleteMethod(endPointUrl);
    deleteMethod.setRequestHeader(AUTHORIZATION_HEADER, getAuthHeaderValue());
    return send(httpClient, deleteMethod);
}

From source file:org.wso2.carbon.appfactory.s4.integration.utils.DomainMappingUtils.java

/**
 * Send rest GET request to Stratos SM/*from  w  w w.  ja v  a 2 s  .c o m*/
 *
 * @param stage                         the stage of the Stratos SM
 * @param getSubscriptionDomainEndPoint end point to send the message
 * @throws AppFactoryException
 */
public static DomainMappingResponse sendGetRequest(String stage, String getSubscriptionDomainEndPoint)
        throws AppFactoryException {
    HttpClient httpClient = new HttpClient(new MultiThreadedHttpConnectionManager());
    String endPointUrl = getSMUrl(stage) + getSubscriptionDomainEndPoint;
    GetMethod getMethod = new GetMethod(endPointUrl);
    getMethod.setRequestHeader(AUTHORIZATION_HEADER, getAuthHeaderValue());
    return send(httpClient, getMethod);
}

From source file:org.wso2.carbon.automation.test.utils.axis2client.ConfigurationContextProvider.java

private ConfigurationContextProvider() {
    try {/*from   ww  w  . j a  va  2  s .com*/
        MultiThreadedHttpConnectionManager httpConnectionManager;
        HttpClient httpClient;
        HttpConnectionManagerParams params;
        configurationContext = ConfigurationContextFactory.createConfigurationContextFromFileSystem(
                FrameworkPathUtil.getSystemResourceLocation() + File.separator + "client", null);
        httpConnectionManager = new MultiThreadedHttpConnectionManager();
        params = new HttpConnectionManagerParams();
        params.setDefaultMaxConnectionsPerHost(25);
        httpConnectionManager.setParams(params);
        httpClient = new HttpClient(httpConnectionManager);
        configurationContext.setProperty(HTTPConstants.CACHED_HTTP_CLIENT, httpClient);
        configurationContext.setProperty(HTTPConstants.REUSE_HTTP_CLIENT, Constants.VALUE_TRUE);
    } catch (AxisFault axisFault) {
        log.error(axisFault);
    }
}

From source file:org.wso2.carbon.bpel.core.ode.integration.BPELServerImpl.java

private void initHttpConnectionManager() throws Exception {
    httpConnectionManager = new MultiThreadedHttpConnectionManager();
    int maxConnectionsPerHost = bpelServerConfiguration.getMaxConnectionsPerHost();
    int maxTotalConnections = bpelServerConfiguration.getMaxTotalConnections();
    if (log.isDebugEnabled()) {
        log.debug(HttpConnectionManagerParams.MAX_HOST_CONNECTIONS + "=" + maxConnectionsPerHost);
        log.debug(HttpConnectionManagerParams.MAX_TOTAL_CONNECTIONS + "=" + maxTotalConnections);
    }/* w  w w  .java2  s . c  om*/
    if (maxConnectionsPerHost < 1 || maxTotalConnections < 1) {
        String errmsg = HttpConnectionManagerParams.MAX_HOST_CONNECTIONS + " and "
                + HttpConnectionManagerParams.MAX_TOTAL_CONNECTIONS + " must be positive integers!";
        log.error(errmsg);
        throw new Exception(errmsg);
    }
    httpConnectionManager.getParams().setDefaultMaxConnectionsPerHost(maxConnectionsPerHost);
    httpConnectionManager.getParams().setMaxTotalConnections(maxTotalConnections);

    // TODO: Modify this and move configuration to bps.xml
    // Register the connection manager to a idle check thread
    idleConnectionTimeoutThread = new IdleConnectionTimeoutThread();
    idleConnectionTimeoutThread.setName("Http_Idle_Connection_Timeout_Thread");
    long idleConnectionTimeout = Long
            .parseLong(odeConfigurationProperties.getProperty("http.idle.connection.timeout", "30000"));
    long idleConnectionCheckInterval = Long
            .parseLong(odeConfigurationProperties.getProperty("http.idle.connection.check.interval", "30000"));

    if (log.isDebugEnabled()) {
        log.debug("http.idle.connection.timeout=" + idleConnectionTimeout);
        log.debug("http.idle.connection.check.interval=" + idleConnectionCheckInterval);
    }
    idleConnectionTimeoutThread.setConnectionTimeout(idleConnectionTimeout);
    idleConnectionTimeoutThread.setTimeoutInterval(idleConnectionCheckInterval);

    idleConnectionTimeoutThread.addConnectionManager(httpConnectionManager);
    idleConnectionTimeoutThread.start();
}

From source file:org.wso2.carbon.core.init.CarbonServerManager.java

private ConfigurationContext getClientConfigurationContext() throws AxisFault {
    String clientRepositoryLocation = serverConfig.getFirstProperty(CLIENT_REPOSITORY_LOCATION);
    String clientAxis2XmlLocationn = serverConfig.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());
    }/*from   ww w. j  ava2 s .c  om*/
    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);
    registerHouseKeepingTask(clientConfigContextToReturn);
    clientConfigContextToReturn.setProperty(ServerConstants.WORK_DIR, serverWorkDir);
    return clientConfigContextToReturn;
}

From source file:org.wso2.carbon.device.mgt.extensions.remote.session.authentication.oauth.OAuthTokenValidatorStubFactory.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 va2  s. co m
private HttpClient createHttpClient() {
    HttpConnectionManagerParams params = new HttpConnectionManagerParams();
    params.setDefaultMaxConnectionsPerHost(Integer
            .parseInt(tokenValidationProperties.get(RemoteSessionConstants.MAXIMUM_HTTP_CONNECTION_PER_HOST)));
    params.setMaxTotalConnections(Integer
            .parseInt(tokenValidationProperties.get(RemoteSessionConstants.MAXIMUM_TOTAL_HTTP_CONNECTION)));
    HttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
    connectionManager.setParams(params);
    return new HttpClient(connectionManager);
}

From source file:org.wso2.carbon.device.mgt.input.adapter.http.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 .ja  va 2 s  .co  m
private HttpClient createHttpClient() {
    HttpConnectionManagerParams params = new HttpConnectionManagerParams();
    params.setDefaultMaxConnectionsPerHost(
            Integer.parseInt(globalProperties.get(HTTPEventAdapterConstants.MAXIMUM_HTTP_CONNECTION_PER_HOST)));
    params.setMaxTotalConnections(
            Integer.parseInt(globalProperties.get(HTTPEventAdapterConstants.MAXIMUM_TOTAL_HTTP_CONNECTION)));
    HttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
    connectionManager.setParams(params);
    return new HttpClient(connectionManager);
}

From source file:org.wso2.carbon.device.mgt.iot.input.adapter.http.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 a2 s  .c om*/
private HttpClient createHttpClient() {
    HttpConnectionManagerParams params = new HttpConnectionManagerParams();
    params.setDefaultMaxConnectionsPerHost(Integer.parseInt(eventAdapterConfiguration.getProperties()
            .get(HTTPEventAdapterConstants.MAXIMUM_HTTP_CONNECTION_PER_HOST)));
    params.setMaxTotalConnections(Integer.parseInt(eventAdapterConfiguration.getProperties()
            .get(HTTPEventAdapterConstants.MAXIMUM_TOTAL_HTTP_CONNECTION)));
    HttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
    connectionManager.setParams(params);
    return new HttpClient(connectionManager);
}