Author: jdonnerstag
Date: Sat Aug 28 17:53:46 2010
New Revision: 990399
URL: http://svn.apache.org/viewvc?rev=990399&view=rev
Log:
fixed WICKET-3022: All exceptions are handled by RequestCycle and no longer
"visible" to WicketTester
Issue: WICKET-3022
Modified:
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
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=990399&r1=990398&r2=990399&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 17:53:46 2010
@@ -204,12 +204,13 @@ public class RequestCycle extends Reques
}
/**
- * Processes the request.
+ * 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.
*
* @return <code>true</code> if the request resolved to a Wicket
request, <code>false</code>
* otherwise.
*/
- public boolean processRequest()
+ public boolean processRequestAndDetachWithoutExceptionHandling()
{
try
{
@@ -220,58 +221,59 @@ 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;
}
/**
- * Convenience method that processes the request and detaches the
{...@link RequestCycle}.
+ * Processes the request and detaches the {...@link RequestCycle}.
Exceptions are caught and
+ * managed.
+ *
+ * @see #handleException(Exception)
+ * @see #executeExceptionRequestHandler(IRequestHandler, int)
*
* @return <code>true</code> if the request resolved to a Wicket
request, <code>false</code>
* otherwise.
*/
public boolean processRequestAndDetach()
{
- boolean result;
try
{
- result = processRequest();
+ return
processRequestAndDetachWithoutExceptionHandling();
}
- finally
+ catch (Exception e)
{
- detach();
+ IRequestHandler handler = handleException(e);
+ if (handler != null)
+ {
+ return executeExceptionRequestHandler(handler,
getExceptionRetryCount());
+ }
+ else
+ {
+ log.error("Error during request processing", e);
+ }
}
- return result;
+ return false;
}
/**
*
* @param handler
* @param retryCount
+ * @return False, in case all retry attempts failed and the request
could not be handled
*/
- private void executeExceptionRequestHandler(final IRequestHandler
handler, final int retryCount)
+ private boolean executeExceptionRequestHandler(final IRequestHandler
handler,
+ final int retryCount)
{
try
{
executeRequestHandler(handler);
+ return true;
}
catch (Exception e)
{
@@ -280,12 +282,12 @@ public class RequestCycle extends Reques
IRequestHandler next = handleException(e);
if (handler != null)
{
- executeExceptionRequestHandler(next,
retryCount - 1);
- return;
+ return
executeExceptionRequestHandler(next, retryCount - 1);
}
}
log.error("Error during processing error message", e);
}
+ return false;
}
/**
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=990399&r1=990398&r2=990399&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 17:53:46 2010
@@ -497,7 +497,21 @@ public class BaseWicketTester
applyRequest();
requestCycle.scheduleRequestHandlerAfterCurrent(null);
- if (!requestCycle.processRequestAndDetach())
+ // 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)
{
return false;
}
@@ -1902,23 +1916,9 @@ public class BaseWicketTester
this.delegate = delegate;
}
- public IRequestHandler map(Exception e)
+ public IRequestHandler map(final Exception e)
{
- if (exposeExceptions)
- {
- if (e instanceof RuntimeException)
- {
- throw (RuntimeException)e;
- }
- else
- {
- throw new WicketRuntimeException(e);
- }
- }
- else
- {
- return delegate.map(e);
- }
+ return delegate.map(e);
}
}