— core/src/main/java/org/icefaces/impl/push/servlet/ICEpushResourceHandler.java (revision 33350)
+++ core/src/main/java/org/icefaces/impl/push/servlet/ICEpushResourceHandler.java (working copy)
@@ -38,7 +38,7 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
-import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
@@ -170,8 +170,11 @@
if (mainServlet == null) {
Class mainServletClass = (Class) ExtensionRegistry.getBestExtension(servletContext, "org.icepush.MainServlet");
try {
- Constructor mainServletConstructor = mainServletClass.getConstructor(new Class[]
{ServletContext.class});
- mainServlet = (MainServlet) mainServletConstructor.newInstance(servletContext);
+ Method mainServletGet = mainServletClass
+ .getMethod("getInstance",
+ new Class[]{ServletContext.class}
);
+ mainServlet = (MainServlet) mainServletGet
+ .invoke(null, servletContext);
} catch (Exception e) {
log.log(Level.SEVERE, "Cannot instantiate extension org.icepush.MainServlet.", e);
throw new RuntimeException(e);
Index: icepush/core/src/main/java/org/icepush/servlet/ICEpushServlet.java
===================================================================
-
- icepush/core/src/main/java/org/icepush/servlet/ICEpushServlet.java (revision 33350)
+++ icepush/core/src/main/java/org/icepush/servlet/ICEpushServlet.java (working copy)
@@ -25,7 +25,7 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
-import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -38,8 +38,10 @@
ServletContext servletContext = servletConfig.getServletContext();
Class mainServletClass = (Class) ExtensionRegistry.getBestExtension(servletContext, "org.icepush.MainServlet");
try {
- Constructor mainServletConstructor = mainServletClass.getConstructor(new Class[]
{ServletContext.class});
- mainServlet = (PseudoServlet) mainServletConstructor.newInstance(servletContext);
+ Method mainServletGet = mainServletClass.getMethod("getInstance",
+ new Class[]{ServletContext.class}
);
+ mainServlet = (PseudoServlet) mainServletGet
+ .invoke(null, servletContext);
} catch (Exception e) {
Log.log(Level.SEVERE, "Cannot instantiate extension org.icepush.MainServlet.", e);
throw new ServletException(e);
Index: icepush/core/src/main/java/org/icepush/servlet/MainServlet.java
===================================================================
-
- icepush/core/src/main/java/org/icepush/servlet/MainServlet.java (revision 33350)
+++ icepush/core/src/main/java/org/icepush/servlet/MainServlet.java (working copy)
@@ -47,6 +47,16 @@
protected Configuration configuration;
protected boolean terminateConnectionOnShutdown;
+ public synchronized static MainServlet getInstance(ServletContext context) {
+ MainServlet mainServlet = (MainServlet) context
+ .getAttribute(MainServlet.class.getName());
+ if (null == mainServlet)
{
+ mainServlet = new MainServlet(context);
+ context.setAttribute(MainServlet.class.getName(), mainServlet);
+ }
+ return mainServlet;
+ }
+
public MainServlet(final ServletContext context)
{
this(context, true);
}
Pages to be updated via push:
http://localhost:8080/simple/pushed.jsp
http://localhost:8080/simple/pushed.jsf
Pages initiating update via push:
http://localhost:8080/simple/pushall.jsp (simply load to cause push)
http://localhost:8080/simple/pushit.jsf (press button to push)
If the FacesServlet is commented out in web.xml, then the pure JSP example will function. If org.icepush.servlet.ICEpushServlet is commented out, JSF will function. It appears that JSF is also loaded automatically even if the servlet is not registered if a JSF page is fetched.