use of org.atmosphere.cpr.AtmosphereInterceptor in project atmosphere by Atmosphere.
the class MeteorServiceProcessor method handle.
@Override
public void handle(AtmosphereFramework framework, Class<Servlet> annotatedClass) {
try {
ReflectorServletProcessor r = framework.newClassInstance(ReflectorServletProcessor.class, ReflectorServletProcessor.class);
r.setServletClassName(annotatedClass.getName());
LinkedList<AtmosphereInterceptor> l = new LinkedList<>();
MeteorService m = annotatedClass.getAnnotation(MeteorService.class);
framework.setBroadcasterCacheClassName(m.broadcasterCache().getName());
String mapping = m.path();
atmosphereConfig(m.atmosphereConfig(), framework);
filters(m.broadcastFilters(), framework);
AtmosphereInterceptor aa = listeners(m.listeners(), framework);
if (aa != null) {
l.add(aa);
}
AnnotationUtil.interceptorsForHandler(framework, Arrays.asList(m.interceptors()), l);
if (m.path().contains("{")) {
l.addFirst(framework.newClassInstance(AtmosphereInterceptor.class, MeteorServiceInterceptor.class));
}
framework.addAtmosphereHandler(mapping, r, broadcaster(framework, m.broadcaster(), m.path()), l);
} catch (Throwable e) {
logger.warn("", e);
}
}
use of org.atmosphere.cpr.AtmosphereInterceptor 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<? extends AtmosphereInterceptor>[] interceptors = a.interceptors();
LinkedList<AtmosphereInterceptor> l = new LinkedList<>();
for (Class<? extends AtmosphereInterceptor> i : interceptors) {
try {
AtmosphereInterceptor ai = framework.newClassInstance(AtmosphereInterceptor.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.cpr.AtmosphereInterceptor in project atmosphere by Atmosphere.
the class AtmosphereInterceptorServiceProcessor method handle.
@Override
public void handle(final AtmosphereFramework framework, Class<AtmosphereInterceptor> annotatedClass) {
try {
final AtmosphereInterceptor a = framework.newClassInstance(AtmosphereInterceptor.class, annotatedClass);
framework.getAtmosphereConfig().startupHook(framework1 -> framework1.interceptor(a));
} catch (Throwable e) {
logger.warn("", e);
}
}
use of org.atmosphere.cpr.AtmosphereInterceptor in project atmosphere by Atmosphere.
the class AtmosphereServiceProcessor method handle.
@Override
public void handle(AtmosphereFramework framework, Class<Object> annotatedClass) {
try {
AtmosphereService a = annotatedClass.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 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.cpr.AtmosphereInterceptor in project cxf by apache.
the class AtmosphereWebSocketJettyDestinationTest method testUseCustomAtmoosphereInterceptors.
@Test
public void testUseCustomAtmoosphereInterceptors() throws Exception {
Bus bus = new ExtensionManagerBus();
bus.setProperty("atmosphere.interceptors", Arrays.asList(new CustomInterceptor1(), new CustomInterceptor2()));
DestinationRegistry registry = new HTTPTransportFactory().getRegistry();
EndpointInfo endpoint = new EndpointInfo();
endpoint.setAddress(ENDPOINT_ADDRESS);
endpoint.setName(ENDPOINT_NAME);
AtmosphereWebSocketServletDestination dest = new AtmosphereWebSocketServletDestination(bus, registry, endpoint, ENDPOINT_ADDRESS);
List<AtmosphereInterceptor> ais = dest.getAtmosphereFramework().interceptors();
int added = 0;
for (AtmosphereInterceptor a : ais) {
if (CustomInterceptor1.class.equals(a.getClass())) {
added++;
} else if (CustomInterceptor2.class.equals(a.getClass())) {
added++;
break;
}
}
assertEquals(2, added);
}
Aggregations