use of jakarta.servlet.ServletException in project atmosphere by Atmosphere.
the class AnnotationScanningTest method create.
@BeforeMethod
public void create() throws Throwable {
framework = new AtmosphereFramework();
framework.setDefaultBroadcasterClassName(SimpleBroadcaster.class.getName());
framework.addAnnotationPackage(AnnotationScanningTest.class);
framework.setAsyncSupport(new AsynchronousProcessor(framework.getAtmosphereConfig()) {
@Override
public Action service(AtmosphereRequest req, AtmosphereResponse res) throws IOException, ServletException {
return suspended(req, res);
}
public void action(AtmosphereResourceImpl r) {
try {
resumed(r.getRequest(), r.getResponse());
} catch (IOException e) {
e.printStackTrace();
} catch (ServletException e) {
e.printStackTrace();
}
}
}).init().addAtmosphereHandler("/a", new AtmosphereHandlerAdapter() {
@Override
public void onRequest(AtmosphereResource resource) throws IOException {
resource.suspend();
}
});
}
use of jakarta.servlet.ServletException in project atmosphere by Atmosphere.
the class AtmosphereHandlerTest method create.
@BeforeMethod
public void create() throws Throwable {
framework = new AtmosphereFramework();
framework.setAsyncSupport(new AsynchronousProcessor(framework.getAtmosphereConfig()) {
@Override
public Action service(AtmosphereRequest req, AtmosphereResponse res) throws IOException, ServletException {
return suspended(req, res);
}
public void action(AtmosphereResourceImpl r) {
try {
resumed(r.getRequest(), r.getResponse());
} catch (IOException e) {
e.printStackTrace();
} catch (ServletException e) {
e.printStackTrace();
}
}
}).init(new ServletConfig() {
@Override
public String getServletName() {
return "void";
}
@Override
public ServletContext getServletContext() {
return mock(ServletContext.class);
}
@Override
public String getInitParameter(String name) {
return null;
}
@Override
public Enumeration<String> getInitParameterNames() {
return null;
}
});
}
use of jakarta.servlet.ServletException in project atmosphere by Atmosphere.
the class BroadcasterTest method testCancelAtmosphereResource.
@Test
public void testCancelAtmosphereResource() throws ExecutionException, InterruptedException, ServletException, IOException {
Broadcaster two = ar.getAtmosphereConfig().getBroadcasterFactory().get(DefaultBroadcaster.class, "two");
two.addAtmosphereResource(ar);
ar.getRequest().setAttribute(FrameworkConfig.ATMOSPHERE_RESOURCE, ar);
ar.getAtmosphereConfig().framework().setAsyncSupport(new AsynchronousProcessor(ar.getAtmosphereConfig()) {
@Override
public Action service(AtmosphereRequest req, AtmosphereResponse res) throws IOException, ServletException {
return Action.CONTINUE;
}
});
AsynchronousProcessor.class.cast(ar.getAtmosphereConfig().framework().getAsyncSupport()).cancelled(ar.getRequest(), ar.getResponse());
assertEquals(broadcaster.getAtmosphereResources().size(), 0);
assertEquals(two.getAtmosphereResources().size(), 0);
}
use of jakarta.servlet.ServletException in project atmosphere by Atmosphere.
the class BroadcasterTest method testTimeoutAtmosphereResource.
@Test
public void testTimeoutAtmosphereResource() throws ExecutionException, InterruptedException, ServletException, IOException {
Broadcaster two = ar.getAtmosphereConfig().getBroadcasterFactory().get(DefaultBroadcaster.class, "two");
two.addAtmosphereResource(ar);
ar.getRequest().setAttribute(FrameworkConfig.ATMOSPHERE_RESOURCE, ar);
ar.getAtmosphereConfig().framework().setAsyncSupport(new AsynchronousProcessor(ar.getAtmosphereConfig()) {
@Override
public Action service(AtmosphereRequest req, AtmosphereResponse res) throws IOException, ServletException {
return Action.CONTINUE;
}
});
AsynchronousProcessor.class.cast(ar.getAtmosphereConfig().framework().getAsyncSupport()).timedout(ar.getRequest(), ar.getResponse());
assertEquals(broadcaster.getAtmosphereResources().size(), 0);
assertEquals(two.getAtmosphereResources().size(), 0);
}
use of jakarta.servlet.ServletException in project atmosphere by Atmosphere.
the class AtmosphereInterceptorTest method configureTest.
@Test
public void configureTest() throws ServletException, IOException {
final AtomicInteger count = new AtomicInteger();
framework = new AtmosphereFramework();
framework.setAsyncSupport(mock(AsyncSupport.class));
framework.interceptor(new AtmosphereInterceptor() {
@Override
public void configure(AtmosphereConfig config) {
count.incrementAndGet();
}
@Override
public Action inspect(AtmosphereResource r) {
return Action.CREATED;
}
@Override
public void destroy() {
}
@Override
public void postInspect(AtmosphereResource r) {
}
});
framework.init(new ServletConfig() {
@Override
public String getServletName() {
return "void";
}
@Override
public ServletContext getServletContext() {
return mock(ServletContext.class);
}
@Override
public String getInitParameter(String name) {
return null;
}
@Override
public Enumeration<String> getInitParameterNames() {
return null;
}
});
config = framework.getAtmosphereConfig();
processor = new AsynchronousProcessor(config) {
@Override
public Action service(AtmosphereRequest req, AtmosphereResponse res) throws IOException, ServletException {
return action(req, res);
}
};
framework.addAtmosphereHandler("/*", handler);
assertEquals(Action.CREATED, processor.service(mock(AtmosphereRequestImpl.class), AtmosphereResponseImpl.newInstance()));
assertEquals(1, count.get());
}
Aggregations