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 PathTest method testSingletonManagedWebSocketPathMessage.
@Test
public void testSingletonManagedWebSocketPathMessage() 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("/singleton/ws/bar").method("GET").build();
processor.open(w, request, AtmosphereResponseImpl.newInstance(framework.getAtmosphereConfig(), request, w));
assertEquals(instanceCount, 0);
assertNotNull(r.get());
assertEquals(MyInterceptor.invokationCount, 1);
assertEquals(r.get(), "/singleton/ws/bar");
}
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");
}
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 camel by apache.
the class WebsocketProducer method getWebSocket.
private WebSocket getWebSocket(final String connectionKey, final List<String> notValidConnectionKeys) {
WebSocket websocket;
if (connectionKey == null) {
throw new IllegalArgumentException("Failed to send message to single connection; connection key is not set.");
} else {
websocket = getEndpoint().getWebSocketStore().getWebSocket(connectionKey);
if (websocket == null) {
//collect for call back to handle not sent message(s) to guaranty delivery
notValidConnectionKeys.add(connectionKey);
log.debug("Failed to send message to single connection; connetion key is not valid. {}", connectionKey);
}
}
return websocket;
}
Aggregations