cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From reinh...@apache.org
Subject svn commit: r525736 - in /cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/tools/rcl/wrapper/servlet: CocoonReloadingListener.java ReloadingSpringFilter.java
Date Thu, 05 Apr 2007 07:19:07 GMT
Author: reinhard
Date: Thu Apr  5 00:19:06 2007
New Revision: 525736

URL: http://svn.apache.org/viewvc?view=rev&rev=525736
Log:
Use the SpringReloader to reload Spring. 
It has to be loaded by the ReloadingClassloader instead of the Context classloader.

Modified:
    cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/tools/rcl/wrapper/servlet/CocoonReloadingListener.java
    cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/tools/rcl/wrapper/servlet/ReloadingSpringFilter.java

Modified: cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/tools/rcl/wrapper/servlet/CocoonReloadingListener.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/tools/rcl/wrapper/servlet/CocoonReloadingListener.java?view=diff&rev=525736&r1=525735&r2=525736
==============================================================================
--- cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/tools/rcl/wrapper/servlet/CocoonReloadingListener.java
(original)
+++ cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/tools/rcl/wrapper/servlet/CocoonReloadingListener.java
Thu Apr  5 00:19:06 2007
@@ -59,11 +59,10 @@
                 changedFileParentPath.endsWith("config/spring")                     // local
Spring bean configurations
            ) {                
             log.debug("Configuration or .class file change detected [" + operation + "]:
" + changedFile);
-            System.out.println("Configuration or .class file change detected [" + operation
+ "]: " + changedFile);
+//            System.out.println("Configuration or .class file change detected [" + operation
+ "]: " + changedFile);
             reload = true;
         } else {
             log.debug("Other file change detected, no reload [" + operation + "]: " + changedFile);
 // any other file change
-            System.out.println("Other file change detected, no reload [" + operation + "]:
" + changedFile);
         }
     }
 

Modified: cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/tools/rcl/wrapper/servlet/ReloadingSpringFilter.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/tools/rcl/wrapper/servlet/ReloadingSpringFilter.java?view=diff&rev=525736&r1=525735&r2=525736
==============================================================================
--- cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/tools/rcl/wrapper/servlet/ReloadingSpringFilter.java
(original)
+++ cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-webapp-wrapper/src/main/java/org/apache/cocoon/tools/rcl/wrapper/servlet/ReloadingSpringFilter.java
Thu Apr  5 00:19:06 2007
@@ -17,21 +17,18 @@
 package org.apache.cocoon.tools.rcl.wrapper.servlet;
 
 import java.io.IOException;
+import java.lang.reflect.Method;
 
 import javax.servlet.Filter;
 import javax.servlet.FilterChain;
 import javax.servlet.FilterConfig;
+import javax.servlet.ServletContext;
 import javax.servlet.ServletException;
 import javax.servlet.ServletRequest;
 import javax.servlet.ServletResponse;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.springframework.web.context.ContextLoader;
-import org.springframework.web.context.WebApplicationContext;
-import org.springframework.web.context.support.ServletContextFactoryBean;
-import org.springframework.web.context.support.WebApplicationContextUtils;
-import org.springframework.web.context.support.XmlWebApplicationContext;
 
 /**
  * This servlet filter reloads the Spring application context whenever a relevant change
in the
@@ -49,33 +46,22 @@
             ServletException {
         
         if(CocoonReloadingListener.isReload()) {
-            synchronized (this) {         
+            synchronized (this) {        
+                log.info("Performing a reload of the Spring application context.");
+                System.out.println("Performing a reload of the Spring application context.");
               
                 // load the spring context loader from the reloading classloader
                 ClassLoader cl = ReloadingClassloaderManager.getClassLoader(config.getServletContext());
-                ContextLoader springContextLoader = null;
+                Object reloader = null;
                 try {
-                    Class contextLoaderClass = cl.loadClass(ContextLoader.class.getName());
-                    springContextLoader = (ContextLoader) contextLoaderClass.newInstance();
+                    reloader = cl.loadClass("org.apache.cocoon.tools.rcl.springreloader.SpringReloader").newInstance();
                 } catch (Exception e) {
-                    throw new ServletException("Cannot load class " + ContextLoader.class.getName(),
e);
+                    throw new ServletException("Can't create SpringReloader.", e);
                 }
-
-                // close old Spring application context
-                XmlWebApplicationContext oldAc = (XmlWebApplicationContext) 
-                        WebApplicationContextUtils.getRequiredWebApplicationContext(this.config.getServletContext());
-                     oldAc.close();
-                if(log.isDebugEnabled()) {                     
-                    this.log.debug("Removing old application context: " + oldAc);
-                }
-                this.config.getServletContext().removeAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
-
-                // create the new Spring application context
-                ServletContextFactoryBean b = new ServletContextFactoryBean();
-                b.setServletContext(this.config.getServletContext());
-                XmlWebApplicationContext xac = (XmlWebApplicationContext) springContextLoader.
-                        initWebApplicationContext(this.config.getServletContext());
-                if(log.isDebugEnabled()) {
-                    log.debug("Reloading Spring application context: " + xac);
+                try {
+                    Method reloadMethod = reloader.getClass().getMethod("reload", new Class[]{ServletContext.class}
); 
+                    reloadMethod.invoke(reloader, new Object[]{config.getServletContext()});
+                } catch(Exception e) {
+                    new ServletException("Problems occurred, while invoking the SpringReloader
reload method.", e);
                 }
             }
         }



Mime
View raw message