Author: ivaynberg
Date: Sat Oct 30 05:25:07 2010
New Revision: 1028991
URL: http://svn.apache.org/viewvc?rev=1028991&view=rev
Log:
Issue: WICKET-3143
Modified:
wicket/trunk/wicket/src/main/java/org/apache/wicket/DefaultExceptionMapper.java
wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/HeaderBufferingWebResponse.java
wicket/trunk/wicket/src/main/java/org/apache/wicket/settings/IExceptionSettings.java
wicket/trunk/wicket/src/main/java/org/apache/wicket/settings/Settings.java
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=1028991&r1=1028990&r2=1028991&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 Oct 30 05:25:07 2010
@@ -21,11 +21,13 @@ import org.apache.wicket.markup.html.pag
import org.apache.wicket.protocol.http.PageExpiredException;
import org.apache.wicket.request.IExceptionMapper;
import org.apache.wicket.request.IRequestHandler;
+import org.apache.wicket.request.Request;
import org.apache.wicket.request.cycle.RequestCycle;
import org.apache.wicket.request.handler.EmptyRequestHandler;
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.WebRequest;
import org.apache.wicket.request.http.handler.ErrorCodeResponseHandler;
import org.apache.wicket.request.mapper.StalePageException;
import org.apache.wicket.settings.IExceptionSettings;
@@ -59,6 +61,18 @@ public class DefaultExceptionMapper impl
private IRequestHandler internalMap(Exception e)
{
+ final Application application = Application.get();
+
+ // check if we are processing an Ajax request and if we want to
invoke the failure handler
+ if (isProcessingAjaxRequest())
+ {
+ switch
(application.getExceptionSettings().getAjaxErrorHandlingStrategy())
+ {
+ case INVOKE_FAILURE_HANDLER :
+ return new
ErrorCodeResponseHandler(500);
+ }
+ }
+
if (e instanceof StalePageException)
{
// If the page was stale, just rerender it
@@ -79,7 +93,7 @@ public class DefaultExceptionMapper impl
}
else
{
- final Application application = Application.get();
+
final UnexpectedExceptionDisplay
unexpectedExceptionDisplay = application.getExceptionSettings()
.getUnexpectedExceptionDisplay();
@@ -116,13 +130,30 @@ public class DefaultExceptionMapper impl
/*
* Use NEVER_REDIRECT policy to preserve the original page's
URL for non-Ajax requests and
- * to indicate the error for Ajax requests so that their
onFailure() is being called
+ * always redirect for ajax requests
*/
RenderPageRequestHandler.RedirectPolicy redirect =
RenderPageRequestHandler.RedirectPolicy.NEVER_REDIRECT;
+ if (isProcessingAjaxRequest())
+ {
+ redirect =
RenderPageRequestHandler.RedirectPolicy.ALWAYS_REDIRECT;
+ }
+
return new RenderPageRequestHandler(pageProvider, redirect);
}
+ private boolean isProcessingAjaxRequest()
+ {
+
+ RequestCycle rc = RequestCycle.get();
+ Request request = rc.getRequest();
+ if (request instanceof WebRequest)
+ {
+ return ((WebRequest)request).isAjax();
+ }
+ return false;
+ }
+
/**
* @return the page being rendered when the exception was thrown, or
{...@code null} if it cannot
* be extracted
Modified:
wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/HeaderBufferingWebResponse.java
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/HeaderBufferingWebResponse.java?rev=1028991&r1=1028990&r2=1028991&view=diff
==============================================================================
---
wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/HeaderBufferingWebResponse.java
(original)
+++
wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/HeaderBufferingWebResponse.java
Sat Oct 30 05:25:07 2010
@@ -142,7 +142,6 @@ class HeaderBufferingWebResponse extends
@Override
public void setStatus(int sc)
{
- checkHeader();
bufferedResponse.setStatus(sc);
}
Modified:
wicket/trunk/wicket/src/main/java/org/apache/wicket/settings/IExceptionSettings.java
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/settings/IExceptionSettings.java?rev=1028991&r1=1028990&r2=1028991&view=diff
==============================================================================
---
wicket/trunk/wicket/src/main/java/org/apache/wicket/settings/IExceptionSettings.java
(original)
+++
wicket/trunk/wicket/src/main/java/org/apache/wicket/settings/IExceptionSettings.java
Sat Oct 30 05:25:07 2010
@@ -91,4 +91,28 @@ public interface IExceptionSettings
* The unexpectedExceptionDisplay to set.
*/
void setUnexpectedExceptionDisplay(UnexpectedExceptionDisplay
unexpectedExceptionDisplay);
+
+ /**
+ * Sets strategy used to handle errors during Ajax request processing
+ *
+ * @param strategy
+ */
+ void setAjaxErrorHandlingStrategy(AjaxErrorStrategy strategy);
+
+ /**
+ * @return strategy used to handle errors during Ajax request processing
+ */
+ AjaxErrorStrategy getAjaxErrorHandlingStrategy();
+
+ /**
+ * How to handle errors while processing an Ajax request
+ *
+ * @author igor
+ */
+ public static enum AjaxErrorStrategy {
+ /** redirect to error page, just like a normal requset */
+ REDIRECT_TO_ERROR_PAGE,
+ /** invoke client side failure handler */
+ INVOKE_FAILURE_HANDLER
+ }
}
Modified:
wicket/trunk/wicket/src/main/java/org/apache/wicket/settings/Settings.java
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/settings/Settings.java?rev=1028991&r1=1028990&r2=1028991&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/settings/Settings.java
(original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/settings/Settings.java
Sat Oct 30 05:25:07 2010
@@ -323,6 +323,8 @@ public final class Settings
private MarkupFactory markupFactory;
+ private AjaxErrorStrategy errorHandlingStrategyDuringAjaxRequests =
AjaxErrorStrategy.REDIRECT_TO_ERROR_PAGE;
+
/**
* Create the application settings, carrying out any necessary
initializations.
*
@@ -1433,4 +1435,22 @@ public final class Settings
{
this.useTimestampOnResourcesName = useTimestampOnResourcesName;
}
+
+ /**
+ * @see
org.apache.wicket.settings.IExceptionSettings#getAjaxErrorHandlingStrategy()
+ */
+ public AjaxErrorStrategy getAjaxErrorHandlingStrategy()
+ {
+ return errorHandlingStrategyDuringAjaxRequests;
+ }
+
+ /**
+ * @see
org.apache.wicket.settings.IExceptionSettings#setAjaxErrorHandlingStrategy(org.apache.wicket.settings.IExceptionSettings.AjaxErrorStrategy)
+ */
+ public void setAjaxErrorHandlingStrategy(
+ AjaxErrorStrategy errorHandlingStrategyDuringAjaxRequests)
+ {
+ this.errorHandlingStrategyDuringAjaxRequests =
errorHandlingStrategyDuringAjaxRequests;
+ }
+
}