View Javadoc
1   /*
2    *  Licensed to the Apache Software Foundation (ASF) under one
3    *  or more contributor license agreements.  See the NOTICE file
4    *  distributed with this work for additional information
5    *  regarding copyright ownership.  The ASF licenses this file
6    *  to you under the Apache License, Version 2.0 (the
7    *  "License"); you may not use this file except in compliance
8    *  with the License.  You may obtain a copy of the License at
9    *  
10   *    http://www.apache.org/licenses/LICENSE-2.0
11   *  
12   *  Unless required by applicable law or agreed to in writing,
13   *  software distributed under the License is distributed on an
14   *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   *  KIND, either express or implied.  See the License for the
16   *  specific language governing permissions and limitations
17   *  under the License. 
18   *  
19   */
20  package org.apache.mina.http.api;
21  
22  /**
23   * An <code>Enumeration</code> of all known HTTP status codes.
24   * 
25   * @author <a href="http://mina.apache.org">Apache MINA Project</a>
26   */
27  public enum HttpStatus {
28  
29      /**
30       * 100 - Continue
31       */
32      INFORMATIONAL_CONTINUE(100, "HTTP/1.1 100 Continue"),
33      /**
34       * 101 - Switching Protocols
35       */
36      INFORMATIONAL_SWITCHING_PROTOCOLS(101, "HTTP/1.1 101 Swtiching Protocols"),
37      /**
38       * 200 - OK
39       */
40      SUCCESS_OK(200, "HTTP/1.1 200 OK"),
41      /**
42       * 201 - Created
43       */
44      SUCCESS_CREATED(201, "HTTP/1.1 201 Created"),
45      /**
46       * 202 - Accepted
47       */
48      SUCCESS_ACCEPTED(202, "HTTP/1.1 202 Accepted"),
49      /**
50       * 203 - Non-Authoritative Information
51       */
52      SUCCESS_NON_AUTHORATIVE_INFORMATION(203, "HTTP/1.1 203 Non-Authoritative Information"),
53      /**
54       * 204 - No Content
55       */
56      SUCCESS_NO_CONTENT(204, "HTTP/1.1 204 No Content"),
57      /**
58       * 205 - Reset Content
59       */
60      SUCCESS_RESET_CONTENT(205, "HTTP/1.1 205 Reset Content"),
61      /**
62       * 206 - Created
63       */
64      SUCCESS_PARTIAL_CONTENT(206, "HTTP/1.1 206 Partial Content"),
65  
66      /**
67       * 300 - Multiple Choices
68       */
69      REDIRECTION_MULTIPLE_CHOICES(300, "HTTP/1.1 300 Multiple Choices"),
70      /**
71       * 301 - Moved Permanently
72       */
73      REDIRECTION_MOVED_PERMANENTLY(301, "HTTP/1.1 301 Moved Permanently"),
74      /**
75       * 302 - Found / Moved Temporarily
76       */
77      REDIRECTION_FOUND(302, "HTTP/1.1 302 Found"),
78      /**
79       * 303 - See Others
80       */
81      REDIRECTION_SEE_OTHER(303, "HTTP/1.1 303 See Other"),
82      /**
83       * 304 - Not Modified
84       */
85      REDIRECTION_NOT_MODIFIED(304, "HTTP/1.1 304 Not Modified"),
86      /**
87       * 305 - Use Proxy
88       */
89      REDIRECTION_USE_PROXY(305, "HTTP/1.1 305 Use Proxy"),
90      /**
91       * 307 - Temporary Redirect
92       */
93      REDIRECTION_TEMPORARILY_REDIRECT(307, "HTTP/1.1 307 Temporary Redirect"),
94  
95      /**
96       * 400 - Bad Request
97       */
98      CLIENT_ERROR_BAD_REQUEST(400, "HTTP/1.1 400 Bad Request"),
99      /**
100      * 401 - Unauthorized
101      */
102     CLIENT_ERROR_UNAUTHORIZED(401, "HTTP/1.1 401 Unauthorized"),
103     /**
104      * 403 - Forbidden
105      */
106     CLIENT_ERROR_FORBIDDEN(403, "HTTP/1.1 403 Forbidden"),
107     /**
108      * 404 - Not Found
109      */
110     CLIENT_ERROR_NOT_FOUND(404, "HTTP/1.1 404 Not Found"),
111     /**
112      * 405 - Method Not Allowed
113      */
114     CLIENT_ERROR_METHOD_NOT_ALLOWED(405, "HTTP/1.1 405 Method Not Allowed"),
115     /**
116      * 406 - Not Acceptable
117      */
118     CLIENT_ERROR_NOT_ACCEPTABLE(406, "HTTP/1.1 406 Not Acceptable"),
119     /**
120      * 407 - Proxy Authentication Required
121      */
122     CLIENT_ERROR_PROXY_AUTHENTICATION_REQUIRED(407, "HTTP/1.1 407 Proxy Authentication Required"),
123     /**
124      * 408 - Request Timeout
125      */
126     CLIENT_ERROR_REQUEST_TIMEOUT(408, "HTTP/1.1 408 Request Timeout"),
127     /**
128      * 409 - Conflict
129      */
130     CLIENT_ERROR_CONFLICT(409, "HTTP/1.1 409 Conflict"),
131     /**
132      * 410 - Gone
133      */
134     CLIENT_ERROR_GONE(410, "HTTP/1.1 410 Gone"),
135     /**
136      * 411 - Length Required
137      */
138     CLIENT_ERROR_LENGTH_REQUIRED(411, "HTTP/1.1 411 Length Required"),
139     /**
140      * 412 - Precondition Failed
141      */
142     CLIENT_ERROR_PRECONDITION_FAILED(412, "HTTP/1.1 412 Precondition Failed"),
143     /**
144      * 413 - Request Entity Too Large
145      */
146     CLIENT_ERROR_REQUEST_ENTITY_TOO_LARGE(413, "HTTP/1.1 413 Request Entity Too Large"),
147     /**
148      * 414 - Bad Request
149      */
150     CLIENT_ERROR_REQUEST_URI_TOO_LONG(414, "HTTP/1.1 414 Request-URI Too Long"),
151     /**
152      * 415 - Unsupported Media Type
153      */
154     CLIENT_ERROR_UNSUPPORTED_MEDIA_TYPE(415, "HTTP/1.1 415 Unsupported Media Type"),
155     /**
156      * 416 - Requested Range Not Satisfiable
157      */
158     CLIENT_ERROR_REQUESTED_RANGE_NOT_SATISFIABLE(416, "HTTP/1.1 416 Requested Range Not Satisfiable"),
159     /**
160      * 417 - Expectation Failed
161      */
162     CLIENT_ERROR_EXPECTATION_FAILED(417, "HTTP/1.1 417 Expectation Failed"),
163 
164     /**
165      * 500 - Internal Server Error
166      */
167     SERVER_ERROR_INTERNAL_SERVER_ERROR(500, "HTTP/1.1 500 Internal Server Error"),
168     /**
169      * 501 - Not Implemented
170      */
171     SERVER_ERROR_NOT_IMPLEMENTED(501, "HTTP/1.1 501 Not Implemented"),
172     /**
173      * 502 - Bad Gateway
174      */
175     SERVER_ERROR_BAD_GATEWAY(502, "HTTP/1.1 502 Bad Gateway"),
176     /**
177      * 503 - Service Unavailable
178      */
179     SERVER_ERROR_SERVICE_UNAVAILABLE(503, "HTTP/1.1 503 Service Unavailable"),
180     /**
181      * 504 - Gateway Timeout
182      */
183     SERVER_ERROR_GATEWAY_TIMEOUT(504, "HTTP/1.1 504 Gateway Timeout"),
184     /**
185      * 505 - HTTP Version Not Supported
186      */
187     SERVER_ERROR_HTTP_VERSION_NOT_SUPPORTED(505, "HTTP/1.1 505 HTTP Version Not Supported");
188 
189     /** The code associated with this status, for example "404" for "Not Found". */
190     private int code;
191 
192     /**
193      * The line associated with this status, "HTTP/1.1 501 Not Implemented".
194      */
195     private String line;
196 
197     /**
198      * Create an instance of this type.
199      * 
200      * @param code the status code.
201      * @param phrase the associated phrase.
202      */
203     private HttpStatus(int code, String phrase) {
204         this.code = code;
205         line = phrase;
206     }
207 
208     /**
209      * Retrieve the status code for this instance.
210      * 
211      * @return the status code.
212      */
213     public int code() {
214         return code;
215     }
216 
217     /**
218      * Retrieve the status line for this instance.
219      * 
220      * @return the status line.
221      */
222     public String line() {
223         return line + "\r\n";
224     }
225 }