use of org.atmosphere.config.AtmosphereHandlerProperty in project atmosphere by Atmosphere.
the class AtmosphereFramework method loadAtmosphereDotXml.
/**
* Load AtmosphereHandler defined under META-INF/atmosphere.xml.
*
* @param stream The input stream we read from.
* @param c The classloader
*/
protected void loadAtmosphereDotXml(InputStream stream, URLClassLoader c) throws IOException, ServletException {
if (stream == null) {
return;
}
logger.info("Found Atmosphere Configuration under {}", atmosphereDotXmlPath);
AtmosphereConfigReader.getInstance().parse(config, stream);
AtmosphereHandler handler = null;
for (AtmosphereHandlerConfig atmoHandler : config.getAtmosphereHandlerConfig()) {
try {
if (!atmoHandler.getClassName().startsWith("@")) {
if (!ReflectorServletProcessor.class.getName().equals(atmoHandler.getClassName())) {
handler = newClassInstance(AtmosphereHandler.class, (Class<AtmosphereHandler>) IOUtils.loadClass(this.getClass(), atmoHandler.getClassName()));
} else {
handler = newClassInstance(AtmosphereHandler.class, ReflectorServletProcessor.class);
}
logger.info("Installed AtmosphereHandler {} mapped to context-path: {}", handler, atmoHandler.getContextRoot());
}
for (ApplicationConfiguration a : atmoHandler.getApplicationConfig()) {
initParams.put(a.getParamName(), a.getParamValue());
}
for (FrameworkConfiguration a : atmoHandler.getFrameworkConfig()) {
initParams.put(a.getParamName(), a.getParamValue());
}
for (AtmosphereHandlerProperty handlerProperty : atmoHandler.getProperties()) {
if (handlerProperty.getValue() != null && handlerProperty.getValue().indexOf("jersey") != -1) {
initParams.put(DISABLE_ONSTATE_EVENT, "true");
useStreamForFlushingComments = true;
broadcasterClassName = lookupDefaultBroadcasterType(JERSEY_BROADCASTER);
broadcasterFactory.destroy();
broadcasterFactory = null;
configureBroadcasterFactory();
configureBroadcaster();
}
if (handler != null) {
IntrospectionUtils.setProperty(handler, handlerProperty.getName(), handlerProperty.getValue());
IntrospectionUtils.addProperty(handler, handlerProperty.getName(), handlerProperty.getValue());
}
}
sessionSupport(Boolean.valueOf(atmoHandler.getSupportSession()));
if (handler != null) {
String broadcasterClass = atmoHandler.getBroadcaster();
Broadcaster b;
/**
* If there is more than one AtmosphereHandler defined, their Broadcaster
* may clash each other with the BroadcasterFactory. In that case we will use the
* last one defined.
*/
if (broadcasterClass != null) {
broadcasterClassName = broadcasterClass;
ClassLoader cl = Thread.currentThread().getContextClassLoader();
Class<? extends Broadcaster> bc = (Class<? extends Broadcaster>) cl.loadClass(broadcasterClassName);
broadcasterFactory = newClassInstance(BroadcasterFactory.class, DefaultBroadcasterFactory.class);
broadcasterFactory.configure(bc, broadcasterLifeCyclePolicy, config);
}
b = broadcasterFactory.lookup(atmoHandler.getContextRoot(), true);
AtmosphereHandlerWrapper wrapper = new AtmosphereHandlerWrapper(handler, b, config);
addMapping(atmoHandler.getContextRoot(), wrapper);
String bc = atmoHandler.getBroadcasterCache();
if (bc != null) {
broadcasterCacheClassName = bc;
}
if (atmoHandler.getCometSupport() != null) {
asyncSupport = (AsyncSupport) c.loadClass(atmoHandler.getCometSupport()).getDeclaredConstructor(new Class[] { AtmosphereConfig.class }).newInstance(new Object[] { config });
}
if (atmoHandler.getBroadcastFilterClasses() != null) {
broadcasterFilters.addAll(atmoHandler.getBroadcastFilterClasses());
}
LinkedList<AtmosphereInterceptor> l = new LinkedList<AtmosphereInterceptor>();
if (atmoHandler.getAtmosphereInterceptorClasses() != null) {
for (String a : atmoHandler.getAtmosphereInterceptorClasses()) {
try {
AtmosphereInterceptor ai = newClassInstance(AtmosphereInterceptor.class, (Class<AtmosphereInterceptor>) IOUtils.loadClass(getClass(), a));
l.add(ai);
} catch (Throwable e) {
logger.warn("", e);
}
}
}
addInterceptorToWrapper(wrapper, l);
if (!l.isEmpty()) {
logger.info("Installed AtmosphereInterceptor {} mapped to AtmosphereHandler {}", l, atmoHandler.getClassName());
}
}
} catch (Throwable t) {
logger.warn("Unable to load AtmosphereHandler class: " + atmoHandler.getClassName(), t);
throw new ServletException(t);
}
}
}
use of org.atmosphere.config.AtmosphereHandlerProperty in project atmosphere by Atmosphere.
the class AtmosphereConfigReader method parse.
/**
* Parse the atmosphere-handlers element.
*
* @param document
*/
private AtmosphereConfig parse(AtmosphereConfig config, Document document) {
Element element = document.getDocumentElement();
NodeList atmosphereHandlers = element.getElementsByTagName("atmosphere-handler");
for (int i = 0; i < atmosphereHandlers.getLength(); i++) {
AtmosphereHandlerConfig atmoHandler = new AtmosphereHandlerConfig();
Node root = atmosphereHandlers.item(i);
// parse Attributes
for (int j = 0; j < root.getAttributes().getLength(); j++) {
Node attribute = root.getAttributes().item(j);
if (attribute.getNodeName().equals("support-session")) {
atmoHandler.setSupportSession(attribute.getNodeValue());
} else if (attribute.getNodeName().equals("context-root")) {
atmoHandler.setContextRoot(attribute.getNodeValue());
} else if (attribute.getNodeName().equals("class-name")) {
atmoHandler.setClassName(attribute.getNodeValue());
} else if (attribute.getNodeName().equals("broadcaster")) {
atmoHandler.setBroadcaster(attribute.getNodeValue());
} else if (attribute.getNodeName().equals("broadcasterCache")) {
atmoHandler.setBroadcasterCache(attribute.getNodeValue());
} else if (attribute.getNodeName().equals("broadcastFilterClasses")) {
String[] values = attribute.getNodeValue().split(",");
for (String value : values) {
atmoHandler.getBroadcastFilterClasses().add(value);
}
} else if (attribute.getNodeName().equals("comet-support")) {
atmoHandler.setCometSupport(attribute.getNodeValue());
} else if (attribute.getNodeName().equals("interceptorClasses")) {
String[] values = attribute.getNodeValue().split(",");
for (String value : values) {
atmoHandler.getAtmosphereInterceptorClasses().add(value);
}
}
}
NodeList list = root.getChildNodes();
for (int j = 0; j < list.getLength(); j++) {
Node n = list.item(j);
if (n.getNodeName().equals("property")) {
String param = n.getAttributes().getNamedItem("name").getNodeValue();
String value = n.getAttributes().getNamedItem("value").getNodeValue();
atmoHandler.getProperties().add(new AtmosphereHandlerProperty(param, value));
} else if (n.getNodeName().equals("applicationConfig")) {
String param = null;
String value = null;
for (int k = 0; k < n.getChildNodes().getLength(); k++) {
Node n2 = n.getChildNodes().item(k);
if (n2.getNodeName().equals("param-name")) {
param = n2.getFirstChild().getNodeValue();
} else if (n2.getNodeName().equals("param-value")) {
if (n2 != null) {
value = n2.getFirstChild().getNodeValue();
}
}
}
if (param != null) {
atmoHandler.getApplicationConfig().add(new ApplicationConfiguration(param, value));
}
} else if (n.getNodeName().equals("frameworkConfig")) {
String param = null;
String value = null;
for (int k = 0; k < n.getChildNodes().getLength(); k++) {
Node n2 = n.getChildNodes().item(k);
if (n2.getNodeName().equals("param-name")) {
param = n2.getFirstChild().getNodeValue();
} else if (n2.getNodeName().equals("param-value")) {
if (n2 != null) {
value = n2.getFirstChild().getNodeValue();
}
}
}
if (param != null) {
atmoHandler.getFrameworkConfig().add(new FrameworkConfiguration(param, value));
}
}
}
config.getAtmosphereHandlerConfig().add(atmoHandler);
}
return config;
}
Aggregations