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);
}
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;
}
}
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);
}
}
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);
}
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()));
}
Aggregations