use of com.atlassian.httpclient.api.factory.HttpClientOptions in project jira-plugin by jenkinsci.
the class ApacheAsyncHttpClientTest method simple_post.
@Test
public void simple_post() throws Exception {
TestHandler testHandler = new TestHandler();
prepare(testHandler);
ApacheAsyncHttpClient httpClient = new ApacheAsyncHttpClient(null, buildApplicationProperties(), new NoOpThreadLocalContextManager(), new HttpClientOptions());
Response response = //
httpClient.newRequest("http://localhost:" + connector.getLocalPort() + "/foo").setEntity(//
"FOO").setContentType(//
"text").post().get(10, TimeUnit.SECONDS);
Assert.assertEquals(200, response.getStatusCode());
Assert.assertEquals(CONTENT_RESPONSE, IOUtils.toString(response.getEntityStream()));
Assert.assertEquals("FOO", testHandler.postReceived);
}
use of com.atlassian.httpclient.api.factory.HttpClientOptions in project jira-plugin by jenkinsci.
the class JiraSite method getHttpClientOptions.
private HttpClientOptions getHttpClientOptions() {
final HttpClientOptions options = new HttpClientOptions();
options.setRequestTimeout(readTimeout, TimeUnit.SECONDS);
options.setSocketTimeout(timeout, TimeUnit.SECONDS);
options.setCallbackExecutor(getExecutorService());
options.setIoThreadCount(ioThreadCount);
return options;
}
use of com.atlassian.httpclient.api.factory.HttpClientOptions in project jira-plugin by jenkinsci.
the class ApacheAsyncHttpClient method createClientBuilder.
private HttpAsyncClientBuilder createClientBuilder() throws IOReactorException {
final HttpClientOptions options = httpClientOptions;
final IOReactorConfig reactorConfig = IOReactorConfig.custom().setIoThreadCount(options.getIoThreadCount()).setSelectInterval(options.getIoSelectInterval()).setInterestOpQueued(true).build();
final DefaultConnectingIOReactor ioReactor = new DefaultConnectingIOReactor(reactorConfig);
ioReactor.setExceptionHandler(new IOReactorExceptionHandler() {
@Override
public boolean handle(final IOException e) {
log.error("IO exception in reactor ", e);
return false;
}
@Override
public boolean handle(final RuntimeException e) {
log.error("Fatal runtime error", e);
return false;
}
});
final PoolingNHttpClientConnectionManager connectionManager = new PoolingNHttpClientConnectionManager(ioReactor, ManagedNHttpClientConnectionFactory.INSTANCE, getRegistry(options), DefaultSchemePortResolver.INSTANCE, SystemDefaultDnsResolver.INSTANCE, options.getConnectionPoolTimeToLive(), TimeUnit.MILLISECONDS) {
@Override
protected void finalize() throws Throwable {
// is still active.
try {
this.shutdown();
} catch (Throwable e) {
// ignore e.printStackTrace();
}
}
};
connectionManager.setDefaultMaxPerRoute(options.getMaxConnectionsPerHost());
final RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout((int) options.getConnectionTimeout()).setConnectionRequestTimeout((int) options.getLeaseTimeout()).setCookieSpec(options.getIgnoreCookies() ? CookieSpecs.IGNORE_COOKIES : CookieSpecs.DEFAULT).setSocketTimeout((int) options.getSocketTimeout()).build();
final HttpAsyncClientBuilder clientBuilder = HttpAsyncClients.custom().setThreadFactory(ThreadFactories.namedThreadFactory(options.getThreadPrefix() + "-io", ThreadFactories.Type.DAEMON)).setDefaultIOReactorConfig(reactorConfig).setConnectionManager(connectionManager).setRedirectStrategy(new RedirectStrategy()).setUserAgent(getUserAgent(options)).setDefaultRequestConfig(requestConfig);
if (Jenkins.get() != null) {
ProxyConfiguration proxyConfiguration = Jenkins.getInstance().proxy;
if (proxyConfiguration != null) {
final HttpHost proxy = new HttpHost(proxyConfiguration.name, proxyConfiguration.port);
// clientBuilder.setProxy( proxy );
if (StringUtils.isNotBlank(proxyConfiguration.getUserName())) {
clientBuilder.setProxyAuthenticationStrategy(ProxyAuthenticationStrategy.INSTANCE);
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(new AuthScope(proxyConfiguration.name, proxyConfiguration.port), new UsernamePasswordCredentials(proxyConfiguration.getUserName(), proxyConfiguration.getPassword()));
clientBuilder.setDefaultCredentialsProvider(credsProvider);
}
clientBuilder.setRoutePlanner(new JenkinsProxyRoutePlanner(proxy, proxyConfiguration.getNoProxyHostPatterns()));
}
}
return clientBuilder;
}
use of com.atlassian.httpclient.api.factory.HttpClientOptions in project staf by simpleworks-gmbh.
the class AsynchronousHttpClientFactory method createClient.
@SuppressWarnings("static-method")
public DisposableHttpClient createClient(final URI serverUri, final AuthenticationHandler authenticationHandler) {
final HttpClientOptions options = new HttpClientOptions();
@SuppressWarnings({ "rawtypes", "unchecked" }) final DefaultHttpClientFactory defaultHttpClientFactory = new DefaultHttpClientFactory(new NoOpEventPublisher(), new RestClientApplicationProperties(serverUri), new ThreadLocalContextManager() {
@Override
public Object getThreadLocalContext() {
return null;
}
@Override
public void setThreadLocalContext(final Object context) {
// nothing to do.
}
@Override
public void clearThreadLocalContext() {
// nothing to do.
}
});
final HttpClient httpClient = defaultHttpClientFactory.create(options);
return new AtlassianHttpClientDecorator(httpClient, authenticationHandler) {
@Override
public void destroy() throws Exception {
defaultHttpClientFactory.dispose(httpClient);
}
};
}
use of com.atlassian.httpclient.api.factory.HttpClientOptions in project cx-flow by checkmarx-ltd.
the class CustomAsynchronousHttpClientFactory method createClientCustom.
@SuppressWarnings("unchecked")
public DisposableHttpClient createClientCustom(final URI serverUri, final AuthenticationHandler authenticationHandler, int socketTimeoutInMs) {
final HttpClientOptions options = new HttpClientOptions();
options.setSocketTimeout(socketTimeoutInMs, TimeUnit.MILLISECONDS);
options.setRequestTimeout(socketTimeoutInMs, TimeUnit.MILLISECONDS);
final DefaultHttpClientFactory defaultHttpClientFactory = new DefaultHttpClientFactory(new NoOpEventPublisher(), new RestClientApplicationProperties(serverUri), new ThreadLocalContextManager() {
@Override
public Object getThreadLocalContext() {
return null;
}
@Override
public void setThreadLocalContext(Object context) {
}
@Override
public void clearThreadLocalContext() {
}
});
final HttpClient httpClient = defaultHttpClientFactory.create(options);
return new AtlassianHttpClientDecorator(httpClient, authenticationHandler) {
@Override
public void destroy() throws Exception {
defaultHttpClientFactory.dispose(httpClient);
}
};
}
Aggregations