You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by re...@apache.org on 2007/03/14 09:35:25 UTC

svn commit: r518068 - /cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/DispatcherServlet.java

Author: reinhard
Date: Wed Mar 14 01:35:24 2007
New Revision: 518068

URL: http://svn.apache.org/viewvc?view=rev&rev=518068
Log:
reload the mountableServlets map when the Spring app context was reset

Modified:
    cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/DispatcherServlet.java

Modified: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/DispatcherServlet.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/DispatcherServlet.java?view=diff&rev=518068&r1=518067&r2=518068
==============================================================================
--- cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/DispatcherServlet.java (original)
+++ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/DispatcherServlet.java Wed Mar 14 01:35:24 2007
@@ -35,7 +35,7 @@
 import org.apache.commons.logging.LogFactory;
 import org.springframework.beans.BeanWrapperImpl;
 import org.springframework.beans.factory.BeanFactoryUtils;
-import org.springframework.beans.factory.ListableBeanFactory;
+import org.springframework.context.ApplicationContext;
 import org.springframework.web.context.support.WebApplicationContextUtils;
 
 /**
@@ -55,44 +55,26 @@
     private static final String MOUNT_PATH = "mountPath";
 
     /** All registered mountable servlets. */
-    private Map mountableServlets = new HashMap();
-
-    /**
-     * The Spring bean factory.
-     */
-    private ListableBeanFactory beanFactory;
+    private Map mountableServlets;
+    
+    /** The startup date of the Spring application context used to setup the  mountable servlets. */
+    private long applicationContextStartDate;
     
     /** By default we use the logger for this class. */
     private Log logger = LogFactory.getLog(getClass());
 
-    
     public void init() throws ServletException {
-    	// get the beanFactory from the web application context
-        this.beanFactory =
-            WebApplicationContextUtils.getRequiredWebApplicationContext(this.getServletContext());
-        
-        // setup logger
-        this.logger.info("DispatcherServlet is initializing");
-        
-        // the returned map contains the bean names as key and the beans as values
-        final Map servlets = 
-            BeanFactoryUtils.beansOfTypeIncludingAncestors(this.beanFactory, Servlet.class);
-        
-        // register and initialize the servlets that has a mount path property
-        final Iterator i = servlets.values().iterator();
-        while ( i.hasNext() ) {
-            final Servlet servlet = (Servlet) i.next();
-            BeanWrapperImpl wrapper = new BeanWrapperImpl(servlet);
-            if (wrapper.isReadableProperty(MOUNT_PATH)) {
-                String mountPath = (String) wrapper.getPropertyValue(MOUNT_PATH);
-                this.logger.debug("DispatcherServlet: initializing servlet " + servlet + " at " + mountPath);
-                this.mountableServlets.put(mountPath, servlet);
-            }
-        }
+        createMountableServletsMap();
         this.log("Block dispatcher was initialized successfully.");        
     }
 
     protected void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
+        ApplicationContext appContext =
+            WebApplicationContextUtils.getRequiredWebApplicationContext(this.getServletContext());
+        if (appContext.getStartupDate() != this.applicationContextStartDate) {
+            createMountableServletsMap(); 
+        }
+        
         String path = req.getPathInfo();
         path = path == null ? "" : path;
         // find the servlet which mount path is the longest prefix of the path info
@@ -122,6 +104,36 @@
         }
         
         servlet.service(request, res);
+    }
+    
+    private void createMountableServletsMap() {
+        Map mServlets = new HashMap();
+        // get the beanFactory from the web application context
+        ApplicationContext appContext =
+            WebApplicationContextUtils.getRequiredWebApplicationContext(this.getServletContext());
+
+        // the returned map contains the bean names as key and the beans as values
+        final Map servlets = 
+            BeanFactoryUtils.beansOfTypeIncludingAncestors(appContext, Servlet.class);
+        
+        // register and initialize the servlets that have a mount path property
+        final Iterator i = servlets.values().iterator();
+        while ( i.hasNext() ) {
+            final Servlet servlet = (Servlet) i.next();
+            BeanWrapperImpl wrapper = new BeanWrapperImpl(servlet);
+            if (wrapper.isReadableProperty(MOUNT_PATH)) {
+                String mountPath = (String) wrapper.getPropertyValue(MOUNT_PATH);
+                this.logger.debug("DispatcherServlet: initializing servlet " + servlet + " at " 
+                        + mountPath);
+                mServlets.put(mountPath, servlet);
+            }
+        }
+        this.mountableServlets = mServlets;
+        
+        // set the application context start date
+        this.applicationContextStartDate =  appContext.getStartupDate();
+        
+        this.logger.info("DispatcherServlet is (re)set the table of mountable servlets based on " + appContext);        
     }
     
     private void getInterfaces(Set interfaces, Class clazz) {