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 <code>HTTP 302 Found</code> 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 using custom message. 056 * @param message Message to send as the response. 057 * @param location <code>Location</code> header value. 058 */ 059 public Found(String message, URI location) { 060 super(message); 061 this.location = location; 062 } 063 064 /** 065 * Constructor. 066 * @param location <code>Location</code> header value. 067 */ 068 public Found(URI location) { 069 this(MESSAGE, location); 070 } 071 072 /** 073 * @return <code>Location</code> header value. 074 */ 075 @ResponseHeader(name="Location", description="Location of resource.") 076 public URI getLocation() { 077 return location; 078 } 079}