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