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.*;
030import org.apache.juneau.internal.*;
031
032/**
033 * Exception representing an HTTP 410 ().
034 *
035 * <p>
036 * Indicates that the resource requested is no longer available and will not be available again.
037 * <br>This should be used when a resource has been intentionally removed and the resource should be purged.
038 * <br>Upon receiving a 410 status code, the client should not request the resource in the future.
039 * <br>Clients such as search engines should remove the resource from their indices.
040 * <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.
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 * @serial exclude
047 */
048@Response
049@StatusCode(STATUS_CODE)
050@Schema(description=REASON_PHRASE)
051public class Gone extends BasicHttpException {
052   private static final long serialVersionUID = 1L;
053
054   /** HTTP status code */
055   public static final int STATUS_CODE = 410;
056
057   /** Reason phrase */
058   public static final String REASON_PHRASE = "Gone";
059
060   /** Default status line */
061   private static final BasicStatusLine STATUS_LINE = BasicStatusLine.create(STATUS_CODE, REASON_PHRASE);
062
063   /** Reusable unmodifiable instance */
064   public static final Gone INSTANCE = new Gone().setUnmodifiable();
065
066   /**
067    * Constructor.
068    *
069    * @param cause The caused-by exception.  Can be <jk>null</jk>.
070    * @param msg The message.  Can be <jk>null</jk>.
071    * @param args The message arguments.
072    */
073   public Gone(Throwable cause, String msg, Object...args) {
074      super(STATUS_CODE, cause, msg, args);
075      setStatusLine(STATUS_LINE.copy());
076   }
077
078   /**
079    * Constructor.
080    */
081   public Gone() {
082      this((Throwable)null, REASON_PHRASE);
083   }
084
085   /**
086    * Constructor.
087    *
088    * @param msg The message.  Can be <jk>null</jk>.
089    * @param args Optional {@link MessageFormat}-style arguments in the message.
090    */
091   public Gone(String msg, Object...args) {
092      this((Throwable)null, msg, args);
093   }
094
095   /**
096    * Constructor.
097    *
098    * @param cause The cause.  Can be <jk>null</jk>.
099    */
100   public Gone(Throwable cause) {
101      this(cause, cause == null ? REASON_PHRASE : cause.getMessage());
102   }
103
104   /**
105    * Constructor.
106    *
107    * <p>
108    * This is the constructor used when parsing an HTTP response.
109    *
110    * @param response The HTTP response to copy from.  Must not be <jk>null</jk>.
111    * @throws AssertionError If HTTP response status code does not match what was expected.
112    */
113   public Gone(HttpResponse response) {
114      super(response);
115      assertStatusCode(response);
116   }
117
118   /**
119    * Copy constructor.
120    *
121    * @param copyFrom The bean to copy.
122    */
123   protected Gone(Gone copyFrom) {
124      super(copyFrom);
125   }
126
127   /**
128    * Creates a modifiable copy of this bean.
129    *
130    * @return A new modifiable bean.
131    */
132   public Gone copy() {
133      return new Gone(this);
134   }
135   @Override /* Overridden from BasicRuntimeException */
136   public Gone setMessage(String message, Object...args) {
137      super.setMessage(message, args);
138      return this;
139   }
140
141   @Override /* Overridden from BasicRuntimeException */
142   public Gone setUnmodifiable() {
143      super.setUnmodifiable();
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 setHeaders2(Header...values) {
161      super.setHeaders2(values);
162      return this;
163   }
164
165   @Override /* Overridden from BasicHttpException */
166   public Gone setLocale2(Locale value) {
167      super.setLocale2(value);
168      return this;
169   }
170
171   @Override /* Overridden from BasicHttpException */
172   public Gone setProtocolVersion(ProtocolVersion value) {
173      super.setProtocolVersion(value);
174      return this;
175   }
176
177   @Override /* Overridden from BasicHttpException */
178   public Gone setReasonPhrase2(String value) {
179      super.setReasonPhrase2(value);
180      return this;
181   }
182
183   @Override /* Overridden from BasicHttpException */
184   public Gone setReasonPhraseCatalog(ReasonPhraseCatalog value) {
185      super.setReasonPhraseCatalog(value);
186      return this;
187   }
188
189   @Override /* Overridden from BasicHttpException */
190   public Gone setStatusCode2(int code) throws IllegalStateException{
191      super.setStatusCode2(code);
192      return this;
193   }
194
195   @Override /* Overridden from BasicHttpException */
196   public Gone setStatusLine(BasicStatusLine value) {
197      super.setStatusLine(value);
198      return this;
199   }
200}