use of org.atmosphere.config.service.AtmosphereHandlerService 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.config.service.AtmosphereHandlerService 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);
}
}
}
}
}
Aggregations