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:org.springframework.ws.transport.http.CommonsHttpMessageSender.java

/**
 * Sets the maximum number of connections per host for the underlying HttpClient. The maximum number of connections
 * per host can be set in a form accepted by the {@code java.util.Properties} class, like as follows:
 * <pre>//from w w w  . j av a  2  s.  c  o  m
 * https://www.example.com=1
 * http://www.example.com:8080=7
 * www.springframework.org=10
 * *=5
 * </pre>
 * The host can be specified as hostname, or as URI (with scheme and port). The special host name {@code *} can be
 * used to specify {@link org.apache.commons.httpclient.HostConfiguration#ANY_HOST_CONFIGURATION}.
 *
 * @param maxConnectionsPerHost a properties object specifying the maximum number of connection
 * @see org.apache.commons.httpclient.params.HttpConnectionManagerParams#setMaxConnectionsPerHost(org.apache.commons.httpclient.HostConfiguration,
 *      int)
 */
public void setMaxConnectionsPerHost(Map<String, String> maxConnectionsPerHost) throws URIException {
    for (String host : maxConnectionsPerHost.keySet()) {
        HostConfiguration hostConfiguration = new HostConfiguration();
        if ("*".equals(host)) {
            hostConfiguration = HostConfiguration.ANY_HOST_CONFIGURATION;
        } else if (host.startsWith("http://")) {
            HttpURL httpURL = new HttpURL(host);
            hostConfiguration.setHost(httpURL);
        } else if (host.startsWith("https://")) {
            HttpsURL httpsURL = new HttpsURL(host);
            hostConfiguration.setHost(httpsURL);
        } else {
            hostConfiguration.setHost(host);
        }
        int maxHostConnections = Integer.parseInt(maxConnectionsPerHost.get(host));
        getHttpClient().getHttpConnectionManager().getParams().setMaxConnectionsPerHost(hostConfiguration,
                maxHostConnections);
    }
}

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);
    }//  ww w.  ja  v a 2 s  .co m
}

From source file:voldemort.store.readonly.swapper.StoreSwapperTest.java

@Test
public void testHttpStoreSwapper() throws Exception {
    ExecutorService executor = Executors.newCachedThreadPool();

    try {// w w w. j  a v a 2  s .  c  o m
        // Use the http store swapper
        HttpConnectionManager manager = new MultiThreadedHttpConnectionManager();
        manager.getParams().setMaxTotalConnections(10);
        manager.getParams().setMaxConnectionsPerHost(HostConfiguration.ANY_HOST_CONFIGURATION, 10);
        HttpClient client = new HttpClient(manager);
        StoreSwapper swapper = new HttpStoreSwapper(cluster, executor, client, "read-only/mgmt", true, true);
        testFetchSwap(swapper);
    } finally {
        executor.shutdown();
    }
}

From source file:voldemort.store.readonly.swapper.StoreSwapperTest.java

@Test
public void testHttpStoreSwapperWithoutRollback() throws Exception {
    ExecutorService executor = Executors.newCachedThreadPool();

    try {//from   www  .  j a v a2s  .  co  m
        // Use the http store swapper
        HttpConnectionManager manager = new MultiThreadedHttpConnectionManager();
        manager.getParams().setMaxTotalConnections(10);
        manager.getParams().setMaxConnectionsPerHost(HostConfiguration.ANY_HOST_CONFIGURATION, 10);
        HttpClient client = new HttpClient(manager);
        StoreSwapper swapper = new HttpStoreSwapper(cluster, executor, client, "read-only/mgmt", false, false);
        testFetchSwapWithoutRollback(swapper);
    } finally {
        executor.shutdown();
    }
}