use of org.atmosphere.websocket.WebSocketHandlerAdapter in project atmosphere by Atmosphere.
the class WebSocketProcessorTest method basicProgrammaticAPIWorkflow.
@Test
public void basicProgrammaticAPIWorkflow() throws IOException, ServletException, ExecutionException, InterruptedException {
ByteArrayOutputStream b = new ByteArrayOutputStream();
final WebSocket w = new ArrayBaseWebSocket(b);
final WebSocketProcessor processor = WebSocketProcessorFactory.getDefault().getWebSocketProcessor(framework);
framework.addWebSocketHandler("/*", new WebSocketProcessor.WebSocketHandlerProxy(new WebSocketHandlerAdapter() {
@Override
public void onTextMessage(WebSocket webSocket, String data) throws IOException {
webSocket.write(data);
}
@Override
public void onOpen(WebSocket webSocket) throws IOException {
webSocket.write(webSocket.resource().getRequest().getReader().readLine());
}
}));
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");
framework.getBroadcasterFactory().lookup("/*").broadcast("yoBroadcast").get();
assertEquals(b.toString(), "yoCometyoWebSocketyoBroadcast");
}
Aggregations