Updated Branches:
  refs/heads/master f8fcdc91b -> dc3372ee6

WICKET-4872 set contextClassLoader before creating application;
destroy application before initializing the new one

Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/dc3372ee
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/dc3372ee
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/dc3372ee

Branch: refs/heads/master
Commit: dc3372ee6ca6ac4526fcc9d9ea41a31781bfda33
Parents: f8fcdc9
Author: svenmeier <[email protected]>
Authored: Wed Nov 21 23:42:47 2012 +0100
Committer: svenmeier <[email protected]>
Committed: Wed Nov 21 23:42:47 2012 +0100

----------------------------------------------------------------------
 .../protocol/http/ReloadingWicketFilter.java       |   10 +-
 .../apache/wicket/protocol/http/WicketFilter.java  |   80 ++++++++-------
 2 files changed, 47 insertions(+), 43 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/dc3372ee/wicket-core/src/main/java/org/apache/wicket/protocol/http/ReloadingWicketFilter.java
----------------------------------------------------------------------
diff --git 
a/wicket-core/src/main/java/org/apache/wicket/protocol/http/ReloadingWicketFilter.java
 
b/wicket-core/src/main/java/org/apache/wicket/protocol/http/ReloadingWicketFilter.java
index 0bc6e9d..6c7cc00 100644
--- 
a/wicket-core/src/main/java/org/apache/wicket/protocol/http/ReloadingWicketFilter.java
+++ 
b/wicket-core/src/main/java/org/apache/wicket/protocol/http/ReloadingWicketFilter.java
@@ -96,11 +96,9 @@ import org.apache.wicket.util.listener.IChangeListener;
  * </p>
  * 
  * <p>
- * When using Spring, the application must not be a Spring bean itself, 
otherwise the reloading
- * mechanism won't be able to reload the application. In particular, make sure 
<b>not</b> to use
- * org.apache.wicket.spring.SpringWebApplicationFactory in web.xml. If you 
really need to inject
- * dependencies in your application, use 
DefaultListableBeanFactory.autowireBeanProperties() in the
- * init() method.
+ * When using org.apache.wicket.spring.SpringWebApplicationFactory, the 
application must be a bean
+ * with "prototype" scope and the "applicationBean" init parameter must be 
explicitly set, otherwise
+ * the reloading mechanism won't be able to recreate the application.
  * </p>
  * 
  * <p>
@@ -154,6 +152,8 @@ public class ReloadingWicketFilter extends WicketFilter
                        @Override
                        public void onChange()
                        {
+                               destroy();
+
                                // Remove the ModificationWatcher from the 
current reloading class loader
                                reloadingClassLoader.destroy();
 

http://git-wip-us.apache.org/repos/asf/wicket/blob/dc3372ee/wicket-core/src/main/java/org/apache/wicket/protocol/http/WicketFilter.java
----------------------------------------------------------------------
diff --git 
a/wicket-core/src/main/java/org/apache/wicket/protocol/http/WicketFilter.java 
b/wicket-core/src/main/java/org/apache/wicket/protocol/http/WicketFilter.java
index 681a6a1..1394944 100644
--- 
a/wicket-core/src/main/java/org/apache/wicket/protocol/http/WicketFilter.java
+++ 
b/wicket-core/src/main/java/org/apache/wicket/protocol/http/WicketFilter.java
@@ -332,66 +332,70 @@ public class WicketFilter implements Filter
                this.isServlet = isServlet;
                initIgnorePaths(filterConfig);
 
-               // locate application instance unless it was already specified 
during construction
-               if (application == null)
+               final ClassLoader previousClassLoader = 
Thread.currentThread().getContextClassLoader();
+               final ClassLoader newClassLoader = getClassLoader();
+               try
                {
-                       applicationFactory = getApplicationFactory();
-                       application = 
applicationFactory.createApplication(this);
-               }
+                       if (previousClassLoader != newClassLoader)
+                       {
+                               
Thread.currentThread().setContextClassLoader(newClassLoader);
+                       }
 
-               application.setName(filterConfig.getFilterName());
-               application.setWicketFilter(this);
+                       // locate application instance unless it was already 
specified during construction
+                       if (application == null)
+                       {
+                               applicationFactory = getApplicationFactory();
+                               application = 
applicationFactory.createApplication(this);
+                       }
 
-               // Allow the filterPath to be preset via setFilterPath()
-               String configureFilterPath = getFilterPath();
+                       application.setName(filterConfig.getFilterName());
+                       application.setWicketFilter(this);
 
-               if (configureFilterPath == null)
-               {
-                       configureFilterPath = 
getFilterPathFromConfig(filterConfig);
+                       // Allow the filterPath to be preset via setFilterPath()
+                       String configureFilterPath = getFilterPath();
 
                        if (configureFilterPath == null)
                        {
-                               configureFilterPath = 
getFilterPathFromWebXml(isServlet, filterConfig);
+                               configureFilterPath = 
getFilterPathFromConfig(filterConfig);
 
                                if (configureFilterPath == null)
                                {
-                                       configureFilterPath = 
getFilterPathFromAnnotation(isServlet);
+                                       configureFilterPath = 
getFilterPathFromWebXml(isServlet, filterConfig);
+
+                                       if (configureFilterPath == null)
+                                       {
+                                               configureFilterPath = 
getFilterPathFromAnnotation(isServlet);
+                                       }
+                               }
+
+                               if (configureFilterPath != null)
+                               {
+                                       setFilterPath(configureFilterPath);
                                }
                        }
 
-                       if (configureFilterPath != null)
+                       if (getFilterPath() == null)
                        {
-                               setFilterPath(configureFilterPath);
+                               log.warn("Unable to determine filter path from 
filter init-param, web.xml, "
+                                       + "or servlet 3.0 annotations. Assuming 
user will set filter path "
+                                       + "manually by calling 
setFilterPath(String)");
                        }
-               }
 
-               if (getFilterPath() == null)
-               {
-                       log.warn("Unable to determine filter path from filter 
init-param, web.xml, "
-                               + "or servlet 3.0 annotations. Assuming user 
will set filter path "
-                               + "manually by calling setFilterPath(String)");
-               }
-
-               final ClassLoader previousClassLoader = 
Thread.currentThread().getContextClassLoader();
-               final ClassLoader newClassLoader = getClassLoader();
+                       ThreadContext.setApplication(application);
+                       try
+                       {
+                               application.initApplication();
 
-               ThreadContext.setApplication(application);
-               try
-               {
-                       if (previousClassLoader != newClassLoader)
+                               // Give the application the option to log that 
it is started
+                               application.logStarted();
+                       }
+                       finally
                        {
-                               
Thread.currentThread().setContextClassLoader(newClassLoader);
+                               ThreadContext.detach();
                        }
-
-                       application.initApplication();
-
-                       // Give the application the option to log that it is 
started
-                       application.logStarted();
                }
                finally
                {
-                       ThreadContext.detach();
-
                        if (newClassLoader != previousClassLoader)
                        {
                                
Thread.currentThread().setContextClassLoader(previousClassLoader);

Reply via email to