001// ***************************************************************************************************************************
002// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.  See the NOTICE file *
003// * distributed with this work for additional information regarding copyright ownership.  The ASF licenses this file        *
004// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance            *
005// * with the License.  You may obtain a copy of the License at                                                              *
006// *                                                                                                                         *
007// *  http://www.apache.org/licenses/LICENSE-2.0                                                                             *
008// *                                                                                                                         *
009// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an  *
010// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the License for the        *
011// * specific language governing permissions and limitations under the License.                                              *
012// ***************************************************************************************************************************
013package org.apache.juneau.http.response;
014
015import static org.apache.juneau.http.response.TemporaryRedirect.*;
016
017import java.net.*;
018
019import org.apache.juneau.annotation.BeanIgnore;
020import org.apache.juneau.http.annotation.*;
021
022/**
023 * Represents an <c>HTTP 307 Temporary Redirect</c> response.
024 *
025 * <p>
026 * In this case, the request should be repeated with another URI; however, future requests should still use the original URI.
027 * In contrast to how 302 was historically implemented, the request method is not allowed to be changed when reissuing the original request.
028 * For example, a POST request should be repeated using another POST request.
029 */
030@Response(code=CODE, description=MESSAGE)
031@BeanIgnore
032public class TemporaryRedirect extends HttpResponse {
033
034   /** HTTP status code */
035   public static final int CODE = 307;
036
037   /** Default message */
038   public static final String MESSAGE = "Temporary Redirect";
039
040   /** Reusable instance. */
041   public static final TemporaryRedirect INSTANCE = new TemporaryRedirect();
042
043   private final URI location;
044
045   /**
046    * Constructor using HTTP-standard message.
047    */
048   public TemporaryRedirect() {
049      this(MESSAGE, null);
050   }
051
052   /**
053    * Constructor with no redirect.
054    * <p>
055    * Used for end-to-end interfaces.
056    *
057    * @param message Message to send as the response.
058    */
059   public TemporaryRedirect(String message) {
060      super(message);
061      this.location = null;
062   }
063
064   /**
065    * Constructor using custom message.
066    * @param message Message to send as the response.
067    * @param location <c>Location</c> header value.
068    */
069   public TemporaryRedirect(String message, URI location) {
070      super(message);
071      this.location = location;
072   }
073
074   /**
075    * Constructor.
076    * @param location <c>Location</c> header value.
077    */
078   public TemporaryRedirect(URI location) {
079      this(MESSAGE, location);
080   }
081
082   /**
083    * @return <c>Location</c> header value.
084    */
085   @ResponseHeader(name="Location", description="Temporary location of resource.")
086   public URI getLocation() {
087      return location;
088   }
089}