use of org.asynchttpclient.AsyncHttpClientConfig in project camel by apache.
the class WebsocketSSLContextInUriRouteExampleTest method createAsyncHttpSSLClient.
protected AsyncHttpClient createAsyncHttpSSLClient() throws IOException, GeneralSecurityException {
AsyncHttpClient c;
AsyncHttpClientConfig config;
DefaultAsyncHttpClientConfig.Builder builder = new DefaultAsyncHttpClientConfig.Builder();
SSLContext sslContext = new SSLContextParameters().createSSLContext(context());
JdkSslContext ssl = new JdkSslContext(sslContext, true, ClientAuth.REQUIRE);
builder.setSslContext(ssl);
builder.setAcceptAnyCertificate(true);
config = builder.build();
c = new DefaultAsyncHttpClient(config);
return c;
}
use of org.asynchttpclient.AsyncHttpClientConfig in project camel by apache.
the class WebsocketSSLRouteExampleTest method createAsyncHttpSSLClient.
protected AsyncHttpClient createAsyncHttpSSLClient() throws IOException, GeneralSecurityException {
AsyncHttpClient c;
AsyncHttpClientConfig config;
DefaultAsyncHttpClientConfig.Builder builder = new DefaultAsyncHttpClientConfig.Builder();
SSLContext sslContext = new SSLContextParameters().createSSLContext(context());
JdkSslContext ssl = new JdkSslContext(sslContext, true, ClientAuth.REQUIRE);
builder.setSslContext(ssl);
builder.setAcceptAnyCertificate(true);
config = builder.build();
c = new DefaultAsyncHttpClient(config);
return c;
}
use of org.asynchttpclient.AsyncHttpClientConfig in project async-http-client by AsyncHttpClient.
the class HttpsProxyTest method testConfigProxy.
@Test(groups = "standalone")
public void testConfigProxy() throws Exception {
AsyncHttpClientConfig config = //
config().setFollowRedirect(//
true).setProxyServer(//
proxyServer("localhost", port1).build()).setUseInsecureTrustManager(//
true).build();
try (AsyncHttpClient asyncHttpClient = asyncHttpClient(config)) {
Response r = asyncHttpClient.executeRequest(get(getTargetUrl2())).get();
assertEquals(r.getStatusCode(), 200);
}
}
use of org.asynchttpclient.AsyncHttpClientConfig in project async-http-client by AsyncHttpClient.
the class MaxConnectionsInThreads method testMaxConnectionsWithinThreads.
@Test(groups = "standalone")
public void testMaxConnectionsWithinThreads() throws Exception {
String[] urls = new String[] { getTargetUrl(), getTargetUrl() };
AsyncHttpClientConfig config = //
config().setConnectTimeout(//
1000).setRequestTimeout(//
5000).setKeepAlive(//
true).setMaxConnections(//
1).setMaxConnectionsPerHost(//
1).build();
final CountDownLatch inThreadsLatch = new CountDownLatch(2);
final AtomicInteger failedCount = new AtomicInteger();
try (AsyncHttpClient client = asyncHttpClient(config)) {
for (final String url : urls) {
Thread t = new Thread() {
public void run() {
client.prepareGet(url).execute(new AsyncCompletionHandlerBase() {
@Override
public Response onCompleted(Response response) throws Exception {
Response r = super.onCompleted(response);
inThreadsLatch.countDown();
return r;
}
@Override
public void onThrowable(Throwable t) {
super.onThrowable(t);
failedCount.incrementAndGet();
inThreadsLatch.countDown();
}
});
}
};
t.start();
}
inThreadsLatch.await();
assertEquals(failedCount.get(), 1, "Max Connections should have been reached when launching from concurrent threads");
final CountDownLatch notInThreadsLatch = new CountDownLatch(2);
failedCount.set(0);
for (final String url : urls) {
client.prepareGet(url).execute(new AsyncCompletionHandlerBase() {
@Override
public Response onCompleted(Response response) throws Exception {
Response r = super.onCompleted(response);
notInThreadsLatch.countDown();
return r;
}
@Override
public void onThrowable(Throwable t) {
super.onThrowable(t);
failedCount.incrementAndGet();
notInThreadsLatch.countDown();
}
});
}
notInThreadsLatch.await();
assertEquals(failedCount.get(), 1, "Max Connections should have been reached when launching from main thread");
}
}
use of org.asynchttpclient.AsyncHttpClientConfig in project async-http-client by AsyncHttpClient.
the class BodyChunkTest method negativeContentTypeTest.
@Test(groups = "standalone")
public void negativeContentTypeTest() throws Exception {
AsyncHttpClientConfig config = //
config().setConnectTimeout(//
100).setMaxConnections(//
50).setRequestTimeout(// 5 minutes
5 * 60 * 1000).build();
try (AsyncHttpClient client = asyncHttpClient(config)) {
RequestBuilder requestBuilder = //
post(getTargetUrl()).setHeader("Content-Type", //
"message/rfc822").setBody(new InputStreamBodyGenerator(new ByteArrayInputStream(MY_MESSAGE.getBytes())));
Future<Response> future = client.executeRequest(requestBuilder.build());
System.out.println("waiting for response");
Response response = future.get();
assertEquals(response.getStatusCode(), 200);
assertEquals(response.getResponseBody(), MY_MESSAGE);
}
}
Aggregations