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.flow;
018
019import javax.servlet.http.HttpServletResponse;
020
021import org.apache.wicket.request.RequestHandlerExecutor.ReplaceHandlerException;
022import org.apache.wicket.request.http.handler.RedirectRequestHandler;
023
024/**
025 * Causes Wicket to interrupt current request processing and send a redirect to the given url.
026 * 
027 * Use this if you want to redirect to an external or none Wicket url. If you want to redirect to a
028 * page use the <em>org.apache.wicket.RestartResponseException</em>
029 *
030 * Also see org.apache.wicket.RestartResponseAtInterceptPageException
031 */
032public class RedirectToUrlException extends ReplaceHandlerException
033{
034        private static final long serialVersionUID = 1L;
035
036        /**
037         * Construct.
038         * 
039         * @param redirectUrl
040         *            URL to redirect to.
041         */
042        public RedirectToUrlException(final String redirectUrl)
043        {
044                this(redirectUrl, HttpServletResponse.SC_MOVED_TEMPORARILY);
045        }
046
047        /**
048         * Construct.
049         * 
050         * @param redirectUrl
051         *            URL to redirect to.
052         * @param statusCode
053         *            301 (Moved permanently) or 302 (Moved temporarily)
054         */
055        public RedirectToUrlException(final String redirectUrl, final int statusCode)
056        {
057                super(new RedirectRequestHandler(redirectUrl, statusCode), true);
058        }
059
060        /**
061         * Construct.
062         *
063         * @param redirectUrl
064         *            URL to redirect to.
065         * @param statusCode
066         *            301 (Moved permanently) or 302 (Moved temporarily)
067         * @param mode
068         *            The way to made the redirect - via sendRedirect() or directly via setStatus()+setHeader("Location", ...)
069         */
070        public RedirectToUrlException(final String redirectUrl, final int statusCode, RedirectRequestHandler.Mode mode)
071        {
072                super(new RedirectRequestHandler(redirectUrl, statusCode).mode(mode), true);
073        }
074}