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.juneau.http.response; 018 019import static org.apache.juneau.http.response.Found.*; 020 021import java.net.*; 022import java.util.*; 023 024import org.apache.http.*; 025import org.apache.http.Header; 026import org.apache.juneau.annotation.*; 027import org.apache.juneau.http.*; 028import org.apache.juneau.http.annotation.*; 029import org.apache.juneau.http.header.*; 030import org.apache.juneau.internal.*; 031 032/** 033 * Represents an <c>HTTP 302 Found</c> response. 034 * 035 * <p> 036 * Tells the client to look at (browse to) another url. 302 has been superseded by 303 and 307. 037 * This is an example of industry practice contradicting the standard. 038 * 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. 039 * Therefore, HTTP/1.1 added status codes 303 and 307 to distinguish between the two behaviours. 040 * However, some Web applications and frameworks use the 302 status code as if it were the 303. 041 * 042 * <h5 class='section'>See Also:</h5><ul> 043 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/JuneauRestCommonBasics">juneau-rest-common Basics</a> 044 * </ul> 045 */ 046@Response 047@StatusCode(STATUS_CODE) 048@Schema(description=REASON_PHRASE) 049public class Found extends BasicHttpResponse { 050 051 /** HTTP status code */ 052 public static final int STATUS_CODE = 302; 053 054 /** Default message */ 055 public static final String REASON_PHRASE = "Found"; 056 057 /** Default status line */ 058 private static final BasicStatusLine STATUS_LINE = BasicStatusLine.create(STATUS_CODE, REASON_PHRASE); 059 060 /** Default unmodifiable instance */ 061 public static final Found INSTANCE = new Found().setUnmodifiable(); 062 063 /** 064 * Constructor. 065 */ 066 public Found() { 067 super(STATUS_LINE); 068 } 069 070 /** 071 * Copy constructor. 072 * 073 * @param copyFrom The bean to copy from. 074 */ 075 public Found(Found copyFrom) { 076 super(copyFrom); 077 } 078 079 /** 080 * Constructor. 081 * 082 * <p> 083 * This is the constructor used when parsing an HTTP response. 084 * 085 * @param response The HTTP response to copy from. Must not be <jk>null</jk>. 086 * @throws AssertionError If HTTP response status code does not match what was expected. 087 */ 088 public Found(HttpResponse response) { 089 super(response); 090 assertStatusCode(response); 091 } 092 093 /** 094 * Creates a builder for this class initialized with the contents of this bean. 095 * 096 * @return A new builder bean. 097 */ 098 public Found copy() { 099 return new Found(this); 100 } 101 @Override /* Overridden from BasicHttpResponse */ 102 public Found setContent(String value) { 103 super.setContent(value); 104 return this; 105 } 106 107 @Override /* Overridden from BasicHttpResponse */ 108 public Found setContent(HttpEntity value) { 109 super.setContent(value); 110 return this; 111 } 112 113 @Override /* Overridden from BasicHttpResponse */ 114 public Found setHeader2(Header value) { 115 super.setHeader2(value); 116 return this; 117 } 118 119 @Override /* Overridden from BasicHttpResponse */ 120 public Found setHeader2(String name, String value) { 121 super.setHeader2(name, value); 122 return this; 123 } 124 125 @Override /* Overridden from BasicHttpResponse */ 126 public Found setHeaders(List<Header> values) { 127 super.setHeaders(values); 128 return this; 129 } 130 131 @Override /* Overridden from BasicHttpResponse */ 132 public Found setHeaders(HeaderList value) { 133 super.setHeaders(value); 134 return this; 135 } 136 137 @Override /* Overridden from BasicHttpResponse */ 138 public Found setHeaders2(Header...values) { 139 super.setHeaders2(values); 140 return this; 141 } 142 143 @Override /* Overridden from BasicHttpResponse */ 144 public Found setLocale2(Locale value) { 145 super.setLocale2(value); 146 return this; 147 } 148 149 @Override /* Overridden from BasicHttpResponse */ 150 public Found setLocation(String value) { 151 super.setLocation(value); 152 return this; 153 } 154 155 @Override /* Overridden from BasicHttpResponse */ 156 public Found setLocation(URI value) { 157 super.setLocation(value); 158 return this; 159 } 160 161 @Override /* Overridden from BasicHttpResponse */ 162 public Found setProtocolVersion(ProtocolVersion value) { 163 super.setProtocolVersion(value); 164 return this; 165 } 166 167 @Override /* Overridden from BasicHttpResponse */ 168 public Found setReasonPhrase2(String value) { 169 super.setReasonPhrase2(value); 170 return this; 171 } 172 173 @Override /* Overridden from BasicHttpResponse */ 174 public Found setReasonPhraseCatalog(ReasonPhraseCatalog value) { 175 super.setReasonPhraseCatalog(value); 176 return this; 177 } 178 179 @Override /* Overridden from BasicHttpResponse */ 180 public Found setStatusCode2(int value) { 181 super.setStatusCode2(value); 182 return this; 183 } 184 185 @Override /* Overridden from BasicHttpResponse */ 186 public Found setStatusLine(BasicStatusLine value) { 187 super.setStatusLine(value); 188 return this; 189 } 190 191 @Override /* Overridden from BasicHttpResponse */ 192 public Found setUnmodifiable() { 193 super.setUnmodifiable(); 194 return this; 195 } 196}