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.Gone.*; 020 021import java.text.*; 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.*; 030 031/** 032 * Exception representing an HTTP 410 (). 033 * 034 * <p> 035 * Indicates that the resource requested is no longer available and will not be available again. 036 * <br>This should be used when a resource has been intentionally removed and the resource should be purged. 037 * <br>Upon receiving a 410 status code, the client should not request the resource in the future. 038 * <br>Clients such as search engines should remove the resource from their indices. 039 * <br>Most use cases do not require clients and search engines to purge the resource, and a <js>"404 Not Found"</js> may be used instead. 040 * 041 * <h5 class='section'>See Also:</h5><ul> 042 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/JuneauRestCommonBasics">juneau-rest-common Basics</a> 043 * </ul> 044 * 045 * @serial exclude 046 */ 047@Response 048@StatusCode(STATUS_CODE) 049@Schema(description = REASON_PHRASE) 050public class Gone extends BasicHttpException { 051 private static final long serialVersionUID = 1L; 052 053 /** HTTP status code */ 054 public static final int STATUS_CODE = 410; 055 056 /** Reason phrase */ 057 public static final String REASON_PHRASE = "Gone"; 058 059 /** Default status line */ 060 private static final BasicStatusLine STATUS_LINE = BasicStatusLine.create(STATUS_CODE, REASON_PHRASE); 061 062 /** Reusable unmodifiable instance */ 063 public static final Gone INSTANCE = new Gone().setUnmodifiable(); 064 065 /** 066 * Constructor. 067 */ 068 public Gone() { 069 this((Throwable)null, REASON_PHRASE); 070 } 071 072 /** 073 * Constructor. 074 * 075 * <p> 076 * This is the constructor used when parsing an HTTP response. 077 * 078 * @param response The HTTP response to copy from. Must not be <jk>null</jk>. 079 * @throws AssertionError If HTTP response status code does not match what was expected. 080 */ 081 public Gone(HttpResponse response) { 082 super(response); 083 assertStatusCode(response); 084 } 085 086 /** 087 * Constructor. 088 * 089 * @param msg The message. Can be <jk>null</jk>. 090 * @param args Optional {@link MessageFormat}-style arguments in the message. 091 */ 092 public Gone(String msg, Object...args) { 093 this((Throwable)null, msg, args); 094 } 095 096 /** 097 * Constructor. 098 * 099 * @param cause The cause. Can be <jk>null</jk>. 100 */ 101 public Gone(Throwable cause) { 102 this(cause, cause == null ? REASON_PHRASE : cause.getMessage()); 103 } 104 105 /** 106 * Constructor. 107 * 108 * @param cause The caused-by exception. Can be <jk>null</jk>. 109 * @param msg The message. Can be <jk>null</jk>. 110 * @param args The message arguments. 111 */ 112 public Gone(Throwable cause, String msg, Object...args) { 113 super(STATUS_CODE, cause, msg, args); 114 setStatusLine(STATUS_LINE.copy()); 115 } 116 117 /** 118 * Copy constructor. 119 * 120 * @param copyFrom The bean to copy. 121 */ 122 protected Gone(Gone copyFrom) { 123 super(copyFrom); 124 } 125 126 /** 127 * Creates a modifiable copy of this bean. 128 * 129 * @return A new modifiable bean. 130 */ 131 public Gone copy() { 132 return new Gone(this); 133 } 134 135 @Override /* Overridden from BasicHttpException */ 136 public Gone setContent(HttpEntity value) { 137 super.setContent(value); 138 return this; 139 } 140 141 @Override /* Overridden from BasicHttpException */ 142 public Gone setContent(String value) { 143 super.setContent(value); 144 return this; 145 } 146 147 @Override /* Overridden from BasicHttpException */ 148 public Gone setHeader2(String name, Object value) { 149 super.setHeader2(name, value); 150 return this; 151 } 152 153 @Override /* Overridden from BasicHttpException */ 154 public Gone setHeaders(HeaderList value) { 155 super.setHeaders(value); 156 return this; 157 } 158 159 @Override /* Overridden from BasicHttpException */ 160 public Gone setHeaders(List<Header> values) { 161 super.setHeaders(values); 162 return this; 163 } 164 165 @Override /* Overridden from BasicHttpException */ 166 public Gone setHeaders2(Header...values) { 167 super.setHeaders2(values); 168 return this; 169 } 170 171 @Override /* Overridden from BasicHttpException */ 172 public Gone setLocale2(Locale value) { 173 super.setLocale2(value); 174 return this; 175 } 176 177 @Override /* Overridden from BasicRuntimeException */ 178 public Gone setMessage(String message, Object...args) { 179 super.setMessage(message, args); 180 return this; 181 } 182 183 @Override /* Overridden from BasicHttpException */ 184 public Gone setProtocolVersion(ProtocolVersion value) { 185 super.setProtocolVersion(value); 186 return this; 187 } 188 189 @Override /* Overridden from BasicHttpException */ 190 public Gone setReasonPhrase2(String value) { 191 super.setReasonPhrase2(value); 192 return this; 193 } 194 195 @Override /* Overridden from BasicHttpException */ 196 public Gone setReasonPhraseCatalog(ReasonPhraseCatalog value) { 197 super.setReasonPhraseCatalog(value); 198 return this; 199 } 200 201 @Override /* Overridden from BasicHttpException */ 202 public Gone setStatusCode2(int code) throws IllegalStateException { 203 super.setStatusCode2(code); 204 return this; 205 } 206 207 @Override /* Overridden from BasicHttpException */ 208 public Gone setStatusLine(BasicStatusLine value) { 209 super.setStatusLine(value); 210 return this; 211 } 212 213 @Override /* Overridden from BasicRuntimeException */ 214 public Gone setUnmodifiable() { 215 super.setUnmodifiable(); 216 return this; 217 } 218}