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 java.net.*;
016
017import static org.apache.juneau.http.response.Found.*;
018
019import org.apache.juneau.annotation.BeanIgnore;
020import org.apache.juneau.http.annotation.*;
021
022/**
023 * Represents an <c>HTTP 302 Found</c> response.
024 *
025 * <p>
026 * Tells the client to look at (browse to) another url. 302 has been superseded by 303 and 307.
027 * This is an example of industry practice contradicting the standard.
028 * The HTTP/1.0 specification (RFC 1945) required the client to perform a temporary redirect (the original describing phrase was "Moved Temporarily"), but popular browsers implemented 302 with the functionality of a 303 See Other.
029 * Therefore, HTTP/1.1 added status codes 303 and 307 to distinguish between the two behaviours.
030 * However, some Web applications and frameworks use the 302 status code as if it were the 303.
031 */
032@Response(code=CODE, description=MESSAGE)
033@BeanIgnore
034public class Found extends HttpResponse {
035
036   /** HTTP status code */
037   public static final int CODE = 302;
038
039   /** Default message */
040   public static final String MESSAGE = "Found";
041
042   /** Reusable instance. */
043   public static final Found INSTANCE = new Found();
044
045   private final URI location;
046
047   /**
048    * Constructor using HTTP-standard message.
049    */
050   public Found() {
051      this(MESSAGE, null);
052   }
053
054   /**
055    * Constructor with no redirect.
056    * <p>
057    * Used for end-to-end interfaces.
058    *
059    * @param message Message to send as the response.
060    */
061   public Found(String message) {
062      super(message);
063      this.location = null;
064   }
065
066   /**
067    * Constructor using custom message.
068    * @param message Message to send as the response.
069    * @param location <c>Location</c> header value.
070    */
071   public Found(String message, URI location) {
072      super(message);
073      this.location = location;
074   }
075
076   /**
077    * Constructor.
078    * @param location <c>Location</c> header value.
079    */
080   public Found(URI location) {
081      this(MESSAGE, location);
082   }
083
084   /**
085    * @return <c>Location</c> header value.
086    */
087   @ResponseHeader(name="Location", description="Location of resource.")
088   public URI getLocation() {
089      return location;
090   }
091}