KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > lutris > http > HttpStatus


1
2 /*
3  * Enhydra Java Application Server Project
4  *
5  * The contents of this file are subject to the Enhydra Public License
6  * Version 1.1 (the "License"); you may not use this file except in
7  * compliance with the License. You may obtain a copy of the License on
8  * the Enhydra web site ( http://www.enhydra.org/ ).
9  *
10  * Software distributed under the License is distributed on an "AS IS"
11  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
12  * the License for the specific terms governing rights and limitations
13  * under the License.
14  *
15  * The Initial Developer of the Enhydra Application Server is Lutris
16  * Technologies, Inc. The Enhydra Application Server and portions created
17  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
18  * All Rights Reserved.
19  *
20  * Contributor(s):
21  *
22  * $Id: HttpStatus.java,v 1.1 2004/04/21 19:31:58 slobodan Exp $
23  */

24
25
26
27
28
29 package com.lutris.http;
30
31 public class HttpStatus {
32
33     // Informational
34
public final static int doContinue = 100;
35     public final static int switchingProtocols = 101;
36
37     // Success
38
public final static int ok = 200;
39     public final static int created = 201;
40     public final static int accepted = 202;
41     public final static int nonAuthoritativeInformation = 203;
42     public final static int noContent = 204;
43     public final static int resetContent = 205;
44     public final static int partialContent = 206;
45
46     // Redirection
47
public final static int multipleChoices = 300;
48     public final static int movedPermanently = 301;
49     public final static int movedTemporarily = 302;
50     public final static int seeOther = 303;
51     public final static int notModified = 304;
52     public final static int useProxy = 305;
53
54     // Client error
55
public final static int badRequest = 400;
56     public final static int unauthorized = 401;
57     public final static int paymentRequired = 402;
58     public final static int forbidden = 403;
59     public final static int notFound = 404;
60     public final static int methodNotAllowed = 405;
61     public final static int notAcceptable = 406;
62     public final static int proxyAuthenticationRequired = 407;
63     public final static int requestTimeout = 408;
64     public final static int conflict = 409;
65     public final static int gone = 410;
66     public final static int lenghtRequired = 411;
67     public final static int preconditionFailed = 412;
68     public final static int requestEntityTooLarge = 413;
69     public final static int requestUriTooLarge = 414;
70     public final static int unsupportedMediaType = 415;
71
72     // Server error
73
public final static int internalServerError = 500;
74     public final static int notImplemented = 501;
75     public final static int badGateway = 502;
76     public final static int serviceUnavailable = 503;
77     public final static int gatewayTimeout = 504;
78     public final static int httpVersionNotSupported = 505;
79
80     /*
81      * Table of default messages. First dimension is indexed by
82      * (code / 100) - 1 and second diminsion by the remainder, with
83      * the last element of each class being a default value if
84      * the status code is past the end.
85      */

86     private static final String JavaDoc[][] statusMsgs = {
87         {
88             /* 100 */ "Continue",
89             /* 101 */ "Switching Protocols",
90             /* 1xx */ "Informational",
91         }, {
92             /* 200 */ "OK",
93             /* 201 */ "Created",
94             /* 202 */ "Accepted",
95             /* 203 */ "Non-Authoritative Information",
96             /* 204 */ "No Content",
97             /* 205 */ "Reset Content",
98             /* 206 */ "Partial Content",
99             /* 2xx */ "Success",
100         }, {
101             /* 300 */ "Multiple Choices",
102             /* 301 */ "Moved Permanently",
103             /* 302 */ "Moved Temporarily",
104             /* 303 */ "See Other",
105             /* 304 */ "Not Modified",
106             /* 305 */ "Use Proxy",
107             /* 3xx */ "Redirection",
108         }, {
109             /* 400 */ "Bad Request",
110             /* 401 */ "Unauthorized",
111             /* 402 */ "Payment Required",
112             /* 403 */ "Forbidden",
113             /* 404 */ "Not Found",
114             /* 405 */ "Method Not Allowed",
115             /* 406 */ "Not Acceptable",
116             /* 407 */ "Proxy Authentication Required",
117             /* 408 */ "Request Time-out",
118             /* 409 */ "Conflict",
119             /* 410 */ "Gone",
120             /* 411 */ "Length Required",
121             /* 412 */ "Precondition Failed",
122             /* 413 */ "Request Entity Too Large",
123             /* 414 */ "Request-URI Too Large",
124             /* 415 */ "Unsupported Media Type",
125             /* 4xx */ "Client Error",
126         }, {
127             /* 500 */ "Internal Server Error",
128             /* 501 */ "Not Implemented",
129             /* 502 */ "Bad Gateway",
130             /* 503 */ "Service Unavailable",
131             /* 504 */ "Gateway Time-out",
132             /* 505 */ "HTTP Version not supported",
133             /* 5xx */ "Server Error",
134         }
135     };
136
137     /**
138      * Get the default status message for a HTTP status code.
139      */

140     public static String JavaDoc getStatusMsg(int statusCode) {
141         int codeSet = (statusCode / 100);
142         int setIdx = statusCode - (codeSet * 100);
143         if ((codeSet <= 0) || (codeSet > statusMsgs.length)) {
144             return "Invalid status code";
145         }
146         if (setIdx >= statusMsgs[codeSet-1].length) {
147             setIdx = statusMsgs[codeSet-1].length - 1;
148         }
149         return statusMsgs[codeSet-1][setIdx];
150     }
151 }
152
Popular Tags