You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by sv...@apache.org on 2013/04/19 11:54:09 UTC

git commit: WICKET-5146 call #destroy() when #init() fails, since the web container will not do it

Updated Branches:
  refs/heads/master 34f436421 -> dd47bd125


WICKET-5146 call #destroy() when #init() fails, since the web container
will not do it

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

Branch: refs/heads/master
Commit: dd47bd125fd6fb5a11ee898881e767144e601835
Parents: 34f4364
Author: svenmeier <sv...@apache.org>
Authored: Fri Apr 19 11:53:38 2013 +0200
Committer: svenmeier <sv...@apache.org>
Committed: Fri Apr 19 11:53:38 2013 +0200

----------------------------------------------------------------------
 .../apache/wicket/protocol/http/WicketFilter.java  |   28 +++++++++++++-
 1 files changed, 26 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/dd47bd12/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 be577f3..f40a0c9 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
@@ -431,6 +431,23 @@ public class WicketFilter implements Filter
 				ThreadContext.detach();
 			}
 		}
+		catch (Exception e)
+		{
+			// #destroy() might not be called by the web container when #init() fails,
+			// so destroy now
+			log.warn("initialization failed, destroying now");
+
+			try
+			{
+				destroy();
+			}
+			catch (Exception destroyException)
+			{
+				log.warn("Unable to destroy after initialization failure", destroyException);
+			}
+
+			throw new ServletException(e);
+		}
 		finally
 		{
 			if (newClassLoader != previousClassLoader)
@@ -578,7 +595,14 @@ public class WicketFilter implements Filter
 
 		if (applicationFactory != null)
 		{
-			applicationFactory.destroy(this);
+			try
+			{
+				applicationFactory.destroy(this);
+			}
+			finally
+			{
+				applicationFactory = null;
+			}
 		}
 	}
 
@@ -781,7 +805,7 @@ public class WicketFilter implements Filter
 	 * level "/" then an empty string should be used instead.
 	 * 
 	 * @param filterPath
-	 * @return
+	 * @return canonic filter path
 	 */
 	static String canonicaliseFilterPath(String filterPath)
 	{