Author: nbelaevski
Date: 2011-04-28 20:08:15 -0400 (Thu, 28 Apr 2011)
New Revision: 22455
Modified:
trunk/core/impl/src/main/java/org/richfaces/webapp/PushServletContainerInitializer.java
Log:
Added check for Atmosphere presence to PushServletContainerInitializer
Modified:
trunk/core/impl/src/main/java/org/richfaces/webapp/PushServletContainerInitializer.java
===================================================================
---
trunk/core/impl/src/main/java/org/richfaces/webapp/PushServletContainerInitializer.java 2011-04-28
21:49:58 UTC (rev 22454)
+++
trunk/core/impl/src/main/java/org/richfaces/webapp/PushServletContainerInitializer.java 2011-04-29
00:08:15 UTC (rev 22455)
@@ -33,6 +33,8 @@
import javax.servlet.ServletRegistration.Dynamic;
import org.richfaces.application.push.impl.PushContextFactoryImpl;
+import org.richfaces.log.Logger;
+import org.richfaces.log.RichfacesLogger;
import com.google.common.collect.Iterables;
@@ -42,6 +44,12 @@
*/
public class PushServletContainerInitializer implements ServletContainerInitializer {
+ private static final Logger LOGGER = RichfacesLogger.WEBAPP.getLogger();
+
+ private static final String ATMOSPHERE_SERVLET_CLASS =
"org.atmosphere.cpr.AtmosphereServlet";
+
+ private static final String SKIP_SERVLET_REGISTRATION_PARAM =
"org.richfaces.push.skipPushServletRegistration";
+
private static final String PUSH_CONTEXT_DEFAULT_MAPPING = '/' +
PushContextFactoryImpl.PUSH_CONTEXT_RESOURCE_NAME;
private boolean hasPushFilterMapping(ServletContext context) {
@@ -75,6 +83,14 @@
}
public void onStartup(Set<Class<?>> clasess, ServletContext
servletContext) throws ServletException {
+ if
(Boolean.valueOf(servletContext.getInitParameter(SKIP_SERVLET_REGISTRATION_PARAM))) {
+ return;
+ }
+
+ if (!isAtmospherePresent()) {
+ return;
+ }
+
if (hasPushFilterMapping(servletContext)) {
return;
}
@@ -96,4 +112,20 @@
}
}
+ private boolean isAtmospherePresent() {
+ try {
+ Class.forName(ATMOSPHERE_SERVLET_CLASS, false,
Thread.currentThread().getContextClassLoader());
+
+ return true;
+ } catch (ClassNotFoundException e) {
+ //no atmosphere present - no push then
+ LOGGER.debug("AtmosphereServlet class is not present in classpath,
PushServlet won't be registered automatically");
+ } catch (LinkageError e) {
+ //atmosphere is missing some dependency - no push too
+ LOGGER.error(e.getMessage(), e);
+ }
+
+ return false;
+ }
+
}
Show replies by date