use of jakarta.servlet.ServletException in project atmosphere by Atmosphere.
the class AtmosphereFramework method loadConfiguration.
public void loadConfiguration(ServletConfig sc) throws ServletException {
if (!autoDetectHandlers)
return;
try {
URL url = sc.getServletContext().getResource(handlersPath);
ClassLoader urlC = url == null ? getClass().getClassLoader() : new URLClassLoader(new URL[] { url }, Thread.currentThread().getContextClassLoader());
loadAtmosphereDotXml(sc.getServletContext().getResourceAsStream(atmosphereDotXmlPath), urlC);
if (atmosphereHandlers.isEmpty()) {
autoDetectAtmosphereHandlers(sc.getServletContext(), urlC);
if (atmosphereHandlers.isEmpty()) {
detectSupportedFramework(sc);
}
}
autoDetectWebSocketHandler(sc.getServletContext(), urlC);
} catch (Throwable t) {
throw new ServletException(t);
}
}
use of jakarta.servlet.ServletException 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 jakarta.servlet.ServletException in project atmosphere by Atmosphere.
the class WebSocketProcessorTest 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 action(req, res);
}
});
framework.addInitParameter(RECYCLE_ATMOSPHERE_REQUEST_RESPONSE, "false");
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;
}
});
}
use of jakarta.servlet.ServletException in project atmosphere by Atmosphere.
the class AtmosphereSessionTest method testTrackAndTryAcquire.
@Test
public void testTrackAndTryAcquire() throws IOException, ServletException, InterruptedException {
final CountDownLatch latch = new CountDownLatch(1);
final AtomicReference<AtmosphereSession> session = new AtomicReference<AtmosphereSession>();
framework.addAtmosphereHandler("/acquire", new AtmosphereHandlerAdapter() {
@Override
public void onRequest(AtmosphereResource resource) throws IOException {
if (session.get() == null) {
session.set(new AtmosphereSession(resource));
}
resource.suspend(2, TimeUnit.SECONDS);
}
@Override
public void onStateChange(AtmosphereResourceEvent event) throws IOException {
latch.countDown();
}
});
final String qs = "&X-Atmosphere-tracking-id=c8834462-c46e-4dad-a22f-b86aabe3f883&X-Atmosphere-Framework=2.0.4-javascript&X-Atmosphere-Transport=sse&X-Atmosphere-TrackMessageSize=true&X-atmo-protocol=true&_=1380799455333";
AtmosphereRequest request = new AtmosphereRequestImpl.Builder().queryString(qs).pathInfo("/acquire").build();
framework.doCometSupport(request, AtmosphereResponseImpl.newInstance());
latch.await(10, TimeUnit.SECONDS);
assertNull(session.get().acquire());
final AtomicReference<AtmosphereResource> rrr = new AtomicReference<AtmosphereResource>();
final CountDownLatch _latch = new CountDownLatch(1);
framework.addAtmosphereHandler("/acquire", new AtmosphereHandlerAdapter() {
@Override
public void onRequest(final AtmosphereResource resource) throws IOException {
resource.suspend(2, TimeUnit.SECONDS);
}
@Override
public void onStateChange(AtmosphereResourceEvent event) throws IOException {
try {
rrr.set(session.get().tryAcquire());
_latch.countDown();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
});
request = new AtmosphereRequestImpl.Builder().queryString(qs).pathInfo("/acquire").build();
framework.doCometSupport(request, AtmosphereResponseImpl.newInstance(request));
_latch.await(10, TimeUnit.SECONDS);
assertNotNull(rrr.get());
new Thread() {
public void run() {
try {
Thread.sleep(1000);
AtmosphereRequest request = new AtmosphereRequestImpl.Builder().queryString(qs).pathInfo("/acquire").build();
framework.doCometSupport(request, AtmosphereResponseImpl.newInstance(request));
} catch (Exception e) {
e.printStackTrace();
}
}
}.start();
assertNotNull(session.get().tryAcquire());
}
use of jakarta.servlet.ServletException in project atmosphere by Atmosphere.
the class ManagedAtmosphereHandlerTest method create.
@BeforeMethod
public void create() throws Throwable {
framework = new AtmosphereFramework();
framework.setDefaultBroadcasterClassName(SimpleBroadcaster.class.getName());
framework.addAnnotationPackage(ManagedGet.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(new ServletConfig() {
@Override
public String getServletName() {
return "void";
}
@Override
public ServletContext getServletContext() {
return mock(ServletContext.class);
}
@Override
public String getInitParameter(String name) {
return ApplicationConfig.CLIENT_HEARTBEAT_INTERVAL_IN_SECONDS.equals(name) ? "10" : null;
}
@Override
public Enumeration<String> getInitParameterNames() {
return null;
}
});
}
Aggregations