Example usage for org.apache.http.impl.conn PoolingClientConnectionManager PoolingClientConnectionManager

List of usage examples for org.apache.http.impl.conn PoolingClientConnectionManager PoolingClientConnectionManager

Introduction

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

Prototype

public PoolingClientConnectionManager() 

Source Link

Usage

From source file:org.onehippo.cms7.brokenlinks.LinkChecker.java

public LinkChecker(CheckExternalBrokenLinksConfig config, Session session) {
    this.session = session;
    ClientConnectionManager connManager = new PoolingClientConnectionManager();
    HttpParams params = new SyncBasicHttpParams();
    params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, config.getSocketTimeout());
    params.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, config.getConnectionTimeout());
    params.setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false);
    params.setBooleanParameter(ClientPNames.HANDLE_AUTHENTICATION, false);

    HttpClient client = null;/*from  w  ww.  j  a v a2s.c  o  m*/
    try {
        final String httpClientClassName = config.getHttpClientClassName();
        Class<? extends HttpClient> clientClass = (Class<? extends HttpClient>) Class
                .forName(httpClientClassName);
        final Constructor<? extends HttpClient> constructor = clientClass
                .getConstructor(ClientConnectionManager.class, HttpParams.class);
        client = constructor.newInstance(connManager, params);
    } catch (ClassNotFoundException e) {
        log.error("Could not find configured http client class", e);
    } catch (NoSuchMethodException e) {
        log.error("Could not find constructor of signature <init>(ClientConnectionmanager, HttpParams)", e);
    } catch (InvocationTargetException e) {
        log.error("Could not invoke constructor of httpClient", e);
    } catch (InstantiationException e) {
        log.error("Could not instantiate http client", e);
    } catch (IllegalAccessException e) {
        log.error("Not allowed to access http client constructor", e);
    }
    if (client == null) {
        client = new DefaultHttpClient(connManager, params);
    }

    httpClient = client;
    nrOfThreads = config.getNrOfHttpThreads();
    // authentication preemptive true
    // allow circular redirects true
}

From source file:com.canoo.dolphin.client.ClientContextFactory.java

/**
 * Create a {@link ClientContext} based on the given configuration. This method doesn't block and returns a
 * {@link CompletableFuture} to receive its result. If the {@link ClientContext} can't be created the
 * {@link CompletableFuture#get()} will throw a {@link ClientInitializationException}.
 *
 * @param clientConfiguration the configuration
 * @return the future//from  ww w .  j  av a 2 s.  c  o m
 */
public static CompletableFuture<ClientContext> connect(final ClientConfiguration clientConfiguration) {
    Assert.requireNonNull(clientConfiguration, "clientConfiguration");
    final CompletableFuture<ClientContext> result = new CompletableFuture<>();

    Level openDolphinLogLevel = clientConfiguration.getDolphinLogLevel();
    Logger openDolphinLogger = Logger.getLogger("org.opendolphin");
    openDolphinLogger.setLevel(openDolphinLogLevel);

    Executors.newSingleThreadExecutor().execute(() -> {
        try {
            final ForwardableCallback<DolphinRemotingException> remotingErrorHandler = new ForwardableCallback<>();
            final ClientDolphin clientDolphin = new ClientDolphin();
            clientDolphin.setClientModelStore(new ClientModelStore(clientDolphin));
            final HttpClient httpClient = new DefaultHttpClient(new PoolingClientConnectionManager());
            final ClientConnector clientConnector = new DolphinPlatformHttpClientConnector(clientDolphin,
                    new OptimizedJsonCodec(), httpClient, clientConfiguration.getServerEndpoint(),
                    remotingErrorHandler, clientConfiguration.getUiThreadHandler());
            clientDolphin.setClientConnector(clientConnector);
            final DolphinCommandHandler dolphinCommandHandler = new DolphinCommandHandler(clientDolphin);
            final EventDispatcher dispatcher = new ClientEventDispatcher(clientDolphin);
            final BeanRepository beanRepository = new BeanRepositoryImpl(clientDolphin, dispatcher);
            final Converters converters = new Converters(beanRepository);
            final PresentationModelBuilderFactory builderFactory = new ClientPresentationModelBuilderFactory(
                    clientDolphin);
            final ClassRepository classRepository = new ClassRepositoryImpl(clientDolphin, converters,
                    builderFactory);
            final ListMapper listMapper = new ListMapperImpl(clientDolphin, classRepository, beanRepository,
                    builderFactory, dispatcher);
            final BeanBuilder beanBuilder = new ClientBeanBuilderImpl(classRepository, beanRepository,
                    listMapper, builderFactory, dispatcher);
            final ClientPlatformBeanRepository platformBeanRepository = new ClientPlatformBeanRepository(
                    clientDolphin, beanRepository, dispatcher, converters);
            final ClientBeanManagerImpl clientBeanManager = new ClientBeanManagerImpl(beanRepository,
                    beanBuilder, clientDolphin);
            final ControllerProxyFactory controllerProxyFactory = new ControllerProxyFactoryImpl(
                    platformBeanRepository, dolphinCommandHandler, clientDolphin);
            final ClientContext clientContext = new ClientContextImpl(clientConfiguration, clientDolphin,
                    controllerProxyFactory, dolphinCommandHandler, platformBeanRepository, clientBeanManager,
                    remotingErrorHandler);
            clientDolphin.startPushListening(PlatformConstants.POLL_EVENT_BUS_COMMAND_NAME,
                    PlatformConstants.RELEASE_EVENT_BUS_COMMAND_NAME);
            clientConfiguration.getUiThreadHandler()
                    .executeInsideUiThread(() -> result.complete(clientContext));
        } catch (Exception e) {
            result.obtrudeException(new ClientInitializationException("Can not connect to server!", e));
            throw new ClientInitializationException(e);
        }
    });
    return result;
}

From source file:org.n52.server.util.SosAdapterFactory.java

private static HttpClient createHttpClient(SOSMetadata metadata) {
    PoolingClientConnectionManager cm = new PoolingClientConnectionManager();
    cm.setMaxTotal(metadata.getHttpConnectionPoolSize());

    int timeout = metadata.getTimeout();
    SimpleHttpClient simpleClient = new SimpleHttpClient(timeout, timeout, cm);
    return new GzipEnabledHttpClient(new ProxyAwareHttpClient(simpleClient));
}

From source file:org.jboss.as.test.integration.jaxrs.validator.cdi.BeanValidationCdiIntegrationTestCase.java

@Test
public void testInvalidRequest() throws Exception {
    DefaultHttpClient client = new DefaultHttpClient(new PoolingClientConnectionManager());

    HttpGet get = new HttpGet(url + "myjaxrs/order/11");
    HttpResponse result = client.execute(get);
    result = client.execute(get);// w w w  .  ja v a  2s  . c  o m

    Assert.assertEquals("Parameter constraint violated", 400, result.getStatusLine().getStatusCode());
}

From source file:org.jboss.as.test.integration.jaxrs.validator.BeanValidationConfiguredGloballyTestCase.java

@Test
public void testInvalidRequestsAreAcceptedDependingOnGlobalValidationConfiguration() throws Exception {
    DefaultHttpClient client = new DefaultHttpClient(new PoolingClientConnectionManager());

    HttpGet get = new HttpGet(url + "myjaxrs/globally-configured-validate/3/disabled");
    HttpResponse result = client.execute(get);

    Assert.assertEquals("No constraint violated", 200, result.getStatusLine().getStatusCode());
    EntityUtils.consume(result.getEntity());

    get = new HttpGet(url + "myjaxrs/globally-configured-validate/3/enabled");
    result = client.execute(get);//from   ww  w. j a va 2 s . co m
    Assert.assertEquals("Parameter constraint violated", 400, result.getStatusLine().getStatusCode());
}

From source file:com.twitter.hbc.SitestreamController.java

/**
 * Construct a sitestream controller using the default host (sitestream.twitter.com) and a
 * DefaultHttpClient.//from   www  .  j a v a2s.c o m
 */
public SitestreamController(Authentication auth) {
    this.client = new DefaultHttpClient(new PoolingClientConnectionManager());
    this.hosts = new HttpHosts(Constants.SITESTREAM_HOST);
    this.auth = Preconditions.checkNotNull(auth);
}

From source file:org.gluu.oxtrust.service.UmaProtectionService.java

@Create
public void init() {
    if (this.umaMetadataConfiguration != null) {
        ClientConnectionManager connectoinManager = new PoolingClientConnectionManager();
        final DefaultHttpClient defaultHttpClient = new DefaultHttpClient(connectoinManager);
        final ApacheHttpClient4Executor clientExecutor = new ApacheHttpClient4Executor(defaultHttpClient);

        this.resourceSetPermissionRegistrationService = UmaClientFactory.instance()
                .createResourceSetPermissionRegistrationService(this.umaMetadataConfiguration, clientExecutor);
        this.resourceSetRegistrationService = UmaClientFactory.instance()
                .createResourceSetRegistrationService(this.umaMetadataConfiguration, clientExecutor);
        this.rptStatusService = UmaClientFactory.instance()
                .createRptStatusService(this.umaMetadataConfiguration, clientExecutor);
    }//from   w  w w.  jav a2s. c o m
}

From source file:pl.psnc.synat.wrdz.common.https.HttpsClientHelper.java

/**
 * Gets HTTPS client that can authenticate in WRDZ modules.
 * /* ww w. ja v  a  2s.c o  m*/
 * @param module
 *            module that wants to be authenticated
 * @return HTTPS client
 */
public synchronized HttpClient getHttpsClient(WrdzModule module) {
    DefaultHttpClient httpClient = httpsClients.get(module);
    if (httpClient == null) {
        logger.debug("HTTPS client for module " + module.name() + " is not yet initialized");
        try {
            SSLSocketFactory socketFactory;
            if (config.getHttpsVerifyHostname()) {
                socketFactory = new SSLSocketFactory(new TrustAllStrategy());
            } else {
                socketFactory = new SSLSocketFactory(new TrustAllStrategy(),
                        SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
            }
            Scheme scheme = new Scheme("https", 443, socketFactory);
            PoolingClientConnectionManager connectionManager = new PoolingClientConnectionManager();
            connectionManager.getSchemeRegistry().register(scheme);

            String cipher = config.getModulesPassword();
            byte[] key = SECRET.getBytes("utf-8");
            Cipher c = Cipher.getInstance("AES");
            SecretKeySpec k = new SecretKeySpec(key, "AES");
            c.init(Cipher.DECRYPT_MODE, k);
            byte[] decrypted = c.doFinal(Base64.decodeBase64(cipher));
            String password = new String(decrypted, "utf-8");
            UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(module.name(), password);

            httpClient = new DefaultHttpClient(connectionManager);
            httpClient.getCredentialsProvider().setCredentials(AuthScope.ANY, credentials);
            httpsClients.put(module, httpClient);
        } catch (Exception e) {
            throw new WrdzRuntimeException(e.getMessage(), e);
        }
    }
    return httpClient;
}