View Javadoc

1   /*
2    * Copyright (c) 2006-2007 Creative Sphere Limited.
3    * All rights reserved. This program and the accompanying materials
4    * are made available under the terms of the Eclipse Public License v1.0
5    * which accompanies this distribution, and is available at
6    * http://www.eclipse.org/legal/epl-v10.html
7    *
8    * Contributors:
9    *
10   *   Creative Sphere - initial API and implementation
11   *
12   */
13  package org.abstracthorizon.danube.http;
14  
15  /**
16   * This class descibes HTTP response status.
17   *
18   * @author Daniel Sendula
19   */
20  public class Status {
21  
22      public static final Status CONTINUE = new Status("100", "Continue");
23  
24      public static final Status OK = new Status("200", "OK");
25  
26      public static final Status CREATED = new Status("201", "Created");
27  
28      public static final Status NO_CONTENT = new Status("204", "No Content");
29  
30      public static final Status PARTIAL_CONTENT = new Status("206", "Partial Content");
31  
32      public static final Status MOVED_PERMANENTLY = new Status("301", "Moved Permanently");
33  
34      public static final Status FOUND = new Status("302", "Found");
35  
36      public static final Status SEE_OTHER = new Status("303", "See Other");
37  
38      public static final Status BAD_REQUEST = new Status("400", "Bad Request");
39  
40      public static final Status UNAUTHORIZED = new Status("401", "Unauthorized");
41  
42      public static final Status FORBIDDEN = new Status("403", "Forbidden");
43  
44      public static final Status NOT_FOUND = new Status("404", "Not Found");
45  
46      public static final Status METHOD_NOT_ALLOWED = new Status("405", "Method Not Allowed");
47  
48      public static final Status CONFLICT = new Status("409", "Conflict");
49  
50      public static final Status GONE = new Status("410", "Gone");
51  
52      public static final Status LENGTH_REQUIRED = new Status("411", "Length Required");
53  
54      public static final Status PRECONDITION_FAILED = new Status("412", "Precondition Failed");
55  
56      public static final Status UNSUPPORTED_MEDIA_TYPE = new Status("415", "Unsupported Media Type");
57  
58      public static final Status RANGE_NOT_SATISFIABLE = new Status("416", "Requested Range Not Satisfiable");
59  
60      public static final Status EXPECTATION_FAILED = new Status("417", "Expectation failed");
61  
62      public static final Status INTERNAL_SERVER_ERROR = new Status("500", "Internal Server Error");
63  
64      public static final Status NOT_IMPLEMENTED = new Status("501", "Not Implemented");
65  
66      /** Response code */
67      protected String code;
68  
69      /** Response message */
70      protected String message;
71  
72      /**
73       * Constructor
74       */
75      public Status() {
76      }
77  
78      /**
79       * Constructor
80       * @param statusCode status code
81       * @param statusMessage status message
82       */
83      public Status(String statusCode, String statusMessage) {
84          this.code = statusCode;
85          this.message = statusMessage;
86      }
87  
88      /**
89       * Returns status code
90       * @return status code
91       */
92      public String getCode() {
93          return code;
94      }
95  
96      /**
97       * Returns status message
98       * @return status message
99       */
100     public String getMessage() {
101         return message;
102     }
103 
104     /**
105      * Returns full status (code, space, message)
106      * @return full status (code, space, message)
107      */
108     public String getFullStatus() {
109         return code + " " + message;
110     }
111 
112     /**
113      * Returns status as a string
114      * @return status as a string
115      */
116     public String toString() {
117         return "Status[" + getFullStatus() + "]";
118     }
119 }