Search in sources :

Example 1 with WebSocketListener

use of org.asynchttpclient.ws.WebSocketListener 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();
}
Also used : WebSocketListener(org.asynchttpclient.ws.WebSocketListener) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) RouteBuilder(org.apache.camel.builder.RouteBuilder) DefaultAsyncHttpClient(org.asynchttpclient.DefaultAsyncHttpClient) AsyncHttpClient(org.asynchttpclient.AsyncHttpClient) DefaultAsyncHttpClient(org.asynchttpclient.DefaultAsyncHttpClient) WebSocket(org.asynchttpclient.ws.WebSocket) Test(org.junit.Test)

Example 2 with WebSocketListener

use of org.asynchttpclient.ws.WebSocketListener 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();
}
Also used : WebSocketListener(org.asynchttpclient.ws.WebSocketListener) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) RouteBuilder(org.apache.camel.builder.RouteBuilder) DefaultAsyncHttpClient(org.asynchttpclient.DefaultAsyncHttpClient) AsyncHttpClient(org.asynchttpclient.AsyncHttpClient) DefaultAsyncHttpClient(org.asynchttpclient.DefaultAsyncHttpClient) WebSocket(org.asynchttpclient.ws.WebSocket) Test(org.junit.Test)

Aggregations

RouteBuilder (org.apache.camel.builder.RouteBuilder)2 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)2 AsyncHttpClient (org.asynchttpclient.AsyncHttpClient)2 DefaultAsyncHttpClient (org.asynchttpclient.DefaultAsyncHttpClient)2 WebSocket (org.asynchttpclient.ws.WebSocket)2 WebSocketListener (org.asynchttpclient.ws.WebSocketListener)2 Test (org.junit.Test)2