Search in sources :

Example 21 with AtmosphereResponse

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

the class TrackMessageSizeInterceptor method inspect.

@Override
public Action inspect(final AtmosphereResource r) {
    if (AtmosphereResource.TRANSPORT.UNDEFINED == r.transport() || Utils.webSocketMessage(r))
        return Action.CONTINUE;
    final AtmosphereResponse response = r.getResponse();
    super.inspect(r);
    AsyncIOWriter writer = response.getAsyncIOWriter();
    if (AtmosphereInterceptorWriter.class.isAssignableFrom(writer.getClass())) {
        AtmosphereInterceptorWriter.class.cast(writer).interceptor(interceptor);
    } else {
        logger.warn("Unable to apply {}. Your AsyncIOWriter must implement {}", getClass().getName(), AtmosphereInterceptorWriter.class.getName());
    }
    return Action.CONTINUE;
}
Also used : AtmosphereResponse(org.atmosphere.runtime.AtmosphereResponse) AsyncIOWriter(org.atmosphere.runtime.AsyncIOWriter) AtmosphereInterceptorWriter(org.atmosphere.runtime.AtmosphereInterceptorWriter)

Example 22 with AtmosphereResponse

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

Example 23 with AtmosphereResponse

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

Example 24 with AtmosphereResponse

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

Example 25 with AtmosphereResponse

use of org.atmosphere.runtime.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(javax.servlet.ServletException) AtmosphereResponse(org.atmosphere.runtime.AtmosphereResponse) AtmosphereRequest(org.atmosphere.runtime.AtmosphereRequest) AsynchronousProcessor(org.atmosphere.runtime.AsynchronousProcessor) AtmosphereFramework(org.atmosphere.runtime.AtmosphereFramework) AtmosphereResourceImpl(org.atmosphere.runtime.AtmosphereResourceImpl) IOException(java.io.IOException) BeforeMethod(org.testng.annotations.BeforeMethod)

Aggregations

AtmosphereResponse (org.atmosphere.runtime.AtmosphereResponse)25 AtmosphereRequest (org.atmosphere.runtime.AtmosphereRequest)18 IOException (java.io.IOException)16 AtmosphereResourceImpl (org.atmosphere.runtime.AtmosphereResourceImpl)12 AsyncIOWriter (org.atmosphere.runtime.AsyncIOWriter)11 AtmosphereInterceptorWriter (org.atmosphere.runtime.AtmosphereInterceptorWriter)9 ServletException (javax.servlet.ServletException)8 AsynchronousProcessor (org.atmosphere.runtime.AsynchronousProcessor)6 AtmosphereFramework (org.atmosphere.runtime.AtmosphereFramework)6 BeforeMethod (org.testng.annotations.BeforeMethod)6 AsyncIOInterceptorAdapter (org.atmosphere.runtime.AsyncIOInterceptorAdapter)5 SimpleBroadcaster (org.atmosphere.util.SimpleBroadcaster)5 Enumeration (java.util.Enumeration)4 ServletConfig (javax.servlet.ServletConfig)4 ServletContext (javax.servlet.ServletContext)4 AtmosphereResourceEvent (org.atmosphere.runtime.AtmosphereResourceEvent)3 Test (org.testng.annotations.Test)3 List (java.util.List)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 Action (org.atmosphere.runtime.Action)2