Search in sources :

Example 6 with AtmosphereInterceptor

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

the class MeteorServiceProcessor method handle.

@Override
public void handle(AtmosphereFramework framework, Class<Servlet> annotatedClass) {
    try {
        ReflectorServletProcessor r = framework.newClassInstance(ReflectorServletProcessor.class, ReflectorServletProcessor.class);
        r.setServletClassName(annotatedClass.getName());
        LinkedList<AtmosphereInterceptor> l = new LinkedList<>();
        MeteorService m = annotatedClass.getAnnotation(MeteorService.class);
        framework.setBroadcasterCacheClassName(m.broadcasterCache().getName());
        String mapping = m.path();
        atmosphereConfig(m.atmosphereConfig(), framework);
        filters(m.broadcastFilters(), framework);
        AtmosphereInterceptor aa = listeners(m.listeners(), framework);
        if (aa != null) {
            l.add(aa);
        }
        AnnotationUtil.interceptorsForHandler(framework, Arrays.asList(m.interceptors()), l);
        if (m.path().contains("{")) {
            l.addFirst(framework.newClassInstance(AtmosphereInterceptor.class, MeteorServiceInterceptor.class));
        }
        framework.addAtmosphereHandler(mapping, r, broadcaster(framework, m.broadcaster(), m.path()), l);
    } catch (Throwable e) {
        logger.warn("", e);
    }
}
Also used : AtmosphereInterceptor(org.atmosphere.cpr.AtmosphereInterceptor) MeteorService(org.atmosphere.config.service.MeteorService) ReflectorServletProcessor(org.atmosphere.handler.ReflectorServletProcessor) MeteorServiceInterceptor(org.atmosphere.config.managed.MeteorServiceInterceptor) LinkedList(java.util.LinkedList)

Example 7 with AtmosphereInterceptor

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

the class AtmosphereHandlerServiceProcessor method handle.

@Override
public void handle(AtmosphereFramework framework, Class<AtmosphereHandler> annotatedClass) {
    try {
        AtmosphereHandlerService a = annotatedClass.getAnnotation(AtmosphereHandlerService.class);
        atmosphereConfig(a.atmosphereConfig(), framework);
        filters(a.broadcastFilters(), framework);
        Class<? extends AtmosphereInterceptor>[] interceptors = a.interceptors();
        LinkedList<AtmosphereInterceptor> l = new LinkedList<>();
        for (Class<? extends AtmosphereInterceptor> i : interceptors) {
            try {
                AtmosphereInterceptor ai = framework.newClassInstance(AtmosphereInterceptor.class, i);
                l.add(ai);
            } catch (Throwable e) {
                logger.warn("", e);
            }
        }
        AtmosphereInterceptor aa = listeners(a.listeners(), framework);
        if (aa != null) {
            l.add(aa);
        }
        if (a.path().contains("{")) {
            l.addFirst(framework.newClassInstance(AtmosphereInterceptor.class, AtmosphereHandlerServiceInterceptor.class));
        }
        framework.sessionSupport(a.supportSession());
        AtmosphereHandler handler = framework.newClassInstance(AtmosphereHandler.class, annotatedClass);
        for (String s : a.properties()) {
            String[] nv = s.split("=");
            IntrospectionUtils.setProperty(handler, nv[0], nv[1]);
            IntrospectionUtils.addProperty(handler, nv[0], nv[1]);
        }
        AnnotationUtil.interceptorsForHandler(framework, Arrays.asList(a.interceptors()), l);
        framework.addAtmosphereHandler(a.path(), handler, broadcaster(framework, a.broadcaster(), a.path()), l);
        framework.setBroadcasterCacheClassName(a.broadcasterCache().getName());
    } catch (Throwable e) {
        logger.warn("", e);
    }
}
Also used : AtmosphereInterceptor(org.atmosphere.cpr.AtmosphereInterceptor) AtmosphereHandlerService(org.atmosphere.config.service.AtmosphereHandlerService) AtmosphereHandlerServiceInterceptor(org.atmosphere.config.managed.AtmosphereHandlerServiceInterceptor) AtmosphereHandler(org.atmosphere.cpr.AtmosphereHandler) LinkedList(java.util.LinkedList)

Example 8 with AtmosphereInterceptor

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

the class AtmosphereInterceptorServiceProcessor method handle.

@Override
public void handle(final AtmosphereFramework framework, Class<AtmosphereInterceptor> annotatedClass) {
    try {
        final AtmosphereInterceptor a = framework.newClassInstance(AtmosphereInterceptor.class, annotatedClass);
        framework.getAtmosphereConfig().startupHook(framework1 -> framework1.interceptor(a));
    } catch (Throwable e) {
        logger.warn("", e);
    }
}
Also used : AtmosphereInterceptor(org.atmosphere.cpr.AtmosphereInterceptor)

Example 9 with AtmosphereInterceptor

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

the class AtmosphereServiceProcessor method handle.

@Override
public void handle(AtmosphereFramework framework, Class<Object> annotatedClass) {
    try {
        AtmosphereService a = annotatedClass.getAnnotation(AtmosphereService.class);
        framework.setBroadcasterCacheClassName(a.broadcasterCache().getName());
        atmosphereConfig(a.atmosphereConfig(), framework);
        framework.setDefaultBroadcasterClassName(a.broadcaster().getName());
        filters(a.broadcastFilters(), framework);
        LinkedList<AtmosphereInterceptor> l = new LinkedList<>();
        AtmosphereInterceptor aa = listeners(a.listeners(), framework);
        if (aa != null) {
            l.add(aa);
        }
        if (!a.servlet().isEmpty()) {
            final ReflectorServletProcessor r = framework.newClassInstance(ReflectorServletProcessor.class, ReflectorServletProcessor.class);
            r.setServletClassName(a.servlet());
            String mapping = a.path();
            AnnotationUtil.interceptorsForHandler(framework, Arrays.asList(a.interceptors()), l);
            if (!a.dispatch()) {
                AtmosphereHandler proxy = new AtmosphereServletProcessor() {

                    private String method = "GET";

                    @Override
                    public void onRequest(AtmosphereResource resource) throws IOException {
                        if (!resource.getRequest().getMethod().equalsIgnoreCase(method)) {
                            r.onRequest(resource);
                        }
                    }

                    @Override
                    public void onStateChange(AtmosphereResourceEvent event) throws IOException {
                        r.onStateChange(event);
                    }

                    @Override
                    public void destroy() {
                        r.destroy();
                    }

                    @Override
                    public void init(AtmosphereConfig config) throws ServletException {
                        String s = config.getInitParameter(ATMOSPHERERESOURCE_INTERCEPTOR_METHOD);
                        if (s != null) {
                            method = s;
                        }
                        r.init(config);
                    }
                };
                framework.addAtmosphereHandler(mapping, proxy, l);
            } else {
                framework.addAtmosphereHandler(mapping, r, l);
            }
        } else {
            interceptors(a.interceptors(), framework);
        }
    } catch (Throwable e) {
        logger.warn("", e);
    }
}
Also used : AtmosphereService(org.atmosphere.config.service.AtmosphereService) AtmosphereInterceptor(org.atmosphere.cpr.AtmosphereInterceptor) AtmosphereConfig(org.atmosphere.cpr.AtmosphereConfig) AtmosphereHandler(org.atmosphere.cpr.AtmosphereHandler) AtmosphereResource(org.atmosphere.cpr.AtmosphereResource) AtmosphereServletProcessor(org.atmosphere.cpr.AtmosphereServletProcessor) AtmosphereResourceEvent(org.atmosphere.cpr.AtmosphereResourceEvent) ReflectorServletProcessor(org.atmosphere.handler.ReflectorServletProcessor) LinkedList(java.util.LinkedList)

Example 10 with AtmosphereInterceptor

use of org.atmosphere.cpr.AtmosphereInterceptor in project cxf by apache.

the class AtmosphereWebSocketJettyDestinationTest method testUseCustomAtmoosphereInterceptors.

@Test
public void testUseCustomAtmoosphereInterceptors() throws Exception {
    Bus bus = new ExtensionManagerBus();
    bus.setProperty("atmosphere.interceptors", Arrays.asList(new CustomInterceptor1(), new CustomInterceptor2()));
    DestinationRegistry registry = new HTTPTransportFactory().getRegistry();
    EndpointInfo endpoint = new EndpointInfo();
    endpoint.setAddress(ENDPOINT_ADDRESS);
    endpoint.setName(ENDPOINT_NAME);
    AtmosphereWebSocketServletDestination dest = new AtmosphereWebSocketServletDestination(bus, registry, endpoint, ENDPOINT_ADDRESS);
    List<AtmosphereInterceptor> ais = dest.getAtmosphereFramework().interceptors();
    int added = 0;
    for (AtmosphereInterceptor a : ais) {
        if (CustomInterceptor1.class.equals(a.getClass())) {
            added++;
        } else if (CustomInterceptor2.class.equals(a.getClass())) {
            added++;
            break;
        }
    }
    assertEquals(2, added);
}
Also used : AtmosphereInterceptor(org.atmosphere.cpr.AtmosphereInterceptor) Bus(org.apache.cxf.Bus) ExtensionManagerBus(org.apache.cxf.bus.extension.ExtensionManagerBus) DestinationRegistry(org.apache.cxf.transport.http.DestinationRegistry) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) HTTPTransportFactory(org.apache.cxf.transport.http.HTTPTransportFactory) ExtensionManagerBus(org.apache.cxf.bus.extension.ExtensionManagerBus) Test(org.junit.Test)

Aggregations

AtmosphereInterceptor (org.atmosphere.cpr.AtmosphereInterceptor)15 Bus (org.apache.cxf.Bus)6 ExtensionManagerBus (org.apache.cxf.bus.extension.ExtensionManagerBus)6 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)6 DestinationRegistry (org.apache.cxf.transport.http.DestinationRegistry)6 HTTPTransportFactory (org.apache.cxf.transport.http.HTTPTransportFactory)6 Test (org.junit.Test)6 LinkedList (java.util.LinkedList)5 AtmosphereHandler (org.atmosphere.cpr.AtmosphereHandler)3 IOException (java.io.IOException)2 WebSocketHandlerService (org.atmosphere.config.service.WebSocketHandlerService)2 AtmosphereRequest (org.atmosphere.cpr.AtmosphereRequest)2 AtmosphereResourceEvent (org.atmosphere.cpr.AtmosphereResourceEvent)2 AtmosphereResourceImpl (org.atmosphere.cpr.AtmosphereResourceImpl)2 BroadcastFilter (org.atmosphere.cpr.BroadcastFilter)2 ReflectorServletProcessor (org.atmosphere.handler.ReflectorServletProcessor)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 Reader (java.io.Reader)1 StringReader (java.io.StringReader)1