001: /*
002: * Enhydra Java Application Server Project
003: *
004: * The contents of this file are subject to the Enhydra Public License
005: * Version 1.1 (the "License"); you may not use this file except in
006: * compliance with the License. You may obtain a copy of the License on
007: * the Enhydra web site ( http://www.enhydra.org/ ).
008: *
009: * Software distributed under the License is distributed on an "AS IS"
010: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
011: * the License for the specific terms governing rights and limitations
012: * under the License.
013: *
014: * The Initial Developer of the Enhydra Application Server is Lutris
015: * Technologies, Inc. The Enhydra Application Server and portions created
016: * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
017: * All Rights Reserved.
018: *
019: * Contributor(s):
020: *
021: * $Id: HttpStatus.java,v 1.2 2006-06-15 13:47:00 sinisa Exp $
022: */
023:
024: package com.lutris.http;
025:
026: public class HttpStatus {
027:
028: // Informational
029: public final static int doContinue = 100;
030: public final static int switchingProtocols = 101;
031:
032: // Success
033: public final static int ok = 200;
034: public final static int created = 201;
035: public final static int accepted = 202;
036: public final static int nonAuthoritativeInformation = 203;
037: public final static int noContent = 204;
038: public final static int resetContent = 205;
039: public final static int partialContent = 206;
040:
041: // Redirection
042: public final static int multipleChoices = 300;
043: public final static int movedPermanently = 301;
044: public final static int movedTemporarily = 302;
045: public final static int seeOther = 303;
046: public final static int notModified = 304;
047: public final static int useProxy = 305;
048:
049: // Client error
050: public final static int badRequest = 400;
051: public final static int unauthorized = 401;
052: public final static int paymentRequired = 402;
053: public final static int forbidden = 403;
054: public final static int notFound = 404;
055: public final static int methodNotAllowed = 405;
056: public final static int notAcceptable = 406;
057: public final static int proxyAuthenticationRequired = 407;
058: public final static int requestTimeout = 408;
059: public final static int conflict = 409;
060: public final static int gone = 410;
061: public final static int lenghtRequired = 411;
062: public final static int preconditionFailed = 412;
063: public final static int requestEntityTooLarge = 413;
064: public final static int requestUriTooLarge = 414;
065: public final static int unsupportedMediaType = 415;
066:
067: // Server error
068: public final static int internalServerError = 500;
069: public final static int notImplemented = 501;
070: public final static int badGateway = 502;
071: public final static int serviceUnavailable = 503;
072: public final static int gatewayTimeout = 504;
073: public final static int httpVersionNotSupported = 505;
074:
075: /*
076: * Table of default messages. First dimension is indexed by
077: * (code / 100) - 1 and second diminsion by the remainder, with
078: * the last element of each class being a default value if
079: * the status code is past the end.
080: */
081: private static final String[][] statusMsgs = { {
082: /* 100 */"Continue",
083: /* 101 */"Switching Protocols",
084: /* 1xx */"Informational", }, {
085: /* 200 */"OK",
086: /* 201 */"Created",
087: /* 202 */"Accepted",
088: /* 203 */"Non-Authoritative Information",
089: /* 204 */"No Content",
090: /* 205 */"Reset Content",
091: /* 206 */"Partial Content",
092: /* 2xx */"Success", }, {
093: /* 300 */"Multiple Choices",
094: /* 301 */"Moved Permanently",
095: /* 302 */"Moved Temporarily",
096: /* 303 */"See Other",
097: /* 304 */"Not Modified",
098: /* 305 */"Use Proxy",
099: /* 3xx */"Redirection", }, {
100: /* 400 */"Bad Request",
101: /* 401 */"Unauthorized",
102: /* 402 */"Payment Required",
103: /* 403 */"Forbidden",
104: /* 404 */"Not Found",
105: /* 405 */"Method Not Allowed",
106: /* 406 */"Not Acceptable",
107: /* 407 */"Proxy Authentication Required",
108: /* 408 */"Request Time-out",
109: /* 409 */"Conflict",
110: /* 410 */"Gone",
111: /* 411 */"Length Required",
112: /* 412 */"Precondition Failed",
113: /* 413 */"Request Entity Too Large",
114: /* 414 */"Request-URI Too Large",
115: /* 415 */"Unsupported Media Type",
116: /* 4xx */"Client Error", }, {
117: /* 500 */"Internal Server Error",
118: /* 501 */"Not Implemented",
119: /* 502 */"Bad Gateway",
120: /* 503 */"Service Unavailable",
121: /* 504 */"Gateway Time-out",
122: /* 505 */"HTTP Version not supported",
123: /* 5xx */"Server Error", } };
124:
125: /**
126: * Get the default status message for a HTTP status code.
127: */
128: public static String getStatusMsg(int statusCode) {
129: int codeSet = (statusCode / 100);
130: int setIdx = statusCode - (codeSet * 100);
131: if ((codeSet <= 0) || (codeSet > statusMsgs.length)) {
132: return "Invalid status code";
133: }
134: if (setIdx >= statusMsgs[codeSet - 1].length) {
135: setIdx = statusMsgs[codeSet - 1].length - 1;
136: }
137: return statusMsgs[codeSet - 1][setIdx];
138: }
139: }
|