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