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.wings.recorder.Script.java

public Script() {
    client = new HttpClient(new MultiThreadedHttpConnectionManager());
}

From source file:org.wso2.appfactory.dynamicslave.JenkinsClient.java

public JenkinsClient(String username, String password, String url) {
    httpClient = new HttpClient(new MultiThreadedHttpConnectionManager());
    httpClient.getState().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password));
    httpClient.getParams().setAuthenticationPreemptive(true);
    this.url = url;
    LOGGER.log(Level.FINEST, "Creating a client for " + url);
}

From source file:org.wso2.carbon.andes.authentication.andes.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 2s .  com
private HttpClient createHttpClient() {
    HttpConnectionManagerParams params = new HttpConnectionManagerParams();
    params.setDefaultMaxConnectionsPerHost(config.getMaximumHttpConnectionPerHost());
    params.setMaxTotalConnections(config.getMaximumTotalHttpConnection());
    HttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
    connectionManager.setParams(params);
    return new HttpClient(connectionManager);
}

From source file:org.wso2.carbon.appfactory.common.util.MutualAuthHttpClient.java

/**
 * Send rest POST request to Stratos SM.
 *
 * @param body        message body//from ww w.j a v a2  s. c om
 * @param endPointUrl end point to send the message
 * @throws org.wso2.carbon.appfactory.common.AppFactoryException
 */
public static ServerResponse sendPostRequest(String body, String endPointUrl, String username)
        throws AppFactoryException {
    HttpClient httpClient = new HttpClient(new MultiThreadedHttpConnectionManager());
    PostMethod postMethod = new PostMethod(endPointUrl);

    // password as garbage value since we authenticate with mutual ssl
    postMethod.setRequestHeader(AUTHORIZATION_HEADER, getAuthHeaderValue(username));
    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.common.util.MutualAuthHttpClient.java

/**
 * Send REST DELETE request to stratos SM.
 *
 * @param endPointUrl end point to send the message
 * @throws org.wso2.carbon.appfactory.common.AppFactoryException
 *//*  w  w  w .  ja va 2 s  .c om*/
public static ServerResponse sendDeleteRequest(String endPointUrl, String username) throws AppFactoryException {
    HttpClient httpClient = new HttpClient(new MultiThreadedHttpConnectionManager());
    DeleteMethod deleteMethod = new DeleteMethod(endPointUrl);
    deleteMethod.setRequestHeader(AUTHORIZATION_HEADER, getAuthHeaderValue(username));
    return send(httpClient, deleteMethod);
}

From source file:org.wso2.carbon.appfactory.common.util.MutualAuthHttpClient.java

/**
 * Send rest GET request to Stratos SM/*from   ww  w.j  av a  2s  .co m*/
 *
 * @param endPointUrl end point to send the message
 * @throws org.wso2.carbon.appfactory.common.AppFactoryException
 */
public static ServerResponse sendGetRequest(String endPointUrl, String username) throws AppFactoryException {
    HttpClient httpClient = new HttpClient(new MultiThreadedHttpConnectionManager());
    GetMethod getMethod = new GetMethod(endPointUrl);
    getMethod.setRequestHeader(AUTHORIZATION_HEADER, getAuthHeaderValue(username));
    return send(httpClient, getMethod);
}

From source file:org.wso2.carbon.appfactory.git.util.Util.java

public static void setMaxTotalConnection(ServiceClient client) {
    ServiceContext context = client.getServiceContext();
    MultiThreadedHttpConnectionManager connManager = (MultiThreadedHttpConnectionManager) context
            .getProperty(HTTPConstants.MULTITHREAD_HTTP_CONNECTION_MANAGER);
    if (connManager == null) {
        connManager = new MultiThreadedHttpConnectionManager();
        context.setProperty(HTTPConstants.MULTITHREAD_HTTP_CONNECTION_MANAGER, connManager);
        connManager.getParams().setMaxTotalConnections(200);
        connManager.getParams().setMaxConnectionsPerHost(HostConfiguration.ANY_HOST_CONFIGURATION, 200);
    }/*from   ww w. jav a2s.  c o  m*/
}

From source file:org.wso2.carbon.appfactory.issuetracking.IssueTrackerConnector.java

public IssueTrackerConnector() throws AppFactoryException {
    this.httpClient = new HttpClient(new MultiThreadedHttpConnectionManager());
    this.issueTrackerUrl = AppFactoryUtil.getAppfactoryConfiguration()
            .getFirstProperty("IssueTrackerConnector.issueTracker.Property.Url");
}

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

public HttpClient getNewHttpClient() {
    return new HttpClient(new MultiThreadedHttpConnectionManager());
}

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

/**
 * /* w  ww  .  j  a  v  a2 s.com*/
 * @param request
 * @throws AppFactoryException
 */
public static void sendRequest(String request) throws AppFactoryException {
    // create a post request to addAPI.
    HttpClient httpClient = new HttpClient(new MultiThreadedHttpConnectionManager());
    String endPoint = "https://" + AWS_HOST + "/2013-04-01/hostedzone/" + getHostedZoneId() + "/rrset";
    PostMethod postMethod = new PostMethod(endPoint);

    try {
        String stringToSign = getGMTTime();
        postMethod.setRequestHeader("Content-Type", "text/xml");
        postMethod.setRequestHeader("Host", AWS_HOST);
        postMethod.setRequestHeader("x-amz-date", stringToSign);
        String authHeaderval = "AWS3-HTTPS AWSAccessKeyId=" + getAccessKeyId() + ",Algorithm="
                + HMAC_SHA1_ALGORITHM + ",Signature="
                + calculateRFC2104HMAC(stringToSign, getSecretAccessKey());
        postMethod.setRequestHeader("X-Amzn-Authorization", authHeaderval);

        postMethod.setRequestEntity(new StringRequestEntity(request, "application/json", "UTF-8"));
        int responseCode = 0;
        String responseString = null;

        responseCode = httpClient.executeMethod(postMethod);

        responseString = postMethod.getResponseBodyAsString();

        if (log.isDebugEnabled()) {
            log.debug(" AWSRoute53DomainNameService response id: " + responseCode + " message:O "
                    + responseString);
        }

    } catch (UnsupportedEncodingException e) {
        String msg = "Error occured while invoking AWS Route API 53 to add/delete CNAME reocrds";
        log.error(msg, e);
        throw new AppFactoryException(msg, e);
    } catch (HttpException e) {
        String msg = "Error occured while invoking AWS Route API 53 to add/delete CNAME reocrds";
        log.error(msg, e);
        throw new AppFactoryException(msg, e);
    } catch (IOException e) {
        String msg = "Error occured while invoking AWS Route API 53 to add/delete CNAME reocrds";
        log.error(msg, e);
        throw new AppFactoryException(msg, e);
    } finally {
        postMethod.releaseConnection();
    }

}