use of org.atmosphere.config.service.WebSocketHandlerService in project atmosphere by Atmosphere.
the class DefaultWebSocketProcessor method postProcessMapping.
protected WebSocketHandler postProcessMapping(WebSocket webSocket, AtmosphereRequest request, WebSocketHandlerProxy w) {
WebSocketHandlerProxy p = null;
String path = w.path();
if (wildcardMapping()) {
String pathInfo = null;
try {
pathInfo = request.getPathInfo();
} catch (IllegalStateException ex) {
// http://java.net/jira/browse/GRIZZLY-1301
}
if (pathInfo != null) {
path = request.getServletPath() + pathInfo;
} else {
path = request.getServletPath();
}
if (path == null || path.isEmpty()) {
path = "/";
}
synchronized (handlers) {
p = handlers.get(path);
if (p == null) {
// AtmosphereHandlerService
WebSocketHandlerService a = w.proxied.getClass().getAnnotation(WebSocketHandlerService.class);
if (a != null) {
String targetPath = a.path();
if (targetPath.indexOf("{") != -1 && targetPath.indexOf("}") != -1) {
try {
boolean singleton = w.proxied.getClass().getAnnotation(Singleton.class) != null;
if (!singleton) {
w = new WebSocketHandlerProxy(a.broadcaster(), framework.newClassInstance(WebSocketHandler.class, w.proxied.getClass()));
}
registerWebSocketHandler(path, new WebSocketHandlerProxy(a.broadcaster(), w));
request.localAttributes().put(Named.class.getName(), path.substring(targetPath.indexOf("{")));
p = handlers.get(path);
} catch (Throwable e) {
logger.warn("Unable to create WebSocketHandler", e);
}
}
}
}
}
}
try {
webSocket.resource().setBroadcaster(AnnotationUtil.broadcaster(framework, p != null ? p.broadcasterClazz : w.broadcasterClazz, path));
} catch (Exception e) {
logger.error("", e);
}
return p != null ? p : w;
}
use of org.atmosphere.config.service.WebSocketHandlerService in project atmosphere by Atmosphere.
the class WebSocketHandlerServiceProcessor method handle.
@Override
public void handle(AtmosphereFramework framework, Class<WebSocketHandler> annotatedClass) {
try {
WebSocketHandlerService m = annotatedClass.getAnnotation(WebSocketHandlerService.class);
atmosphereConfig(m.atmosphereConfig(), framework);
framework.addAtmosphereHandler(m.path(), AtmosphereFramework.REFLECTOR_ATMOSPHEREHANDLER).initWebSocket();
framework.setDefaultBroadcasterClassName(m.broadcaster().getName());
filters(m.broadcastFilters(), framework);
final LinkedList<AtmosphereInterceptor> l = new LinkedList<>();
AtmosphereInterceptor aa = listeners(m.listeners(), framework);
if (aa != null) {
l.add(aa);
}
AnnotationUtil.interceptorsForHandler(framework, Arrays.asList(m.interceptors()), l);
framework.setBroadcasterCacheClassName(m.broadcasterCache().getName());
WebSocketProcessor p = WebSocketProcessorFactory.getDefault().getWebSocketProcessor(framework);
framework.addAtmosphereHandler(m.path(), REFLECTOR_ATMOSPHEREHANDLER, l);
p.registerWebSocketHandler(m.path(), new WebSocketProcessor.WebSocketHandlerProxy(broadcasterClass(framework, m.broadcaster()), framework.newClassInstance(WebSocketHandler.class, annotatedClass)));
} catch (Throwable e) {
logger.warn("", e);
}
}
Aggregations