Search in sources :

Example 6 with ServletException

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();
        }
    });
}
Also used : SimpleBroadcaster(org.atmosphere.util.SimpleBroadcaster) ServletException(jakarta.servlet.ServletException) AtmosphereResponse(org.atmosphere.cpr.AtmosphereResponse) Action(org.atmosphere.cpr.Action) AtmosphereHandlerAdapter(org.atmosphere.handler.AtmosphereHandlerAdapter) AtmosphereRequest(org.atmosphere.cpr.AtmosphereRequest) AtmosphereResource(org.atmosphere.cpr.AtmosphereResource) AsynchronousProcessor(org.atmosphere.cpr.AsynchronousProcessor) AtmosphereFramework(org.atmosphere.cpr.AtmosphereFramework) IOException(java.io.IOException) AtmosphereResourceImpl(org.atmosphere.cpr.AtmosphereResourceImpl) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 7 with ServletException

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;
        }
    });
}
Also used : ServletException(jakarta.servlet.ServletException) Enumeration(java.util.Enumeration) ServletConfig(jakarta.servlet.ServletConfig) ServletContext(jakarta.servlet.ServletContext) IOException(java.io.IOException) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 8 with ServletException

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);
}
Also used : ServletException(jakarta.servlet.ServletException) SimpleBroadcaster(org.atmosphere.util.SimpleBroadcaster) IOException(java.io.IOException) Test(org.testng.annotations.Test)

Example 9 with ServletException

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);
}
Also used : ServletException(jakarta.servlet.ServletException) SimpleBroadcaster(org.atmosphere.util.SimpleBroadcaster) IOException(java.io.IOException) Test(org.testng.annotations.Test)

Example 10 with ServletException

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());
}
Also used : Enumeration(java.util.Enumeration) ServletConfig(jakarta.servlet.ServletConfig) IOException(java.io.IOException) ServletException(jakarta.servlet.ServletException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ServletContext(jakarta.servlet.ServletContext) Test(org.testng.annotations.Test)

Aggregations

ServletException (jakarta.servlet.ServletException)127 IOException (java.io.IOException)78 Test (org.junit.jupiter.api.Test)31 HttpServletRequest (jakarta.servlet.http.HttpServletRequest)23 HttpServletResponse (jakarta.servlet.http.HttpServletResponse)23 ServletContext (jakarta.servlet.ServletContext)19 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)17 MockHttpServletRequest (org.springframework.web.testfixture.servlet.MockHttpServletRequest)15 FilterChain (jakarta.servlet.FilterChain)13 MockHttpServletResponse (org.springframework.web.testfixture.servlet.MockHttpServletResponse)13 Enumeration (java.util.Enumeration)12 BeforeEach (org.junit.jupiter.api.BeforeEach)12 HttpHeaders (org.springframework.http.HttpHeaders)11 BeforeMethod (org.testng.annotations.BeforeMethod)11 ServletConfig (jakarta.servlet.ServletConfig)10 ServletRequest (jakarta.servlet.ServletRequest)10 ServletResponse (jakarta.servlet.ServletResponse)10 Arrays (java.util.Arrays)10 UnavailableException (jakarta.servlet.UnavailableException)9 HttpMethod (org.springframework.http.HttpMethod)9