use of org.apache.apex.shaded.ning19.com.ning.http.client.ws.WebSocket in project apex-core by apache.
the class PubSubWebSocketClient method openConnectionAsync.
public void openConnectionAsync() throws IOException {
throwable.set(null);
if (loginUrl != null && userName != null && password != null) {
// get the session key first before attempting web socket
JSONObject json = new JSONObject();
try {
json.put("userName", userName);
json.put("password", password);
} catch (JSONException ex) {
throw new RuntimeException(ex);
}
client.preparePost(loginUrl).setHeader("Content-Type", "application/json").setBody(json.toString()).execute(new AsyncCompletionHandler<Response>() {
@Override
public Response onCompleted(Response response) throws Exception {
List<Cookie> cookies = response.getCookies();
BoundRequestBuilder brb = client.prepareGet(uri.toString());
if (cookies != null) {
for (Cookie cookie : cookies) {
brb.addCookie(cookie);
}
}
connection = brb.execute(new WebSocketUpgradeHandler.Builder().addWebSocketListener(new PubSubWebSocket()).build()).get();
return response;
}
});
} else {
final PubSubWebSocket webSocket = new PubSubWebSocket() {
@Override
public void onOpen(WebSocket ws) {
connection = ws;
super.onOpen(ws);
}
};
client.prepareGet(uri.toString()).execute(new WebSocketUpgradeHandler.Builder().addWebSocketListener(webSocket).build());
}
}
Aggregations