Search in sources :

Example 16 with AtmosphereResponse

use of org.atmosphere.cpr.AtmosphereResponse 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(BroadcasterCacheTest.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 | 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 : AtmosphereResponse(org.atmosphere.cpr.AtmosphereResponse) Enumeration(java.util.Enumeration) ServletConfig(jakarta.servlet.ServletConfig) IOException(java.io.IOException) SimpleBroadcaster(org.atmosphere.util.SimpleBroadcaster) ServletException(jakarta.servlet.ServletException) AtmosphereRequest(org.atmosphere.cpr.AtmosphereRequest) AsynchronousProcessor(org.atmosphere.cpr.AsynchronousProcessor) AtmosphereFramework(org.atmosphere.cpr.AtmosphereFramework) ServletContext(jakarta.servlet.ServletContext) AtmosphereResourceImpl(org.atmosphere.cpr.AtmosphereResourceImpl) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 17 with AtmosphereResponse

use of org.atmosphere.cpr.AtmosphereResponse in project atmosphere by Atmosphere.

the class CustomAnnotationTest method create.

@BeforeMethod
public void create() throws Throwable {
    framework = new AtmosphereFramework();
    framework.setDefaultBroadcasterClassName(SimpleBroadcaster.class.getName());
    framework.addAnnotationPackage(MyAnnotation.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 null;
        }

        @Override
        public Enumeration<String> getInitParameterNames() {
            return null;
        }
    });
}
Also used : AtmosphereResponse(org.atmosphere.cpr.AtmosphereResponse) Enumeration(java.util.Enumeration) ServletConfig(jakarta.servlet.ServletConfig) IOException(java.io.IOException) SimpleBroadcaster(org.atmosphere.util.SimpleBroadcaster) ServletException(jakarta.servlet.ServletException) AtmosphereRequest(org.atmosphere.cpr.AtmosphereRequest) AsynchronousProcessor(org.atmosphere.cpr.AsynchronousProcessor) AtmosphereFramework(org.atmosphere.cpr.AtmosphereFramework) ServletContext(jakarta.servlet.ServletContext) AtmosphereResourceImpl(org.atmosphere.cpr.AtmosphereResourceImpl) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 18 with AtmosphereResponse

use of org.atmosphere.cpr.AtmosphereResponse in project atmosphere by Atmosphere.

the class PathTest method create.

@BeforeMethod
public void create() throws Throwable {
    framework = new AtmosphereFramework();
    framework.addAnnotationPackage(AtmosphereHandlerPath.class);
    framework.setAsyncSupport(new AsynchronousProcessor(framework.getAtmosphereConfig()) {

        @Override
        public Action service(AtmosphereRequest req, AtmosphereResponse res) throws IOException, ServletException {
            return suspended(req, res);
        }

        @Override
        public void action(AtmosphereResourceImpl r) {
            try {
                resumed(r.getRequest(), r.getResponse());
            } catch (IOException e) {
                e.printStackTrace();
            } catch (ServletException e) {
                e.printStackTrace();
            }
        }
    }).init();
}
Also used : ServletException(jakarta.servlet.ServletException) AtmosphereResponse(org.atmosphere.cpr.AtmosphereResponse) AtmosphereRequest(org.atmosphere.cpr.AtmosphereRequest) AsynchronousProcessor(org.atmosphere.cpr.AsynchronousProcessor) AtmosphereFramework(org.atmosphere.cpr.AtmosphereFramework) AtmosphereResourceImpl(org.atmosphere.cpr.AtmosphereResourceImpl) IOException(java.io.IOException) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 19 with AtmosphereResponse

use of org.atmosphere.cpr.AtmosphereResponse in project atmosphere by Atmosphere.

the class DefaultWebSocketProcessor method configure.

public WebSocketProcessor configure(AtmosphereConfig config) {
    this.framework = config.framework();
    this.webSocketProtocol = framework.getWebSocketProtocol();
    destroyable = Boolean.parseBoolean(framework.getAtmosphereConfig().getInitParameter(RECYCLE_ATMOSPHERE_REQUEST_RESPONSE));
    executeAsync = Boolean.parseBoolean(framework.getAtmosphereConfig().getInitParameter(WEBSOCKET_PROTOCOL_EXECUTION));
    allow1005StatusCode = Boolean.parseBoolean(framework.getAtmosphereConfig().getInitParameter(ALLOW_WEBSOCKET_STATUS_CODE_1005_AS_DISCONNECT));
    String s = framework.getAtmosphereConfig().getInitParameter(IN_MEMORY_STREAMING_BUFFER_SIZE);
    if (s != null) {
        byteBufferMaxSize = Integer.parseInt(s);
        charBufferMaxSize = byteBufferMaxSize;
    }
    if (executeAsync) {
        asyncExecutor = ExecutorsFactory.getAsyncOperationExecutor(config, "WebSocket");
    } else {
        asyncExecutor = VoidExecutorService.VOID;
    }
    scheduler = ExecutorsFactory.getScheduler(config);
    optimizeMapping();
    closingTime = Long.valueOf(config.getInitParameter(ApplicationConfig.CLOSED_ATMOSPHERE_THINK_TIME, "0"));
    invokeInterceptors = Boolean.valueOf(config.getInitParameter(INVOKE_ATMOSPHERE_INTERCEPTOR_ON_WEBSOCKET_MESSAGE, "true"));
    config.startupHook(framework -> {
        if (AsynchronousProcessor.class.isAssignableFrom(framework.getAsyncSupport().getClass())) {
            asynchronousProcessor = AsynchronousProcessor.class.cast(framework.getAsyncSupport());
        } else {
            asynchronousProcessor = new AsynchronousProcessor(framework.getAtmosphereConfig()) {

                @Override
                public Action service(AtmosphereRequest req, AtmosphereResponse res) throws IOException, ServletException {
                    return framework.getAsyncSupport().service(req, res);
                }
            };
        }
    });
    return this;
}
Also used : ServletException(jakarta.servlet.ServletException) AtmosphereResponse(org.atmosphere.cpr.AtmosphereResponse) Action(org.atmosphere.cpr.Action) AtmosphereRequest(org.atmosphere.cpr.AtmosphereRequest) AsynchronousProcessor(org.atmosphere.cpr.AsynchronousProcessor) IOException(java.io.IOException)

Example 20 with AtmosphereResponse

use of org.atmosphere.cpr.AtmosphereResponse in project atmosphere by Atmosphere.

the class EncoderDecoderTest method create.

@BeforeMethod
public void create() throws Throwable {
    framework = new AtmosphereFramework();
    framework.setDefaultBroadcasterClassName(SimpleBroadcaster.class.getName());
    framework.addAnnotationPackage(ManagedMessage.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 null;
        }

        @Override
        public Enumeration<String> getInitParameterNames() {
            return null;
        }
    });
    latch.set(new CountDownLatch(1));
}
Also used : AtmosphereResponse(org.atmosphere.cpr.AtmosphereResponse) Enumeration(java.util.Enumeration) ServletConfig(jakarta.servlet.ServletConfig) IOException(java.io.IOException) CountDownLatch(java.util.concurrent.CountDownLatch) SimpleBroadcaster(org.atmosphere.util.SimpleBroadcaster) ServletException(jakarta.servlet.ServletException) AtmosphereRequest(org.atmosphere.cpr.AtmosphereRequest) AsynchronousProcessor(org.atmosphere.cpr.AsynchronousProcessor) AtmosphereFramework(org.atmosphere.cpr.AtmosphereFramework) ServletContext(jakarta.servlet.ServletContext) AtmosphereResourceImpl(org.atmosphere.cpr.AtmosphereResourceImpl) BeforeMethod(org.testng.annotations.BeforeMethod)

Aggregations

AtmosphereResponse (org.atmosphere.cpr.AtmosphereResponse)29 AtmosphereRequest (org.atmosphere.cpr.AtmosphereRequest)21 IOException (java.io.IOException)19 AsyncIOWriter (org.atmosphere.cpr.AsyncIOWriter)12 AtmosphereResourceImpl (org.atmosphere.cpr.AtmosphereResourceImpl)12 AtmosphereInterceptorWriter (org.atmosphere.cpr.AtmosphereInterceptorWriter)10 ServletException (jakarta.servlet.ServletException)9 AsynchronousProcessor (org.atmosphere.cpr.AsynchronousProcessor)7 AtmosphereFramework (org.atmosphere.cpr.AtmosphereFramework)7 BeforeMethod (org.testng.annotations.BeforeMethod)6 AsyncIOInterceptorAdapter (org.atmosphere.cpr.AsyncIOInterceptorAdapter)5 SimpleBroadcaster (org.atmosphere.util.SimpleBroadcaster)5 ServletConfig (jakarta.servlet.ServletConfig)4 ServletContext (jakarta.servlet.ServletContext)4 Enumeration (java.util.Enumeration)4 Action (org.atmosphere.cpr.Action)4 AtmosphereResource (org.atmosphere.cpr.AtmosphereResource)3 AtmosphereResourceEvent (org.atmosphere.cpr.AtmosphereResourceEvent)3 Test (org.testng.annotations.Test)3 List (java.util.List)2