Example usage for org.apache.http.impl.conn.tsccm ThreadSafeClientConnManager ThreadSafeClientConnManager

List of usage examples for org.apache.http.impl.conn.tsccm ThreadSafeClientConnManager ThreadSafeClientConnManager

Introduction

In this page you can find the example usage for org.apache.http.impl.conn.tsccm ThreadSafeClientConnManager ThreadSafeClientConnManager.

Prototype

public ThreadSafeClientConnManager() 

Source Link

Usage

From source file:annis.libgui.Helper.java

/**
 * Creates an authentificiated REST client 
 * @param userName//from www .j  a v a2  s .com
 * @param password
 * @return A newly created client.
 */
public static Client createRESTClient(String userName, String password) {

    DefaultApacheHttpClient4Config rc = new DefaultApacheHttpClient4Config();
    rc.getClasses().add(SaltProjectProvider.class);

    rc.getProperties().put(ApacheHttpClient4Config.PROPERTY_CONNECTION_MANAGER,
            new ThreadSafeClientConnManager());

    if (userName != null && password != null) {
        CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
        credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(userName, password));

        rc.getProperties().put(ApacheHttpClient4Config.PROPERTY_CREDENTIALS_PROVIDER, credentialsProvider);
        rc.getProperties().put(ApacheHttpClient4Config.PROPERTY_PREEMPTIVE_BASIC_AUTHENTICATION, true);

    }

    Client c = ApacheHttpClient4.create(rc);
    return c;
}

From source file:com.baidu.oped.apm.profiler.errorTest.ConcurrentCall.java

@Test
public void test() throws IOException, InterruptedException {
    ((ThreadPoolExecutor) executorService).prestartAllCoreThreads();

    ThreadSafeClientConnManager cm = new ThreadSafeClientConnManager();
    cm.setMaxTotal(200);/*from   ww  w  .j av  a  2 s  . co  m*/
    cm.setDefaultMaxPerRoute(200);

    final HttpClient client = new DefaultHttpClient(cm);
    int call = 400;
    final CountDownLatch latch = new CountDownLatch(call);
    for (int i = 0; i < call; i++) {
        executorService.execute(new Runnable() {
            @Override
            public void run() {
                try {
                    String url = getUrl();
                    logger.info("execute {}", url);
                    final HttpGet httpGet = new HttpGet(url);
                    final HttpResponse execute = client.execute(httpGet);
                    execute.getEntity().getContent().close();

                } catch (ClientProtocolException e) {
                    e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
                } catch (IOException e) {
                    e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
                } finally {
                    latch.countDown();
                }
            }
        });
    }
    latch.await();
    executorService.shutdown();
    cm.shutdown();

}

From source file:org.eclipse.mylyn.commons.repositories.http.tests.HttpUtilTest.java

@Before
public void setUp() throws Exception {
    testProxy = new TestProxy();
    testProxy.startAndWait();/*from   w  w w . j a va  2 s  . c o  m*/
    connectionManager = new ThreadSafeClientConnManager();
    client = new DefaultHttpClient() {
        @Override
        protected ClientConnectionManager createClientConnectionManager() {
            return connectionManager;
        }
    };
}

From source file:com.flicklib.service.HttpClientSourceLoader.java

@Inject
public HttpClientSourceLoader(@Named(value = Constants.HTTP_TIMEOUT) final Integer timeout) {

    ThreadSafeClientConnManager tm = new ThreadSafeClientConnManager();
    tm.setDefaultMaxPerRoute(20);//from   w  ww  . j ava  2 s. co  m
    tm.setMaxTotal(200);
    client = new DefaultHttpClient(tm);

    if (timeout != null) {
        // wait max x sec
        HttpConnectionParams.setSoTimeout(client.getParams(), timeout);
    }
}

From source file:org.wso2.carbon.identity.entitlement.modules.MessageSendingModuleOnUserOperation.java

public MessageSendingModuleOnUserOperation(PEPEndpointInfo endpointInfo, String notificationType,
        String eventType) {/*from  w w  w  .  j  ava2 s.com*/

    this.endpointInfo = endpointInfo;
    this.notificationType = notificationType;
    this.eventType = eventType;
    connectionManager = new ThreadSafeClientConnManager();
}

From source file:com.basho.riak.client.util.ClientUtils.java

/**
 * Construct a new {@link HttpClient} instance given a {@link RiakConfig}.
 * // w w w.j a v a 2 s.c  o m
 * @param config
 *            {@link RiakConfig} containing HttpClient configuration
 *            specifics.
 * @return A new {@link HttpClient}
 */
public static HttpClient newHttpClient(RiakConfig config) {

    HttpClient http = config.getHttpClient();
    ClientConnectionManager m;

    if (http == null) {
        m = new ThreadSafeClientConnManager();
        if (config.getMaxConnections() != null) {
            ((ThreadSafeClientConnManager) m).setMaxTotal(config.getMaxConnections());
            ((ThreadSafeClientConnManager) m).setDefaultMaxPerRoute(config.getMaxConnections());
        }
        http = new DefaultHttpClient(m);

        if (config.getRetryHandler() != null) {
            ((DefaultHttpClient) http).setHttpRequestRetryHandler(config.getRetryHandler());
        }
    } else {
        m = http.getConnectionManager();
    }

    HttpParams cp = http.getParams();
    if (config.getTimeout() != null) {
        cp.setIntParameter(AllClientPNames.CONNECTION_TIMEOUT, config.getTimeout());
        cp.setIntParameter(AllClientPNames.SO_TIMEOUT, config.getTimeout());
    }

    return http;
}

From source file:org.wso2.carbon.identity.entitlement.modules.MessageSendingModuleOnPolicyUpdate.java

public MessageSendingModuleOnPolicyUpdate(PEPEndpointInfo endpointInfo, String notificationType) {

    this.endpointInfo = endpointInfo;
    this.notificationType = notificationType;
    connectionManager = new ThreadSafeClientConnManager();
}

From source file:org.commonjava.couch.io.CouchHttpClient.java

@PostConstruct
private void setupClient() {
    final ThreadSafeClientConnManager ccm = new ThreadSafeClientConnManager();
    ccm.setMaxTotal(config.getMaxConnections());

    final DefaultHttpClient c = new DefaultHttpClient(ccm);

    if (config.getDatabaseUser() != null) {
        final AuthScope scope = new AuthScope(config.getDatabaseHost(), config.getDatabasePort());
        final UsernamePasswordCredentials cred = new UsernamePasswordCredentials(config.getDatabaseUser(),
                config.getDatabasePassword());

        c.getCredentialsProvider().setCredentials(scope, cred);
    }//w ww .j  a va2  s  .  c  o m

    client = c;
}

From source file:org.jboss.narayana.rts.TransactionAwareResource.java

private static Client createClient() {
    ClientConnectionManager cm = new ThreadSafeClientConnManager();
    HttpClient httpClient = new DefaultHttpClient(cm);
    ApacheHttpClient4Engine engine = new ApacheHttpClient4Engine(httpClient);

    return new ResteasyClientBuilder().httpEngine(engine).build();
}

From source file:uk.ac.ox.oucs.vle.XcriPopulatorInput.java

public void init() {
    // We will have multiple threads using the same httpClient.
    httpClient = new DefaultHttpClient(new ThreadSafeClientConnManager());
    httpClient.getParams().setParameter(CoreProtocolPNames.USER_AGENT, "SES Import")
            .setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, connectionTimeout)
            .setIntParameter(CoreConnectionPNames.SO_TIMEOUT, socketTimeout);
}