001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.wicket.request.http.flow; 018 019import javax.servlet.http.HttpServletResponse; 020 021import org.apache.wicket.request.flow.ResetResponseException; 022import org.apache.wicket.request.http.handler.ErrorCodeRequestHandler; 023 024/** 025 * Causes Wicket to abort processing and set the specified HTTP error code, with the provided 026 * message if specified. 027 * 028 * @author igor.vaynberg 029 * 030 */ 031public final class AbortWithHttpErrorCodeException extends ResetResponseException 032{ 033 private static final long serialVersionUID = 1L; 034 035 private final int errorCode; 036 private final String message; 037 038 /** 039 * Constructor 040 * 041 * @param errorCode 042 * the servlet error code; use one of the 043 * {@link javax.servlet.http.HttpServletResponse} constants 044 * @param message 045 * the optional message to send to the client 046 * @see javax.servlet.http.HttpServletResponse 047 */ 048 public AbortWithHttpErrorCodeException(final int errorCode, final String message) 049 { 050 super(new ErrorCodeRequestHandler(errorCode, message)); 051 this.errorCode = errorCode; 052 this.message = message; 053 } 054 055 /** 056 * Constructor 057 * 058 * @param errorCode 059 * the servlet error code; use one of the 060 * {@link javax.servlet.http.HttpServletResponse} constants 061 * @see javax.servlet.http.HttpServletResponse 062 */ 063 public AbortWithHttpErrorCodeException(final int errorCode) 064 { 065 this(errorCode, null); 066 } 067 068 069 /** 070 * Gets the error code. 071 * 072 * @return errorCode 073 * @see HttpServletResponse 074 */ 075 public int getErrorCode() 076 { 077 return errorCode; 078 } 079 080 /** 081 * Gets the error message 082 * 083 * @return error message 084 */ 085 086 @Override 087 public String getMessage() 088 { 089 return message; 090 } 091 092 093}