Search in sources :

Example 1 with AtmosphereFramework

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

the class AtmosphereInterceptorServiceProcessor method handle.

@Override
public void handle(final AtmosphereFramework framework, Class<AtmosphereInterceptor> annotatedClass) {
    try {
        final AtmosphereInterceptor a = (AtmosphereInterceptor) framework.newClassInstance(AtmosphereInterceptor.class, annotatedClass);
        framework.getAtmosphereConfig().startupHook(new AtmosphereConfig.StartupHook() {

            @Override
            public void started(AtmosphereFramework framework) {
                framework.interceptor(a);
            }
        });
    } catch (Throwable e) {
        logger.warn("", e);
    }
}
Also used : AtmosphereInterceptor(org.atmosphere.runtime.AtmosphereInterceptor) AtmosphereConfig(org.atmosphere.runtime.AtmosphereConfig) AtmosphereFramework(org.atmosphere.runtime.AtmosphereFramework)

Example 2 with AtmosphereFramework

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

Example 3 with AtmosphereFramework

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

the class SSEAtmosphereInterceptorTest method setup.

@BeforeMethod
public void setup() throws Exception {
    framework = new AtmosphereFramework();
    framework.setAsyncSupport(Mockito.mock(AsyncSupport.class));
    framework.init(new ServletConfig() {

        @Override
        public String getServletName() {
            return "void";
        }

        @Override
        public ServletContext getServletContext() {
            return Mockito.mock(ServletContext.class);
        }

        @Override
        public String getInitParameter(String name) {
            return null;
        }

        @Override
        public Enumeration<String> getInitParameterNames() {
            return null;
        }
    });
    config = framework.getAtmosphereConfig();
}
Also used : Enumeration(java.util.Enumeration) AtmosphereFramework(org.atmosphere.runtime.AtmosphereFramework) AsyncSupport(org.atmosphere.runtime.AsyncSupport) ServletConfig(javax.servlet.ServletConfig) ServletContext(javax.servlet.ServletContext) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 4 with AtmosphereFramework

use of org.atmosphere.runtime.AtmosphereFramework 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;
        }
    });
}
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 5 with AtmosphereFramework

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

the class WebSocketTest method create.

@BeforeMethod
public void create() throws Throwable {
    framework = new AtmosphereFramework();
    framework.setAsyncSupport(new BlockingIOCometSupport(framework.getAtmosphereConfig()));
    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;
        }
    });
}
Also used : BlockingIOCometSupport(org.atmosphere.container.BlockingIOCometSupport) Enumeration(java.util.Enumeration) AtmosphereFramework(org.atmosphere.runtime.AtmosphereFramework) ServletConfig(javax.servlet.ServletConfig) ServletContext(javax.servlet.ServletContext) BeforeMethod(org.testng.annotations.BeforeMethod)

Aggregations

AtmosphereFramework (org.atmosphere.runtime.AtmosphereFramework)9 BeforeMethod (org.testng.annotations.BeforeMethod)8 IOException (java.io.IOException)6 Enumeration (java.util.Enumeration)6 ServletConfig (javax.servlet.ServletConfig)6 ServletContext (javax.servlet.ServletContext)6 ServletException (javax.servlet.ServletException)6 AsynchronousProcessor (org.atmosphere.runtime.AsynchronousProcessor)6 AtmosphereRequest (org.atmosphere.runtime.AtmosphereRequest)6 AtmosphereResourceImpl (org.atmosphere.runtime.AtmosphereResourceImpl)6 AtmosphereResponse (org.atmosphere.runtime.AtmosphereResponse)6 SimpleBroadcaster (org.atmosphere.util.SimpleBroadcaster)5 CountDownLatch (java.util.concurrent.CountDownLatch)1 BlockingIOCometSupport (org.atmosphere.container.BlockingIOCometSupport)1 AtmosphereHandlerAdapter (org.atmosphere.handler.AtmosphereHandlerAdapter)1 Action (org.atmosphere.runtime.Action)1 AsyncSupport (org.atmosphere.runtime.AsyncSupport)1 AtmosphereConfig (org.atmosphere.runtime.AtmosphereConfig)1 AtmosphereInterceptor (org.atmosphere.runtime.AtmosphereInterceptor)1 AtmosphereResource (org.atmosphere.runtime.AtmosphereResource)1