use of org.atmosphere.runtime.AtmosphereHandler 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<?>[] interceptors = a.interceptors();
LinkedList<AtmosphereInterceptor> l = new LinkedList<AtmosphereInterceptor>();
for (Class i : interceptors) {
try {
AtmosphereInterceptor ai = (AtmosphereInterceptor) framework.newClassInstance(AtmosphereHandler.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);
}
}
use of org.atmosphere.runtime.AtmosphereHandler 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);
}
}
use of org.atmosphere.runtime.AtmosphereHandler in project atmosphere by Atmosphere.
the class AtmosphereHandlerServiceInterceptor method mapAnnotatedService.
protected void mapAnnotatedService(boolean reMap, String path, AtmosphereRequest request, AtmosphereHandlerWrapper w) {
synchronized (config.handlers()) {
if (config.handlers().get(path) == null) {
// AtmosphereHandlerService
AtmosphereHandlerService m = w.atmosphereHandler.getClass().getAnnotation(AtmosphereHandlerService.class);
if (m != null) {
try {
String targetPath = m.path();
if (targetPath.indexOf("{") != -1 && targetPath.indexOf("}") != -1) {
boolean singleton = w.atmosphereHandler.getClass().getAnnotation(Singleton.class) != null;
AtmosphereHandler newW = w.atmosphereHandler;
if (!singleton) {
newW = config.framework().newClassInstance(AtmosphereHandler.class, w.atmosphereHandler.getClass());
}
request.localAttributes().put(Named.class.getName(), path.substring(targetPath.indexOf("{")));
AtmosphereResourceImpl.class.cast(request.resource()).atmosphereHandler(newW);
config.framework().addAtmosphereHandler(path, newW, config.getBroadcasterFactory().lookup(w.broadcaster.getClass(), path, true), w.interceptors);
request.setAttribute(FrameworkConfig.NEW_MAPPING, "true");
}
} catch (Throwable e) {
logger.warn("Unable to create AtmosphereHandler", e);
}
}
}
}
}
use of org.atmosphere.runtime.AtmosphereHandler in project atmosphere by Atmosphere.
the class ManagedServiceProcessor method handle.
@Override
public void handle(AtmosphereFramework framework, Class<Object> annotatedClass) {
try {
Class<?> aClass = annotatedClass;
ManagedService a = aClass.getAnnotation(ManagedService.class);
framework.setBroadcasterCacheClassName(a.broadcasterCache().getName());
List<AtmosphereInterceptor> l = new LinkedList<AtmosphereInterceptor>();
AnnotationUtil.defaultManagedServiceInterceptors(framework, l);
atmosphereConfig(a.atmosphereConfig(), framework);
filters(a.broadcastFilters(), framework);
AtmosphereInterceptor aa = listeners(a.listeners(), framework);
if (aa != null) {
l.add(aa);
}
Object c = framework.newClassInstance(Object.class, aClass);
AtmosphereHandler handler = framework.newClassInstance(ManagedAtmosphereHandler.class, ManagedAtmosphereHandler.class).configure(framework.getAtmosphereConfig(), c);
framework.filterManipulator(new BroadcasterConfig.FilterManipulator() {
@Override
public Object unwrap(Object o) {
if (o != null && ManagedAtmosphereHandler.Managed.class.isAssignableFrom(o.getClass())) {
o = ManagedAtmosphereHandler.Managed.class.cast(o).object();
}
return o;
}
@Override
public BroadcastFilter.BroadcastAction wrap(BroadcastFilter.BroadcastAction a, boolean wasWrapped) {
if (wasWrapped) {
return new BroadcastFilter.BroadcastAction(a.action(), new ManagedAtmosphereHandler.Managed(a.message()));
} else {
return a;
}
}
});
AnnotationUtil.interceptorsForManagedService(framework, Arrays.asList(a.interceptors()), l);
framework.addAtmosphereHandler(a.path(), handler, broadcaster(framework, a.broadcaster(), a.path()), l);
} catch (Throwable e) {
logger.warn("", e);
}
}
Aggregations