Search in sources :

Example 1 with AtmosphereConfig

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

the class AtmosphereServiceProcessor method handle.

@Override
public void handle(AtmosphereFramework framework, Class<Object> annotatedClass) {
    try {
        Class<?> aClass = annotatedClass;
        AtmosphereService a = aClass.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>();
        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.runtime.AtmosphereInterceptor) AtmosphereConfig(org.atmosphere.runtime.AtmosphereConfig) AtmosphereResource(org.atmosphere.runtime.AtmosphereResource) LinkedList(java.util.LinkedList) AtmosphereHandler(org.atmosphere.runtime.AtmosphereHandler) AtmosphereServletProcessor(org.atmosphere.runtime.AtmosphereServletProcessor) AtmosphereResourceEvent(org.atmosphere.runtime.AtmosphereResourceEvent) ReflectorServletProcessor(org.atmosphere.handler.ReflectorServletProcessor)

Example 2 with AtmosphereConfig

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

the class Utils method inject.

public static final void inject(AtmosphereResource r) throws IllegalAccessException {
    AtmosphereConfig config = r.getAtmosphereConfig();
    // No Injectable supports Injection
    if (config.properties().get(NEED_RUNTIME_INJECTION) == null) {
        return;
    }
    AtmosphereObjectFactory injectableFactory = config.framework().objectFactory();
    if (!InjectableObjectFactory.class.isAssignableFrom(injectableFactory.getClass())) {
        return;
    }
    Object injectIn = injectWith(r);
    if (injectIn != null) {
        inject(injectIn, injectIn.getClass(), r);
    }
}
Also used : AtmosphereConfig(org.atmosphere.runtime.AtmosphereConfig) AtmosphereObjectFactory(org.atmosphere.runtime.AtmosphereObjectFactory) InjectableObjectFactory(org.atmosphere.inject.InjectableObjectFactory)

Aggregations

AtmosphereConfig (org.atmosphere.runtime.AtmosphereConfig)2 LinkedList (java.util.LinkedList)1 AtmosphereService (org.atmosphere.config.service.AtmosphereService)1 ReflectorServletProcessor (org.atmosphere.handler.ReflectorServletProcessor)1 InjectableObjectFactory (org.atmosphere.inject.InjectableObjectFactory)1 AtmosphereHandler (org.atmosphere.runtime.AtmosphereHandler)1 AtmosphereInterceptor (org.atmosphere.runtime.AtmosphereInterceptor)1 AtmosphereObjectFactory (org.atmosphere.runtime.AtmosphereObjectFactory)1 AtmosphereResource (org.atmosphere.runtime.AtmosphereResource)1 AtmosphereResourceEvent (org.atmosphere.runtime.AtmosphereResourceEvent)1 AtmosphereServletProcessor (org.atmosphere.runtime.AtmosphereServletProcessor)1