001: // ========================================================================
002: // Copyright 2004-2005 Mort Bay Consulting Pty. Ltd.
003: // ------------------------------------------------------------------------
004: // Licensed under the Apache License, Version 2.0 (the "License");
005: // you may not use this file except in compliance with the License.
006: // You may obtain a copy of the License at
007: // http://www.apache.org/licenses/LICENSE-2.0
008: // Unless required by applicable law or agreed to in writing, software
009: // distributed under the License is distributed on an "AS IS" BASIS,
010: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
011: // See the License for the specific language governing permissions and
012: // limitations under the License.
013: // ========================================================================
014:
015: package org.mortbay.jetty;
016:
017: import org.mortbay.io.Buffer;
018: import org.mortbay.io.BufferCache;
019: import org.mortbay.io.ByteArrayBuffer;
020:
021: /* ------------------------------------------------------------------------------- */
022: /**
023: *
024: */
025: public class HttpStatus {
026: public final static String Continue = "Continue",
027: Switching_Protocols = "Switching Protocols",
028: Processing = "Processing",
029: OK = "OK",
030: Created = "Created",
031: Accepted = "Accepted",
032: Non_Authoritative_Information = "Non Authoritative Information",
033: No_Content = "No Content",
034: Reset_Content = "Reset Content",
035: Partial_Content = "Partial Content",
036: Multi_Status = "Multi Status",
037: Multiple_Choices = "Multiple Choices",
038: Moved_Permanently = "Moved Permanently",
039: Moved_Temporarily = "Moved Temporarily",
040: Found = "Found",
041: See_Other = "See Other",
042: Not_Modified = "Not Modified",
043: Use_Proxy = "Use Proxy",
044: Bad_Request = "Bad Request",
045: Unauthorized = "Unauthorized",
046: Payment_Required = "Payment Required",
047: Forbidden = "Forbidden",
048: Not_Found = "Not Found",
049: Method_Not_Allowed = "Method Not Allowed",
050: Not_Acceptable = "Not Acceptable",
051: Proxy_Authentication_Required = "Proxy Authentication Required",
052: Request_Timeout = "Request Timeout",
053: Conflict = "Conflict",
054: Gone = "Gone",
055: Length_Required = "Length Required",
056: Precondition_Failed = "Precondition Failed",
057: Request_Entity_Too_Large = "Request Entity Too Large",
058: Request_URI_Too_Large = "Request URI Too Large",
059: Unsupported_Media_Type = "Unsupported Media Type",
060: Requested_Range_Not_Satisfiable = "Requested Range Not Satisfiable",
061: Expectation_Failed = "Expectation Failed",
062: Unprocessable_Entity = "Unprocessable Entity",
063: Locked = "Locked", Failed_Dependency = "Failed Dependency",
064: Internal_Server_Error = "Internal Server Error",
065: Not_Implemented = "Not Implemented",
066: Bad_Gateway = "Bad Gateway",
067: Service_Unavailable = "Service Unavailable",
068: Gateway_Timeout = "Gateway Timeout",
069: HTTP_Version_Not_Supported = "HTTP Version Not Supported",
070: Insufficient_Storage = "Insufficient Storage",
071: Unknown = "Unknown";
072:
073: public final static int ORDINAL_100_Continue = 100,
074: ORDINAL_101_Switching_Protocols = 101,
075: ORDINAL_102_Processing = 102, ORDINAL_200_OK = 200,
076: ORDINAL_201_Created = 201, ORDINAL_202_Accepted = 202,
077: ORDINAL_203_Non_Authoritative_Information = 203,
078: ORDINAL_204_No_Content = 204,
079: ORDINAL_205_Reset_Content = 205,
080: ORDINAL_206_Partial_Content = 206,
081: ORDINAL_207_Multi_Status = 207,
082: ORDINAL_300_Multiple_Choices = 300,
083: ORDINAL_301_Moved_Permanently = 301,
084: ORDINAL_302_Moved_Temporarily = 302,
085: ORDINAL_302_Found = 302, ORDINAL_303_See_Other = 303,
086: ORDINAL_304_Not_Modified = 304,
087: ORDINAL_305_Use_Proxy = 305, ORDINAL_400_Bad_Request = 400,
088: ORDINAL_401_Unauthorized = 401,
089: ORDINAL_402_Payment_Required = 402,
090: ORDINAL_403_Forbidden = 403, ORDINAL_404_Not_Found = 404,
091: ORDINAL_405_Method_Not_Allowed = 405,
092: ORDINAL_406_Not_Acceptable = 406,
093: ORDINAL_407_Proxy_Authentication_Required = 407,
094: ORDINAL_408_Request_Timeout = 408,
095: ORDINAL_409_Conflict = 409, ORDINAL_410_Gone = 410,
096: ORDINAL_411_Length_Required = 411,
097: ORDINAL_412_Precondition_Failed = 412,
098: ORDINAL_413_Request_Entity_Too_Large = 413,
099: ORDINAL_414_Request_URI_Too_Large = 414,
100: ORDINAL_415_Unsupported_Media_Type = 415,
101: ORDINAL_416_Requested_Range_Not_Satisfiable = 416,
102: ORDINAL_417_Expectation_Failed = 417,
103: ORDINAL_422_Unprocessable_Entity = 422,
104: ORDINAL_423_Locked = 423,
105: ORDINAL_424_Failed_Dependency = 424,
106: ORDINAL_500_Internal_Server_Error = 500,
107: ORDINAL_501_Not_Implemented = 501,
108: ORDINAL_502_Bad_Gateway = 502,
109: ORDINAL_503_Service_Unavailable = 503,
110: ORDINAL_504_Gateway_Timeout = 504,
111: ORDINAL_505_HTTP_Version_Not_Supported = 505,
112: ORDINAL_507_Insufficient_Storage = 507,
113: ORDINAL_999_Unknown = 999;
114:
115: public static final BufferCache CACHE = new BufferCache();
116:
117: public static final Buffer Continue_BUFFER = CACHE.add(Continue,
118: ORDINAL_100_Continue),
119: Switching_Protocols_BUFFER = CACHE.add(Switching_Protocols,
120: ORDINAL_101_Switching_Protocols),
121: Processing_BUFFER = CACHE.add(Processing,
122: ORDINAL_102_Processing),
123: OK_BUFFER = CACHE.add(OK, ORDINAL_200_OK),
124: Created_BUFFER = CACHE.add(Created, ORDINAL_201_Created),
125: Accepted_BUFFER = CACHE.add(Accepted, ORDINAL_202_Accepted),
126: Non_Authoritative_Information_BUFFER = CACHE.add(
127: Non_Authoritative_Information,
128: ORDINAL_203_Non_Authoritative_Information),
129: No_Content_BUFFER = CACHE.add(No_Content,
130: ORDINAL_204_No_Content),
131: Reset_Content_BUFFER = CACHE.add(Reset_Content,
132: ORDINAL_205_Reset_Content),
133: Partial_Content_BUFFER = CACHE.add(Partial_Content,
134: ORDINAL_206_Partial_Content),
135: Multi_Status_BUFFER = CACHE.add(Multi_Status,
136: ORDINAL_207_Multi_Status),
137: Multiple_Choices_BUFFER = CACHE.add(Multiple_Choices,
138: ORDINAL_300_Multiple_Choices),
139: Moved_Permanently_BUFFER = CACHE.add(Moved_Permanently,
140: ORDINAL_301_Moved_Permanently),
141: Moved_Temporarily_BUFFER = CACHE.add(Moved_Temporarily,
142: ORDINAL_302_Moved_Temporarily),
143: Found_BUFFER = CACHE.add(Found, ORDINAL_302_Found),
144: See_Other_BUFFER = CACHE.add(See_Other,
145: ORDINAL_303_See_Other),
146: Not_Modified_BUFFER = CACHE.add(Not_Modified,
147: ORDINAL_304_Not_Modified),
148: Use_Proxy_BUFFER = CACHE.add(Use_Proxy,
149: ORDINAL_305_Use_Proxy),
150: Bad_Request_BUFFER = CACHE.add(Bad_Request,
151: ORDINAL_400_Bad_Request),
152: Unauthorized_BUFFER = CACHE.add(Unauthorized,
153: ORDINAL_401_Unauthorized),
154: Payment_Required_BUFFER = CACHE.add(Payment_Required,
155: ORDINAL_402_Payment_Required),
156: Forbidden_BUFFER = CACHE.add(Forbidden,
157: ORDINAL_403_Forbidden),
158: Not_Found_BUFFER = CACHE.add(Not_Found,
159: ORDINAL_404_Not_Found),
160: Method_Not_Allowed_BUFFER = CACHE.add(Method_Not_Allowed,
161: ORDINAL_405_Method_Not_Allowed),
162: Not_Acceptable_BUFFER = CACHE.add(Not_Acceptable,
163: ORDINAL_406_Not_Acceptable),
164: Proxy_Authentication_Required_BUFFER = CACHE.add(
165: Proxy_Authentication_Required,
166: ORDINAL_407_Proxy_Authentication_Required),
167: Request_Timeout_BUFFER = CACHE.add(Request_Timeout,
168: ORDINAL_408_Request_Timeout),
169: Conflict_BUFFER = CACHE.add(Conflict, ORDINAL_409_Conflict),
170: Gone_BUFFER = CACHE.add(Gone, ORDINAL_410_Gone),
171: Length_Required_BUFFER = CACHE.add(Length_Required,
172: ORDINAL_411_Length_Required),
173: Precondition_Failed_BUFFER = CACHE.add(Precondition_Failed,
174: ORDINAL_412_Precondition_Failed),
175: Request_Entity_Too_Large_BUFFER = CACHE.add(
176: Request_Entity_Too_Large,
177: ORDINAL_413_Request_Entity_Too_Large),
178: Request_URI_Too_Large_BUFFER = CACHE.add(
179: Request_URI_Too_Large,
180: ORDINAL_414_Request_URI_Too_Large),
181: Unsupported_Media_Type_BUFFER = CACHE.add(
182: Unsupported_Media_Type,
183: ORDINAL_415_Unsupported_Media_Type),
184: Requested_Range_Not_Satisfiable_BUFFER = CACHE.add(
185: Requested_Range_Not_Satisfiable,
186: ORDINAL_416_Requested_Range_Not_Satisfiable),
187: Expectation_Failed_BUFFER = CACHE.add(Expectation_Failed,
188: ORDINAL_417_Expectation_Failed),
189: Unprocessable_Entity_BUFFER = CACHE.add(
190: Unprocessable_Entity,
191: ORDINAL_422_Unprocessable_Entity),
192: Locked_BUFFER = CACHE.add(Locked, ORDINAL_423_Locked),
193: Failed_Dependency_BUFFER = CACHE.add(Failed_Dependency,
194: ORDINAL_424_Failed_Dependency),
195: Internal_Server_Error_BUFFER = CACHE.add(
196: Internal_Server_Error,
197: ORDINAL_500_Internal_Server_Error),
198: Not_Implemented_BUFFER = CACHE.add(Not_Implemented,
199: ORDINAL_501_Not_Implemented),
200: Bad_Gateway_BUFFER = CACHE.add(Bad_Gateway,
201: ORDINAL_502_Bad_Gateway),
202: Service_Unavailable_BUFFER = CACHE.add(Service_Unavailable,
203: ORDINAL_503_Service_Unavailable),
204: Gateway_Timeout_BUFFER = CACHE.add(Gateway_Timeout,
205: ORDINAL_504_Gateway_Timeout),
206: HTTP_Version_Not_Supported_BUFFER = CACHE.add(
207: HTTP_Version_Not_Supported,
208: ORDINAL_505_HTTP_Version_Not_Supported),
209: Insufficient_Storage_BUFFER = CACHE.add(
210: Insufficient_Storage,
211: ORDINAL_507_Insufficient_Storage),
212: Unknown_BUFFER = CACHE.add(Unknown, ORDINAL_999_Unknown);
213:
214: // Build cache of response lines for status
215: private static Buffer[] __responseLine = new Buffer[600];
216: static {
217: int versionLength = HttpVersions.HTTP_1_1_BUFFER.length();
218:
219: for (int i = 0; i < __responseLine.length; i++) {
220: Buffer reason = CACHE.get(i);
221: if (reason == null)
222: continue;
223:
224: byte[] bytes = new byte[versionLength + 5 + reason.length()
225: + 2];
226: HttpVersions.HTTP_1_1_BUFFER.peek(0, bytes, 0,
227: versionLength);
228: bytes[versionLength + 0] = ' ';
229: bytes[versionLength + 1] = (byte) ('0' + i / 100);
230: bytes[versionLength + 2] = (byte) ('0' + (i % 100) / 10);
231: bytes[versionLength + 3] = (byte) ('0' + (i % 10));
232: bytes[versionLength + 4] = ' ';
233: reason.peek(0, bytes, versionLength + 5, reason.length());
234: bytes[versionLength + 5 + reason.length()] = HttpTokens.CARRIAGE_RETURN;
235: bytes[versionLength + 6 + reason.length()] = HttpTokens.LINE_FEED;
236: __responseLine[i] = new ByteArrayBuffer(bytes, 0,
237: bytes.length, Buffer.IMMUTABLE);
238: }
239: }
240:
241: /* ------------------------------------------------------------ */
242: /**
243: * @param status
244: * @return HTTP response line for the status code including CRLF
245: */
246: public static Buffer getResponseLine(int status) {
247: if (status > __responseLine.length)
248: return null;
249: return __responseLine[status];
250: }
251: }
|