hi guys, looks like our latest request cycle refactoring broke onRuntimeException handler in Application. i looked into fixing it and there doesnt seem to be a very clean way.

first, we no longer deal with a runtime exception, our IExceptionResponseStrategy now deals with a regular exception. so i renamed onRuntimeException to onException and it now takes a regular exception as a param.

secondly it is now public since the response strategy and application are no longer in the same package.

finally there is also some weirdness in mock application since you cant rethrow a checked exception without declaring it so i have to wrap it in a runtime exception which is not what user might expect.

im attaching the patch. if no one is against this fix i will commit it. just wanted to check since this will break some clients.

-Igor

### Eclipse Workspace Patch 1.0
#P wicket
Index: src/java/wicket/request/compound/DefaultExceptionResponseProcessor.java
===================================================================
RCS file: 
/cvsroot/wicket/wicket/src/java/wicket/request/compound/DefaultExceptionResponseProcessor.java,v
retrieving revision 1.2
diff -u -r1.2 DefaultExceptionResponseProcessor.java
--- src/java/wicket/request/compound/DefaultExceptionResponseProcessor.java     
30 Nov 2005 06:57:08 -0000      1.2
+++ src/java/wicket/request/compound/DefaultExceptionResponseProcessor.java     
18 Dec 2005 07:57:00 -0000
@@ -54,7 +54,13 @@
                final Session session = requestCycle.getSession();
                final Application application = session.getApplication();
                final ApplicationSettings settings = application.getSettings();
-               if (settings.getUnexpectedExceptionDisplay() != 
ApplicationSettings.SHOW_NO_EXCEPTION_PAGE)
+
+               Page page = 
application.onException(requestCycle.getResponsePage(), e);
+               if (page != null)
+               {
+                       requestCycle.setResponsePage(page);
+               }
+               else if (settings.getUnexpectedExceptionDisplay() != 
ApplicationSettings.SHOW_NO_EXCEPTION_PAGE)
                {
                        Class internalErrorPageClass = 
application.getPages().getInternalErrorPage();
                        Page responsePage = requestCycle.getResponsePage();
Index: src/java/wicket/Application.java
===================================================================
RCS file: /cvsroot/wicket/wicket/src/java/wicket/Application.java,v
retrieving revision 1.85
diff -u -r1.85 Application.java
--- src/java/wicket/Application.java    14 Dec 2005 20:14:48 -0000      1.85
+++ src/java/wicket/Application.java    18 Dec 2005 07:56:59 -0000
@@ -599,7 +599,7 @@
         *            The exception
         * @return Any error page to redirect to
         */
-       protected Page onRuntimeException(final Page page, final 
RuntimeException e)
+       public Page onException(final Page page, final Exception e)
        {
                return null;
        }
Index: src/java/wicket/protocol/http/MockWebApplication.java
===================================================================
RCS file: 
/cvsroot/wicket/wicket/src/java/wicket/protocol/http/MockWebApplication.java,v
retrieving revision 1.35
diff -u -r1.35 MockWebApplication.java
--- src/java/wicket/protocol/http/MockWebApplication.java       6 Dec 2005 
22:17:44 -0000       1.35
+++ src/java/wicket/protocol/http/MockWebApplication.java       18 Dec 2005 
07:57:00 -0000
@@ -411,16 +411,20 @@
         * @param ex
         * @return Page
         */
-       protected Page onRuntimeException(final Page page, final 
RuntimeException ex)
+       public Page onException(final Page page, final Exception ex)
        {
                if (rethrowRuntimeException)
                {
                        log.info("Caught exception: " + ex.getMessage());
-                       throw ex;
+                       if (ex instanceof RuntimeException) {
+                               throw (RuntimeException)ex;
+                       } else {
+                               throw new RuntimeException(ex);
+                       }
                }
                else
                {
-                       return super.onRuntimeException(page, ex);
+                       return super.onException(page, ex);
                }
        }
 }
\ No newline at end of file
Index: src/test/wicket/ExceptionThrowingPage.java
===================================================================
RCS file: src/test/wicket/ExceptionThrowingPage.java
diff -N src/test/wicket/ExceptionThrowingPage.java
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ src/test/wicket/ExceptionThrowingPage.java  1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,28 @@
+package wicket;
+
+import wicket.markup.html.WebPage;
+import wicket.markup.html.link.Link;
+
+/**
+ * Page that throws a runtime exception when the link is clicked
+ * 
+ * @author Igor Vaynberg (ivaynberg)
+ */
+public class ExceptionThrowingPage extends WebPage
+{
+       private static final long serialVersionUID = 1L;
+
+       /**
+        * Construct.
+        * @param exceptionMsg 
+        */
+       public ExceptionThrowingPage(final String exceptionMsg) {
+               add(new Link("clickme") {
+                       private static final long serialVersionUID = 1L;
+
+                       public void onClick() {
+                               throw new RuntimeException(exceptionMsg);
+                       }
+               });
+       }
+}
Index: src/test/wicket/ApplicationTest.java
===================================================================
RCS file: src/test/wicket/ApplicationTest.java
diff -N src/test/wicket/ApplicationTest.java
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ src/test/wicket/ApplicationTest.java        1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,61 @@
+package wicket;
+
+import javax.servlet.ServletException;
+
+import wicket.model.Model;
+import wicket.util.tester.WicketTester;
+import junit.framework.TestCase;
+
+/**
+ * Test case for [EMAIL PROTECTED] Application} class
+ * 
+ * @author Igor Vaynberg (ivaynberg)
+ */
+public class ApplicationTest extends TestCase
+{
+       /**
+        * test application.onRuntimeException() contract
+        * 
+        * @throws ServletException
+        */
+       public void testOnException() throws ServletException
+       {
+               final String invalid = "invalid";
+               final String valid = "valid";
+               final String msg = "test";
+
+               final Model model = new Model("invalid");
+
+               WicketTester tester = new WicketTester()
+               {
+                       public Page onException(Page page, Exception ex)
+                       {
+                               Throwable root = ex;
+                               while (root.getCause() != null)
+                               {
+                                       root = root.getCause();
+                               }
+                               if (msg.equals(root.getMessage())
+                                               && 
page.getClass().equals(ExceptionThrowingPage.class))
+                               {
+                                       model.setObject(valid);
+                               }
+                               return null;
+                       }
+               };
+
+               tester.startPage(new ExceptionThrowingPage(msg));
+               try
+               {
+                       tester.clickLink("clickme");
+               }
+               catch (WicketRuntimeException e)
+               {
+                       // noop
+               }
+
+               
assertFalse(tester.getLastRenderedPage().getClass().equals(ExceptionThrowingPage.class));
+               assertEquals(valid, model.getObject(null));
+       }
+
+}
Index: src/test/wicket/ExceptionThrowingPage.html
===================================================================
RCS file: src/test/wicket/ExceptionThrowingPage.html
diff -N src/test/wicket/ExceptionThrowingPage.html
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ src/test/wicket/ExceptionThrowingPage.html  1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,1 @@
+<a href="#" wicket:id="clickme">click me for a runtime exception</a>

Reply via email to