You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by eh...@apache.org on 2006/10/12 14:04:20 UTC

svn commit: r463220 - in /incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket: AbortWithHttpStatusException.java protocol/http/servlet/AbortWithHttpStatusException.java

Author: ehillenius
Date: Thu Oct 12 05:04:20 2006
New Revision: 463220

URL: http://svn.apache.org/viewvc?view=rev&rev=463220
Log:
Deprecated for 2.0 and moved copy to correct package (who thought of putting this in the wicket. core package anyway)

Added:
    incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/protocol/http/servlet/AbortWithHttpStatusException.java
Modified:
    incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/AbortWithHttpStatusException.java

Modified: incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/AbortWithHttpStatusException.java
URL: http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/AbortWithHttpStatusException.java?view=diff&rev=463220&r1=463219&r2=463220
==============================================================================
--- incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/AbortWithHttpStatusException.java (original)
+++ incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/AbortWithHttpStatusException.java Thu Oct 12 05:04:20 2006
@@ -32,6 +32,7 @@
  * @author Igor Vaynberg (ivaynberg)
  * @author Gili Tzabari
  * @see HttpServletResponse
+ * @deprecated moves to package wicket.protocol.http.servlet in 2.0
  */
 public class AbortWithHttpStatusException extends AbortException
 {

Added: incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/protocol/http/servlet/AbortWithHttpStatusException.java
URL: http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/protocol/http/servlet/AbortWithHttpStatusException.java?view=auto&rev=463220
==============================================================================
--- incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/protocol/http/servlet/AbortWithHttpStatusException.java (added)
+++ incubator/wicket/branches/wicket-1.x/wicket/src/main/java/wicket/protocol/http/servlet/AbortWithHttpStatusException.java Thu Oct 12 05:04:20 2006
@@ -0,0 +1,90 @@
+/*
+ * $Id: RestartResponseAtInterceptPageException.java,v 1.10 2006/02/13 00:16:32
+ * jonathanlocke Exp $ $Revision: 1.15 $ $Date: 2006/02/13 09:27:16 $
+ * 
+ * ==============================================================================
+ * 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.
+ */
+package wicket.protocol.http.servlet;
+
+import javax.servlet.http.HttpServletResponse;
+
+import wicket.AbortException;
+import wicket.RequestCycle;
+import wicket.Response;
+import wicket.protocol.http.WebResponse;
+import wicket.request.target.basic.EmptyRequestTarget;
+
+/**
+ * Causes Wicket to abort processing and set the specified HTTP status code. An
+ * {@link IllegalStateException} will be thrown if HTTP status code could not be
+ * set and the optional parameter is specified as false.
+ * 
+ * This exception can be thrown from a page or a resource.
+ * 
+ * @author Igor Vaynberg (ivaynberg)
+ * @author Gili Tzabari
+ * @see HttpServletResponse
+ */
+public class AbortWithHttpStatusException extends AbortException
+{
+	private static final long serialVersionUID = 1L;
+	private final int status;
+
+	/**
+	 * Constructor
+	 * 
+	 * @param status
+	 *            The http response status code
+	 * @param statusCodeOptional
+	 *            If true and http status could not be set, an
+	 *            IllegalStateException will be thrown
+	 */
+	public AbortWithHttpStatusException(int status, boolean statusCodeOptional)
+	{
+		this.status = status;
+
+		RequestCycle rc = RequestCycle.get();
+		if (rc == null)
+		{
+			if (!statusCodeOptional)
+			{
+				throw new IllegalStateException(
+						"This exception can only be thrown from within request processing cycle");
+			}
+		}
+		else
+		{
+			Response r = rc.getResponse();
+			if (!(r instanceof WebResponse))
+			{
+				throw new IllegalStateException(
+						"This exception can only be thrown when wicket is processing an http request");
+			}
+
+			WebResponse wr = (WebResponse)r;
+			wr.getHttpServletResponse().setStatus(status);
+
+			// abort any further response processing
+			rc.setRequestTarget(EmptyRequestTarget.getInstance());
+		}
+	}
+
+	/**
+	 * @return the response status code
+	 */
+	public final int getStatus()
+	{
+		return status;
+	}
+}