@Override public void handle(AtmosphereFramework framework, Class<?> annotatedClass) { try { Class<WebSocketHandler> s = (Class<WebSocketHandler>) annotatedClass; WebSocketHandlerService m = s.getAnnotation(WebSocketHandlerService.class); atmosphereConfig(m.atmosphereConfig(), framework); framework .addAtmosphereHandler(m.path(), AtmosphereFramework.REFLECTOR_ATMOSPHEREHANDLER) .initWebSocket(); framework.setDefaultBroadcasterClassName(m.broadcaster().getName()); filters(m.broadcastFilters(), framework); interceptors(m.interceptors(), framework); AtmosphereInterceptor aa = listeners(m.listeners(), framework); if (aa != null) { framework.interceptor(aa); } WebSocketProcessor p = WebSocketProcessorFactory.getDefault().getWebSocketProcessor(framework); p.registerWebSocketHandler( m.path(), new WebSocketProcessor.WebSocketHandlerProxy( broadcasterClass(framework, m.broadcaster()), framework.newClassInstance(s))); } catch (Throwable e) { logger.warn("", e); } }
@Override public void handle(AtmosphereFramework framework, Class<BroadcastFilter> annotatedClass) { try { framework.broadcasterFilters( (BroadcastFilter) framework.newClassInstance(BroadcastFilter.class, annotatedClass)); } catch (Exception e) { logger.warn("", e); } }
@Override public void handle( AtmosphereFramework framework, Class<AtmosphereFrameworkListener> annotatedClass) { try { framework.frameworkListener( framework.newClassInstance(AtmosphereFrameworkListener.class, annotatedClass)); } catch (Exception e) { logger.error("", e); } }
/** * Adds the appropriate interceptor for each action. * * @param config the configuration * @param clazz the interceptor * @param action the actions * @throws InstantiationException if interceptor class can't be instantiated * @throws IllegalAccessException if interceptor class can't be instantiated */ private void configureInterceptor( final AtmosphereConfig config, final Class<? extends StompInterceptor> clazz, final org.atmosphere.stomp.protocol.Action... action) throws InstantiationException, IllegalAccessException { final StompInterceptor interceptor = framework.newClassInstance(StompInterceptor.class, clazz); interceptor.configure(config); for (org.atmosphere.stomp.protocol.Action a : action) { interceptors.put(a, interceptor); } }
/** {@inheritDoc} */ @Override public void configure(final AtmosphereConfig config) { framework = config.framework(); arsf = AtmosphereResourceSessionFactory.getDefault(); setStompFormat(PropertyClass.STOMP_FORMAT_CLASS.retrieve(StompFormat.class, config)); try { // TODO: user must map AtmosphereServlet to /stomp in web.xml, can we offer a chance to set a // custom location ? framework.addAtmosphereHandler( "/stomp", framework.newClassInstance( AtmosphereHandler.class, AbstractReflectorAtmosphereHandler.Default.class)); interceptors = new ConcurrentHashMap<org.atmosphere.stomp.protocol.Action, StompInterceptor>(); configureInterceptor( config, ConnectInterceptor.class, org.atmosphere.stomp.protocol.Action.CONNECT, org.atmosphere.stomp.protocol.Action.STOMP, org.atmosphere.stomp.protocol.Action.NULL); configureInterceptor( config, SubscribeInterceptor.class, org.atmosphere.stomp.protocol.Action.SUBSCRIBE); configureInterceptor( config, UnsubscribeInterceptor.class, org.atmosphere.stomp.protocol.Action.UNSUBSCRIBE); configureInterceptor( config, SendInterceptor.class, org.atmosphere.stomp.protocol.Action.SEND); final BroadcastFilterLifecycle filter = framework.newClassInstance(BroadcastFilterLifecycle.class, StompBroadcastFilter.class); framework.broadcasterFilters(filter); filter.init(config); } catch (InstantiationException e) { logger.error("", e); } catch (IllegalAccessException e) { logger.error("", e); } }
/** * Checks in the {@link AtmosphereConfig} if the {@link #propertyName} is defined as an * init-param and instantiate the appropriate class. * * <p>If instantiation fails, the exception is logged and {@code null} is returned. * * @param desiredType the type to be returned * @param config the configuration that provides parameters * @param <T> the generic for modular call * @return the instance of the expected class, {@code null} if an error occurs */ public <T> T retrieve(final Class<T> desiredType, final AtmosphereConfig config) { final String initParameter = config.getInitParameter(this.propertyName); final String className = (initParameter != null) ? initParameter : defaultClass; try { final AtmosphereFramework fwk = config.framework(); final Object retval = fwk.newClassInstance( desiredType, desiredType.getClass().cast(Class.forName(className))); return desiredType.cast(retval); } catch (Exception e) { logger.error("Unable to initialize {}", getClass().getName(), e); return null; } }