public final static boolean requestScopedInjection(AtmosphereConfig config, AtmosphereHandler h) { AtmosphereObjectFactory injectableFactory = config.framework().objectFactory(); if (!InjectableObjectFactory.class.isAssignableFrom(injectableFactory.getClass())) { return false; } try { Object obj = injectWith(h); return obj == null ? false : InjectableObjectFactory.class.cast(config.framework().objectFactory()).needRequestScoped(obj.getClass()); } catch (Exception e) { LOGGER.error("", e); return false; } }
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); } }
private static final Object injectWith(AtmosphereResource r) { // Check for null when disconnect happens. This happens when websocket are closed by both the client and the server // concurrently. if (r == null) { return null; } AtmosphereHandler h = r.getAtmosphereHandler(); if (r.getAtmosphereHandler() == null) { return null; } if (AtmosphereFramework.REFLECTOR_ATMOSPHEREHANDLER.getClass().isAssignableFrom(h.getClass())) { if (AtmosphereResourceImpl.class.cast(r).webSocket() == null || AtmosphereResourceImpl.class.cast(r).webSocket().webSocketHandler() == null) { return null; } return WebSocketProcessor.WebSocketHandlerProxy.class.cast(AtmosphereResourceImpl.class.cast(r).webSocket().webSocketHandler()).proxied(); } else { return injectWith(h); } }