Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   //
   //  ========================================================================
   //  Copyright (c) 1995-2013 Mort Bay Consulting Pty. Ltd.
   //  ------------------------------------------------------------------------
   //  All rights reserved. This program and the accompanying materials
   //  are made available under the terms of the Eclipse Public License v1.0
   //  and Apache License v2.0 which accompanies this distribution.
   //
   //      The Eclipse Public License is available at
  //      http://www.eclipse.org/legal/epl-v10.html
  //
  //      The Apache License v2.0 is available at
  //      http://www.opensource.org/licenses/apache2.0.php
  //
  //  You may elect to redistribute this code under either of these licenses.
  //  ========================================================================
  //
  
  package org.eclipse.jetty.http;

HttpStatusCode enum class, for status codes based on various HTTP RFCs. (see table below)

EnumCodeMessage RFC 1945 - HTTP/1.0 RFC 2616 - HTTP/1.1 RFC 2518 - WEBDAV
Informational - 1xxisInformational(int)
CONTINUE_100100Continue  Sec. 10.1.1 
SWITCHING_PROTOCOLS_101101Switching Protocols  Sec. 10.1.2 
PROCESSING_102102Processing   Sec. 10.1
Success - 2xxisSuccess(int)
OK_200200OK Sec. 9.2 Sec. 10.2.1 
CREATED_201201Created Sec. 9.2 Sec. 10.2.2 
ACCEPTED_202202Accepted Sec. 9.2 Sec. 10.2.3 
NON_AUTHORITATIVE_INFORMATION_203203Non Authoritative Information  Sec. 10.2.4 
NO_CONTENT_204204No Content Sec. 9.2 Sec. 10.2.5 
RESET_CONTENT_205205Reset Content  Sec. 10.2.6 
PARTIAL_CONTENT_206206Partial Content  Sec. 10.2.7 
MULTI_STATUS_207207Multi-Status   Sec. 10.2
 207Partial Update OK  draft/01 
Redirection - 3xxisRedirection(int)
MULTIPLE_CHOICES_300300Multiple Choices Sec. 9.3 Sec. 10.3.1 
MOVED_PERMANENTLY_301301Moved Permanently Sec. 9.3 Sec. 10.3.2 
MOVED_TEMPORARILY_302302Moved Temporarily Sec. 9.3(now "302 Found") 
FOUND_302302Found(was "302 Moved Temporarily") Sec. 10.3.3 
SEE_OTHER_303303See Other  Sec. 10.3.4 
NOT_MODIFIED_304304Not Modified Sec. 9.3 Sec. 10.3.5 
USE_PROXY_305305Use Proxy  Sec. 10.3.6 
 306(Unused)  Sec. 10.3.7 
TEMPORARY_REDIRECT_307307Temporary Redirect  Sec. 10.3.8 
Client Error - 4xxisClientError(int)
BAD_REQUEST_400400Bad Request Sec. 9.4 Sec. 10.4.1 
UNAUTHORIZED_401401Unauthorized Sec. 9.4 Sec. 10.4.2 
PAYMENT_REQUIRED_402402Payment Required Sec. 9.4 Sec. 10.4.3 
FORBIDDEN_403403Forbidden Sec. 9.4 Sec. 10.4.4 
NOT_FOUND_404404Not Found Sec. 9.4 Sec. 10.4.5 
METHOD_NOT_ALLOWED_405405Method Not Allowed  Sec. 10.4.6 
NOT_ACCEPTABLE_406406Not Acceptable  Sec. 10.4.7 
PROXY_AUTHENTICATION_REQUIRED_407407Proxy Authentication Required  Sec. 10.4.8 
REQUEST_TIMEOUT_408408Request Timeout  Sec. 10.4.9 
CONFLICT_409409Conflict  Sec. 10.4.10  
GONE_410410Gone  Sec. 10.4.11  
LENGTH_REQUIRED_411411Length Required  Sec. 10.4.12  
PRECONDITION_FAILED_412412Precondition Failed  Sec. 10.4.13  
REQUEST_ENTITY_TOO_LARGE_413413Request Entity Too Large  Sec. 10.4.14  
REQUEST_URI_TOO_LONG_414414Request-URI Too Long  Sec. 10.4.15  
UNSUPPORTED_MEDIA_TYPE_415415Unsupported Media Type  Sec. 10.4.16  
REQUESTED_RANGE_NOT_SATISFIABLE_416416Requested Range Not Satisfiable  Sec. 10.4.17  
EXPECTATION_FAILED_417417Expectation Failed  Sec. 10.4.18  
 418Reauthentication Required  draft/01 
 418Unprocessable Entity   draft/05
 419Proxy Reauthentication Required</stike>  draft/01 
 419Insufficient Space on Resource</stike>   draft/05
 420Method Failure   draft/05
 421(Unused)   
UNPROCESSABLE_ENTITY_422422Unprocessable Entity   Sec. 10.3
LOCKED_423423Locked   Sec. 10.4
FAILED_DEPENDENCY_424424Failed Dependency   Sec. 10.5
Server Error - 5xxisServerError(int)
INTERNAL_SERVER_ERROR_500500Internal Server Error Sec. 9.5 Sec. 10.5.1 
NOT_IMPLEMENTED_501501Not Implemented Sec. 9.5 Sec. 10.5.2 
BAD_GATEWAY_502502Bad Gateway Sec. 9.5 Sec. 10.5.3 
SERVICE_UNAVAILABLE_503503Service Unavailable Sec. 9.5 Sec. 10.5.4 
GATEWAY_TIMEOUT_504504Gateway Timeout  Sec. 10.5.5 
HTTP_VERSION_NOT_SUPPORTED_505505HTTP Version Not Supported  Sec. 10.5.6 
 506(Unused)   
INSUFFICIENT_STORAGE_507507Insufficient Storage   Sec. 10.6

Version:
$Id$
 
 public class HttpStatus
 {
     public final static int CONTINUE_100 = 100;
     public final static int SWITCHING_PROTOCOLS_101 = 101;
     public final static int PROCESSING_102 = 102;
 
     public final static int OK_200 = 200;
     public final static int CREATED_201 = 201;
     public final static int ACCEPTED_202 = 202;
     public final static int NON_AUTHORITATIVE_INFORMATION_203 = 203;
     public final static int NO_CONTENT_204 = 204;
     public final static int RESET_CONTENT_205 = 205;
     public final static int PARTIAL_CONTENT_206 = 206;
     public final static int MULTI_STATUS_207 = 207;
 
     public final static int MULTIPLE_CHOICES_300 = 300;
     public final static int MOVED_PERMANENTLY_301 = 301;
     public final static int MOVED_TEMPORARILY_302 = 302;
     public final static int FOUND_302 = 302;
     public final static int SEE_OTHER_303 = 303;
     public final static int NOT_MODIFIED_304 = 304;
     public final static int USE_PROXY_305 = 305;
     public final static int TEMPORARY_REDIRECT_307 = 307;
 
     public final static int BAD_REQUEST_400 = 400;
     public final static int UNAUTHORIZED_401 = 401;
     public final static int PAYMENT_REQUIRED_402 = 402;
     public final static int FORBIDDEN_403 = 403;
     public final static int NOT_FOUND_404 = 404;
     public final static int METHOD_NOT_ALLOWED_405 = 405;
     public final static int NOT_ACCEPTABLE_406 = 406;
     public final static int PROXY_AUTHENTICATION_REQUIRED_407 = 407;
     public final static int REQUEST_TIMEOUT_408 = 408;
     public final static int CONFLICT_409 = 409;
     public final static int GONE_410 = 410;
     public final static int LENGTH_REQUIRED_411 = 411;
     public final static int PRECONDITION_FAILED_412 = 412;
     public final static int REQUEST_ENTITY_TOO_LARGE_413 = 413;
     public final static int REQUEST_URI_TOO_LONG_414 = 414;
     public final static int UNSUPPORTED_MEDIA_TYPE_415 = 415;
     public final static int REQUESTED_RANGE_NOT_SATISFIABLE_416 = 416;
     public final static int EXPECTATION_FAILED_417 = 417;
     public final static int UNPROCESSABLE_ENTITY_422 = 422;
     public final static int LOCKED_423 = 423;
     public final static int FAILED_DEPENDENCY_424 = 424;
 
     public final static int INTERNAL_SERVER_ERROR_500 = 500;
     public final static int NOT_IMPLEMENTED_501 = 501;
     public final static int BAD_GATEWAY_502 = 502;
     public final static int SERVICE_UNAVAILABLE_503 = 503;
     public final static int GATEWAY_TIMEOUT_504 = 504;
     public final static int HTTP_VERSION_NOT_SUPPORTED_505 = 505;
     public final static int INSUFFICIENT_STORAGE_507 = 507;
 
     public static final int MAX_CODE = 507;
 
 
     private static final Code[] codeMap = new Code[+1];
 
     static
     {
         for (Code code : Code.values())
         {
             [code._code] = code;
         }
     }
 
 
     public enum Code
     {
         /*
          * --------------------------------------------------------------------
          * Informational messages in 1xx series. As defined by ... RFC 1945 -
          * HTTP/1.0 RFC 2616 - HTTP/1.1 RFC 2518 - WebDAV
          */

        
100 Continue
 
         CONTINUE("Continue"),
        
101 Switching Protocols
 
         SWITCHING_PROTOCOLS("Switching Protocols"),
        
102 Processing
 
         PROCESSING("Processing"),
 
         /*
          * --------------------------------------------------------------------
          * Success messages in 2xx series. As defined by ... RFC 1945 - HTTP/1.0
          * RFC 2616 - HTTP/1.1 RFC 2518 - WebDAV
          */

        
200 OK
 
         OK("OK"),
        
201 Created
 
         CREATED("Created"),
        
202 Accepted
 
         ACCEPTED("Accepted"),
        
203 Non Authoritative Information
 
         NON_AUTHORITATIVE_INFORMATION("Non Authoritative Information"),
        
204 No Content
 
         NO_CONTENT("No Content"),
        
205 Reset Content
 
         RESET_CONTENT("Reset Content"),
        
206 Partial Content
 
         PARTIAL_CONTENT("Partial Content"),
        
207 Multi-Status
 
         MULTI_STATUS("Multi-Status"),
 
         /*
          * --------------------------------------------------------------------
          * Redirection messages in 3xx series. As defined by ... RFC 1945 -
          * HTTP/1.0 RFC 2616 - HTTP/1.1
          */

        
300 Mutliple Choices
 
         MULTIPLE_CHOICES("Multiple Choices"),
        
301 Moved Permanently
 
         MOVED_PERMANENTLY("Moved Permanently"),
        
302 Moved Temporarily
 
         MOVED_TEMPORARILY("Moved Temporarily"),
        
302 Found
 
         FOUND("Found"),
        
303 See Other
 
         SEE_OTHER("See Other"),
        
304 Not Modified
 
         NOT_MODIFIED("Not Modified"),
        
305 Use Proxy
 
         USE_PROXY("Use Proxy"),
        
307 Temporary Redirect
 
         TEMPORARY_REDIRECT("Temporary Redirect"),
 
         /*
          * --------------------------------------------------------------------
          * Client Error messages in 4xx series. As defined by ... RFC 1945 -
          * HTTP/1.0 RFC 2616 - HTTP/1.1 RFC 2518 - WebDAV
          */

        
400 Bad Request
 
         BAD_REQUEST("Bad Request"),
        
401 Unauthorized
 
         UNAUTHORIZED("Unauthorized"),
        
402 Payment Required
 
         PAYMENT_REQUIRED("Payment Required"),
        
403 Forbidden
 
         FORBIDDEN("Forbidden"),
        
404 Not Found
 
         NOT_FOUND("Not Found"),
        
405 Method Not Allowed
 
         METHOD_NOT_ALLOWED("Method Not Allowed"),
        
406 Not Acceptable
 
         NOT_ACCEPTABLE("Not Acceptable"),
        
407 Proxy Authentication Required
 
         PROXY_AUTHENTICATION_REQUIRED("Proxy Authentication Required"),
        
408 Request Timeout
 
         REQUEST_TIMEOUT("Request Timeout"),
        
409 Conflict
 
         CONFLICT("Conflict"),
        
410 Gone
 
         GONE("Gone"),
        
411 Length Required
 
         LENGTH_REQUIRED("Length Required"),
        
412 Precondition Failed
 
         PRECONDITION_FAILED("Precondition Failed"),
        
413 Request Entity Too Large
 
         REQUEST_ENTITY_TOO_LARGE("Request Entity Too Large"),
        
414 Request-URI Too Long
 
         REQUEST_URI_TOO_LONG("Request-URI Too Long"),
        
415 Unsupported Media Type
 
         UNSUPPORTED_MEDIA_TYPE("Unsupported Media Type"),
        
416 Requested Range Not Satisfiable
 
         REQUESTED_RANGE_NOT_SATISFIABLE("Requested Range Not Satisfiable"),
        
417 Expectation Failed
 
         EXPECTATION_FAILED("Expectation Failed"),
        
422 Unprocessable Entity
 
         UNPROCESSABLE_ENTITY("Unprocessable Entity"),
        
423 Locked
 
         LOCKED("Locked"),
        
424 Failed Dependency
 
         FAILED_DEPENDENCY("Failed Dependency"),
 
         /*
          * --------------------------------------------------------------------
          * Server Error messages in 5xx series. As defined by ... RFC 1945 -
          * HTTP/1.0 RFC 2616 - HTTP/1.1 RFC 2518 - WebDAV
          */

        
500 Server Error
 
         INTERNAL_SERVER_ERROR("Server Error"),
        
501 Not Implemented
 
         NOT_IMPLEMENTED("Not Implemented"),
        
502 Bad Gateway
 
         BAD_GATEWAY("Bad Gateway"),
        
503 Service Unavailable
 
         SERVICE_UNAVAILABLE("Service Unavailable"),
        
504 Gateway Timeout
 
         GATEWAY_TIMEOUT("Gateway Timeout"),
        
505 HTTP Version Not Supported
 
         HTTP_VERSION_NOT_SUPPORTED("HTTP Version Not Supported"),
        
507 Insufficient Storage
 
         INSUFFICIENT_STORAGE("Insufficient Storage");
 
         private final int _code;
         private final String _message;
 
         private Code(int codeString message)
         {
             this. = code;
             =message;
         }
 
         public int getCode()
         {
             return ;
         }
 
         public String getMessage()
         {
             return ;
         }
 
 
         public boolean equals(int code)
         {
             return (this. == code);
         }
 
         @Override
         public String toString()
         {
             return String.format("[%03d %s]",this.,this.getMessage());
         }

        
Simple test against an code to determine if it falls into the Informational message category as defined in the RFC 1945 - HTTP/1.0, and RFC 2616 - HTTP/1.1.

Returns:
true if within range of codes that belongs to Informational messages.
 
         public boolean isInformational()
         {
             return HttpStatus.isInformational(this.);
         }

        
Simple test against an code to determine if it falls into the Success message category as defined in the RFC 1945 - HTTP/1.0, and RFC 2616 - HTTP/1.1.

Returns:
true if within range of codes that belongs to Success messages.
 
         public boolean isSuccess()
         {
             return HttpStatus.isSuccess(this.);
         }

        
Simple test against an code to determine if it falls into the Redirection message category as defined in the RFC 1945 - HTTP/1.0, and RFC 2616 - HTTP/1.1.

Returns:
true if within range of codes that belongs to Redirection messages.
 
         public boolean isRedirection()
         {
             return HttpStatus.isRedirection(this.);
         }

        
Simple test against an code to determine if it falls into the Client Error message category as defined in the RFC 1945 - HTTP/1.0, and RFC 2616 - HTTP/1.1.

Returns:
true if within range of codes that belongs to Client Error messages.
 
         public boolean isClientError()
         {
             return HttpStatus.isClientError(this.);
         }

        
Simple test against an code to determine if it falls into the Server Error message category as defined in the RFC 1945 - HTTP/1.0, and RFC 2616 - HTTP/1.1.

Returns:
true if within range of codes that belongs to Server Error messages.
 
         public boolean isServerError()
         {
             return HttpStatus.isServerError(this.);
         }
     }


    
Get the HttpStatusCode for a specific code

Parameters:
code the code to lookup.
Returns:
the HttpStatus if found, or null if not found.
 
     public static Code getCode(int code)
     {
         if (code <= )
         {
             return [code];
         }
         return null;
     }

    
Get the status message for a specific code.

Parameters:
code the code to look up
Returns:
the specific message, or the code number itself if code does not match known list.
 
     public static String getMessage(int code)
     {
         Code codeEnum = getCode(code);
         if (codeEnum != null)
         {
             return codeEnum.getMessage();
         }
         else
         {
             return Integer.toString(code);
         }
     }

    
Simple test against an code to determine if it falls into the Informational message category as defined in the RFC 1945 - HTTP/1.0, and RFC 2616 - HTTP/1.1.

Parameters:
code the code to test.
Returns:
true if within range of codes that belongs to Informational messages.
 
     public static boolean isInformational(int code)
     {
         return ((100 <= code) && (code <= 199));
     }

    
Simple test against an code to determine if it falls into the Success message category as defined in the RFC 1945 - HTTP/1.0, and RFC 2616 - HTTP/1.1.

Parameters:
code the code to test.
Returns:
true if within range of codes that belongs to Success messages.
 
     public static boolean isSuccess(int code)
     {
         return ((200 <= code) && (code <= 299));
     }

    
Simple test against an code to determine if it falls into the Redirection message category as defined in the RFC 1945 - HTTP/1.0, and RFC 2616 - HTTP/1.1.

Parameters:
code the code to test.
Returns:
true if within range of codes that belongs to Redirection messages.
 
    public static boolean isRedirection(int code)
    {
        return ((300 <= code) && (code <= 399));
    }

    
Simple test against an code to determine if it falls into the Client Error message category as defined in the RFC 1945 - HTTP/1.0, and RFC 2616 - HTTP/1.1.

Parameters:
code the code to test.
Returns:
true if within range of codes that belongs to Client Error messages.
    public static boolean isClientError(int code)
    {
        return ((400 <= code) && (code <= 499));
    }

    
Simple test against an code to determine if it falls into the Server Error message category as defined in the RFC 1945 - HTTP/1.0, and RFC 2616 - HTTP/1.1.

Parameters:
code the code to test.
Returns:
true if within range of codes that belongs to Server Error messages.
    public static boolean isServerError(int code)
    {
        return ((500 <= code) && (code <= 599));
    }
New to GrepCode? Check out our FAQ X