2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 package gr.ebs.gss.server.webdav;
19 import java.util.Hashtable;
21 import javax.servlet.http.HttpServletResponse;
24 * Wraps the HttpServletResponse class to abstract the
25 * specific protocol used. To support other protocols
26 * we would only need to modify this class and the
27 * WebDavRetCode classes.
30 * @version 1.0, 16 Nov 1997
35 // ----------------------------------------------------- Instance Variables
39 * This Hashtable contains the mapping of HTTP and WebDAV
40 * status codes to descriptive text. This is a static
43 private static Hashtable<Integer,String> mapStatusCodes =
44 new Hashtable<Integer,String>();
47 // ------------------------------------------------------ HTTP Status Codes
51 * Status code (200) indicating the request succeeded normally.
53 public static final int SC_OK = HttpServletResponse.SC_OK;
57 * Status code (201) indicating the request succeeded and created
58 * a new resource on the server.
60 public static final int SC_CREATED = HttpServletResponse.SC_CREATED;
64 * Status code (202) indicating that a request was accepted for
65 * processing, but was not completed.
67 public static final int SC_ACCEPTED = HttpServletResponse.SC_ACCEPTED;
71 * Status code (204) indicating that the request succeeded but that
72 * there was no new information to return.
74 public static final int SC_NO_CONTENT = HttpServletResponse.SC_NO_CONTENT;
78 * Status code (301) indicating that the resource has permanently
79 * moved to a new location, and that future references should use a
80 * new URI with their requests.
82 public static final int SC_MOVED_PERMANENTLY =
83 HttpServletResponse.SC_MOVED_PERMANENTLY;
87 * Status code (302) indicating that the resource has temporarily
88 * moved to another location, but that future references should
89 * still use the original URI to access the resource.
91 public static final int SC_MOVED_TEMPORARILY =
92 HttpServletResponse.SC_MOVED_TEMPORARILY;
96 * Status code (304) indicating that a conditional GET operation
97 * found that the resource was available and not modified.
99 public static final int SC_NOT_MODIFIED =
100 HttpServletResponse.SC_NOT_MODIFIED;
104 * Status code (400) indicating the request sent by the client was
105 * syntactically incorrect.
107 public static final int SC_BAD_REQUEST =
108 HttpServletResponse.SC_BAD_REQUEST;
112 * Status code (401) indicating that the request requires HTTP
115 public static final int SC_UNAUTHORIZED =
116 HttpServletResponse.SC_UNAUTHORIZED;
120 * Status code (403) indicating the server understood the request
121 * but refused to fulfill it.
123 public static final int SC_FORBIDDEN = HttpServletResponse.SC_FORBIDDEN;
127 * Status code (404) indicating that the requested resource is not
130 public static final int SC_NOT_FOUND = HttpServletResponse.SC_NOT_FOUND;
134 * Status code (500) indicating an error inside the HTTP service
135 * which prevented it from fulfilling the request.
137 public static final int SC_INTERNAL_SERVER_ERROR =
138 HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
142 * Status code (501) indicating the HTTP service does not support
143 * the functionality needed to fulfill the request.
145 public static final int SC_NOT_IMPLEMENTED =
146 HttpServletResponse.SC_NOT_IMPLEMENTED;
150 * Status code (502) indicating that the HTTP server received an
151 * invalid response from a server it consulted when acting as a
154 public static final int SC_BAD_GATEWAY =
155 HttpServletResponse.SC_BAD_GATEWAY;
159 * Status code (503) indicating that the HTTP service is
160 * temporarily overloaded, and unable to handle the request.
162 public static final int SC_SERVICE_UNAVAILABLE =
163 HttpServletResponse.SC_SERVICE_UNAVAILABLE;
167 * Status code (100) indicating the client may continue with
168 * its request. This interim response is used to inform the
169 * client that the initial part of the request has been
170 * received and has not yet been rejected by the server.
172 public static final int SC_CONTINUE = 100;
176 * Status code (405) indicating the method specified is not
177 * allowed for the resource.
179 public static final int SC_METHOD_NOT_ALLOWED = 405;
183 * Status code (409) indicating that the request could not be
184 * completed due to a conflict with the current state of the
187 public static final int SC_CONFLICT = 409;
191 * Status code (412) indicating the precondition given in one
192 * or more of the request-header fields evaluated to false
193 * when it was tested on the server.
195 public static final int SC_PRECONDITION_FAILED = 412;
199 * Status code (413) indicating the server is refusing to
200 * process a request because the request entity is larger
201 * than the server is willing or able to process.
203 public static final int SC_REQUEST_TOO_LONG = 413;
207 * Status code (415) indicating the server is refusing to service
208 * the request because the entity of the request is in a format
209 * not supported by the requested resource for the requested
212 public static final int SC_UNSUPPORTED_MEDIA_TYPE = 415;
215 // -------------------------------------------- Extended WebDav status code
219 * Status code (207) indicating that the response requires
220 * providing status for multiple independent operations.
222 public static final int SC_MULTI_STATUS = 207;
223 // This one colides with HTTP 1.1
224 // "207 Parital Update OK"
228 * Status code (418) indicating the entity body submitted with
229 * the PATCH method was not understood by the resource.
231 public static final int SC_UNPROCESSABLE_ENTITY = 418;
232 // This one colides with HTTP 1.1
233 // "418 Reauthentication Required"
237 * Status code (419) indicating that the resource does not have
238 * sufficient space to record the state of the resource after the
239 * execution of this method.
241 public static final int SC_INSUFFICIENT_SPACE_ON_RESOURCE = 419;
242 // This one colides with HTTP 1.1
243 // "419 Proxy Reauthentication Required"
247 * Status code (420) indicating the method was not executed on
248 * a particular resource within its scope because some part of
249 * the method's execution failed causing the entire method to be
252 public static final int SC_METHOD_FAILURE = 420;
256 * Status code (423) indicating the destination resource of a
257 * method is locked, and either the request did not contain a
258 * valid Lock-Info header, or the Lock-Info header identifies
259 * a lock held by another principal.
261 public static final int SC_LOCKED = 423;
264 // ------------------------------------------------------------ Initializer
268 // HTTP 1.0 tatus Code
269 addStatusCodeMap(SC_OK, "OK");
270 addStatusCodeMap(SC_CREATED, "Created");
271 addStatusCodeMap(SC_ACCEPTED, "Accepted");
272 addStatusCodeMap(SC_NO_CONTENT, "No Content");
273 addStatusCodeMap(SC_MOVED_PERMANENTLY, "Moved Permanently");
274 addStatusCodeMap(SC_MOVED_TEMPORARILY, "Moved Temporarily");
275 addStatusCodeMap(SC_NOT_MODIFIED, "Not Modified");
276 addStatusCodeMap(SC_BAD_REQUEST, "Bad Request");
277 addStatusCodeMap(SC_UNAUTHORIZED, "Unauthorized");
278 addStatusCodeMap(SC_FORBIDDEN, "Forbidden");
279 addStatusCodeMap(SC_NOT_FOUND, "Not Found");
280 addStatusCodeMap(SC_INTERNAL_SERVER_ERROR, "Internal Server Error");
281 addStatusCodeMap(SC_NOT_IMPLEMENTED, "Not Implemented");
282 addStatusCodeMap(SC_BAD_GATEWAY, "Bad Gateway");
283 addStatusCodeMap(SC_SERVICE_UNAVAILABLE, "Service Unavailable");
284 addStatusCodeMap(SC_CONTINUE, "Continue");
285 addStatusCodeMap(SC_METHOD_NOT_ALLOWED, "Method Not Allowed");
286 addStatusCodeMap(SC_CONFLICT, "Conflict");
287 addStatusCodeMap(SC_PRECONDITION_FAILED, "Precondition Failed");
288 addStatusCodeMap(SC_REQUEST_TOO_LONG, "Request Too Long");
289 addStatusCodeMap(SC_UNSUPPORTED_MEDIA_TYPE, "Unsupported Media Type");
290 // WebDav Status Codes
291 addStatusCodeMap(SC_MULTI_STATUS, "Multi-Status");
292 addStatusCodeMap(SC_UNPROCESSABLE_ENTITY, "Unprocessable Entity");
293 addStatusCodeMap(SC_INSUFFICIENT_SPACE_ON_RESOURCE,
294 "Insufficient Space On Resource");
295 addStatusCodeMap(SC_METHOD_FAILURE, "Method Failure");
296 addStatusCodeMap(SC_LOCKED, "Locked");
300 // --------------------------------------------------------- Public Methods
304 * Returns the HTTP status text for the HTTP or WebDav status code
305 * specified by looking it up in the static mapping. This is a
308 * @param nHttpStatusCode [IN] HTTP or WebDAV status code
309 * @return A string with a short descriptive phrase for the
310 * HTTP status code (e.g., "OK").
312 public static String getStatusText(int nHttpStatusCode) {
313 Integer intKey = new Integer(nHttpStatusCode);
315 if (!mapStatusCodes.containsKey(intKey))
317 return mapStatusCodes.get(intKey);
321 // -------------------------------------------------------- Private Methods
325 * Adds a new status code -> status text mapping. This is a static
326 * method because the mapping is a static variable.
328 * @param nKey [IN] HTTP or WebDAV status code
329 * @param strVal [IN] HTTP status text
331 private static void addStatusCodeMap(int nKey, String strVal) {
332 mapStatusCodes.put(new Integer(nKey), strVal);