use of org.asynchttpclient.DefaultAsyncHttpClient in project camel by apache.
the class WebsocketTwoRoutesExampleTest method testWSHttpCallEcho.
@Test
public void testWSHttpCallEcho() throws Exception {
// We call the route WebSocket BAR
received.clear();
latch = new CountDownLatch(1);
AsyncHttpClient c = new DefaultAsyncHttpClient();
WebSocket websocket = c.prepareGet("ws://localhost:" + port + "/bar").execute(new WebSocketUpgradeHandler.Builder().addWebSocketListener(new WebSocketTextListener() {
@Override
public void onMessage(String message) {
received.add(message);
log.info("received --> " + message);
latch.countDown();
}
@Override
public void onOpen(WebSocket websocket) {
}
@Override
public void onClose(WebSocket websocket) {
}
@Override
public void onError(Throwable t) {
t.printStackTrace();
}
}).build()).get();
websocket.sendMessage("Beer");
assertTrue(latch.await(10, TimeUnit.SECONDS));
assertEquals(1, received.size());
assertEquals("The bar has Beer", received.get(0));
websocket.close();
c.close();
// We call the route WebSocket PUB
received.clear();
latch = new CountDownLatch(1);
c = new DefaultAsyncHttpClient();
websocket = c.prepareGet("ws://localhost:" + port + "/pub").execute(new WebSocketUpgradeHandler.Builder().addWebSocketListener(new WebSocketTextListener() {
@Override
public void onMessage(String message) {
received.add(message);
log.info("received --> " + message);
latch.countDown();
}
@Override
public void onOpen(WebSocket websocket) {
}
@Override
public void onClose(WebSocket websocket) {
}
@Override
public void onError(Throwable t) {
t.printStackTrace();
}
}).build()).get();
websocket.sendMessage("wine");
assertTrue(latch.await(10, TimeUnit.SECONDS));
assertEquals(1, received.size());
assertEquals("The pub has wine", received.get(0));
websocket.close();
c.close();
}
use of org.asynchttpclient.DefaultAsyncHttpClient in project camel by apache.
the class WebsocketTwoRoutesToSIndividualAndBroadcastEndpointExampleTest method testWSHttpCallEcho.
@Test
public void testWSHttpCallEcho() throws Exception {
// We call the route WebSocket BAR
received.clear();
latch = new CountDownLatch(2);
AsyncHttpClient c = new DefaultAsyncHttpClient();
WebSocket websocket = c.prepareGet("ws://localhost:" + port + "/bar").execute(new WebSocketUpgradeHandler.Builder().addWebSocketListener(new WebSocketTextListener() {
@Override
public void onMessage(String message) {
received.add(message);
log.info("received --> " + message);
latch.countDown();
}
@Override
public void onOpen(WebSocket websocket) {
}
@Override
public void onClose(WebSocket websocket) {
}
@Override
public void onError(Throwable t) {
t.printStackTrace();
}
}).build()).get();
websocket.sendMessage("Beer");
assertTrue(latch.await(10, TimeUnit.SECONDS));
assertEquals(2, received.size());
//Cannot guarantee the order in which messages are received
assertTrue(received.contains("The bar has Beer"));
assertTrue(received.contains("Broadcasting to Bar"));
websocket.close();
c.close();
}
use of org.asynchttpclient.DefaultAsyncHttpClient in project camel by apache.
the class WebsocketTwoRoutesToSameEndpointExampleTest method testWSHttpCallEcho.
@Test
public void testWSHttpCallEcho() throws Exception {
// We call the route WebSocket BAR
received.clear();
latch = new CountDownLatch(2);
DefaultAsyncHttpClient c = new DefaultAsyncHttpClient();
WebSocket websocket = c.prepareGet("ws://localhost:" + port + "/bar").execute(new WebSocketUpgradeHandler.Builder().addWebSocketListener(new WebSocketTextListener() {
@Override
public void onMessage(String message) {
received.add(message);
log.info("received --> " + message);
latch.countDown();
}
@Override
public void onOpen(WebSocket websocket) {
}
@Override
public void onClose(WebSocket websocket) {
}
@Override
public void onError(Throwable t) {
t.printStackTrace();
}
}).build()).get();
websocket.sendMessage("Beer");
assertTrue(latch.await(10, TimeUnit.SECONDS));
assertEquals(2, received.size());
//Cannot guarantee the order in which messages are received
assertTrue(received.contains("The bar has Beer"));
assertTrue(received.contains("Broadcasting to Bar"));
websocket.close();
c.close();
}
use of org.asynchttpclient.DefaultAsyncHttpClient in project camel by apache.
the class WebsocketConsumerRouteTest method testWSBytesHttpCall.
@Test
public void testWSBytesHttpCall() throws Exception {
AsyncHttpClient c = new DefaultAsyncHttpClient();
WebSocket websocket = c.prepareGet("ws://127.0.0.1:" + port + "/echo").execute(new WebSocketUpgradeHandler.Builder().addWebSocketListener(new WebSocketListener() {
@Override
public void onOpen(WebSocket websocket) {
}
@Override
public void onClose(WebSocket websocket) {
}
@Override
public void onError(Throwable t) {
t.printStackTrace();
}
}).build()).get();
MockEndpoint result = getMockEndpoint("mock:result");
final byte[] testmessage = "Test".getBytes("utf-8");
result.expectedBodiesReceived(testmessage);
websocket.sendMessage(testmessage);
result.assertIsSatisfied();
websocket.close();
c.close();
}
use of org.asynchttpclient.DefaultAsyncHttpClient in project camel by apache.
the class WebsocketConsumerRouteTest method testWSHttpCall.
@Test
public void testWSHttpCall() throws Exception {
AsyncHttpClient c = new DefaultAsyncHttpClient();
WebSocket websocket = c.prepareGet("ws://127.0.0.1:" + port + "/echo").execute(new WebSocketUpgradeHandler.Builder().addWebSocketListener(new WebSocketListener() {
@Override
public void onOpen(WebSocket websocket) {
}
@Override
public void onClose(WebSocket websocket) {
}
@Override
public void onError(Throwable t) {
t.printStackTrace();
}
}).build()).get();
MockEndpoint result = getMockEndpoint("mock:result");
result.expectedBodiesReceived("Test");
websocket.sendMessage("Test");
result.assertIsSatisfied();
websocket.close();
c.close();
}
Aggregations