Search in sources :

Example 31 with MultiThreadedHttpConnectionManager

use of org.apache.commons.httpclient.MultiThreadedHttpConnectionManager in project cloudstack by apache.

the class UriUtils method getHttpClient.

/**
 * Return HttpClient with connection timeout
 */
private static HttpClient getHttpClient() {
    MultiThreadedHttpConnectionManager s_httpClientManager = new MultiThreadedHttpConnectionManager();
    s_httpClientManager.getParams().setConnectionTimeout(5000);
    return new HttpClient(s_httpClientManager);
}
Also used : HttpClient(org.apache.commons.httpclient.HttpClient) MultiThreadedHttpConnectionManager(org.apache.commons.httpclient.MultiThreadedHttpConnectionManager)

Example 32 with MultiThreadedHttpConnectionManager

use of org.apache.commons.httpclient.MultiThreadedHttpConnectionManager in project zaproxy by zaproxy.

the class HttpSender method createHttpClientViaProxy.

private HttpClient createHttpClientViaProxy() {
    if (!param.isUseProxyChain()) {
        return createHttpClient();
    }
    httpConnManagerProxy = new MultiThreadedHttpConnectionManager();
    setCommonManagerParams(httpConnManagerProxy);
    HttpClient clientProxy = new HttpClient(httpConnManagerProxy);
    clientProxy.getHostConfiguration().setProxy(param.getProxyChainName(), param.getProxyChainPort());
    setProxyAuth(clientProxy);
    return clientProxy;
}
Also used : HttpClient(org.apache.commons.httpclient.HttpClient) MultiThreadedHttpConnectionManager(org.apache.commons.httpclient.MultiThreadedHttpConnectionManager)

Example 33 with MultiThreadedHttpConnectionManager

use of org.apache.commons.httpclient.MultiThreadedHttpConnectionManager in project zaproxy by zaproxy.

the class HttpSender method createHttpClient.

private HttpClient createHttpClient() {
    httpConnManager = new MultiThreadedHttpConnectionManager();
    setCommonManagerParams(httpConnManager);
    return new HttpClient(httpConnManager);
}
Also used : HttpClient(org.apache.commons.httpclient.HttpClient) MultiThreadedHttpConnectionManager(org.apache.commons.httpclient.MultiThreadedHttpConnectionManager)

Example 34 with MultiThreadedHttpConnectionManager

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

the class NTLMMediator method mediate.

public boolean mediate(MessageContext messageContext) {
    if (log.isDebugEnabled()) {
        log.debug("[NTLMMediator] mediate method Invoked.");
    }
    // Creating a HTTP authenticator to cater the NTLM Authentication scheme
    HttpTransportProperties.Authenticator authenticator = new HttpTransportProperties.Authenticator();
    List<String> authScheme = new ArrayList<String>();
    authScheme.add(HttpTransportProperties.Authenticator.NTLM);
    authenticator.setAuthSchemes(authScheme);
    // checks the attribute values are dynamic or not and set the dynamic values if available
    String username = this.username;
    if (dynamicUsername != null) {
        username = dynamicUsername.evaluateValue(messageContext);
        if (StringUtils.isEmpty(username)) {
            log.warn("Evaluated value for " + this.username + " is empty");
        }
    }
    String password = this.password;
    if (dynamicPassword != null) {
        password = dynamicPassword.evaluateValue(messageContext);
        if (StringUtils.isEmpty(password)) {
            log.warn("Evaluated value for " + this.password + " is empty");
        }
    }
    String domain = this.domain;
    if (dynamicDomain != null) {
        domain = dynamicDomain.evaluateValue(messageContext);
        if (StringUtils.isEmpty(domain)) {
            log.warn("Evaluated value for " + this.domain + " is empty");
        }
    }
    String host = this.host;
    if (dynamicHost != null) {
        host = dynamicHost.evaluateValue(messageContext);
        if (StringUtils.isEmpty(host)) {
            log.warn("Evaluated value for " + this.host + " is empty");
        }
    }
    String ntlmVersion = this.ntlmVersion;
    if (dynamicNtmlVersion != null) {
        ntlmVersion = dynamicNtmlVersion.evaluateValue(messageContext);
        if (StringUtils.isEmpty(ntlmVersion)) {
            log.warn("Evaluated value for " + this.ntlmVersion + " is empty");
        }
    }
    if (username != null) {
        authenticator.setUsername(username);
    } else {
        if (log.isDebugEnabled()) {
            log.debug("[NTLMMediator] Username not specified.");
        }
    }
    if (password != null) {
        authenticator.setPassword(resolveSecureVaultExpressions(password, messageContext));
    } else {
        if (log.isDebugEnabled()) {
            log.debug("[NTLMMediator] Password not specified.");
        }
    }
    if (host != null) {
        authenticator.setHost(host);
    } else {
        if (log.isDebugEnabled()) {
            log.debug("[NTLMMediator] Host not specified.");
        }
    }
    if (domain != null) {
        authenticator.setDomain(domain);
    } else {
        if (log.isDebugEnabled()) {
            log.debug("[NTLMMediator] Domain not specified.");
        }
    }
    if (ntlmVersion != null) {
        if (log.isDebugEnabled()) {
            log.debug("[NTLMMediator] NTLM version is: " + ntlmVersion);
        }
    } else {
        if (log.isDebugEnabled()) {
            log.debug("[NTLMMediator] NTLM version is not specified.");
        }
    }
    // Set the newly created NTLM authenticator to the Axis2MessageContext
    org.apache.axis2.context.MessageContext axis2MessageContext = ((Axis2MessageContext) messageContext).getAxis2MessageContext();
    axis2MessageContext.getOptions().setProperty(HTTPConstants.AUTHENTICATE, authenticator);
    // Read the MultiThreadedHttpConnectionManager from the cache and set it to the Axis2MessageContext
    MultiThreadedHttpConnectionManager connectionManager;
    String cacheKey = new StringBuilder().append(authenticator.getUsername()).append("@").append(authenticator.getDomain()).append(":").append(authenticator.getPassword()).toString();
    if (connectionManagerCache.containsKey(cacheKey)) {
        connectionManager = connectionManagerCache.get(cacheKey);
    } else {
        connectionManager = connectionManagerCache.put(cacheKey, new MultiThreadedHttpConnectionManager());
    }
    axis2MessageContext.getOptions().setProperty(HTTPConstants.MULTITHREAD_HTTP_CONNECTION_MANAGER, connectionManager);
    axis2MessageContext.getEnvelope().buildWithAttachments();
    return true;
}
Also used : HttpTransportProperties(org.apache.axis2.transport.http.HttpTransportProperties) ArrayList(java.util.ArrayList) MultiThreadedHttpConnectionManager(org.apache.commons.httpclient.MultiThreadedHttpConnectionManager) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext)

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