Skip to content

Instantly share code, notes, and snippets.

@jfarcand
Created January 30, 2014 14:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jfarcand/8709938 to your computer and use it in GitHub Desktop.
Save jfarcand/8709938 to your computer and use it in GitHub Desktop.
@Test(groups = { "online", "default_provider" })
public void testWssRequestProxy() throws IOException, InterruptedException, ExecutionException, TimeoutException {
AsyncHttpClientConfig.Builder b = new AsyncHttpClientConfig.Builder();
b.setFollowRedirects(true);
ProxyServer ps = new ProxyServer(ProxyServer.Protocol.HTTPS, "127.0.0.1", port1);
AsyncHttpClientConfig config = b.build();
AsyncHttpClient asyncHttpClient = getAsyncHttpClient(config);
try {
RequestBuilder rb = new RequestBuilder("GET").setProxyServer(ps).setUrl(getTargetUrl2());
WebSocket websocket = asyncHttpClient.executeRequest(rb.build(), new WebSocketUpgradeHandler.Builder().addWebSocketListener(new WebSocketTextListener() {
@Override
public void onMessage(String message) {
System.out.println(message);
}
@Override
public void onFragment(String fragment, boolean last) {
}
@Override
public void onOpen(com.ning.http.client.websocket.WebSocket websocket) {
System.out.println(websocket);
}
@Override
public void onClose(com.ning.http.client.websocket.WebSocket websocket) {
System.out.println(websocket);
}
@Override
public void onError(Throwable t) {
t.printStackTrace();
}
}).build()).get();
// WebSocket websocket = c.prepareGet(getTargetUrl()).execute(new WebSocketUpgradeHandler.Builder().addWebSocketListener(new WebSocketListener() {
//
// @Override
// public void onOpen(com.ning.http.client.websocket.WebSocket websocket) {
// text.set("OnOpen");
// latch.countDown();
// }
//
// @Override
// public void onClose(com.ning.http.client.websocket.WebSocket websocket) {
// }
//
// @Override
// public void onError(Throwable t) {
// t.printStackTrace();
// latch.countDown();
// }
// }).build()).get();
//
Thread.sleep(600000);
} finally {
asyncHttpClient.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment