You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by ma...@apache.org on 2008/04/13 13:29:04 UTC

svn commit: r647561 - in /wicket: branches/wicket-1.3.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/ branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/redirect/abort/ trunk/wicket/src/main/java/org/apache/wicket/ trunk/wicket/src/...

Author: marrink
Date: Sun Apr 13 04:28:39 2008
New Revision: 647561

URL: http://svn.apache.org/viewvc?rev=647561&view=rev
Log:
RESOLVED - issue WICKET-1418: org.apache.wicket.MarkupContainer swallows AbortException 
https://issues.apache.org/jira/browse/WICKET-1418
Tests Submitted by: Peter Ertl

Added:
    wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/redirect/abort/
    wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/redirect/abort/AbortExceptionPage.html   (with props)
    wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/redirect/abort/AbortExceptionPage.java   (with props)
    wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/redirect/abort/AbortExceptionTest.java   (with props)
    wicket/trunk/wicket/src/test/java/org/apache/wicket/redirect/abort/
    wicket/trunk/wicket/src/test/java/org/apache/wicket/redirect/abort/AbortExceptionPage.html   (with props)
    wicket/trunk/wicket/src/test/java/org/apache/wicket/redirect/abort/AbortExceptionPage.java   (with props)
    wicket/trunk/wicket/src/test/java/org/apache/wicket/redirect/abort/AbortExceptionTest.java   (with props)
Modified:
    wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/RequestCycle.java
    wicket/trunk/wicket/src/main/java/org/apache/wicket/RequestCycle.java

Modified: wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/RequestCycle.java
URL: http://svn.apache.org/viewvc/wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/RequestCycle.java?rev=647561&r1=647560&r2=647561&view=diff
==============================================================================
--- wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/RequestCycle.java (original)
+++ wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/RequestCycle.java Sun Apr 13 04:28:39 2008
@@ -1262,6 +1262,19 @@
 		}
 		catch (RuntimeException e)
 		{
+			/*
+			 * check if the raised exception wraps an abort exception. if so, it is probably wise to
+			 * unwrap and rethrow the abort exception
+			 */
+			Throwable cause = e.getCause();
+			while (cause != null)
+			{
+				if (cause instanceof AbortException)
+				{
+					throw ((AbortException)cause);
+				}
+				cause = cause.getCause();
+			}
 			if (!handlingException)
 			{
 				// set step manually to handle exception

Added: wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/redirect/abort/AbortExceptionPage.html
URL: http://svn.apache.org/viewvc/wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/redirect/abort/AbortExceptionPage.html?rev=647561&view=auto
==============================================================================
--- wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/redirect/abort/AbortExceptionPage.html (added)
+++ wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/redirect/abort/AbortExceptionPage.html Sun Apr 13 04:28:39 2008
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns:wicket="http://wicket.apache.org">
+<head>
+  <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
+  <title>Page</title>
+</head>
+<body>
+
+  <span wicket:id="test">test</span>
+
+</body>
+</html>
\ No newline at end of file

Propchange: wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/redirect/abort/AbortExceptionPage.html
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/redirect/abort/AbortExceptionPage.java
URL: http://svn.apache.org/viewvc/wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/redirect/abort/AbortExceptionPage.java?rev=647561&view=auto
==============================================================================
--- wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/redirect/abort/AbortExceptionPage.java (added)
+++ wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/redirect/abort/AbortExceptionPage.java Sun Apr 13 04:28:39 2008
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.redirect.abort;
+
+import java.util.Collections;
+
+import org.apache.wicket.PageParameters;
+import org.apache.wicket.markup.html.WebPage;
+import org.apache.wicket.markup.html.list.ListItem;
+import org.apache.wicket.markup.html.list.ListView;
+import org.apache.wicket.model.IModel;
+import org.apache.wicket.model.LoadableDetachableModel;
+import org.apache.wicket.protocol.http.servlet.AbortWithWebErrorCodeException;
+
+/**
+ * Page that optionally throws an abortexception during render phase.
+ * 
+ * @author Peter Ertl
+ */
+public class AbortExceptionPage extends WebPage
+{
+	private static final long serialVersionUID = -5906071716129043859L;
+
+	public AbortExceptionPage(PageParameters parameters)
+	{
+		final boolean triggerError = parameters.getBoolean("trigger");
+
+		if (!triggerError)
+			throw new AbortWithWebErrorCodeException(1234, "this error will be rendered");
+
+		IModel model = new LoadableDetachableModel()
+		{
+			private static final long serialVersionUID = -1285116295157071919L;
+
+			protected Object load()
+			{
+				if (triggerError)
+					throw new AbortWithWebErrorCodeException(1234,
+						"this error will NOT be rendered");
+				else
+					return Collections.EMPTY_LIST;
+			}
+		};
+
+		add(new ListView("test", model)
+		{
+			private static final long serialVersionUID = -4176346513350288174L;
+
+			protected void populateItem(final ListItem item)
+			{
+				// not used
+			}
+		});
+	}
+}

Propchange: wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/redirect/abort/AbortExceptionPage.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/redirect/abort/AbortExceptionTest.java
URL: http://svn.apache.org/viewvc/wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/redirect/abort/AbortExceptionTest.java?rev=647561&view=auto
==============================================================================
--- wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/redirect/abort/AbortExceptionTest.java (added)
+++ wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/redirect/abort/AbortExceptionTest.java Sun Apr 13 04:28:39 2008
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.redirect.abort;
+
+import junit.framework.Assert;
+
+import org.apache.wicket.PageParameters;
+import org.apache.wicket.WicketRuntimeException;
+import org.apache.wicket.WicketTestCase;
+import org.apache.wicket.protocol.http.servlet.AbortWithWebErrorCodeException;
+
+/**
+ * Testcase for WICKET-1418, throwing an abortexception during rendering.
+ * 
+ * @author Peter Ertl
+ * @author marrink
+ * 
+ * @see <a href="https://issues.apache.org/jira/browse/WICKET-1418">WICKET-1418</a>
+ */
+public class AbortExceptionTest extends WicketTestCase
+{
+	/**
+	 * Test page without throwing abort.
+	 */
+	public void testNoAbort()
+	{
+		System.out.println("testing good usecase");
+		tester.processRequestCycle(AbortExceptionPage.class, new PageParameters("trigger=false"));
+		Assert.assertEquals(1234, tester.getServletResponse().getCode());
+	}
+
+	/**
+	 * Test page with throwing abort.
+	 */
+	public void testAbort()
+	{
+		try
+		{
+
+			System.out.println("testing bad usecase");
+			tester.processRequestCycle(AbortExceptionPage.class, new PageParameters("trigger=true"));
+			Assert.assertEquals(1234, tester.getServletResponse().getCode()); // this will fail
+		}
+		catch (WicketRuntimeException x)
+		{
+			final Throwable reason = x.getCause();
+
+			Assert.assertEquals(reason.getClass(), AbortWithWebErrorCodeException.class);
+			Assert.fail("this must not happen (we expect a redirect happen here and handled by wicket request processor)");
+		}
+	}
+
+}

Propchange: wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/redirect/abort/AbortExceptionTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/RequestCycle.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/RequestCycle.java?rev=647561&r1=647560&r2=647561&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/RequestCycle.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/RequestCycle.java Sun Apr 13 04:28:39 2008
@@ -1267,6 +1267,19 @@
 		}
 		catch (RuntimeException e)
 		{
+			/*
+			 * check if the raised exception wraps an abort exception. if so, it is probably wise to
+			 * unwrap and rethrow the abort exception
+			 */
+			Throwable cause = e.getCause();
+			while (cause != null)
+			{
+				if (cause instanceof AbortException)
+				{
+					throw ((AbortException)cause);
+				}
+				cause = cause.getCause();
+			}
 			if (!handlingException)
 			{
 				// set step manually to handle exception

Added: wicket/trunk/wicket/src/test/java/org/apache/wicket/redirect/abort/AbortExceptionPage.html
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/redirect/abort/AbortExceptionPage.html?rev=647561&view=auto
==============================================================================
--- wicket/trunk/wicket/src/test/java/org/apache/wicket/redirect/abort/AbortExceptionPage.html (added)
+++ wicket/trunk/wicket/src/test/java/org/apache/wicket/redirect/abort/AbortExceptionPage.html Sun Apr 13 04:28:39 2008
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns:wicket="http://wicket.apache.org">
+<head>
+  <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
+  <title>Page</title>
+</head>
+<body>
+
+  <span wicket:id="test">test</span>
+
+</body>
+</html>
\ No newline at end of file

Propchange: wicket/trunk/wicket/src/test/java/org/apache/wicket/redirect/abort/AbortExceptionPage.html
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: wicket/trunk/wicket/src/test/java/org/apache/wicket/redirect/abort/AbortExceptionPage.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/redirect/abort/AbortExceptionPage.java?rev=647561&view=auto
==============================================================================
--- wicket/trunk/wicket/src/test/java/org/apache/wicket/redirect/abort/AbortExceptionPage.java (added)
+++ wicket/trunk/wicket/src/test/java/org/apache/wicket/redirect/abort/AbortExceptionPage.java Sun Apr 13 04:28:39 2008
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.redirect.abort;
+
+import java.util.Collections;
+
+import org.apache.wicket.PageParameters;
+import org.apache.wicket.markup.html.WebPage;
+import org.apache.wicket.markup.html.list.ListItem;
+import org.apache.wicket.markup.html.list.ListView;
+import org.apache.wicket.model.IModel;
+import org.apache.wicket.model.LoadableDetachableModel;
+import org.apache.wicket.protocol.http.servlet.AbortWithWebErrorCodeException;
+
+/**
+ * Page that optionally throws an abortexception during render phase.
+ * 
+ * @author Peter Ertl
+ */
+public class AbortExceptionPage extends WebPage
+{
+	private static final long serialVersionUID = -5906071716129043859L;
+
+	public AbortExceptionPage(PageParameters parameters)
+	{
+		final boolean triggerError = parameters.getBoolean("trigger");
+
+		if (!triggerError)
+			throw new AbortWithWebErrorCodeException(1234, "this error will be rendered");
+
+		IModel model = new LoadableDetachableModel()
+		{
+			private static final long serialVersionUID = -1285116295157071919L;
+
+			protected Object load()
+			{
+				if (triggerError)
+					throw new AbortWithWebErrorCodeException(1234,
+						"this error will NOT be rendered");
+				else
+					return Collections.EMPTY_LIST;
+			}
+		};
+
+		add(new ListView("test", model)
+		{
+			private static final long serialVersionUID = -4176346513350288174L;
+
+			protected void populateItem(final ListItem item)
+			{
+				// not used
+			}
+		});
+	}
+}

Propchange: wicket/trunk/wicket/src/test/java/org/apache/wicket/redirect/abort/AbortExceptionPage.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: wicket/trunk/wicket/src/test/java/org/apache/wicket/redirect/abort/AbortExceptionTest.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/redirect/abort/AbortExceptionTest.java?rev=647561&view=auto
==============================================================================
--- wicket/trunk/wicket/src/test/java/org/apache/wicket/redirect/abort/AbortExceptionTest.java (added)
+++ wicket/trunk/wicket/src/test/java/org/apache/wicket/redirect/abort/AbortExceptionTest.java Sun Apr 13 04:28:39 2008
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.redirect.abort;
+
+import junit.framework.Assert;
+
+import org.apache.wicket.PageParameters;
+import org.apache.wicket.WicketRuntimeException;
+import org.apache.wicket.WicketTestCase;
+import org.apache.wicket.protocol.http.servlet.AbortWithWebErrorCodeException;
+
+/**
+ * Testcase for WICKET-1418, throwing an abortexception during rendering.
+ * 
+ * @author Peter Ertl
+ * @author marrink
+ * 
+ * @see <a href="https://issues.apache.org/jira/browse/WICKET-1418">WICKET-1418</a>
+ */
+public class AbortExceptionTest extends WicketTestCase
+{
+	/**
+	 * Test page without throwing abort.
+	 */
+	public void testNoAbort()
+	{
+		System.out.println("testing good usecase");
+		tester.processRequestCycle(AbortExceptionPage.class, new PageParameters("trigger=false"));
+		Assert.assertEquals(1234, tester.getServletResponse().getCode());
+	}
+
+	/**
+	 * Test page with throwing abort.
+	 */
+	public void testAbort()
+	{
+		try
+		{
+
+			System.out.println("testing bad usecase");
+			tester.processRequestCycle(AbortExceptionPage.class, new PageParameters("trigger=true"));
+			Assert.assertEquals(1234, tester.getServletResponse().getCode()); // this will fail
+		}
+		catch (WicketRuntimeException x)
+		{
+			final Throwable reason = x.getCause();
+
+			Assert.assertEquals(reason.getClass(), AbortWithWebErrorCodeException.class);
+			Assert.fail("this must not happen (we expect a redirect happen here and handled by wicket request processor)");
+		}
+	}
+
+}

Propchange: wicket/trunk/wicket/src/test/java/org/apache/wicket/redirect/abort/AbortExceptionTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain