use of org.atmosphere.handler.AbstractReflectorAtmosphereHandler in project atmosphere by Atmosphere.
the class AtmosphereFramework method checkWebSocketSupportState.
public void checkWebSocketSupportState() {
if (atmosphereHandlers.isEmpty() && !SimpleHttpProtocol.class.isAssignableFrom(webSocketProtocol.getClass())) {
logger.debug("Adding a void AtmosphereHandler mapped to /* to allow WebSocket application only");
addAtmosphereHandler(Broadcaster.ROOT_MASTER, new AbstractReflectorAtmosphereHandler() {
@Override
public void onRequest(AtmosphereResource r) throws IOException {
logger.debug("No AtmosphereHandler defined.");
if (!r.transport().equals(AtmosphereResource.TRANSPORT.WEBSOCKET)) {
WebSocket.notSupported(r.getRequest(), r.getResponse());
}
}
@Override
public void destroy() {
}
});
}
}
use of org.atmosphere.handler.AbstractReflectorAtmosphereHandler in project atmosphere by Atmosphere.
the class AtmosphereRequestTest method testNormalQueryStringBuilder.
@Test
public void testNormalQueryStringBuilder() throws IOException, ServletException {
framework.addAtmosphereHandler("/a", new AbstractReflectorAtmosphereHandler() {
@Override
public void onRequest(AtmosphereResource resource) throws IOException {
}
@Override
public void destroy() {
}
});
AtmosphereRequest request = new AtmosphereRequestImpl.Builder().pathInfo("/a").build();
request.queryString("a=b");
final AtomicReference<String> e = new AtomicReference<String>();
framework.interceptor(new AtmosphereInterceptor() {
@Override
public void configure(AtmosphereConfig config) {
}
@Override
public Action inspect(AtmosphereResource r) {
e.set(r.getRequest().getQueryString());
return Action.CANCELLED;
}
@Override
public void postInspect(AtmosphereResource r) {
}
@Override
public void destroy() {
}
});
framework.doCometSupport(request, AtmosphereResponseImpl.newInstance());
assertEquals(e.get(), "a=b");
}
use of org.atmosphere.handler.AbstractReflectorAtmosphereHandler in project atmosphere by Atmosphere.
the class AtmosphereRequestTest method testStrinpQueryStringBuilder.
@Test
public void testStrinpQueryStringBuilder() throws IOException, ServletException {
framework.addAtmosphereHandler("/a", new AbstractReflectorAtmosphereHandler() {
@Override
public void onRequest(AtmosphereResource resource) throws IOException {
}
@Override
public void destroy() {
}
});
AtmosphereRequest request = new AtmosphereRequestImpl.Builder().pathInfo("/a").build();
request.queryString("a=b&X-Atmosphere-Transport=websocket");
final AtomicReference<String> e = new AtomicReference<String>();
framework.interceptor(new AtmosphereInterceptor() {
@Override
public void configure(AtmosphereConfig config) {
}
@Override
public Action inspect(AtmosphereResource r) {
e.set(r.getRequest().getQueryString());
return Action.CANCELLED;
}
@Override
public void postInspect(AtmosphereResource r) {
}
@Override
public void destroy() {
}
});
framework.doCometSupport(request, AtmosphereResponseImpl.newInstance());
assertEquals(e.get(), "a=b");
}
use of org.atmosphere.handler.AbstractReflectorAtmosphereHandler in project atmosphere by Atmosphere.
the class AtmosphereRequestTest method testEncodingOnPreSuspend.
@Test
public void testEncodingOnPreSuspend() throws IOException, ServletException {
final AtomicReference<AtmosphereResponse> e = new AtomicReference<AtmosphereResponse>();
framework.addAtmosphereHandler("/a", new AbstractReflectorAtmosphereHandler() {
@Override
public void onRequest(AtmosphereResource resource) throws IOException {
resource.addEventListener(new AtmosphereResourceEventListenerAdapter() {
@Override
public void onPreSuspend(AtmosphereResourceEvent event) {
AtmosphereResponse response = event.getResource().getResponse();
response.setCharacterEncoding("utf-8");
e.set(response);
}
}).suspend(10);
}
@Override
public void destroy() {
}
});
AtmosphereRequest request = new AtmosphereRequestImpl.Builder().pathInfo("/a").build();
framework.doCometSupport(request, AtmosphereResponseImpl.newInstance().delegateToNativeResponse(false));
assertEquals(e.get().getCharacterEncoding(), "utf-8");
}
use of org.atmosphere.handler.AbstractReflectorAtmosphereHandler in project atmosphere by Atmosphere.
the class AtmosphereRequestTest method testRequestBodyString.
@Test
public void testRequestBodyString() throws IOException, ServletException {
final AtomicReference<AtmosphereRequestImpl.Body> e = new AtomicReference<AtmosphereRequestImpl.Body>();
framework.addAtmosphereHandler("/a", new AbstractReflectorAtmosphereHandler() {
@Override
public void onRequest(AtmosphereResource resource) throws IOException {
e.set(resource.getRequest().body());
}
@Override
public void destroy() {
}
});
AtmosphereRequest request = new AtmosphereRequestImpl.Builder().pathInfo("/a").body("test").build();
framework.doCometSupport(request, AtmosphereResponseImpl.newInstance().delegateToNativeResponse(false));
assertNotNull(e.get());
assertTrue(e.get().hasString());
assertFalse(e.get().hasBytes());
assertEquals(e.get().asString(), "test");
}
Aggregations