use of org.eclipse.jetty.websocket.client.ClientUpgradeRequest in project pulsar by yahoo.
the class ProxyPublishConsumeWithoutZKTest method socketTest.
@Test(timeOut = 30000)
public void socketTest() throws Exception {
URI consumeUri = URI.create(CONSUME_URI);
URI produceUri = URI.create(PRODUCE_URI);
WebSocketClient consumeClient = new WebSocketClient();
SimpleConsumerSocket consumeSocket = new SimpleConsumerSocket();
WebSocketClient produceClient = new WebSocketClient();
SimpleProducerSocket produceSocket = new SimpleProducerSocket();
try {
consumeClient.start();
ClientUpgradeRequest consumeRequest = new ClientUpgradeRequest();
Future<Session> consumerFuture = consumeClient.connect(consumeSocket, consumeUri, consumeRequest);
log.info("Connecting to : {}", consumeUri);
ClientUpgradeRequest produceRequest = new ClientUpgradeRequest();
produceClient.start();
Future<Session> producerFuture = produceClient.connect(produceSocket, produceUri, produceRequest);
// let it connect
Assert.assertTrue(consumerFuture.get().isOpen());
Assert.assertTrue(producerFuture.get().isOpen());
while (consumeSocket.getReceivedMessagesCount() < 10) {
Thread.sleep(10);
}
Assert.assertTrue(produceSocket.getBuffer().size() > 0);
Assert.assertEquals(produceSocket.getBuffer(), consumeSocket.getBuffer());
} finally {
ExecutorService executor = newFixedThreadPool(1);
try {
executor.submit(() -> {
try {
consumeClient.stop();
produceClient.stop();
log.info("proxy clients are stopped successfully");
} catch (Exception e) {
log.error(e.getMessage());
}
}).get(2, TimeUnit.SECONDS);
} catch (Exception e) {
log.error("failed to close clients ", e);
}
executor.shutdownNow();
}
}
use of org.eclipse.jetty.websocket.client.ClientUpgradeRequest in project zeppelin by apache.
the class ZeppelinClient method openWatcherSession.
private Session openWatcherSession() {
ClientUpgradeRequest request = new ClientUpgradeRequest();
request.setHeader(WatcherSecurityKey.HTTP_HEADER, WatcherSecurityKey.getKey());
WatcherWebsocket socket = WatcherWebsocket.createInstace();
Future<Session> future = null;
Session session = null;
try {
future = wsClient.connect(socket, zeppelinWebsocketUrl, request);
session = future.get();
} catch (IOException | InterruptedException | ExecutionException e) {
LOG.error("Couldn't establish websocket connection to Zeppelin ", e);
return session;
}
return session;
}
use of org.eclipse.jetty.websocket.client.ClientUpgradeRequest in project zeppelin by apache.
the class ZeppelinClient method openNoteSession.
private Session openNoteSession(String noteId) {
ClientUpgradeRequest request = new ClientUpgradeRequest();
ZeppelinWebsocket socket = new ZeppelinWebsocket(noteId);
Future<Session> future = null;
Session session = null;
try {
future = wsClient.connect(socket, zeppelinWebsocketUrl, request);
session = future.get();
} catch (IOException | InterruptedException | ExecutionException e) {
LOG.error("Couldn't establish websocket connection to Zeppelin ", e);
return session;
}
if (notesConnection.containsKey(noteId)) {
session.close();
session = notesConnection.get(noteId);
} else {
String getNote = serialize(zeppelinGetNoteMsg(noteId));
session.getRemote().sendStringByFuture(getNote);
notesConnection.put(noteId, session);
}
return session;
}
use of org.eclipse.jetty.websocket.client.ClientUpgradeRequest in project zeppelin by apache.
the class ZeppelinhubClient method setConnectionrequest.
private ClientUpgradeRequest setConnectionrequest(String token) {
ClientUpgradeRequest request = new ClientUpgradeRequest();
request.setCookies(Lists.newArrayList(new HttpCookie(ZeppelinHubRepo.TOKEN_HEADER, token)));
return request;
}
use of org.eclipse.jetty.websocket.client.ClientUpgradeRequest in project jetty.project by eclipse.
the class ClientContainer method connect.
private Session connect(EndpointInstance instance, URI path) throws IOException {
Objects.requireNonNull(instance, "EndpointInstance cannot be null");
Objects.requireNonNull(path, "Path cannot be null");
ClientEndpointConfig config = (ClientEndpointConfig) instance.getConfig();
ClientUpgradeRequest req = new ClientUpgradeRequest();
UpgradeListener upgradeListener = null;
for (Extension ext : config.getExtensions()) {
req.addExtensions(new JsrExtensionConfig(ext));
}
if (config.getPreferredSubprotocols().size() > 0) {
req.setSubProtocols(config.getPreferredSubprotocols());
}
if (config.getConfigurator() != null) {
upgradeListener = new JsrUpgradeListener(config.getConfigurator());
}
Future<org.eclipse.jetty.websocket.api.Session> futSess = client.connect(instance, path, req, upgradeListener);
try {
return (JsrSession) futSess.get();
} catch (InterruptedException e) {
throw new IOException("Connect failure", e);
} catch (ExecutionException e) {
// Unwrap Actual Cause
Throwable cause = e.getCause();
if (cause instanceof IOException) {
// Just rethrow
throw (IOException) cause;
} else {
throw new IOException("Connect failure", cause);
}
}
}
Aggregations