use of org.atmosphere.handler.ReflectorServletProcessor in project atmosphere by Atmosphere.
the class AtmosphereResourceTest method verifyTestCompletionAwareForSync.
private void verifyTestCompletionAwareForSync(boolean aware) throws IOException, ServletException {
Servlet s = mock(Servlet.class);
if (aware) {
framework.addInitParameter(ApplicationConfig.RESPONSE_COMPLETION_AWARE, "true");
}
ReflectorServletProcessor handler = new ReflectorServletProcessor(s);
handler.init(framework.getAtmosphereConfig());
AtmosphereRequest request = new AtmosphereRequestImpl.Builder().pathInfo("/a").build();
AtmosphereResponseImpl response = mock(AtmosphereResponseImpl.class);
AtmosphereResourceImpl res = new AtmosphereResourceImpl();
res.initialize(framework.getAtmosphereConfig(), framework.getBroadcasterFactory().get(), request, response, null, null);
res.transport(AtmosphereResource.TRANSPORT.WEBSOCKET);
request.setAttribute(FrameworkConfig.ATMOSPHERE_RESOURCE, res);
request.setAttribute(FrameworkConfig.INJECTED_ATMOSPHERE_RESOURCE, res);
handler.onRequest(res);
verify(response, times(aware ? 1 : 0)).onComplete();
}
use of org.atmosphere.handler.ReflectorServletProcessor in project atmosphere by Atmosphere.
the class AtmosphereFramework method detectSupportedFramework.
/**
* Auto-detect Jersey when no atmosphere.xml file is specified.
*
* @param sc {@link ServletConfig}
* @return true if Jersey classes are detected
* @throws ClassNotFoundException
*/
protected boolean detectSupportedFramework(ServletConfig sc) throws Exception {
String broadcasterClassNameTmp = null;
boolean isJersey;
try {
IOUtils.loadClass(getClass(), JERSEY_CONTAINER);
isJersey = true;
if (!isBroadcasterSpecified) {
broadcasterClassNameTmp = lookupDefaultBroadcasterType(JERSEY_BROADCASTER);
IOUtils.loadClass(getClass(), broadcasterClassNameTmp);
}
useStreamForFlushingComments = true;
StringBuilder packagesInit = new StringBuilder();
for (String s : packages) {
packagesInit.append(s).append(",");
}
initParams.put(FrameworkConfig.JERSEY_SCANNING_PACKAGE, packagesInit.toString());
} catch (Throwable t) {
logger.trace("", t);
return false;
}
logger.debug("Missing META-INF/atmosphere.xml but found the Jersey runtime. Starting Jersey");
// Atmosphere 1.1 : could add regressions
// Jersey will itself handle the headers.
// initParams.put(WRITE_HEADERS, "false");
ReflectorServletProcessor rsp = newClassInstance(ReflectorServletProcessor.class, ReflectorServletProcessor.class);
if (broadcasterClassNameTmp != null)
broadcasterClassName = broadcasterClassNameTmp;
configureDetectedFramework(rsp, isJersey);
sessionSupport(false);
initParams.put(DISABLE_ONSTATE_EVENT, "true");
String mapping = sc.getInitParameter(PROPERTY_SERVLET_MAPPING);
if (mapping == null) {
mapping = sc.getInitParameter(ATMOSPHERE_HANDLER_MAPPING);
if (mapping == null) {
mapping = Broadcaster.ROOT_MASTER;
}
}
Class<? extends Broadcaster> bc = (Class<? extends Broadcaster>) IOUtils.loadClass(getClass(), broadcasterClassName);
broadcasterFactory.destroy();
broadcasterFactory = newClassInstance(BroadcasterFactory.class, DefaultBroadcasterFactory.class);
broadcasterFactory.configure(bc, broadcasterLifeCyclePolicy, config);
for (BroadcasterListener b : broadcasterListeners) {
broadcasterFactory.addBroadcasterListener(b);
}
Broadcaster b;
try {
b = broadcasterFactory.get(bc, mapping);
} catch (IllegalStateException ex) {
logger.warn("Two Broadcaster's named {}. Renaming the second one to {}", mapping, sc.getServletName() + mapping);
b = broadcasterFactory.get(bc, sc.getServletName() + mapping);
}
addAtmosphereHandler(mapping, rsp, b);
return true;
}
use of org.atmosphere.handler.ReflectorServletProcessor in project atmosphere by Atmosphere.
the class MeteorServlet method loadDelegateViaConfig.
private void loadDelegateViaConfig(ServletConfig sc) throws ServletException {
String servletClass = framework().getAtmosphereConfig().getInitParameter(SERVLET_CLASS);
String mapping = framework().getAtmosphereConfig().getInitParameter(MAPPING);
String filterClass = framework().getAtmosphereConfig().getInitParameter(FILTER_CLASS);
String filterName = framework().getAtmosphereConfig().getInitParameter(FILTER_NAME);
if (servletClass != null) {
logger.info("Installed Servlet/Meteor {} mapped to {}", servletClass, mapping == null ? ROOT_MASTER : mapping);
}
if (filterClass != null) {
logger.info("Installed Filter/Meteor {} mapped to /*", filterClass, mapping);
}
// The annotation was used.
if (servletClass != null || filterClass != null) {
ReflectorServletProcessor r = new ReflectorServletProcessor();
r.setServletClassName(servletClass);
r.addFilterClassName(filterClass, filterName);
if (mapping == null) {
mapping = Broadcaster.ROOT_MASTER;
framework().getBroadcasterFactory().remove(Broadcaster.ROOT_MASTER);
}
framework().addAtmosphereHandler(mapping, r).initAtmosphereHandler(sc);
}
}
Aggregations