1 /*
2 * $Header: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpStatus.java,v 1.15 2003/05/12 01:17:49 mbecke Exp $
3 * $Revision: 1.15 $
4 * $Date: 2003/05/12 01:17:49 $
5 *
6 * ====================================================================
7 *
8 * The Apache Software License, Version 1.1
9 *
10 * Copyright (c) 1999-2003 The Apache Software Foundation. All rights
11 * reserved.
12 *
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
15 * are met:
16 *
17 * 1. Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 *
20 * 2. Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in
22 * the documentation and/or other materials provided with the
23 * distribution.
24 *
25 * 3. The end-user documentation included with the redistribution, if
26 * any, must include the following acknowlegement:
27 * "This product includes software developed by the
28 * Apache Software Foundation (http://www.apache.org/)."
29 * Alternately, this acknowlegement may appear in the software itself,
30 * if and wherever such third-party acknowlegements normally appear.
31 *
32 * 4. The names "The Jakarta Project", "Commons", and "Apache Software
33 * Foundation" must not be used to endorse or promote products derived
34 * from this software without prior written permission. For written
35 * permission, please contact apache@apache.org.
36 *
37 * 5. Products derived from this software may not be called "Apache"
38 * nor may "Apache" appear in their names without prior written
39 * permission of the Apache Group.
40 *
41 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
42 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
43 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
44 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
45 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
46 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
47 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
48 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
49 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
50 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
51 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
52 * SUCH DAMAGE.
53 * ====================================================================
54 *
55 * This software consists of voluntary contributions made by many
56 * individuals on behalf of the Apache Software Foundation. For more
57 * information on the Apache Software Foundation, please see
58 * <http://www.apache.org/>.
59 *
60 * [Additional notices, if required by prior licensing conditions]
61 *
62 */
63
64 package org.apache.commons.httpclient;
65
66 /***
67 * Constants enumerating the HTTP status codes.
68 * All status codes defined in RFC1945 (HTTP/1.0, RFC2616 (HTTP/1.1), and
69 * RFC2518 (WebDAV) are supported.
70 *
71 * @see StatusLine
72 * @author Unascribed
73 * @author <a href="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a>
74 * @author <a href="mailto:jsdever@apache.org">Jeff Dever</a>
75 *
76 * TODO: Internationalization of reason phrases
77 *
78 * @version $Id: HttpStatus.java,v 1.15 2003/05/12 01:17:49 mbecke Exp $
79 */
80 public class HttpStatus {
81
82
83 // -------------------------------------------------------- Class Variables
84
85 /*** Reason phrases lookup table. */
86 private static final String[][] REASON_PHRASES = new String[][]{
87 new String[0],
88 new String[3],
89 new String[8],
90 new String[8],
91 new String[25],
92 new String[8]
93 };
94
95
96 // --------------------------------------------------------- Public Methods
97
98 /***
99 * Get the reason phrase for a particular status code.
100 *
101 * This method always returns the English text as specified in the
102 * relevent RFCs and is not internationalized.
103 *
104 * @param statusCode the numeric status code
105 * @return the reason phrase associated with the given status code
106 * or null if the status code is not recognized.
107 *
108 * TODO: getStatusText should be called getReasonPhrase to match RFC
109 */
110 public static String getStatusText(int statusCode) {
111
112 int classIndex = statusCode / 100;
113 int codeIndex = statusCode - classIndex * 100;
114 if (classIndex < 1 || classIndex > (REASON_PHRASES.length - 1)
115 || codeIndex < 0 || codeIndex > REASON_PHRASES[classIndex].length) {
116 return null;
117 }
118 return REASON_PHRASES[classIndex][codeIndex];
119 }
120
121
122 // -------------------------------------------------------- Private Methods
123
124 /***
125 * Store the given reason phrase, by status code.
126 * @param statusCode The status code to lookup
127 * @param reasonPhrase The reason phrase for this status code
128 */
129 private static void addStatusCodeMap(int statusCode, String reasonPhrase) {
130 int classIndex = statusCode / 100;
131 REASON_PHRASES[classIndex][statusCode - classIndex * 100] = reasonPhrase;
132 }
133
134
135 // -------------------------------------------------------------- Constants
136
137 // --- 1xx Informational ---
138
139 /*** <tt>100 Continue</tt> (HTTP/1.1 - RFC 2616) */
140 public static final int SC_CONTINUE = 100;
141 /*** <tt>101 Switching Protocols</tt> (HTTP/1.1 - RFC 2616)*/
142 public static final int SC_SWITCHING_PROTOCOLS = 101;
143 /*** <tt>102 Processing</tt> (WebDAV - RFC 2518) */
144 public static final int SC_PROCESSING = 102;
145
146 // --- 2xx Success ---
147
148 /*** <tt>200 OK</tt> (HTTP/1.0 - RFC 1945) */
149 public static final int SC_OK = 200;
150 /*** <tt>201 Created</tt> (HTTP/1.0 - RFC 1945) */
151 public static final int SC_CREATED = 201;
152 /*** <tt>202 Accepted</tt> (HTTP/1.0 - RFC 1945) */
153 public static final int SC_ACCEPTED = 202;
154 /*** <tt>203 Non Authoritative Information</tt> (HTTP/1.1 - RFC 2616) */
155 public static final int SC_NON_AUTHORITATIVE_INFORMATION = 203;
156 /*** <tt>204 No Content</tt> (HTTP/1.0 - RFC 1945) */
157 public static final int SC_NO_CONTENT = 204;
158 /*** <tt>205 Reset Content</tt> (HTTP/1.1 - RFC 2616) */
159 public static final int SC_RESET_CONTENT = 205;
160 /*** <tt>206 Partial Content</tt> (HTTP/1.1 - RFC 2616) */
161 public static final int SC_PARTIAL_CONTENT = 206;
162 /***
163 * <tt>207 Multi-Status</tt> (WebDAV - RFC 2518) or <tt>207 Partial Update
164 * OK</tt> (HTTP/1.1 - draft-ietf-http-v11-spec-rev-01?)
165 */
166 public static final int SC_MULTI_STATUS = 207;
167
168 // --- 3xx Redirection ---
169
170 /*** <tt>300 Mutliple Choices</tt> (HTTP/1.1 - RFC 2616) */
171 public static final int SC_MULTIPLE_CHOICES = 300;
172 /*** <tt>301 Moved Permanently</tt> (HTTP/1.0 - RFC 1945) */
173 public static final int SC_MOVED_PERMANENTLY = 301;
174 /*** <tt>302 Moved Temporarily</tt> (Sometimes <tt>Found</tt>) (HTTP/1.0 - RFC 1945) */
175 public static final int SC_MOVED_TEMPORARILY = 302;
176 /*** <tt>303 See Other</tt> (HTTP/1.1 - RFC 2616) */
177 public static final int SC_SEE_OTHER = 303;
178 /*** <tt>304 Not Modified</tt> (HTTP/1.0 - RFC 1945) */
179 public static final int SC_NOT_MODIFIED = 304;
180 /*** <tt>305 Use Proxy</tt> (HTTP/1.1 - RFC 2616) */
181 public static final int SC_USE_PROXY = 305;
182 /*** <tt>307 Temporary Redirect</tt> (HTTP/1.1 - RFC 2616) */
183 public static final int SC_TEMPORARY_REDIRECT = 307;
184
185 // --- 4xx Client Error ---
186
187 /*** <tt>400 Bad Request</tt> (HTTP/1.1 - RFC 2616) */
188 public static final int SC_BAD_REQUEST = 400;
189 /*** <tt>401 Unauthorized</tt> (HTTP/1.0 - RFC 1945) */
190 public static final int SC_UNAUTHORIZED = 401;
191 /*** <tt>402 Payment Required</tt> (HTTP/1.1 - RFC 2616) */
192 public static final int SC_PAYMENT_REQUIRED = 402;
193 /*** <tt>403 Forbidden</tt> (HTTP/1.0 - RFC 1945) */
194 public static final int SC_FORBIDDEN = 403;
195 /*** <tt>404 Not Found</tt> (HTTP/1.0 - RFC 1945) */
196 public static final int SC_NOT_FOUND = 404;
197 /*** <tt>405 Method Not Allowed</tt> (HTTP/1.1 - RFC 2616) */
198 public static final int SC_METHOD_NOT_ALLOWED = 405;
199 /*** <tt>406 Not Acceptable</tt> (HTTP/1.1 - RFC 2616) */
200 public static final int SC_NOT_ACCEPTABLE = 406;
201 /*** <tt>407 Proxy Authentication Required</tt> (HTTP/1.1 - RFC 2616)*/
202 public static final int SC_PROXY_AUTHENTICATION_REQUIRED = 407;
203 /*** <tt>408 Request Timeout</tt> (HTTP/1.1 - RFC 2616) */
204 public static final int SC_REQUEST_TIMEOUT = 408;
205 /*** <tt>409 Conflict</tt> (HTTP/1.1 - RFC 2616) */
206 public static final int SC_CONFLICT = 409;
207 /*** <tt>410 Gone</tt> (HTTP/1.1 - RFC 2616) */
208 public static final int SC_GONE = 410;
209 /*** <tt>411 Length Required</tt> (HTTP/1.1 - RFC 2616) */
210 public static final int SC_LENGTH_REQUIRED = 411;
211 /*** <tt>412 Precondition Failed</tt> (HTTP/1.1 - RFC 2616) */
212 public static final int SC_PRECONDITION_FAILED = 412;
213 /*** <tt>413 Request Entity Too Large</tt> (HTTP/1.1 - RFC 2616) */
214 public static final int SC_REQUEST_TOO_LONG = 413;
215 /*** <tt>414 Request-URI Too Long</tt> (HTTP/1.1 - RFC 2616) */
216 public static final int SC_REQUEST_URI_TOO_LONG = 414;
217 /*** <tt>415 Unsupported Media Type</tt> (HTTP/1.1 - RFC 2616) */
218 public static final int SC_UNSUPPORTED_MEDIA_TYPE = 415;
219 /*** <tt>416 Requested Range Not Satisfiable</tt> (HTTP/1.1 - RFC 2616) */
220 public static final int SC_REQUESTED_RANGE_NOT_SATISFIABLE = 416;
221 /*** <tt>417 Expectation Failed</tt> (HTTP/1.1 - RFC 2616) */
222 public static final int SC_EXPECTATION_FAILED = 417;
223
224 /***
225 * Static constant for a 418 error.
226 * <tt>418 Unprocessable Entity</tt> (WebDAV drafts?)
227 * or <tt>418 Reauthentication Required</tt> (HTTP/1.1 drafts?)
228 */
229 // not used
230 // public static final int SC_UNPROCESSABLE_ENTITY = 418;
231
232 /***
233 * Static constant for a 419 error.
234 * <tt>419 Insufficient Space on Resource</tt>
235 * (WebDAV - draft-ietf-webdav-protocol-05?)
236 * or <tt>419 Proxy Reauthentication Required</tt>
237 * (HTTP/1.1 drafts?)
238 */
239 public static final int SC_INSUFFICIENT_SPACE_ON_RESOURCE = 419;
240 /***
241 * Static constant for a 420 error.
242 * <tt>420 Method Failure</tt>
243 * (WebDAV - draft-ietf-webdav-protocol-05?)
244 */
245 public static final int SC_METHOD_FAILURE = 420;
246 /*** <tt>422 Unprocessable Entity</tt> (WebDAV - RFC 2518) */
247 public static final int SC_UNPROCESSABLE_ENTITY = 422;
248 /*** <tt>423 Locked</tt> (WebDAV - RFC 2518) */
249 public static final int SC_LOCKED = 423;
250 /*** <tt>424 Failed Dependency</tt> (WebDAV - RFC 2518) */
251 public static final int SC_FAILED_DEPENDENCY = 424;
252
253 // --- 5xx Server Error ---
254
255 /*** <tt>500 Server Error</tt> (HTTP/1.0 - RFC 1945) */
256 public static final int SC_INTERNAL_SERVER_ERROR = 500;
257 /*** <tt>501 Not Implemented</tt> (HTTP/1.0 - RFC 1945) */
258 public static final int SC_NOT_IMPLEMENTED = 501;
259 /*** <tt>502 Bad Gateway</tt> (HTTP/1.0 - RFC 1945) */
260 public static final int SC_BAD_GATEWAY = 502;
261 /*** <tt>503 Service Unavailable</tt> (HTTP/1.0 - RFC 1945) */
262 public static final int SC_SERVICE_UNAVAILABLE = 503;
263 /*** <tt>504 Gateway Timeout</tt> (HTTP/1.1 - RFC 2616) */
264 public static final int SC_GATEWAY_TIMEOUT = 504;
265 /*** <tt>505 HTTP Version Not Supported</tt> (HTTP/1.1 - RFC 2616) */
266 public static final int SC_HTTP_VERSION_NOT_SUPPORTED = 505;
267
268 /*** <tt>507 Insufficient Storage</tt> (WebDAV - RFC 2518) */
269 public static final int SC_INSUFFICIENT_STORAGE = 507;
270
271
272 // ----------------------------------------------------- Static Initializer
273
274 /*** Set up status code to "reason phrase" map. */
275 static {
276 // HTTP 1.0 Server status codes -- see RFC 1945
277 addStatusCodeMap(SC_OK, "OK");
278 addStatusCodeMap(SC_CREATED, "Created");
279 addStatusCodeMap(SC_ACCEPTED, "Accepted");
280 addStatusCodeMap(SC_NO_CONTENT, "No Content");
281 addStatusCodeMap(SC_MOVED_PERMANENTLY, "Moved Permanently");
282 addStatusCodeMap(SC_MOVED_TEMPORARILY, "Moved Temporarily");
283 addStatusCodeMap(SC_NOT_MODIFIED, "Not Modified");
284 addStatusCodeMap(SC_BAD_REQUEST, "Bad Request");
285 addStatusCodeMap(SC_UNAUTHORIZED, "Unauthorized");
286 addStatusCodeMap(SC_FORBIDDEN, "Forbidden");
287 addStatusCodeMap(SC_NOT_FOUND, "Not Found");
288 addStatusCodeMap(SC_INTERNAL_SERVER_ERROR, "Internal Server Error");
289 addStatusCodeMap(SC_NOT_IMPLEMENTED, "Not Implemented");
290 addStatusCodeMap(SC_BAD_GATEWAY, "Bad Gateway");
291 addStatusCodeMap(SC_SERVICE_UNAVAILABLE, "Service Unavailable");
292
293 // HTTP 1.1 Server status codes -- see RFC 2048
294 addStatusCodeMap(SC_CONTINUE, "Continue");
295 addStatusCodeMap(SC_TEMPORARY_REDIRECT, "Temporary Redirect");
296 addStatusCodeMap(SC_METHOD_NOT_ALLOWED, "Method Not Allowed");
297 addStatusCodeMap(SC_CONFLICT, "Conflict");
298 addStatusCodeMap(SC_PRECONDITION_FAILED, "Precondition Failed");
299 addStatusCodeMap(SC_REQUEST_TOO_LONG, "Request Too Long");
300 addStatusCodeMap(SC_REQUEST_URI_TOO_LONG, "Request-URI Too Long");
301 addStatusCodeMap(SC_UNSUPPORTED_MEDIA_TYPE, "Unsupported Media Type");
302 addStatusCodeMap(SC_MULTIPLE_CHOICES, "Multiple Choices");
303 addStatusCodeMap(SC_SEE_OTHER, "See Other");
304 addStatusCodeMap(SC_USE_PROXY, "Use Proxy");
305 addStatusCodeMap(SC_PAYMENT_REQUIRED, "Payment Required");
306 addStatusCodeMap(SC_NOT_ACCEPTABLE, "Not Acceptable");
307 addStatusCodeMap(SC_PROXY_AUTHENTICATION_REQUIRED,
308 "Proxy Authentication Required");
309 addStatusCodeMap(SC_REQUEST_TIMEOUT,
310 "Request Timeout");
311
312 addStatusCodeMap(SC_SWITCHING_PROTOCOLS, "Switching Protocols");
313 addStatusCodeMap(SC_NON_AUTHORITATIVE_INFORMATION,
314 "Non Authoritative Information");
315 addStatusCodeMap(SC_RESET_CONTENT, "Reset Content");
316 addStatusCodeMap(SC_PARTIAL_CONTENT, "Partial Content");
317 addStatusCodeMap(SC_GATEWAY_TIMEOUT, "Gateway Timeout");
318 addStatusCodeMap(SC_HTTP_VERSION_NOT_SUPPORTED,
319 "Http Version Not Supported");
320 addStatusCodeMap(SC_GONE,
321 "Gone");
322 addStatusCodeMap(SC_LENGTH_REQUIRED,
323 "Length Required");
324 addStatusCodeMap(SC_REQUESTED_RANGE_NOT_SATISFIABLE,
325 "Requested Range Not Satisfiable");
326 addStatusCodeMap(SC_EXPECTATION_FAILED,
327 "Expectation Failed");
328
329 // WebDAV Server-specific status codes
330 addStatusCodeMap(SC_PROCESSING, "Processing");
331 addStatusCodeMap(SC_MULTI_STATUS, "Multi-Status");
332 addStatusCodeMap(SC_UNPROCESSABLE_ENTITY, "Unprocessable Entity");
333 addStatusCodeMap(SC_INSUFFICIENT_SPACE_ON_RESOURCE,
334 "Insufficient Space On Resource");
335 addStatusCodeMap(SC_METHOD_FAILURE, "Method Failure");
336 addStatusCodeMap(SC_LOCKED, "Locked");
337 addStatusCodeMap(SC_INSUFFICIENT_STORAGE , "Insufficient Storage");
338 addStatusCodeMap(SC_FAILED_DEPENDENCY, "Failed Dependency");
339 }
340
341
342 }
This page was automatically generated by Maven