use of org.atmosphere.websocket.WebSocket in project atmosphere by Atmosphere.
the class WebSocketStreamingHandlerTest method multipleWebSocketHandler.
@Test
public void multipleWebSocketHandler() throws IOException, ServletException, ExecutionException, InterruptedException {
ByteArrayOutputStream b = new ByteArrayOutputStream();
final WebSocket w = new ArrayBaseWebSocket(b);
final WebSocketProcessor processor = WebSocketProcessorFactory.getDefault().getWebSocketProcessor(framework);
registerWebSocketHandler("/a", new EchoHandler());
registerWebSocketHandler("/b", new EchoHandler());
AtmosphereRequest request = new AtmosphereRequestImpl.Builder().destroyable(false).body("a").pathInfo("/a").build();
processor.open(w, request, AtmosphereResponseImpl.newInstance(framework.getAtmosphereConfig(), request, w));
processor.invokeWebSocketProtocol(w, "a");
assertEquals(b.toString(), "a");
request = new AtmosphereRequestImpl.Builder().destroyable(false).body("b").pathInfo("/b").build();
processor.open(w, request, AtmosphereResponseImpl.newInstance(framework.getAtmosphereConfig(), request, w));
processor.invokeWebSocketProtocol(w, "b");
// The WebSocketHandler is shared.
assertEquals(b.toString(), "ab");
}
use of org.atmosphere.websocket.WebSocket in project atmosphere by Atmosphere.
the class WebSocketStreamingHandlerTest method basicWorkflow.
@Test
public void basicWorkflow() throws IOException, ServletException, ExecutionException, InterruptedException {
ByteArrayOutputStream b = new ByteArrayOutputStream();
final WebSocket w = new ArrayBaseWebSocket(b);
final WebSocketProcessor processor = WebSocketProcessorFactory.getDefault().getWebSocketProcessor(framework);
registerWebSocketHandler("/*", new EchoHandler());
AtmosphereRequest request = new AtmosphereRequestImpl.Builder().destroyable(false).body("yoComet").pathInfo("/a").build();
processor.open(w, request, AtmosphereResponseImpl.newInstance(framework.getAtmosphereConfig(), request, w));
processor.invokeWebSocketProtocol(w, "yoWebSocket");
assertEquals(b.toString(), "yoWebSocket");
}
use of org.atmosphere.websocket.WebSocket in project atmosphere by Atmosphere.
the class WebSocketHandlerTest method multipleWebSocketAndHandler.
@Test
public void multipleWebSocketAndHandler() throws IOException, ServletException, ExecutionException, InterruptedException {
ByteArrayOutputStream b = new ByteArrayOutputStream();
final WebSocket w = new ArrayBaseWebSocket(b);
final WebSocketProcessor processor = WebSocketProcessorFactory.getDefault().getWebSocketProcessor(framework);
registerWebSocketHandler("/a", new WebSocketProcessor.WebSocketHandlerProxy(new EchoHandler()));
registerWebSocketHandler("/b", new WebSocketProcessor.WebSocketHandlerProxy(new EchoHandler() {
@Override
public void onTextMessage(WebSocket webSocket, String data) throws IOException {
webSocket.write("2" + data);
}
}));
AtmosphereRequest request = new AtmosphereRequestImpl.Builder().destroyable(false).body("a").pathInfo("/a").build();
processor.open(w, request, AtmosphereResponseImpl.newInstance(framework.getAtmosphereConfig(), request, w));
processor.invokeWebSocketProtocol(w, "a");
assertEquals(b.toString(), "a");
ByteArrayOutputStream b2 = new ByteArrayOutputStream();
final WebSocket w2 = new ArrayBaseWebSocket(b2);
request = new AtmosphereRequestImpl.Builder().destroyable(false).body("b").pathInfo("/b").build();
processor.open(w2, request, AtmosphereResponseImpl.newInstance(framework.getAtmosphereConfig(), request, w));
processor.invokeWebSocketProtocol(w2, "b");
// The WebSocketHandler is shared.
assertEquals(b2.toString(), "2b");
}
use of org.atmosphere.websocket.WebSocket in project atmosphere by Atmosphere.
the class ManagedAtmosphereHandlerTest method testWebSocketFactory.
@Test
public void testWebSocketFactory() throws IOException, ServletException {
ByteArrayOutputStream b = new ByteArrayOutputStream();
final WebSocket w = new ArrayBaseWebSocket(b);
final WebSocketProcessor processor = WebSocketProcessorFactory.getDefault().getWebSocketProcessor(framework);
AtmosphereRequest request = new AtmosphereRequestImpl.Builder().destroyable(false).body("yoComet").pathInfo("/websocketfactory").build();
processor.open(w, request, AtmosphereResponseImpl.newInstance(framework.getAtmosphereConfig(), request, w));
assertNotNull(r.get());
assertTrue(Interceptor.invoked);
}
use of org.atmosphere.websocket.WebSocket in project atmosphere by Atmosphere.
the class PathTest method testManagedWebSocketPathMessage.
@Test
public void testManagedWebSocketPathMessage() throws IOException, ServletException {
instanceCount = 0;
ByteArrayOutputStream b = new ByteArrayOutputStream();
final WebSocket w = new ArrayBaseWebSocket(b);
final WebSocketProcessor processor = WebSocketProcessorFactory.getDefault().getWebSocketProcessor(framework);
AtmosphereRequest request = new AtmosphereRequestImpl.Builder().pathInfo("/ws/bar").method("GET").build();
processor.open(w, request, AtmosphereResponseImpl.newInstance(framework.getAtmosphereConfig(), request, w));
assertEquals(instanceCount, 1);
assertNotNull(r.get());
assertEquals(r.get(), "/ws/bar");
}
Aggregations