Search in sources :

Example 11 with PoolingClientConnectionManager

use of org.apache.http.impl.conn.PoolingClientConnectionManager in project oxAuth by GluuFederation.

the class UmaMultithreadTest method before.

@BeforeClass
public void before() {
    ClientConnectionManager connectoinManager = new PoolingClientConnectionManager();
    final DefaultHttpClient defaultHttpClient = new DefaultHttpClient(connectoinManager);
    final ApacheHttpClient4Executor clientExecutor = new ApacheHttpClient4Executor(defaultHttpClient);
    String url = serverUri + "/oxauth/seam/resource/restv1/oxauth/uma-configuration";
    service = UmaClientFactory.instance().createMetaDataConfigurationService(url, clientExecutor);
}
Also used : PoolingClientConnectionManager(org.apache.http.impl.conn.PoolingClientConnectionManager) ApacheHttpClient4Executor(org.jboss.resteasy.client.core.executors.ApacheHttpClient4Executor) ClientConnectionManager(org.apache.http.conn.ClientConnectionManager) PoolingClientConnectionManager(org.apache.http.impl.conn.PoolingClientConnectionManager) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) BeforeClass(org.testng.annotations.BeforeClass)

Example 12 with PoolingClientConnectionManager

use of org.apache.http.impl.conn.PoolingClientConnectionManager in project stanbol by apache.

the class RestfulNlpAnalysisEngine method activate.

/**
     * Activate and read the properties. Configures and initialises a POSTagger for each language configured in
     * CONFIG_LANGUAGES.
     *
     * @param ce the {@link org.osgi.service.component.ComponentContext}
     */
@Activate
protected void activate(ComponentContext ce) throws ConfigurationException, IOException {
    super.activate(ce);
    log.info("activate {} '{}'", getClass().getSimpleName(), getName());
    config = ce.getProperties();
    Object value = config.get(ANALYSIS_SERVICE_URL);
    if (value == null) {
        throw new ConfigurationException(ANALYSIS_SERVICE_URL, "The RESTful Analysis Service URL is missing in the provided configuration!");
    } else {
        try {
            analysisServiceUrl = new URI(value.toString());
            log.info("  ... service: {}", analysisServiceUrl);
        } catch (URISyntaxException e) {
            throw new ConfigurationException(ANALYSIS_SERVICE_URL, "The parsed RESTful Analysis Service URL '" + value + "'is not a valid URL!", e);
        }
    }
    String usr;
    String pwd;
    value = config.get(ANALYSIS_SERVICE_USER);
    if (value != null && !value.toString().isEmpty()) {
        usr = value.toString();
        value = config.get(ANALYSIS_SERVICE_PWD);
        pwd = value == null ? null : value.toString();
    } else {
        // no user set
        usr = null;
        pwd = null;
    }
    //init the http client
    httpParams = new BasicHttpParams();
    httpParams.setParameter(CoreProtocolPNames.USER_AGENT, "Apache Stanbol RESTful NLP Analysis Engine");
    httpParams.setBooleanParameter(ClientPNames.HANDLE_REDIRECTS, true);
    httpParams.setIntParameter(ClientPNames.MAX_REDIRECTS, 3);
    httpParams.setBooleanParameter(CoreConnectionPNames.SO_KEEPALIVE, true);
    connectionManager = new PoolingClientConnectionManager();
    connectionManager.setMaxTotal(20);
    connectionManager.setDefaultMaxPerRoute(20);
    //NOTE: The list of supported languages is the combination of the
    //      languages enabled by the configuration (#languageConfig) and the
    //      languages supported by the RESTful NLP Analysis Service 
    //      (#supportedLanguages)
    //init the language configuration with the engine configuration
    languageConfig.setConfiguration(config);
    httpClient = new DefaultHttpClient(connectionManager, httpParams);
    if (usr != null) {
        log.info("  ... setting user to {}", usr);
        httpClient.getCredentialsProvider().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(usr, pwd));
        // And add request interceptor to have preemptive authentication
        httpClient.addRequestInterceptor(new PreemptiveAuthInterceptor(), 0);
    }
    //STANBOL-1389: deactivated initialization during activation as this can create
    //issues in cases where Stanbol and the NLP service do run in the same
    //servlet container.
    //initRESTfulNlpAnalysisService();
    value = config.get(WRITE_TEXT_ANNOTATIONS_STATE);
    if (value instanceof Boolean) {
        this.writeTextAnnotations = ((Boolean) value).booleanValue();
    } else if (value != null) {
        this.writeTextAnnotations = Boolean.parseBoolean(value.toString());
    } else {
        this.writeTextAnnotations = DEFAULT_WRITE_TEXT_ANNOTATION_STATE;
    }
}
Also used : PoolingClientConnectionManager(org.apache.http.impl.conn.PoolingClientConnectionManager) ConfigurationException(org.osgi.service.cm.ConfigurationException) URISyntaxException(java.net.URISyntaxException) BasicHttpParams(org.apache.http.params.BasicHttpParams) URI(java.net.URI) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) Activate(org.apache.felix.scr.annotations.Activate)

Example 13 with PoolingClientConnectionManager

use of org.apache.http.impl.conn.PoolingClientConnectionManager in project stanbol by apache.

the class RestfulLangidentEngine method activate.

/**
     * Activate and read the properties. Configures and initialises a POSTagger for each language configured in
     * CONFIG_LANGUAGES.
     *
     * @param ce the {@link org.osgi.service.component.ComponentContext}
     */
@Activate
protected void activate(ComponentContext ce) throws ConfigurationException, IOException {
    super.activate(ce);
    log.info("activate {} '{}'", getClass().getSimpleName(), getName());
    @SuppressWarnings("unchecked") Dictionary<String, Object> properties = ce.getProperties();
    Object value = properties.get(ANALYSIS_SERVICE_URL);
    if (value == null) {
        throw new ConfigurationException(ANALYSIS_SERVICE_URL, "The RESTful Language Identification Service URL is missing in the provided configuration!");
    } else {
        try {
            serviceUrl = new URI(value.toString());
            log.info("  ... service: {}", serviceUrl);
        } catch (URISyntaxException e) {
            throw new ConfigurationException(ANALYSIS_SERVICE_URL, "The parsed RESTful Language Identification Service URL '" + value + "'is not a valid URL!", e);
        }
    }
    String usr;
    String pwd;
    value = properties.get(ANALYSIS_SERVICE_USER);
    if (value != null && !value.toString().isEmpty()) {
        usr = value.toString();
        value = properties.get(ANALYSIS_SERVICE_PWD);
        pwd = value == null ? null : value.toString();
    } else {
        // no user set
        usr = null;
        pwd = null;
    }
    //init the http client
    httpParams = new BasicHttpParams();
    httpParams.setParameter(CoreProtocolPNames.USER_AGENT, "Apache Stanbol RESTful Language Identification Engine");
    httpParams.setBooleanParameter(ClientPNames.HANDLE_REDIRECTS, true);
    httpParams.setIntParameter(ClientPNames.MAX_REDIRECTS, 3);
    httpParams.setBooleanParameter(CoreConnectionPNames.SO_KEEPALIVE, true);
    connectionManager = new PoolingClientConnectionManager();
    connectionManager.setMaxTotal(20);
    connectionManager.setDefaultMaxPerRoute(20);
    httpClient = new DefaultHttpClient(connectionManager, httpParams);
    if (usr != null) {
        log.info("  ... setting user to {}", usr);
        httpClient.getCredentialsProvider().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(usr, pwd));
        // And add request interceptor to have preemptive authentication
        httpClient.addRequestInterceptor(new PreemptiveAuthInterceptor(), 0);
    }
}
Also used : PoolingClientConnectionManager(org.apache.http.impl.conn.PoolingClientConnectionManager) ConfigurationException(org.osgi.service.cm.ConfigurationException) URISyntaxException(java.net.URISyntaxException) BasicHttpParams(org.apache.http.params.BasicHttpParams) URI(java.net.URI) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) Activate(org.apache.felix.scr.annotations.Activate)

Example 14 with PoolingClientConnectionManager

use of org.apache.http.impl.conn.PoolingClientConnectionManager in project okhttp by square.

the class ApacheHttpClient method prepare.

@Override
public void prepare(Benchmark benchmark) {
    super.prepare(benchmark);
    ClientConnectionManager connectionManager = new PoolingClientConnectionManager();
    if (benchmark.tls) {
        SslClient sslClient = SslClient.localhost();
        connectionManager.getSchemeRegistry().register(new Scheme("https", 443, new SSLSocketFactory(sslClient.sslContext)));
    }
    client = new DefaultHttpClient(connectionManager);
}
Also used : PoolingClientConnectionManager(org.apache.http.impl.conn.PoolingClientConnectionManager) Scheme(org.apache.http.conn.scheme.Scheme) SslClient(okhttp3.internal.tls.SslClient) SSLSocketFactory(org.apache.http.conn.ssl.SSLSocketFactory) ClientConnectionManager(org.apache.http.conn.ClientConnectionManager) PoolingClientConnectionManager(org.apache.http.impl.conn.PoolingClientConnectionManager) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient)

Example 15 with PoolingClientConnectionManager

use of org.apache.http.impl.conn.PoolingClientConnectionManager in project wildfly by wildfly.

the class BeanValidationCdiIntegrationTestCase method testValidRequest.

@Test
public void testValidRequest() throws Exception {
    DefaultHttpClient client = new DefaultHttpClient(new PoolingClientConnectionManager());
    HttpGet get = new HttpGet(url + "myjaxrs/order/5");
    HttpResponse result = client.execute(get);
    Assert.assertEquals(200, result.getStatusLine().getStatusCode());
    Assert.assertEquals("OrderModel{id=5}", EntityUtils.toString(result.getEntity()));
}
Also used : PoolingClientConnectionManager(org.apache.http.impl.conn.PoolingClientConnectionManager) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) Test(org.junit.Test)

Aggregations

PoolingClientConnectionManager (org.apache.http.impl.conn.PoolingClientConnectionManager)22 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)19 HttpResponse (org.apache.http.HttpResponse)9 HttpGet (org.apache.http.client.methods.HttpGet)9 Test (org.junit.Test)9 Scheme (org.apache.http.conn.scheme.Scheme)7 ClientConnectionManager (org.apache.http.conn.ClientConnectionManager)6 SchemeRegistry (org.apache.http.conn.scheme.SchemeRegistry)6 SSLSocketFactory (org.apache.http.conn.ssl.SSLSocketFactory)6 IOException (java.io.IOException)4 CertificateException (java.security.cert.CertificateException)4 X509Certificate (java.security.cert.X509Certificate)3 UsernamePasswordCredentials (org.apache.http.auth.UsernamePasswordCredentials)3 TrustStrategy (org.apache.http.conn.ssl.TrustStrategy)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)2 Activate (org.apache.felix.scr.annotations.Activate)2 ClientProtocolException (org.apache.http.client.ClientProtocolException)2 PlainSocketFactory (org.apache.http.conn.scheme.PlainSocketFactory)2