You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by mg...@apache.org on 2010/12/01 20:16:40 UTC

svn commit: r1041138 - /wicket/trunk/wicket-examples/src/main/java/org/apache/wicket/examples/WicketExampleRequestCycle.java

Author: mgrigorov
Date: Wed Dec  1 19:16:39 2010
New Revision: 1041138

URL: http://svn.apache.org/viewvc?rev=1041138&view=rev
Log:
Upgrade the code dealing with PageExpiredException to 1.5 classes
Need to be tested that it still serves its purpose

Modified:
    wicket/trunk/wicket-examples/src/main/java/org/apache/wicket/examples/WicketExampleRequestCycle.java

Modified: wicket/trunk/wicket-examples/src/main/java/org/apache/wicket/examples/WicketExampleRequestCycle.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-examples/src/main/java/org/apache/wicket/examples/WicketExampleRequestCycle.java?rev=1041138&r1=1041137&r2=1041138&view=diff
==============================================================================
--- wicket/trunk/wicket-examples/src/main/java/org/apache/wicket/examples/WicketExampleRequestCycle.java (original)
+++ wicket/trunk/wicket-examples/src/main/java/org/apache/wicket/examples/WicketExampleRequestCycle.java Wed Dec  1 19:16:39 2010
@@ -16,8 +16,15 @@
  */
 package org.apache.wicket.examples;
 
+import org.apache.wicket.examples.source.SourcesPage;
+import org.apache.wicket.protocol.http.PageExpiredException;
+import org.apache.wicket.request.IRequestHandler;
+import org.apache.wicket.request.Request;
 import org.apache.wicket.request.cycle.RequestCycle;
 import org.apache.wicket.request.cycle.RequestCycleContext;
+import org.apache.wicket.request.http.WebRequest;
+import org.apache.wicket.request.http.flow.AbortWithHttpErrorCodeException;
+import org.apache.wicket.util.lang.Exceptions;
 
 /**
  * Handles the PageExpiredException so that the SourcesPage can recover from a session expired.
@@ -38,63 +45,43 @@ public class WicketExampleRequestCycle e
 	{
 		super(context);
 	}
-// /**
-// * Construct.
-// *
-// * @param application
-// * @param request
-// * @param response
-// */
-// public WicketExampleRequestCycle(WebApplication application, WebRequest request,
-// Response response)
-// {
-// super(application, request, response);
-// }
-//
-// /**
-// * @see org.apache.wicket.RequestCycle#onRuntimeException(org.apache.wicket.Page,
-// * java.lang.RuntimeException)
-// */
-// @Override
-// public Page onRuntimeException(final Page page, final RuntimeException e)
-// {
-// final Throwable cause;
-// if (e.getCause() != null)
-// {
-// cause = e.getCause();
-// }
-// else
-// {
-// cause = e;
-// }
-//
-// if (cause instanceof PageExpiredException)
-// {
-// handlePageExpiredException((PageExpiredException)cause);
-// }
-// return super.onRuntimeException(page, e);
-// }
-//
-// /**
-// * Checks to see if the request was ajax based. If so we send a 404 so that the
-// * org.apache.wicket.ajax.IAjaxCallDecorator failure script is executed.
-// *
-// * @param e
-// */
-// private void handlePageExpiredException(final PageExpiredException e)
-// {
-// Response response = getOriginalResponse();
-// if (response instanceof BufferedWebResponse)
-// {
-// BufferedWebResponse bufferedWebResponse = (BufferedWebResponse)response;
-// Request request = getRequest();
-// if (bufferedWebResponse.isAjax() &&
-// request.getParameter(SourcesPage.PAGE_CLASS) != null)
-// {
-// // If there is a better way to figure out if SourcesPage was the request, we should
-// // do that.
-// throw new AbortWithWebErrorCodeException(404);
-// }
-// }
-// }
+
+	/**
+	 * @see org.apache.wicket.RequestCycle#onRuntimeException(org.apache.wicket.Page,
+	 *      java.lang.RuntimeException)
+	 */
+	@Override
+	public IRequestHandler handleException(final Exception e)
+	{
+		PageExpiredException pageExpiredException = Exceptions.findCause(e,
+			PageExpiredException.class);
+		if (pageExpiredException != null)
+		{
+			handlePageExpiredException(pageExpiredException);
+		}
+		return super.handleException(e);
+	}
+
+	/**
+	 * Checks to see if the request was ajax based. If so we send a 404 so that the
+	 * org.apache.wicket.ajax.IAjaxCallDecorator failure script is executed.
+	 * 
+	 * @param e
+	 */
+	private void handlePageExpiredException(final PageExpiredException e)
+	{
+		Request request = getRequest();
+		if (request instanceof WebRequest)
+		{
+			WebRequest webRequest = (WebRequest)request;
+
+			if (webRequest.isAjax() &&
+				!request.getRequestParameters().getParameterValue(SourcesPage.PAGE_CLASS).isNull())
+			{
+				// If there is a better way to figure out if SourcesPage was the request, we should
+				// do that.
+				throw new AbortWithHttpErrorCodeException(404, "");
+			}
+		}
+	}
 }