View Javadoc
1   /**
2    * Copyright 2014 Internet2
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *   http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  /*
17   * $Header: /home/hagleyj/i2mi/grouper-misc/grouperClient/src/ext/edu/internet2/middleware/grouperClientExt/org/apache/commons/httpclient/HttpStatus.java,v 1.1 2008-11-30 10:57:19 mchyzer Exp $
18   * $Revision: 1.1 $
19   * $Date: 2008-11-30 10:57:19 $
20   *
21   * ====================================================================
22   *
23   *  Licensed to the Apache Software Foundation (ASF) under one or more
24   *  contributor license agreements.  See the NOTICE file distributed with
25   *  this work for additional information regarding copyright ownership.
26   *  The ASF licenses this file to You under the Apache License, Version 2.0
27   *  (the "License"); you may not use this file except in compliance with
28   *  the License.  You may obtain a copy of the License at
29   *
30   *      http://www.apache.org/licenses/LICENSE-2.0
31   *
32   *  Unless required by applicable law or agreed to in writing, software
33   *  distributed under the License is distributed on an "AS IS" BASIS,
34   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
35   *  See the License for the specific language governing permissions and
36   *  limitations under the License.
37   * ====================================================================
38   *
39   * This software consists of voluntary contributions made by many
40   * individuals on behalf of the Apache Software Foundation.  For more
41   * information on the Apache Software Foundation, please see
42   * <http://www.apache.org/>.
43   *
44   */
45  
46  package edu.internet2.middleware.grouperClientExt.org.apache.commons.httpclient;
47  
48  /**
49   * Constants enumerating the HTTP status codes.
50   * All status codes defined in RFC1945 (HTTP/1.0, RFC2616 (HTTP/1.1), and
51   * RFC2518 (WebDAV) are supported.
52   * 
53   * @see StatusLine
54   * @author Unascribed
55   * @author <a href="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a>
56   * @author <a href="mailto:jsdever@apache.org">Jeff Dever</a>
57   * 
58   * TODO: Internationalization of reason phrases 
59   * 
60   * @version $Id: HttpStatus.java,v 1.1 2008-11-30 10:57:19 mchyzer Exp $
61   */
62  public class HttpStatus {
63  
64  
65      // -------------------------------------------------------- Class Variables
66  
67      /** Reason phrases lookup table. */
68      private static final String[][] REASON_PHRASES = new String[][]{
69          new String[0],
70          new String[3],
71          new String[8],
72          new String[8],
73          new String[25],
74          new String[8]
75      };
76  
77  
78      // --------------------------------------------------------- Public Methods
79  
80      /**
81       * Get the reason phrase for a particular status code.
82       * 
83       * This method always returns the English text as specified in the
84       * relevent RFCs and is not internationalized.
85       * 
86       * @param statusCode the numeric status code
87       * @return the reason phrase associated with the given status code
88       * or null if the status code is not recognized.
89       * 
90       * TODO: getStatusText should be called getReasonPhrase to match RFC
91       */
92      public static String getStatusText(int statusCode) {
93  
94          if (statusCode < 0) {
95              throw new IllegalArgumentException("status code may not be negative");
96          }
97          int classIndex = statusCode / 100;
98          int codeIndex = statusCode - classIndex * 100;
99          if (classIndex < 1 || classIndex > (REASON_PHRASES.length - 1) 
100             || codeIndex < 0 || codeIndex > (REASON_PHRASES[classIndex].length - 1)) {
101             return null;
102         }
103         return REASON_PHRASES[classIndex][codeIndex];
104     }
105 
106 
107     // -------------------------------------------------------- Private Methods
108 
109     /**
110      * Store the given reason phrase, by status code.
111      * @param statusCode The status code to lookup
112      * @param reasonPhrase The reason phrase for this status code
113      */
114     private static void addStatusCodeMap(int statusCode, String reasonPhrase) {
115         int classIndex = statusCode / 100;
116         REASON_PHRASES[classIndex][statusCode - classIndex * 100] = reasonPhrase;
117     }
118 
119 
120     // -------------------------------------------------------------- Constants
121 
122     // --- 1xx Informational ---
123 
124     /** <tt>100 Continue</tt> (HTTP/1.1 - RFC 2616) */
125     public static final int SC_CONTINUE = 100;
126     /** <tt>101 Switching Protocols</tt> (HTTP/1.1 - RFC 2616)*/
127     public static final int SC_SWITCHING_PROTOCOLS = 101;
128     /** <tt>102 Processing</tt> (WebDAV - RFC 2518) */
129     public static final int SC_PROCESSING = 102;
130 
131     // --- 2xx Success ---
132 
133     /** <tt>200 OK</tt> (HTTP/1.0 - RFC 1945) */
134     public static final int SC_OK = 200;
135     /** <tt>201 Created</tt> (HTTP/1.0 - RFC 1945) */
136     public static final int SC_CREATED = 201;
137     /** <tt>202 Accepted</tt> (HTTP/1.0 - RFC 1945) */
138     public static final int SC_ACCEPTED = 202;
139     /** <tt>203 Non Authoritative Information</tt> (HTTP/1.1 - RFC 2616) */
140     public static final int SC_NON_AUTHORITATIVE_INFORMATION = 203;
141     /** <tt>204 No Content</tt> (HTTP/1.0 - RFC 1945) */
142     public static final int SC_NO_CONTENT = 204;
143     /** <tt>205 Reset Content</tt> (HTTP/1.1 - RFC 2616) */
144     public static final int SC_RESET_CONTENT = 205;
145     /** <tt>206 Partial Content</tt> (HTTP/1.1 - RFC 2616) */
146     public static final int SC_PARTIAL_CONTENT = 206;
147     /** 
148      * <tt>207 Multi-Status</tt> (WebDAV - RFC 2518) or <tt>207 Partial Update
149      * OK</tt> (HTTP/1.1 - draft-ietf-http-v11-spec-rev-01?)
150      */
151     public static final int SC_MULTI_STATUS = 207;
152 
153     // --- 3xx Redirection ---
154 
155     /** <tt>300 Mutliple Choices</tt> (HTTP/1.1 - RFC 2616) */
156     public static final int SC_MULTIPLE_CHOICES = 300;
157     /** <tt>301 Moved Permanently</tt> (HTTP/1.0 - RFC 1945) */
158     public static final int SC_MOVED_PERMANENTLY = 301;
159     /** <tt>302 Moved Temporarily</tt> (Sometimes <tt>Found</tt>) (HTTP/1.0 - RFC 1945) */
160     public static final int SC_MOVED_TEMPORARILY = 302;
161     /** <tt>303 See Other</tt> (HTTP/1.1 - RFC 2616) */
162     public static final int SC_SEE_OTHER = 303;
163     /** <tt>304 Not Modified</tt> (HTTP/1.0 - RFC 1945) */
164     public static final int SC_NOT_MODIFIED = 304;
165     /** <tt>305 Use Proxy</tt> (HTTP/1.1 - RFC 2616) */
166     public static final int SC_USE_PROXY = 305;
167     /** <tt>307 Temporary Redirect</tt> (HTTP/1.1 - RFC 2616) */
168     public static final int SC_TEMPORARY_REDIRECT = 307;
169 
170     // --- 4xx Client Error ---
171 
172     /** <tt>400 Bad Request</tt> (HTTP/1.1 - RFC 2616) */
173     public static final int SC_BAD_REQUEST = 400;
174     /** <tt>401 Unauthorized</tt> (HTTP/1.0 - RFC 1945) */
175     public static final int SC_UNAUTHORIZED = 401;
176     /** <tt>402 Payment Required</tt> (HTTP/1.1 - RFC 2616) */
177     public static final int SC_PAYMENT_REQUIRED = 402;
178     /** <tt>403 Forbidden</tt> (HTTP/1.0 - RFC 1945) */
179     public static final int SC_FORBIDDEN = 403;
180     /** <tt>404 Not Found</tt> (HTTP/1.0 - RFC 1945) */
181     public static final int SC_NOT_FOUND = 404;
182     /** <tt>405 Method Not Allowed</tt> (HTTP/1.1 - RFC 2616) */
183     public static final int SC_METHOD_NOT_ALLOWED = 405;
184     /** <tt>406 Not Acceptable</tt> (HTTP/1.1 - RFC 2616) */
185     public static final int SC_NOT_ACCEPTABLE = 406;
186     /** <tt>407 Proxy Authentication Required</tt> (HTTP/1.1 - RFC 2616)*/
187     public static final int SC_PROXY_AUTHENTICATION_REQUIRED = 407;
188     /** <tt>408 Request Timeout</tt> (HTTP/1.1 - RFC 2616) */
189     public static final int SC_REQUEST_TIMEOUT = 408;
190     /** <tt>409 Conflict</tt> (HTTP/1.1 - RFC 2616) */
191     public static final int SC_CONFLICT = 409;
192     /** <tt>410 Gone</tt> (HTTP/1.1 - RFC 2616) */
193     public static final int SC_GONE = 410;
194     /** <tt>411 Length Required</tt> (HTTP/1.1 - RFC 2616) */
195     public static final int SC_LENGTH_REQUIRED = 411;
196     /** <tt>412 Precondition Failed</tt> (HTTP/1.1 - RFC 2616) */
197     public static final int SC_PRECONDITION_FAILED = 412;
198     /** <tt>413 Request Entity Too Large</tt> (HTTP/1.1 - RFC 2616) */
199     public static final int SC_REQUEST_TOO_LONG = 413;
200     /** <tt>414 Request-URI Too Long</tt> (HTTP/1.1 - RFC 2616) */
201     public static final int SC_REQUEST_URI_TOO_LONG = 414;
202     /** <tt>415 Unsupported Media Type</tt> (HTTP/1.1 - RFC 2616) */
203     public static final int SC_UNSUPPORTED_MEDIA_TYPE = 415;
204     /** <tt>416 Requested Range Not Satisfiable</tt> (HTTP/1.1 - RFC 2616) */
205     public static final int SC_REQUESTED_RANGE_NOT_SATISFIABLE = 416;
206     /** <tt>417 Expectation Failed</tt> (HTTP/1.1 - RFC 2616) */
207     public static final int SC_EXPECTATION_FAILED = 417;
208 
209     /**
210      * Static constant for a 418 error.
211      * <tt>418 Unprocessable Entity</tt> (WebDAV drafts?)
212      * or <tt>418 Reauthentication Required</tt> (HTTP/1.1 drafts?)
213      */
214     // not used
215     // public static final int SC_UNPROCESSABLE_ENTITY = 418;
216 
217     /**
218      * Static constant for a 419 error.
219      * <tt>419 Insufficient Space on Resource</tt>
220      * (WebDAV - draft-ietf-webdav-protocol-05?)
221      * or <tt>419 Proxy Reauthentication Required</tt>
222      * (HTTP/1.1 drafts?)
223      */
224     public static final int SC_INSUFFICIENT_SPACE_ON_RESOURCE = 419;
225     /**
226      * Static constant for a 420 error.
227      * <tt>420 Method Failure</tt>
228      * (WebDAV - draft-ietf-webdav-protocol-05?)
229      */
230     public static final int SC_METHOD_FAILURE = 420;
231     /** <tt>422 Unprocessable Entity</tt> (WebDAV - RFC 2518) */
232     public static final int SC_UNPROCESSABLE_ENTITY = 422;
233     /** <tt>423 Locked</tt> (WebDAV - RFC 2518) */
234     public static final int SC_LOCKED = 423;
235     /** <tt>424 Failed Dependency</tt> (WebDAV - RFC 2518) */
236     public static final int SC_FAILED_DEPENDENCY = 424;
237 
238     // --- 5xx Server Error ---
239 
240     /** <tt>500 Server Error</tt> (HTTP/1.0 - RFC 1945) */
241     public static final int SC_INTERNAL_SERVER_ERROR = 500;
242     /** <tt>501 Not Implemented</tt> (HTTP/1.0 - RFC 1945) */
243     public static final int SC_NOT_IMPLEMENTED = 501;
244     /** <tt>502 Bad Gateway</tt> (HTTP/1.0 - RFC 1945) */
245     public static final int SC_BAD_GATEWAY = 502;
246     /** <tt>503 Service Unavailable</tt> (HTTP/1.0 - RFC 1945) */
247     public static final int SC_SERVICE_UNAVAILABLE = 503;
248     /** <tt>504 Gateway Timeout</tt> (HTTP/1.1 - RFC 2616) */
249     public static final int SC_GATEWAY_TIMEOUT = 504;
250     /** <tt>505 HTTP Version Not Supported</tt> (HTTP/1.1 - RFC 2616) */
251     public static final int SC_HTTP_VERSION_NOT_SUPPORTED = 505;
252 
253     /** <tt>507 Insufficient Storage</tt> (WebDAV - RFC 2518) */
254     public static final int SC_INSUFFICIENT_STORAGE = 507;
255 
256 
257     // ----------------------------------------------------- Static Initializer
258 
259     /** Set up status code to "reason phrase" map. */
260     static {
261         // HTTP 1.0 Server status codes -- see RFC 1945
262         addStatusCodeMap(SC_OK, "OK");
263         addStatusCodeMap(SC_CREATED, "Created");
264         addStatusCodeMap(SC_ACCEPTED, "Accepted");
265         addStatusCodeMap(SC_NO_CONTENT, "No Content");
266         addStatusCodeMap(SC_MOVED_PERMANENTLY, "Moved Permanently");
267         addStatusCodeMap(SC_MOVED_TEMPORARILY, "Moved Temporarily");
268         addStatusCodeMap(SC_NOT_MODIFIED, "Not Modified");
269         addStatusCodeMap(SC_BAD_REQUEST, "Bad Request");
270         addStatusCodeMap(SC_UNAUTHORIZED, "Unauthorized");
271         addStatusCodeMap(SC_FORBIDDEN, "Forbidden");
272         addStatusCodeMap(SC_NOT_FOUND, "Not Found");
273         addStatusCodeMap(SC_INTERNAL_SERVER_ERROR, "Internal Server Error");
274         addStatusCodeMap(SC_NOT_IMPLEMENTED, "Not Implemented");
275         addStatusCodeMap(SC_BAD_GATEWAY, "Bad Gateway");
276         addStatusCodeMap(SC_SERVICE_UNAVAILABLE, "Service Unavailable");
277 
278         // HTTP 1.1 Server status codes -- see RFC 2048
279         addStatusCodeMap(SC_CONTINUE, "Continue");
280         addStatusCodeMap(SC_TEMPORARY_REDIRECT, "Temporary Redirect");
281         addStatusCodeMap(SC_METHOD_NOT_ALLOWED, "Method Not Allowed");
282         addStatusCodeMap(SC_CONFLICT, "Conflict");
283         addStatusCodeMap(SC_PRECONDITION_FAILED, "Precondition Failed");
284         addStatusCodeMap(SC_REQUEST_TOO_LONG, "Request Too Long");
285         addStatusCodeMap(SC_REQUEST_URI_TOO_LONG, "Request-URI Too Long");
286         addStatusCodeMap(SC_UNSUPPORTED_MEDIA_TYPE, "Unsupported Media Type");
287         addStatusCodeMap(SC_MULTIPLE_CHOICES, "Multiple Choices");
288         addStatusCodeMap(SC_SEE_OTHER, "See Other");
289         addStatusCodeMap(SC_USE_PROXY, "Use Proxy");
290         addStatusCodeMap(SC_PAYMENT_REQUIRED, "Payment Required");
291         addStatusCodeMap(SC_NOT_ACCEPTABLE, "Not Acceptable");
292         addStatusCodeMap(SC_PROXY_AUTHENTICATION_REQUIRED, 
293             "Proxy Authentication Required");
294         addStatusCodeMap(SC_REQUEST_TIMEOUT, 
295             "Request Timeout");
296 
297         addStatusCodeMap(SC_SWITCHING_PROTOCOLS, "Switching Protocols");
298         addStatusCodeMap(SC_NON_AUTHORITATIVE_INFORMATION,
299                          "Non Authoritative Information");
300         addStatusCodeMap(SC_RESET_CONTENT, "Reset Content");
301         addStatusCodeMap(SC_PARTIAL_CONTENT, "Partial Content");
302         addStatusCodeMap(SC_GATEWAY_TIMEOUT, "Gateway Timeout");
303         addStatusCodeMap(SC_HTTP_VERSION_NOT_SUPPORTED,
304                          "Http Version Not Supported");
305         addStatusCodeMap(SC_GONE,
306                          "Gone");
307         addStatusCodeMap(SC_LENGTH_REQUIRED,
308                          "Length Required");
309         addStatusCodeMap(SC_REQUESTED_RANGE_NOT_SATISFIABLE,
310                          "Requested Range Not Satisfiable");
311         addStatusCodeMap(SC_EXPECTATION_FAILED,
312                          "Expectation Failed");
313 
314         // WebDAV Server-specific status codes
315         addStatusCodeMap(SC_PROCESSING, "Processing");
316         addStatusCodeMap(SC_MULTI_STATUS, "Multi-Status");
317         addStatusCodeMap(SC_UNPROCESSABLE_ENTITY, "Unprocessable Entity");
318         addStatusCodeMap(SC_INSUFFICIENT_SPACE_ON_RESOURCE,
319                          "Insufficient Space On Resource");
320         addStatusCodeMap(SC_METHOD_FAILURE, "Method Failure");
321         addStatusCodeMap(SC_LOCKED, "Locked");
322         addStatusCodeMap(SC_INSUFFICIENT_STORAGE , "Insufficient Storage");
323         addStatusCodeMap(SC_FAILED_DEPENDENCY, "Failed Dependency");
324     }
325 
326 
327 }