use of org.atmosphere.handler.AbstractReflectorAtmosphereHandler in project atmosphere by Atmosphere.
the class AtmosphereRequestTest method testRequestBodyBytes.
@Test
public void testRequestBodyBytes() 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".getBytes()).build();
framework.doCometSupport(request, AtmosphereResponseImpl.newInstance().delegateToNativeResponse(false));
assertNotNull(e.get());
assertTrue(e.get().hasBytes());
assertFalse(e.get().hasString());
assertEquals(new String(e.get().asBytes()), "test");
}
use of org.atmosphere.handler.AbstractReflectorAtmosphereHandler in project atmosphere by Atmosphere.
the class AtmosphereResourceTest method testCancelParentUUID.
@Test
public void testCancelParentUUID() throws IOException, ServletException, InterruptedException {
framework.addAtmosphereHandler("/a", new AbstractReflectorAtmosphereHandler() {
@Override
public void onRequest(AtmosphereResource resource) throws IOException {
}
@Override
public void destroy() {
}
});
final AtmosphereRequest parentRequest = new AtmosphereRequestImpl.Builder().pathInfo("/a").queryString(HeaderConfig.WEBSOCKET_X_ATMOSPHERE_TRANSPORT).build();
final CountDownLatch suspended = new CountDownLatch(1);
framework.interceptor(new AtmosphereInterceptor() {
@Override
public void configure(AtmosphereConfig config) {
}
@Override
public Action inspect(AtmosphereResource r) {
try {
r.getBroadcaster().addAtmosphereResource(r);
if (suspended.getCount() == 1) {
r.suspend();
return Action.SUSPEND;
} else {
return Action.CONTINUE;
}
} finally {
suspended.countDown();
}
}
@Override
public void destroy() {
}
@Override
public void postInspect(AtmosphereResource r) {
}
});
new Thread() {
public void run() {
try {
framework.doCometSupport(parentRequest, AtmosphereResponseImpl.newInstance().request(parentRequest));
} catch (IOException e) {
e.printStackTrace();
} catch (ServletException e) {
e.printStackTrace();
}
}
}.start();
suspended.await();
Map<String, Object> m = new HashMap<String, Object>();
m.put(SUSPENDED_ATMOSPHERE_RESOURCE_UUID, parentRequest.resource().uuid());
AtmosphereRequest request = new AtmosphereRequestImpl.Builder().attributes(m).pathInfo("/a").queryString(HeaderConfig.WEBSOCKET_X_ATMOSPHERE_TRANSPORT).build();
request.setAttribute(FrameworkConfig.WEBSOCKET_MESSAGE, "true");
framework.doCometSupport(request, AtmosphereResponseImpl.newInstance().request(request));
AtmosphereResource r = parentRequest.resource();
Broadcaster b = r.getBroadcaster();
assertEquals(b.getAtmosphereResources().size(), 1);
AtmosphereResourceImpl.class.cast(r).cancel();
assertEquals(b.getAtmosphereResources().size(), 0);
}
use of org.atmosphere.handler.AbstractReflectorAtmosphereHandler in project atmosphere by Atmosphere.
the class AtmosphereRequestTest method testQueryStringAsRequest.
@Test
public void testQueryStringAsRequest() throws IOException, ServletException {
framework.addAtmosphereHandler("/a", new AbstractReflectorAtmosphereHandler() {
@Override
public void onRequest(AtmosphereResource resource) throws IOException {
}
@Override
public void destroy() {
}
});
Map<String, String[]> qs = new HashMap<String, String[]>();
qs.put("Content-Type", new String[] { "application/xml" });
qs.put("X-Atmosphere-Transport", new String[] { "long-polling" });
AtmosphereRequest request = new AtmosphereRequestImpl.Builder().queryStrings(qs).pathInfo("/a").build();
final AtomicReference<String> e = new AtomicReference<String>();
final AtomicReference<String> e2 = new AtomicReference<String>();
framework.interceptor(new AtmosphereInterceptor() {
@Override
public void configure(AtmosphereConfig config) {
}
@Override
public Action inspect(AtmosphereResource r) {
e.set(r.getRequest().getContentType());
e2.set(r.transport().name());
return Action.CANCELLED;
}
@Override
public void postInspect(AtmosphereResource r) {
}
@Override
public void destroy() {
}
});
framework.doCometSupport(request, AtmosphereResponseImpl.newInstance());
assertEquals(e.get(), "application/xml");
assertEquals(e2.get().toLowerCase(), "long_polling");
}
use of org.atmosphere.handler.AbstractReflectorAtmosphereHandler in project atmosphere by Atmosphere.
the class AtmosphereResourceTest method testUUID.
@Test
public void testUUID() 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();
final AtomicReference<String> e = new AtomicReference<String>();
final AtomicReference<String> e2 = new AtomicReference<String>();
framework.interceptor(new AtmosphereInterceptor() {
@Override
public void configure(AtmosphereConfig config) {
}
@Override
public Action inspect(AtmosphereResource r) {
e.set(r.uuid());
e2.set(r.getResponse().getHeader(HeaderConfig.X_ATMOSPHERE_TRACKING_ID));
return Action.CANCELLED;
}
@Override
public void postInspect(AtmosphereResource r) {
}
@Override
public void destroy() {
}
});
framework.doCometSupport(request, AtmosphereResponseImpl.newInstance());
assertEquals(e.get(), e2.get());
}
use of org.atmosphere.handler.AbstractReflectorAtmosphereHandler in project atmosphere by Atmosphere.
the class AtmosphereRequestTest method testQueryStringBuilder.
@Test
public void testQueryStringBuilder() 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().queryString("a=b").pathInfo("/a").build();
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");
}
Aggregations