use of org.atmosphere.websocket.WebSocketEventListenerAdapter in project atmosphere by Atmosphere.
the class WebSocketProcessorTest method onCloseAtmosphereRequestAttribute.
@Test
public void onCloseAtmosphereRequestAttribute() throws IOException, ServletException, ExecutionException, InterruptedException {
ByteArrayOutputStream b = new ByteArrayOutputStream();
final WebSocket w = new ArrayBaseWebSocket(b);
final WebSocketProcessor processor = WebSocketProcessorFactory.getDefault().getWebSocketProcessor(framework);
final AtomicReference<String> uuid = new AtomicReference<String>();
framework.addAtmosphereHandler("/*", new AtmosphereHandler() {
@Override
public void onRequest(AtmosphereResource resource) throws IOException {
resource.addEventListener(new WebSocketEventListenerAdapter() {
@Override
public void onClose(WebSocketEvent event) {
uuid.set((String) event.webSocket().resource().getRequest().getAttribute(SUSPENDED_ATMOSPHERE_RESOURCE_UUID));
}
});
}
@Override
public void onStateChange(AtmosphereResourceEvent event) throws IOException {
}
@Override
public void destroy() {
}
});
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");
processor.notifyListener(w, new WebSocketEventListener.WebSocketEvent("Close", WebSocketEventListener.WebSocketEvent.TYPE.CLOSE, w));
assertNotNull(uuid.get());
assertEquals(uuid.get(), request.getAttribute(SUSPENDED_ATMOSPHERE_RESOURCE_UUID));
}
use of org.atmosphere.websocket.WebSocketEventListenerAdapter in project atmosphere by Atmosphere.
the class WebSocketProcessorTest method onDisconnectAtmosphereRequestAttribute.
@Test
public void onDisconnectAtmosphereRequestAttribute() throws IOException, ServletException, ExecutionException, InterruptedException {
ByteArrayOutputStream b = new ByteArrayOutputStream();
final WebSocket w = new ArrayBaseWebSocket(b);
final WebSocketProcessor processor = WebSocketProcessorFactory.getDefault().getWebSocketProcessor(framework);
final AtomicReference<String> uuid = new AtomicReference<String>();
framework.addAtmosphereHandler("/*", new AtmosphereHandler() {
@Override
public void onRequest(AtmosphereResource resource) throws IOException {
resource.addEventListener(new WebSocketEventListenerAdapter() {
@Override
public void onDisconnect(WebSocketEvent event) {
uuid.set((String) event.webSocket().resource().getRequest().getAttribute(SUSPENDED_ATMOSPHERE_RESOURCE_UUID));
}
});
}
@Override
public void onStateChange(AtmosphereResourceEvent event) throws IOException {
}
@Override
public void destroy() {
}
});
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");
processor.notifyListener(w, new WebSocketEventListener.WebSocketEvent("Disconnect", DISCONNECT, w));
assertNotNull(uuid.get());
assertEquals(uuid.get(), request.getAttribute(SUSPENDED_ATMOSPHERE_RESOURCE_UUID));
}
Aggregations