Author: jbq
Date: Tue Mar  6 02:37:59 2007
New Revision: 515061

URL: http://svn.apache.org/viewvc?view=rev&rev=515061
Log:
WICKET-313 Use standard exception handling in AjaxRequestTarget

Added:
    
incubator/wicket/trunk/wicket/src/test/java/wicket/protocol/http/TestPage.html
      - copied unchanged from r514753, 
incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/protocol/http/TestPage.html
    
incubator/wicket/trunk/wicket/src/test/java/wicket/protocol/http/TestPage.java
      - copied, changed from r514753, 
incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/protocol/http/TestPage.java
Modified:
    
incubator/wicket/trunk/wicket/src/main/java/wicket/ajax/AjaxRequestTarget.java
    
incubator/wicket/trunk/wicket/src/test/java/wicket/protocol/http/WebResponseTest.java

Modified: 
incubator/wicket/trunk/wicket/src/main/java/wicket/ajax/AjaxRequestTarget.java
URL: 
http://svn.apache.org/viewvc/incubator/wicket/trunk/wicket/src/main/java/wicket/ajax/AjaxRequestTarget.java?view=diff&rev=515061&r1=515060&r2=515061
==============================================================================
--- 
incubator/wicket/trunk/wicket/src/main/java/wicket/ajax/AjaxRequestTarget.java 
(original)
+++ 
incubator/wicket/trunk/wicket/src/main/java/wicket/ajax/AjaxRequestTarget.java 
Tue Mar  6 02:37:59 2007
@@ -297,8 +297,7 @@
        public final void respond(final RequestCycle requestCycle)
        {
                final WebResponse response = 
(WebResponse)requestCycle.getResponse();
-               try
-               {
+               response.setAjax(true);
                        final Application app = Application.get();
 
                        // Determine encoding
@@ -338,18 +337,6 @@
                        }
 
                        response.write("</ajax-response>");
-               }
-               catch (RuntimeException ex)
-               {
-                       // log the error but output nothing in the response, 
parse failure
-                       // of response will cause any javascript failureHandler 
to be
-                       // invoked
-                       Log.error("Error while responding to an AJAX request: " 
+ toString(), ex);
-               }
-               finally
-               {
-                       requestCycle.setResponse(response);
-               }
        }
 
        private void fireOnBeforeRespondListeners()

Copied: 
incubator/wicket/trunk/wicket/src/test/java/wicket/protocol/http/TestPage.java 
(from r514753, 
incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/protocol/http/TestPage.java)
URL: 
http://svn.apache.org/viewvc/incubator/wicket/trunk/wicket/src/test/java/wicket/protocol/http/TestPage.java?view=diff&rev=515061&p1=incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/protocol/http/TestPage.java&r1=514753&p2=incubator/wicket/trunk/wicket/src/test/java/wicket/protocol/http/TestPage.java&r2=515061
==============================================================================
--- 
incubator/wicket/branches/wicket-1.x/wicket/src/test/java/wicket/protocol/http/TestPage.java
 (original)
+++ 
incubator/wicket/trunk/wicket/src/test/java/wicket/protocol/http/TestPage.java 
Tue Mar  6 02:37:59 2007
@@ -33,7 +33,7 @@
        public TestPage()
        {
 
-               add(new AjaxLink("link")
+               new AjaxLink(this, "link")
                {
                        /**
                         * 
@@ -51,7 +51,7 @@
                                if (clicked)
                                        throw new 
IllegalStateException("Intentional error");
                        }
-               });
+               };
        }
 
 }

Modified: 
incubator/wicket/trunk/wicket/src/test/java/wicket/protocol/http/WebResponseTest.java
URL: 
http://svn.apache.org/viewvc/incubator/wicket/trunk/wicket/src/test/java/wicket/protocol/http/WebResponseTest.java?view=diff&rev=515061&r1=515060&r2=515061
==============================================================================
--- 
incubator/wicket/trunk/wicket/src/test/java/wicket/protocol/http/WebResponseTest.java
 (original)
+++ 
incubator/wicket/trunk/wicket/src/test/java/wicket/protocol/http/WebResponseTest.java
 Tue Mar  6 02:37:59 2007
@@ -18,6 +18,13 @@
 
 import junit.framework.TestCase;
 
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import wicket.ajax.AjaxEventBehavior;
+import wicket.ajax.markup.html.AjaxLink;
+import wicket.util.tester.WicketTester;
+
 /**
  * 
  * 
@@ -25,6 +32,8 @@
  */
 public class WebResponseTest extends TestCase
 {
+       private static final Logger log = 
LoggerFactory.getLogger(WebResponseTest.class);
+
        /**
         * Test that redirect works correctly when not using ajax
         */
@@ -54,5 +63,42 @@
 
                assertNull(mockResponse.getRedirectLocation());
                assertTrue(mockResponse.containsHeader("Ajax-Location"));
+       }
+
+       public void testErrorPage()
+       {
+               WicketTester tester = new WicketTester();
+               tester.startPage(TestPage.class);
+               AjaxLink link = 
(AjaxLink)tester.getComponentFromLastRenderedPage("link");
+
+               // Cannot use executeAjaxEvent or onClick because WicketTester 
creates
+               // an AjaxRequestTarget from scratch
+               // tester.executeAjaxEvent(link, "onclick");
+               // tester.clickLink("link");
+
+               // FIXME should not be needed
+               tester.createRequestCycle();
+
+               // Invoke the call back URL of the ajax event behavior
+               String callbackUrl = 
((AjaxEventBehavior)link.getBehaviors().get(0)).getCallbackUrl()
+                               .toString();
+               tester.setupRequestAndResponse();
+               // Fake an Ajax request
+               
((MockHttpServletRequest)tester.getServletRequest()).addHeader("Wicket-Ajax", 
"Yes");
+               tester.getServletRequest().setURL(callbackUrl);
+
+               // Do not call tester.processRequestCycle() because it throws an
+               // exception when getting an error page
+               WebRequestCycle cycle = tester.createRequestCycle();
+               cycle.request();
+
+               
assertNull(((MockHttpServletResponse)tester.getWicketResponse().getHttpServletResponse())
+                               .getRedirectLocation());
+               String ajaxLocation = 
((MockHttpServletResponse)tester.getWicketResponse()
+                               
.getHttpServletResponse()).getHeader("Ajax-Location");
+               log.debug(ajaxLocation);
+               assertNotNull(ajaxLocation);
+
+               tester.destroy();
        }
 }


Reply via email to