Example usage for org.apache.commons.httpclient HostConfiguration ANY_HOST_CONFIGURATION

List of usage examples for org.apache.commons.httpclient HostConfiguration ANY_HOST_CONFIGURATION

Introduction

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

Prototype

HostConfiguration ANY_HOST_CONFIGURATION

To view the source code for org.apache.commons.httpclient HostConfiguration ANY_HOST_CONFIGURATION.

Click Source Link

Usage

From source file:edu.harvard.i2b2.common.util.axis2.ServiceClient.java

public static String sendREST(String restEPR, OMElement request) throws Exception {

    String response = null;//from  www  .j a v  a2 s . c  o m
    org.apache.axis2.client.ServiceClient serviceClient = null;
    try {

        serviceClient = new org.apache.axis2.client.ServiceClient();

        ServiceContext context = serviceClient.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(100);
            connManager.getParams().setMaxConnectionsPerHost(HostConfiguration.ANY_HOST_CONFIGURATION, 100);
        }
        HttpClient httpClient = new HttpClient(connManager);

        Options options = new Options();
        options.setTo(new EndpointReference(restEPR));
        options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
        options.setProperty(Constants.Configuration.ENABLE_REST, Constants.VALUE_TRUE);
        options.setProperty(HTTPConstants.CACHED_HTTP_CLIENT, httpClient);
        options.setProperty(HTTPConstants.REUSE_HTTP_CLIENT, Constants.VALUE_TRUE);
        serviceClient.setOptions(options);

        OMElement result = serviceClient.sendReceive(request);
        if (result != null) {
            response = result.toString();
            log.debug(response);
        }
    } catch (Exception e) {
        log.debug("Cleanup Error .", e);
        e.printStackTrace();
        throw new I2B2Exception("" + StackTraceUtil.getStackTrace(e));
    } finally {
        if (serviceClient != null) {
            try {
                serviceClient.cleanupTransport();
                serviceClient.cleanup();
            } catch (AxisFault e) {
                log.debug("Error .", e);
            }
        }
    }

    return response;
}

From source file:com.gs.jrpip.client.FastServletProxyFactory.java

public static void setMaxConnectionsPerHost(int maxConnections) {
    int currentMaxTotalConnection = FastServletProxyFactory.HTTP_CONNECTION_MANAGER.getParams()
            .getMaxTotalConnections();//from ww  w. j a  va2 s  . c  o m

    if (maxConnections > currentMaxTotalConnection) {
        FastServletProxyFactory.setMaxTotalConnections(maxConnections * 10);
    }
    FastServletProxyFactory.HTTP_CONNECTION_MANAGER.getParams()
            .setMaxConnectionsPerHost(HostConfiguration.ANY_HOST_CONFIGURATION, maxConnections);
}

From source file:com.gs.jrpip.client.FastServletProxyFactory.java

public static int getMaxConnectionsPerHost() {
    return FastServletProxyFactory.HTTP_CONNECTION_MANAGER.getParams()
            .getMaxConnectionsPerHost(HostConfiguration.ANY_HOST_CONFIGURATION);
}

From source file:com.ms.commons.utilities.HttpClientUtils.java

public static synchronized void init() {
    if (connectionManager != null) {
        return;//from  w ww  .j  a v a  2  s  .c o m
    }
    connectionManager = new MultiThreadedHttpConnectionManager();
    HttpConnectionManagerParams params = new HttpConnectionManagerParams();
    params.setConnectionTimeout(10000);
    params.setSoTimeout(20000);
    params.setMaxConnectionsPerHost(HostConfiguration.ANY_HOST_CONFIGURATION, 1000);
    params.setMaxTotalConnections(10000);
    connectionManager.setParams(params);
    client = new HttpClient(connectionManager);
    client.getParams().setParameter("http.protocol.max-redirects", 3);
}

From source file:mitm.common.sms.transport.clickatell.ClickatellSMSTransport.java

public void setMaxConnectionsPerHost(int maxConnectionsPerHost) {
    getConnectionManager().getParams().setMaxConnectionsPerHost(HostConfiguration.ANY_HOST_CONFIGURATION,
            maxConnectionsPerHost);/*from ww  w  .  j a v a  2  s.co  m*/
}

From source file:com.xerox.amazonws.common.AWSQueryConnection.java

private void configureHttpClient() {
    MultiThreadedHttpConnectionManager connMgr = new MultiThreadedHttpConnectionManager();
    HttpConnectionManagerParams connParams = connMgr.getParams();
    connParams.setMaxTotalConnections(maxConnections);
    connParams.setMaxConnectionsPerHost(HostConfiguration.ANY_HOST_CONFIGURATION, maxConnections);
    connMgr.setParams(connParams);/*w ww  .  j  a  v  a  2 s  . co  m*/
    hc = new HttpClient(connMgr);
    // NOTE: These didn't seem to help in my initial testing
    //         hc.getParams().setParameter("http.tcp.nodelay", true);
    //         hc.getParams().setParameter("http.connection.stalecheck", false); 
    if (proxyHost != null) {
        HostConfiguration hostConfig = new HostConfiguration();
        hostConfig.setProxy(proxyHost, proxyPort);
        hc.setHostConfiguration(hostConfig);
        log.info("Proxy Host set to " + proxyHost + ":" + proxyPort);
        if (proxyUser != null && !proxyUser.trim().equals("")) {
            if (proxyDomain != null) {
                hc.getState().setProxyCredentials(new AuthScope(proxyHost, proxyPort),
                        new NTCredentials(proxyUser, proxyPassword, proxyHost, proxyDomain));
            } else {
                hc.getState().setProxyCredentials(new AuthScope(proxyHost, proxyPort),
                        new UsernamePasswordCredentials(proxyUser, proxyPassword));
            }
        }
    }
}

From source file:nu.validator.xml.PrudentHttpEntityResolver.java

/**
 * Sets the timeouts of the HTTP client.
 * /* w  w  w. j a v  a  2 s.com*/
 * @param connectionTimeout
 *            timeout until connection established in milliseconds. Zero
 *            means no timeout.
 * @param socketTimeout
 *            timeout for waiting for data in milliseconds. Zero means no
 *            timeout.
 */
public static void setParams(int connectionTimeout, int socketTimeout, int maxRequests) {
    HttpConnectionManagerParams hcmp = client.getHttpConnectionManager().getParams();
    hcmp.setConnectionTimeout(connectionTimeout);
    hcmp.setSoTimeout(socketTimeout);
    hcmp.setMaxConnectionsPerHost(HostConfiguration.ANY_HOST_CONFIGURATION, maxRequests);
    hcmp.setMaxTotalConnections(200); // XXX take this from a property
    PrudentHttpEntityResolver.maxRequests = maxRequests;
    HttpClientParams hcp = client.getParams();
    hcp.setBooleanParameter(HttpClientParams.ALLOW_CIRCULAR_REDIRECTS, true);
    hcp.setIntParameter(HttpClientParams.MAX_REDIRECTS, 20); // Gecko
    // default
}

From source file:org.alfresco.rest.api.tests.client.SharedHttpClientProvider.java

public SharedHttpClientProvider(String alfrescoUrl, int maxNumberOfConnections) {
    setAlfrescoUrl(alfrescoUrl);//  w  ww .  j  a v a 2  s.  c om

    // Initialize manager
    MultiThreadedHttpConnectionManager manager = new MultiThreadedHttpConnectionManager();
    HttpConnectionManagerParams params = new HttpConnectionManagerParams();
    params.setMaxTotalConnections(maxNumberOfConnections);
    params.setMaxConnectionsPerHost(HostConfiguration.ANY_HOST_CONFIGURATION, maxNumberOfConnections);

    // Create the client
    client = new HttpClient(manager);
    client.getParams().setAuthenticationPreemptive(true);
}

From source file:org.apache.abdera.protocol.client.AbderaClient.java

/**
 * Set the maximum number of connections allowed for a single host
 *//*from  w w  w.j av a  2  s  .  c om*/
public AbderaClient setMaxConnectionsPerHost(int max) {
    Map<HostConfiguration, Integer> m = new HashMap<HostConfiguration, Integer>();
    m.put(HostConfiguration.ANY_HOST_CONFIGURATION, max);
    client.getHttpConnectionManager().getParams().setParameter(HttpConnectionManagerParams.MAX_HOST_CONNECTIONS,
            m);
    return this;
}

From source file:org.apache.abdera.protocol.client.AbderaClient.java

/**
 * Return the maximum number of connections allowed for a single host
 *//*from   w w w .  j a  va  2 s . c o m*/
public int getMaxConnectionsPerHost() {
    Map<HostConfiguration, Integer> m = (Map<HostConfiguration, Integer>) client.getHttpConnectionManager()
            .getParams().getParameter(HttpConnectionManagerParams.MAX_HOST_CONNECTIONS);
    if (m == null)
        return MultiThreadedHttpConnectionManager.DEFAULT_MAX_HOST_CONNECTIONS;
    Integer i = m.get(HostConfiguration.ANY_HOST_CONFIGURATION);
    return i != null ? i.intValue() : MultiThreadedHttpConnectionManager.DEFAULT_MAX_HOST_CONNECTIONS;
}