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.http.response;
014
015import static org.apache.juneau.http.response.Forbidden.*;
016
017import java.text.*;
018import java.util.*;
019
020import org.apache.http.*;
021import org.apache.http.Header;
022import org.apache.juneau.annotation.*;
023import org.apache.juneau.http.*;
024import org.apache.juneau.http.annotation.*;
025import org.apache.juneau.http.header.*;
026import org.apache.juneau.internal.*;
027
028/**
029 * Exception representing an HTTP 403 (Forbidden).
030 *
031 * <p>
032 * The request was valid, but the server is refusing action.
033 * <br>The user might not have the necessary permissions for a resource, or may need an account of some sort.
034 *
035 * <h5 class='section'>See Also:</h5><ul>
036 *    <li class='link'><a class="doclink" href="../../../../../index.html#juneau-rest-common">juneau-rest-common</a>
037 * </ul>
038 *
039 * @serial exclude
040 */
041@Response
042@StatusCode(STATUS_CODE)
043@Schema(description=REASON_PHRASE)
044@FluentSetters
045public class Forbidden extends BasicHttpException {
046   private static final long serialVersionUID = 1L;
047
048   /** HTTP status code */
049   public static final int STATUS_CODE = 403;
050
051   /** Reason phrase */
052   public static final String REASON_PHRASE = "Forbidden";
053
054   /** Default status line */
055   private static final BasicStatusLine STATUS_LINE = BasicStatusLine.create(STATUS_CODE, REASON_PHRASE);
056
057   /** Reusable unmodifiable instance */
058   public static final Forbidden INSTANCE = new Forbidden().setUnmodifiable();
059
060   /**
061    * Constructor.
062    *
063    * @param cause The caused-by exception.  Can be <jk>null</jk>.
064    * @param msg The message.  Can be <jk>null</jk>.
065    * @param args The message arguments.
066    */
067   public Forbidden(Throwable cause, String msg, Object...args) {
068      super(STATUS_CODE, cause, msg, args);
069      setStatusLine(STATUS_LINE.copy());
070   }
071
072   /**
073    * Constructor.
074    */
075   public Forbidden() {
076      this((Throwable)null, REASON_PHRASE);
077   }
078
079   /**
080    * Constructor.
081    *
082    * @param msg The message.  Can be <jk>null</jk>.
083    * @param args Optional {@link MessageFormat}-style arguments in the message.
084    */
085   public Forbidden(String msg, Object...args) {
086      this((Throwable)null, msg, args);
087   }
088
089   /**
090    * Constructor.
091    *
092    * @param cause The cause.  Can be <jk>null</jk>.
093    */
094   public Forbidden(Throwable cause) {
095      this(cause, cause == null ? REASON_PHRASE : cause.getMessage());
096   }
097
098   /**
099    * Constructor.
100    *
101    * <p>
102    * This is the constructor used when parsing an HTTP response.
103    *
104    * @param response The HTTP response to copy from.  Must not be <jk>null</jk>.
105    * @throws AssertionError If HTTP response status code does not match what was expected.
106    */
107   public Forbidden(HttpResponse response) {
108      super(response);
109      assertStatusCode(response);
110   }
111
112   /**
113    * Copy constructor.
114    *
115    * @param copyFrom The bean to copy.
116    */
117   protected Forbidden(Forbidden copyFrom) {
118      super(copyFrom);
119   }
120
121   /**
122    * Creates a modifiable copy of this bean.
123    *
124    * @return A new modifiable bean.
125    */
126   public Forbidden copy() {
127      return new Forbidden(this);
128   }
129
130   // <FluentSetters>
131
132   @Override /* GENERATED - org.apache.juneau.BasicRuntimeException */
133   public Forbidden setMessage(String message, Object...args) {
134      super.setMessage(message, args);
135      return this;
136   }
137
138   @Override /* GENERATED - org.apache.juneau.BasicRuntimeException */
139   public Forbidden setUnmodifiable() {
140      super.setUnmodifiable();
141      return this;
142   }
143
144   @Override /* GENERATED - org.apache.juneau.http.response.BasicHttpException */
145   public Forbidden setHeader2(String name, Object value) {
146      super.setHeader2(name, value);
147      return this;
148   }
149
150   @Override /* GENERATED - org.apache.juneau.http.response.BasicHttpException */
151   public Forbidden setHeaders(HeaderList value) {
152      super.setHeaders(value);
153      return this;
154   }
155
156   @Override /* GENERATED - org.apache.juneau.http.response.BasicHttpException */
157   public Forbidden setHeaders2(Header...values) {
158      super.setHeaders2(values);
159      return this;
160   }
161
162   @Override /* GENERATED - org.apache.juneau.http.response.BasicHttpException */
163   public Forbidden setLocale2(Locale value) {
164      super.setLocale2(value);
165      return this;
166   }
167
168   @Override /* GENERATED - org.apache.juneau.http.response.BasicHttpException */
169   public Forbidden setProtocolVersion(ProtocolVersion value) {
170      super.setProtocolVersion(value);
171      return this;
172   }
173
174   @Override /* GENERATED - org.apache.juneau.http.response.BasicHttpException */
175   public Forbidden setReasonPhrase2(String value) {
176      super.setReasonPhrase2(value);
177      return this;
178   }
179
180   @Override /* GENERATED - org.apache.juneau.http.response.BasicHttpException */
181   public Forbidden setReasonPhraseCatalog(ReasonPhraseCatalog value) {
182      super.setReasonPhraseCatalog(value);
183      return this;
184   }
185
186   @Override /* GENERATED - org.apache.juneau.http.response.BasicHttpException */
187   public Forbidden setStatusCode2(int code) throws IllegalStateException{
188      super.setStatusCode2(code);
189      return this;
190   }
191
192   @Override /* GENERATED - org.apache.juneau.http.response.BasicHttpException */
193   public Forbidden setStatusLine(BasicStatusLine value) {
194      super.setStatusLine(value);
195      return this;
196   }
197
198   // </FluentSetters>
199}