You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by iv...@apache.org on 2010/08/28 22:00:53 UTC
svn commit: r990427 - in /wicket/trunk/wicket/src:
main/java/org/apache/wicket/ main/java/org/apache/wicket/request/cycle/
main/java/org/apache/wicket/util/tester/
test/java/org/apache/wicket/markup/html/basic/
test/java/org/apache/wicket/markup/html/b...
Author: ivaynberg
Date: Sat Aug 28 20:00:52 2010
New Revision: 990427
URL: http://svn.apache.org/viewvc?rev=990427&view=rev
Log:
cleaner fix to 3022 that does not complicate the api
Issue: WICKET-3022
Modified:
wicket/trunk/wicket/src/main/java/org/apache/wicket/DefaultExceptionMapper.java
wicket/trunk/wicket/src/main/java/org/apache/wicket/request/cycle/RequestCycle.java
wicket/trunk/wicket/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/basic/SimplePageExpectedResult_8.html
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/border/BoxBorderTestPage_ExpectedResult_10.html
wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/parser/filter/HeaderSectionPageExpectedResult_13.html
Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/DefaultExceptionMapper.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/DefaultExceptionMapper.java?rev=990427&r1=990426&r2=990427&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/DefaultExceptionMapper.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/DefaultExceptionMapper.java Sat Aug 28 20:00:52 2010
@@ -26,6 +26,7 @@ import org.apache.wicket.request.handler
import org.apache.wicket.request.handler.IPageRequestHandler;
import org.apache.wicket.request.handler.PageProvider;
import org.apache.wicket.request.handler.RenderPageRequestHandler;
+import org.apache.wicket.request.http.handler.ErrorCodeResponseHandler;
import org.apache.wicket.request.mapper.StalePageException;
import org.apache.wicket.settings.IExceptionSettings;
import org.apache.wicket.settings.IExceptionSettings.UnexpectedExceptionDisplay;
@@ -47,8 +48,9 @@ public class DefaultExceptionMapper impl
private RenderPageRequestHandler.RedirectPolicy redirectPolicy = RenderPageRequestHandler.RedirectPolicy.NEVER_REDIRECT;
/**
- * get the redirect policy in case of error (controls if the URL changes in case of displaying an error)
- *
+ * get the redirect policy in case of error (controls if the URL changes in case of displaying
+ * an error)
+ *
* @return redirect policy
*/
public RenderPageRequestHandler.RedirectPolicy getRedirectPolicy()
@@ -57,9 +59,11 @@ public class DefaultExceptionMapper impl
}
/**
- * set the redirect policy in case of error (you can control if the URL changes in case of displaying an error)
- *
- * @param redirectPolicy redirection policy
+ * set the redirect policy in case of error (you can control if the URL changes in case of
+ * displaying an error)
+ *
+ * @param redirectPolicy
+ * redirection policy
*/
public void setRedirectPolicy(RenderPageRequestHandler.RedirectPolicy redirectPolicy)
{
@@ -68,6 +72,22 @@ public class DefaultExceptionMapper impl
public IRequestHandler map(Exception e)
{
+ try
+ {
+ return internalMap(e);
+ }
+ catch (RuntimeException e2)
+ {
+ // hmmm, we were already handling an exception! give up
+ logger.error("unexpected exception when handling another exception: " + e.getMessage(),
+ e);
+ return new ErrorCodeResponseHandler(500);
+ }
+
+ }
+
+ private IRequestHandler internalMap(Exception e)
+ {
if (e instanceof StalePageException)
{
// If the page was stale, just rerender it
@@ -97,7 +117,8 @@ public class DefaultExceptionMapper impl
if (IExceptionSettings.SHOW_EXCEPTION_PAGE.equals(unexpectedExceptionDisplay))
{
Page currentPage = extractCurrentPage();
- return createPageRequestHandler(new PageProvider(new ExceptionErrorPage(e, currentPage)));
+ return createPageRequestHandler(new PageProvider(new ExceptionErrorPage(e,
+ currentPage)));
}
else if (IExceptionSettings.SHOW_INTERNAL_ERROR_PAGE.equals(unexpectedExceptionDisplay))
{
Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/request/cycle/RequestCycle.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/request/cycle/RequestCycle.java?rev=990427&r1=990426&r2=990427&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/request/cycle/RequestCycle.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/request/cycle/RequestCycle.java Sat Aug 28 20:00:52 2010
@@ -41,7 +41,6 @@ import org.apache.wicket.request.handler
import org.apache.wicket.request.handler.PageProvider;
import org.apache.wicket.request.handler.RenderPageRequestHandler;
import org.apache.wicket.request.handler.resource.ResourceReferenceRequestHandler;
-import org.apache.wicket.request.http.handler.ErrorCodeResponseHandler;
import org.apache.wicket.request.mapper.parameter.PageParameters;
import org.apache.wicket.request.resource.ResourceReference;
import org.apache.wicket.util.lang.Checks;
@@ -204,13 +203,12 @@ public class RequestCycle extends Reques
}
/**
- * Processes the request and detaches the {@link RequestCycle}, but does not handle any
- * exceptions. Exceptions are not caught and thus are passed through to e.g. WicketTester.
+ * Processes the request.
*
* @return <code>true</code> if the request resolved to a Wicket request, <code>false</code>
* otherwise.
*/
- public boolean processRequestAndDetachWithoutExceptionHandling()
+ public boolean processRequest()
{
try
{
@@ -221,59 +219,58 @@ public class RequestCycle extends Reques
executeRequestHandler(handler);
return true;
}
+
+ }
+ catch (Exception e)
+ {
+ IRequestHandler handler = handleException(e);
+ if (handler != null)
+ {
+ executeExceptionRequestHandler(handler, getExceptionRetryCount());
+ }
+ else
+ {
+ log.error("Error during request processing", e);
+ }
+ return true;
}
finally
{
set(null);
- detach();
}
return false;
}
/**
- * Processes the request and detaches the {@link RequestCycle}. Exceptions are caught and
- * managed.
- *
- * @see #handleException(Exception)
- * @see #executeExceptionRequestHandler(IRequestHandler, int)
+ * Convenience method that processes the request and detaches the {@link RequestCycle}.
*
* @return <code>true</code> if the request resolved to a Wicket request, <code>false</code>
* otherwise.
*/
public boolean processRequestAndDetach()
{
+ boolean result;
try
{
- return processRequestAndDetachWithoutExceptionHandling();
+ result = processRequest();
}
- catch (Exception e)
+ finally
{
- IRequestHandler handler = handleException(e);
- if (handler != null)
- {
- return executeExceptionRequestHandler(handler, getExceptionRetryCount());
- }
- else
- {
- log.error("Error during request processing", e);
- }
+ detach();
}
- return false;
+ return result;
}
/**
*
* @param handler
* @param retryCount
- * @return False, in case all retry attempts failed and the request could not be handled
*/
- private boolean executeExceptionRequestHandler(final IRequestHandler handler,
- final int retryCount)
+ private void executeExceptionRequestHandler(final IRequestHandler handler, final int retryCount)
{
try
{
executeRequestHandler(handler);
- return true;
}
catch (Exception e)
{
@@ -282,12 +279,12 @@ public class RequestCycle extends Reques
IRequestHandler next = handleException(e);
if (handler != null)
{
- return executeExceptionRequestHandler(next, retryCount - 1);
+ executeExceptionRequestHandler(next, retryCount - 1);
+ return;
}
}
log.error("Error during processing error message", e);
}
- return false;
}
/**
@@ -298,16 +295,7 @@ public class RequestCycle extends Reques
*/
protected IRequestHandler handleException(final Exception e)
{
- try
- {
- return exceptionMapper.map(e);
- }
- catch (RuntimeException e2)
- {
- // hmmm, we were already handling an exception! give up
- log.error("unexpected exception when handling another exception: " + e.getMessage(), e);
- return new ErrorCodeResponseHandler(500);
- }
+ return exceptionMapper.map(e);
}
/**
Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java?rev=990427&r1=990426&r2=990427&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java Sat Aug 28 20:00:52 2010
@@ -497,21 +497,7 @@ public class BaseWicketTester
applyRequest();
requestCycle.scheduleRequestHandlerAfterCurrent(null);
- // In production you want RequestCycle to manage any exceptions and react depending on
- // your needs. In WicketTester you usually want the exception to fall through for the
- // junit test to fail.
- boolean requestProcessed;
- if (exposeExceptions == true)
- {
- requestProcessed = requestCycle.processRequestAndDetachWithoutExceptionHandling();
- }
- else
- {
- requestProcessed = requestCycle.processRequestAndDetach();
- }
-
- // In case the request could not be processed, ...
- if (requestProcessed == false)
+ if (!requestCycle.processRequestAndDetach())
{
return false;
}
@@ -1916,9 +1902,23 @@ public class BaseWicketTester
this.delegate = delegate;
}
- public IRequestHandler map(final Exception e)
+ public IRequestHandler map(Exception e)
{
- return delegate.map(e);
+ if (exposeExceptions)
+ {
+ if (e instanceof RuntimeException)
+ {
+ throw (RuntimeException)e;
+ }
+ else
+ {
+ throw new WicketRuntimeException(e);
+ }
+ }
+ else
+ {
+ return delegate.map(e);
+ }
}
}
Modified: wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/basic/SimplePageExpectedResult_8.html
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/basic/SimplePageExpectedResult_8.html?rev=990427&r1=990426&r2=990427&view=diff
==============================================================================
--- wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/basic/SimplePageExpectedResult_8.html (original)
+++ wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/basic/SimplePageExpectedResult_8.html Sat Aug 28 20:00:52 2010
@@ -1 +0,0 @@
-<!-- Dummy content: not relevant -->
\ No newline at end of file
Modified: wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/border/BoxBorderTestPage_ExpectedResult_10.html
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/border/BoxBorderTestPage_ExpectedResult_10.html?rev=990427&r1=990426&r2=990427&view=diff
==============================================================================
--- wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/border/BoxBorderTestPage_ExpectedResult_10.html (original)
+++ wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/html/border/BoxBorderTestPage_ExpectedResult_10.html Sat Aug 28 20:00:52 2010
@@ -1,28 +0,0 @@
-<!--
- ====================================================================
- Licensed 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.
--->
-<html>
-<body>
-<span wicket:id="border1"><wicket:border>
-<!-- with open-close tag -->
-davor <wicket:body>middle-1</wicket:body> danach
-</wicket:border></span>
-<span wicket:id="border2"><wicket:border>
-<!-- with separate open and close tag. Body is treated as pre-view region and
- will be removed from output
--->
-davor <wicket:body>middle-2</wicket:body> danach
-</wicket:border></span>
-</body>
-</html>
Modified: wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/parser/filter/HeaderSectionPageExpectedResult_13.html
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/parser/filter/HeaderSectionPageExpectedResult_13.html?rev=990427&r1=990426&r2=990427&view=diff
==============================================================================
--- wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/parser/filter/HeaderSectionPageExpectedResult_13.html (original)
+++ wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/parser/filter/HeaderSectionPageExpectedResult_13.html Sat Aug 28 20:00:52 2010
@@ -1 +0,0 @@
-<!-- This is just a dummy page, because the test should throw an exception -->