use of org.asynchttpclient.AsyncHttpClient in project async-http-client by AsyncHttpClient.
the class WebSocketWriteCompleteListenerTest method sendByteMessageExpectFailure.
@Test(groups = "standalone", timeOut = 60000, expectedExceptions = ExecutionException.class)
public void sendByteMessageExpectFailure() throws Exception {
try (AsyncHttpClient c = asyncHttpClient()) {
WebSocket websocket = getWebSocket(c);
websocket.close();
closeFuture.get();
websocket.sendMessage("BYTES".getBytes(), resultHandler());
resultFuture.get(10, TimeUnit.SECONDS);
}
}
use of org.asynchttpclient.AsyncHttpClient in project async-http-client by AsyncHttpClient.
the class WebSocketWriteCompleteListenerTest method streamBytes.
@Test(groups = "standalone", timeOut = 60000)
public void streamBytes() throws Exception {
try (AsyncHttpClient c = asyncHttpClient()) {
getWebSocket(c).stream("STREAM".getBytes(), true, resultHandler());
resultFuture.get(10, TimeUnit.SECONDS);
}
}
use of org.asynchttpclient.AsyncHttpClient in project async-http-client by AsyncHttpClient.
the class WebSocketWriteCompleteListenerTest method sendByteMessage.
@Test(groups = "standalone", timeOut = 60000)
public void sendByteMessage() throws Exception {
try (AsyncHttpClient c = asyncHttpClient()) {
getWebSocket(c).sendMessage("BYTES".getBytes(), resultHandler());
resultFuture.get(10, TimeUnit.SECONDS);
}
}
use of org.asynchttpclient.AsyncHttpClient in project async-http-client by AsyncHttpClient.
the class ProxyTest method testProxyProperties.
// @Test(groups = "standalone")
public void testProxyProperties() throws IOException, ExecutionException, TimeoutException, InterruptedException {
// FIXME not threadsafe!
Properties originalProps = new Properties();
originalProps.putAll(System.getProperties());
System.setProperty(ProxyUtils.PROXY_HOST, "127.0.0.1");
System.setProperty(ProxyUtils.PROXY_PORT, String.valueOf(port1));
System.setProperty(ProxyUtils.PROXY_NONPROXYHOSTS, "localhost");
AsyncHttpClientConfigHelper.reloadProperties();
try (AsyncHttpClient client = asyncHttpClient(config().setUseProxyProperties(true))) {
String proxifiedtarget = "http://127.0.0.1:1234/";
Future<Response> f = client.prepareGet(proxifiedtarget).execute();
Response resp = f.get(3, TimeUnit.SECONDS);
assertNotNull(resp);
assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK);
assertEquals(resp.getHeader("target"), "/");
String nonProxifiedtarget = "http://localhost:1234/";
f = client.prepareGet(nonProxifiedtarget).execute();
try {
resp = f.get(3, TimeUnit.SECONDS);
fail("should not be able to connect");
} catch (ExecutionException e) {
// ok, no proxy used
}
} finally {
System.setProperties(originalProps);
}
}
use of org.asynchttpclient.AsyncHttpClient in project async-http-client by AsyncHttpClient.
the class ProxyTest method testGlobalProxy.
@Test(groups = "standalone")
public void testGlobalProxy() throws IOException, ExecutionException, TimeoutException, InterruptedException {
try (AsyncHttpClient client = asyncHttpClient(config().setProxyServer(proxyServer("localhost", port1)))) {
String target = "http://localhost:1234/";
Future<Response> f = client.prepareGet(target).execute();
Response resp = f.get(3, TimeUnit.SECONDS);
assertNotNull(resp);
assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK);
assertEquals(resp.getHeader("target"), "/");
}
}
Aggregations