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  public enum HttpStatus {
26  
27      /**
28       * 200 - OK
29       */
30      SUCCESS_OK(200, "HTTP/1.1 200 OK"),
31      /**
32       * 201 - Created
33       */
34      SUCCESS_CREATED(201, "HTTP/1.1 201 Created"),
35      /**
36       * 202 - Accepted
37       */
38      SUCCESS_ACCEPTED(202, "HTTP/1.1 202 Accepted"),
39      /**
40       * 203 - Non-Authoritative Information
41       */
42      SUCCESS_NON_AUTHORATIVE_INFORMATION(203, "HTTP/1.1 203 Non-Authoritative Information"),
43      /**
44       * 204 - No Content
45       */
46      SUCCESS_NO_CONTENT(204, "HTTP/1.1 204 No Content"),
47      /**
48       * 205 - Reset Content
49       */
50      SUCCESS_RESET_CONTENT(205, "HTTP/1.1 205 Reset Content"),
51      /**
52       * 206 - Created
53       */
54      SUCCESS_PARTIAL_CONTENT(206, "HTTP/1.1 206 Partial Content"),
55  
56      /**
57       * 300 - Multiple Choices
58       */
59      REDIRECTION_MULTIPLE_CHOICES(300, "HTTP/1.1 300 Multiple Choices"),
60      /**
61       * 301 - Moved Permanently
62       */
63      REDIRECTION_MOVED_PERMANENTLY(301, "HTTP/1.1 301 Moved Permanently"),
64      /**
65       * 302 - Found / Moved Temporarily
66       */
67      REDIRECTION_FOUND(302, "HTTP/1.1 302 Found"),
68      /**
69       * 303 - See Others
70       */
71      REDIRECTION_SEE_OTHER(303, "HTTP/1.1 303 See Other"),
72      /**
73       * 304 - Not Modified
74       */
75      REDIRECTION_NOT_MODIFIED(304, "HTTP/1.1 304 Not Modified"),
76      /**
77       * 305 - Use Proxy
78       */
79      REDIRECTION_USE_PROXY(305, "HTTP/1.1 305 Use Proxy"),
80      /**
81       * 307 - Temporary Redirect
82       */
83      REDIRECTION_TEMPORARILY_REDIRECT(307, "HTTP/1.1 307 Temporary Redirect"),
84  
85      /**
86       * 400 - Bad Request
87       */
88      CLIENT_ERROR_BAD_REQUEST(400, "HTTP/1.1 400 Bad Request"),
89      /**
90       * 401 - Unauthorized
91       */
92      CLIENT_ERROR_UNAUTHORIZED(401, "HTTP/1.1 401 Unauthorized"),
93      /**
94       * 403 - Forbidden
95       */
96      CLIENT_ERROR_FORBIDDEN(403, "HTTP/1.1 403 Forbidden"),
97      /**
98       * 404 - Not Found
99       */
100     CLIENT_ERROR_NOT_FOUND(404, "HTTP/1.1 404 Not Found"),
101     /**
102      * 405 - Method Not Allowed
103      */
104     CLIENT_ERROR_METHOD_NOT_ALLOWED(405, "HTTP/1.1 405 Method Not Allowed"),
105     /**
106      * 406 - Not Acceptable
107      */
108     CLIENT_ERROR_NOT_ACCEPTABLE(406, "HTTP/1.1 406 Not Acceptable"),
109     /**
110      * 407 - Proxy Authentication Required
111      */
112     CLIENT_ERROR_PROXY_AUTHENTICATION_REQUIRED(407, "HTTP/1.1 407 Proxy Authentication Required"),
113     /**
114      * 408 - Request Timeout
115      */
116     CLIENT_ERROR_REQUEST_TIMEOUT(408, "HTTP/1.1 408 Request Timeout"),
117     /**
118      * 409 - Conflict
119      */
120     CLIENT_ERROR_CONFLICT(409, "HTTP/1.1 409 Conflict"),
121     /**
122      * 410 - Gone
123      */
124     CLIENT_ERROR_GONE(410, "HTTP/1.1 410 Gone"),
125     /**
126      * 411 - Length Required
127      */
128     CLIENT_ERROR_LENGTH_REQUIRED(411, "HTTP/1.1 411 Length Required"),
129     /**
130      * 412 - Precondition Failed
131      */
132     CLIENT_ERROR_PRECONDITION_FAILED(412, "HTTP/1.1 412 Precondition Failed"),
133     /**
134      * 413 - Request Entity Too Large
135      */
136     CLIENT_ERROR_REQUEST_ENTITY_TOO_LARGE(413, "HTTP/1.1 413 Request Entity Too Large"),
137     /**
138      * 414 - Bad Request
139      */
140     CLIENT_ERROR_REQUEST_URI_TOO_LONG(414, "HTTP/1.1 414 Request-URI Too Long"),
141     /**
142      * 415 - Unsupported Media Type
143      */
144     CLIENT_ERROR_UNSUPPORTED_MEDIA_TYPE(415, "HTTP/1.1 415 Unsupported Media Type"),
145     /**
146      * 416 - Requested Range Not Satisfiable
147      */
148     CLIENT_ERROR_REQUESTED_RANGE_NOT_SATISFIABLE(416, "HTTP/1.1 416 Requested Range Not Satisfiable"),
149     /**
150      * 417 - Expectation Failed
151      */
152     CLIENT_ERROR_EXPECTATION_FAILED(417, "HTTP/1.1 417 Expectation Failed"),
153 
154     /**
155      * 500 - Internal Server Error
156      */
157     SERVER_ERROR_INTERNAL_SERVER_ERROR(500, "HTTP/1.1 500 Internal Server Error"),
158     /**
159      * 501 - Not Implemented
160      */
161     SERVER_ERROR_NOT_IMPLEMENTED(501, "HTTP/1.1 501 Not Implemented"),
162     /**
163      * 502 - Bad Gateway
164      */
165     SERVER_ERROR_BAD_GATEWAY(502, "HTTP/1.1 502 Bad Gateway"),
166     /**
167      * 503 - Service Unavailable
168      */
169     SERVER_ERROR_SERVICE_UNAVAILABLE(503, "HTTP/1.1 503 Service Unavailable"),
170     /**
171      * 504 - Gateway Timeout
172      */
173     SERVER_ERROR_GATEWAY_TIMEOUT(504, "HTTP/1.1 504 Gateway Timeout"),
174     /**
175      * 505 - HTTP Version Not Supported
176      */
177     SERVER_ERROR_HTTP_VERSION_NOT_SUPPORTED(505, "HTTP/1.1 505 HTTP Version Not Supported");
178 
179     /** The code associated with this status, for example "404" for "Not Found". */
180     private int code;
181 
182     /**
183      * The line associated with this status, "HTTP/1.1 501 Not Implemented".
184      */
185     private String line;
186 
187     /**
188      * Create an instance of this type.
189      * 
190      * @param code the status code.
191      * @param phrase the associated phrase.
192      */
193     private HttpStatus(int code, String phrase) {
194         this.code = code;
195         line = phrase;
196     }
197 
198     /**
199      * Retrieve the status code for this instance.
200      * 
201      * @return the status code.
202      */
203     public int code() {
204         return code;
205     }
206 
207     /**
208      * Retrieve the status line for this instance.
209      * 
210      * @return the status line.
211      */
212     public String line() {
213         return line + "\r\n";
214     }
215 }