use of org.atmosphere.websocket.WebSocket in project atmosphere by Atmosphere.
the class WebSocketStreamingHandlerTest method invalidPathHandler.
@Test
public void invalidPathHandler() 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());
AtmosphereRequest request = new AtmosphereRequestImpl.Builder().destroyable(false).body("yoComet").pathInfo("/abcd").build();
try {
processor.open(w, request, AtmosphereResponseImpl.newInstance(framework.getAtmosphereConfig(), request, w));
fail();
} catch (Exception ex) {
assertEquals(ex.getClass(), AtmosphereMappingException.class);
}
}
use of org.atmosphere.websocket.WebSocket in project atmosphere by Atmosphere.
the class WebSocketHandlerTest method invalidPathHandler.
@Test
public void invalidPathHandler() 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()));
AtmosphereRequest request = new AtmosphereRequestImpl.Builder().destroyable(false).body("yoComet").pathInfo("/abcd").build();
try {
processor.open(w, request, AtmosphereResponseImpl.newInstance(framework.getAtmosphereConfig(), request, w));
fail();
} catch (Exception ex) {
assertEquals(ex.getClass(), AtmosphereMappingException.class);
}
}
use of org.atmosphere.websocket.WebSocket in project atmosphere by Atmosphere.
the class WebSocketHandlerTest 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 WebSocketProcessor.WebSocketHandlerProxy(new EchoHandler()));
registerWebSocketHandler("/b", new WebSocketProcessor.WebSocketHandlerProxy(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 WebSocketProcessorTest method basicWebSocketCookieTest.
@Test
public void basicWebSocketCookieTest() throws IOException, ServletException, ExecutionException, InterruptedException {
final AtomicReference<Cookie> cValue = new AtomicReference<Cookie>();
final AtomicReference<AtmosphereResource> r = new AtomicReference<AtmosphereResource>();
ByteArrayOutputStream b = new ByteArrayOutputStream();
WebSocket w = new ArrayBaseWebSocket(b);
final WebSocketProcessor processor = WebSocketProcessorFactory.getDefault().getWebSocketProcessor(framework);
framework.addAtmosphereHandler("/*", new AtmosphereHandler() {
@Override
public void onRequest(AtmosphereResource resource) throws IOException {
r.set(resource);
resource.getBroadcaster().addAtmosphereResource(resource);
}
@Override
public void onStateChange(AtmosphereResourceEvent event) throws IOException {
Cookie[] c = event.getResource().getRequest().getCookies();
cValue.set(c[0]);
}
@Override
public void destroy() {
}
});
Set<Cookie> c = new HashSet<Cookie>();
c.add(new Cookie("yo", "man"));
AtmosphereRequest request = new AtmosphereRequestImpl.Builder().cookies(c).pathInfo("/a").build();
processor.open(w, request, AtmosphereResponseImpl.newInstance(framework.getAtmosphereConfig(), request, w));
r.get().getBroadcaster().broadcast("yo").get();
assertNotNull(cValue.get());
Cookie i = c.iterator().next();
assertEquals(i.getName(), cValue.get().getName());
assertEquals(i.getValue(), cValue.get().getValue());
}
use of org.atmosphere.websocket.WebSocket in project atmosphere by Atmosphere.
the class WebSocketProcessorTest method encodeURLProxyTest.
@Test
public void encodeURLProxyTest() 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> url = new AtomicReference<String>();
framework.addAtmosphereHandler("/*", new AtmosphereHandler() {
@Override
public void onRequest(AtmosphereResource resource) throws IOException {
url.set(resource.getResponse().encodeRedirectURL("http://127.0.0.1:8080"));
}
@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");
assertEquals(url.get(), "http://127.0.0.1:8080");
}
Aggregations