use of org.asynchttpclient.AsyncHttpClientConfig in project camel by apache.
the class AhcEndpoint method doStart.
@Override
protected void doStart() throws Exception {
super.doStart();
if (client == null) {
AsyncHttpClientConfig config = null;
if (clientConfig != null) {
DefaultAsyncHttpClientConfig.Builder builder = AhcComponent.cloneConfig(clientConfig);
if (sslContextParameters != null) {
SSLContext sslContext = sslContextParameters.createSSLContext(getCamelContext());
JdkSslContext ssl = new JdkSslContext(sslContext, true, ClientAuth.REQUIRE);
builder.setSslContext(ssl);
}
config = builder.build();
} else {
if (sslContextParameters != null) {
DefaultAsyncHttpClientConfig.Builder builder = new DefaultAsyncHttpClientConfig.Builder();
SSLContext sslContext = sslContextParameters.createSSLContext(getCamelContext());
JdkSslContext ssl = new JdkSslContext(sslContext, true, ClientAuth.REQUIRE);
builder.setSslContext(ssl);
config = builder.build();
}
}
client = createClient(config);
}
}
use of org.asynchttpclient.AsyncHttpClientConfig in project async-http-client by AsyncHttpClient.
the class RetryNonBlockingIssue method testRetryNonBlockingAsyncConnect.
@Test(groups = "standalone")
public void testRetryNonBlockingAsyncConnect() throws IOException, InterruptedException, ExecutionException {
AsyncHttpClientConfig config = //
config().setKeepAlive(//
true).setMaxConnections(//
100).setConnectTimeout(//
60000).setRequestTimeout(//
30000).build();
try (AsyncHttpClient client = asyncHttpClient(config)) {
List<ListenableFuture<Response>> res = new ArrayList<>();
for (int i = 0; i < 32; i++) {
res.add(testMethodRequest(client, 3, "servlet", UUID.randomUUID().toString()));
}
StringBuilder b = new StringBuilder();
for (ListenableFuture<Response> r : res) {
Response theres = r.get();
assertEquals(theres.getStatusCode(), 200);
b.append("==============\r\n");
b.append("Response Headers\r\n");
HttpHeaders heads = theres.getHeaders();
b.append(heads + "\r\n");
b.append("==============\r\n");
}
System.out.println(b.toString());
System.out.flush();
}
}
use of org.asynchttpclient.AsyncHttpClientConfig in project async-http-client by AsyncHttpClient.
the class RetryNonBlockingIssue method testRetryNonBlocking.
/**
* Tests that a head request can be made
*
* @throws IOException
* @throws ExecutionException
* @throws InterruptedException
*/
@Test(groups = "standalone")
public void testRetryNonBlocking() throws IOException, InterruptedException, ExecutionException {
AsyncHttpClientConfig config = //
config().setKeepAlive(//
true).setMaxConnections(//
100).setConnectTimeout(//
60000).setRequestTimeout(//
30000).build();
try (AsyncHttpClient client = asyncHttpClient(config)) {
List<ListenableFuture<Response>> res = new ArrayList<>();
for (int i = 0; i < 32; i++) {
res.add(testMethodRequest(client, 3, "servlet", UUID.randomUUID().toString()));
}
StringBuilder b = new StringBuilder();
for (ListenableFuture<Response> r : res) {
Response theres = r.get();
assertEquals(200, theres.getStatusCode());
b.append("==============\r\n");
b.append("Response Headers\r\n");
HttpHeaders heads = theres.getHeaders();
b.append(heads + "\r\n");
b.append("==============\r\n");
}
System.out.println(b.toString());
System.out.flush();
}
}
use of org.asynchttpclient.AsyncHttpClientConfig in project async-http-client by AsyncHttpClient.
the class MaxTotalConnectionTest method testMaxTotalConnections.
@Test(groups = "online")
public void testMaxTotalConnections() throws Exception {
String[] urls = new String[] { "http://google.com", "http://gatling.io" };
final CountDownLatch latch = new CountDownLatch(2);
final AtomicReference<Throwable> ex = new AtomicReference<>();
final AtomicReference<String> failedUrl = new AtomicReference<>();
AsyncHttpClientConfig config = //
config().setConnectTimeout(//
1000).setRequestTimeout(//
5000).setKeepAlive(//
false).setMaxConnections(//
2).setMaxConnectionsPerHost(//
1).build();
try (AsyncHttpClient client = asyncHttpClient(config)) {
for (String url : urls) {
final String thisUrl = url;
client.prepareGet(url).execute(new AsyncCompletionHandlerBase() {
@Override
public Response onCompleted(Response response) throws Exception {
Response r = super.onCompleted(response);
latch.countDown();
return r;
}
@Override
public void onThrowable(Throwable t) {
super.onThrowable(t);
ex.set(t);
failedUrl.set(thisUrl);
latch.countDown();
}
});
}
latch.await();
assertNull(ex.get());
assertNull(failedUrl.get());
}
}
use of org.asynchttpclient.AsyncHttpClientConfig in project async-http-client by AsyncHttpClient.
the class MaxTotalConnectionTest method testMaxTotalConnectionsExceedingException.
@Test(groups = "online")
public void testMaxTotalConnectionsExceedingException() throws IOException {
String[] urls = new String[] { "http://google.com", "http://github.com/" };
AsyncHttpClientConfig config = //
config().setConnectTimeout(//
1000).setRequestTimeout(//
5000).setKeepAlive(//
false).setMaxConnections(//
1).setMaxConnectionsPerHost(//
1).build();
try (AsyncHttpClient client = asyncHttpClient(config)) {
List<ListenableFuture<Response>> futures = new ArrayList<>();
for (String url : urls) {
futures.add(client.prepareGet(url).execute());
}
boolean caughtError = false;
int i;
for (i = 0; i < urls.length; i++) {
try {
futures.get(i).get();
} catch (Exception e) {
// assert that 2nd request fails, because
// maxTotalConnections=1
caughtError = true;
break;
}
}
Assert.assertEquals(1, i);
Assert.assertTrue(caughtError);
}
}
Aggregations