• Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/EnglishReasonPhraseCatalog.java $
3  * $Revision: 505744 $
4  * $Date: 2007-02-10 10:58:45 -0800 (Sat, 10 Feb 2007) $
5  *
6  * ====================================================================
7  * Licensed to the Apache Software Foundation (ASF) under one
8  * or more contributor license agreements.  See the NOTICE file
9  * distributed with this work for additional information
10  * regarding copyright ownership.  The ASF licenses this file
11  * to you under the Apache License, Version 2.0 (the
12  * "License"); you may not use this file except in compliance
13  * with the License.  You may obtain a copy of the License at
14  *
15  *   http://www.apache.org/licenses/LICENSE-2.0
16  *
17  * Unless required by applicable law or agreed to in writing,
18  * software distributed under the License is distributed on an
19  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
20  * KIND, either express or implied.  See the License for the
21  * specific language governing permissions and limitations
22  * under the License.
23  * ====================================================================
24  *
25  * This software consists of voluntary contributions made by many
26  * individuals on behalf of the Apache Software Foundation.  For more
27  * information on the Apache Software Foundation, please see
28  * <http://www.apache.org/>.
29  *
30  */
31 
32 package org.apache.http.impl;
33 
34 import java.util.Locale;
35 
36 import org.apache.http.HttpStatus;
37 import org.apache.http.ReasonPhraseCatalog;
38 
39 
40 /**
41  * English reason phrases for HTTP status codes.
42  * All status codes defined in RFC1945 (HTTP/1.0), RFC2616 (HTTP/1.1), and
43  * RFC2518 (WebDAV) are supported.
44  *
45  * @author Unascribed
46  * @author <a href="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a>
47  * @author <a href="mailto:jsdever@apache.org">Jeff Dever</a>
48  *
49  * @version $Revision: 505744 $
50  *
51  * @deprecated Please use {@link java.net.URL#openConnection} instead.
52  *     Please visit <a href="http://android-developers.blogspot.com/2011/09/androids-http-clients.html">this webpage</a>
53  *     for further details.
54  */
55 @Deprecated
56 public class EnglishReasonPhraseCatalog
57     implements ReasonPhraseCatalog {
58 
59     // static array with english reason phrases defined below
60 
61     /**
62      * The default instance of this catalog.
63      * This catalog is thread safe, so there typically
64      * is no need to create other instances.
65      */
66     public final static EnglishReasonPhraseCatalog INSTANCE =
67         new EnglishReasonPhraseCatalog();
68 
69 
70     /**
71      * Restricted default constructor, for derived classes.
72      * If you need an instance of this class, use {@link #INSTANCE INSTANCE}.
73      */
EnglishReasonPhraseCatalog()74     protected EnglishReasonPhraseCatalog() {
75         // no body
76     }
77 
78 
79     /**
80      * Obtains the reason phrase for a status code.
81      *
82      * @param status    the status code, in the range 100-599
83      * @param loc       ignored
84      *
85      * @return  the reason phrase, or <code>null</code>
86      */
getReason(int status, Locale loc)87     public String getReason(int status, Locale loc) {
88         if ((status < 100) || (status >= 600)) {
89             throw new IllegalArgumentException
90                 ("Unknown category for status code " + status + ".");
91         }
92 
93         final int category = status / 100;
94         final int subcode  = status - 100*category;
95 
96         String reason = null;
97         if (REASON_PHRASES[category].length > subcode)
98             reason = REASON_PHRASES[category][subcode];
99 
100         return reason;
101     }
102 
103 
104     /** Reason phrases lookup table. */
105     private static final String[][] REASON_PHRASES = new String[][]{
106         null,
107         new String[3],  // 1xx
108         new String[8],  // 2xx
109         new String[8],  // 3xx
110         new String[25], // 4xx
111         new String[8]   // 5xx
112     };
113 
114 
115 
116     /**
117      * Stores the given reason phrase, by status code.
118      * Helper method to initialize the static lookup table.
119      *
120      * @param status    the status code for which to define the phrase
121      * @param reason    the reason phrase for this status code
122      */
setReason(int status, String reason)123     private static void setReason(int status, String reason) {
124         final int category = status / 100;
125         final int subcode  = status - 100*category;
126         REASON_PHRASES[category][subcode] = reason;
127     }
128 
129 
130     // ----------------------------------------------------- Static Initializer
131 
132     /** Set up status code to "reason phrase" map. */
133     static {
134         // HTTP 1.0 Server status codes -- see RFC 1945
setReason(HttpStatus.SC_OK, "OK")135         setReason(HttpStatus.SC_OK,
136                   "OK");
setReason(HttpStatus.SC_CREATED, "Created")137         setReason(HttpStatus.SC_CREATED,
138                   "Created");
setReason(HttpStatus.SC_ACCEPTED, "Accepted")139         setReason(HttpStatus.SC_ACCEPTED,
140                   "Accepted");
setReason(HttpStatus.SC_NO_CONTENT, "No Content")141         setReason(HttpStatus.SC_NO_CONTENT,
142                   "No Content");
setReason(HttpStatus.SC_MOVED_PERMANENTLY, "Moved Permanently")143         setReason(HttpStatus.SC_MOVED_PERMANENTLY,
144                   "Moved Permanently");
setReason(HttpStatus.SC_MOVED_TEMPORARILY, "Moved Temporarily")145         setReason(HttpStatus.SC_MOVED_TEMPORARILY,
146                   "Moved Temporarily");
setReason(HttpStatus.SC_NOT_MODIFIED, "Not Modified")147         setReason(HttpStatus.SC_NOT_MODIFIED,
148                   "Not Modified");
setReason(HttpStatus.SC_BAD_REQUEST, "Bad Request")149         setReason(HttpStatus.SC_BAD_REQUEST,
150                   "Bad Request");
setReason(HttpStatus.SC_UNAUTHORIZED, "Unauthorized")151         setReason(HttpStatus.SC_UNAUTHORIZED,
152                   "Unauthorized");
setReason(HttpStatus.SC_FORBIDDEN, "Forbidden")153         setReason(HttpStatus.SC_FORBIDDEN,
154                   "Forbidden");
setReason(HttpStatus.SC_NOT_FOUND, "Not Found")155         setReason(HttpStatus.SC_NOT_FOUND,
156                   "Not Found");
setReason(HttpStatus.SC_INTERNAL_SERVER_ERROR, "Internal Server Error")157         setReason(HttpStatus.SC_INTERNAL_SERVER_ERROR,
158                   "Internal Server Error");
setReason(HttpStatus.SC_NOT_IMPLEMENTED, "Not Implemented")159         setReason(HttpStatus.SC_NOT_IMPLEMENTED,
160                   "Not Implemented");
setReason(HttpStatus.SC_BAD_GATEWAY, "Bad Gateway")161         setReason(HttpStatus.SC_BAD_GATEWAY,
162                   "Bad Gateway");
setReason(HttpStatus.SC_SERVICE_UNAVAILABLE, "Service Unavailable")163         setReason(HttpStatus.SC_SERVICE_UNAVAILABLE,
164                   "Service Unavailable");
165 
166         // HTTP 1.1 Server status codes -- see RFC 2048
setReason(HttpStatus.SC_CONTINUE, "Continue")167         setReason(HttpStatus.SC_CONTINUE,
168                   "Continue");
setReason(HttpStatus.SC_TEMPORARY_REDIRECT, "Temporary Redirect")169         setReason(HttpStatus.SC_TEMPORARY_REDIRECT,
170                   "Temporary Redirect");
setReason(HttpStatus.SC_METHOD_NOT_ALLOWED, "Method Not Allowed")171         setReason(HttpStatus.SC_METHOD_NOT_ALLOWED,
172                   "Method Not Allowed");
setReason(HttpStatus.SC_CONFLICT, "Conflict")173         setReason(HttpStatus.SC_CONFLICT,
174                   "Conflict");
setReason(HttpStatus.SC_PRECONDITION_FAILED, "Precondition Failed")175         setReason(HttpStatus.SC_PRECONDITION_FAILED,
176                   "Precondition Failed");
setReason(HttpStatus.SC_REQUEST_TOO_LONG, "Request Too Long")177         setReason(HttpStatus.SC_REQUEST_TOO_LONG,
178                   "Request Too Long");
setReason(HttpStatus.SC_REQUEST_URI_TOO_LONG, "Request-URI Too Long")179         setReason(HttpStatus.SC_REQUEST_URI_TOO_LONG,
180                   "Request-URI Too Long");
setReason(HttpStatus.SC_UNSUPPORTED_MEDIA_TYPE, "Unsupported Media Type")181         setReason(HttpStatus.SC_UNSUPPORTED_MEDIA_TYPE,
182                   "Unsupported Media Type");
setReason(HttpStatus.SC_MULTIPLE_CHOICES, "Multiple Choices")183         setReason(HttpStatus.SC_MULTIPLE_CHOICES,
184                   "Multiple Choices");
setReason(HttpStatus.SC_SEE_OTHER, "See Other")185         setReason(HttpStatus.SC_SEE_OTHER,
186                   "See Other");
setReason(HttpStatus.SC_USE_PROXY, "Use Proxy")187         setReason(HttpStatus.SC_USE_PROXY,
188                   "Use Proxy");
setReason(HttpStatus.SC_PAYMENT_REQUIRED, "Payment Required")189         setReason(HttpStatus.SC_PAYMENT_REQUIRED,
190                   "Payment Required");
setReason(HttpStatus.SC_NOT_ACCEPTABLE, "Not Acceptable")191         setReason(HttpStatus.SC_NOT_ACCEPTABLE,
192                   "Not Acceptable");
setReason(HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED, "Proxy Authentication Required")193         setReason(HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED,
194                   "Proxy Authentication Required");
setReason(HttpStatus.SC_REQUEST_TIMEOUT, "Request Timeout")195         setReason(HttpStatus.SC_REQUEST_TIMEOUT,
196                   "Request Timeout");
197 
setReason(HttpStatus.SC_SWITCHING_PROTOCOLS, "Switching Protocols")198         setReason(HttpStatus.SC_SWITCHING_PROTOCOLS,
199                   "Switching Protocols");
setReason(HttpStatus.SC_NON_AUTHORITATIVE_INFORMATION, "Non Authoritative Information")200         setReason(HttpStatus.SC_NON_AUTHORITATIVE_INFORMATION,
201                   "Non Authoritative Information");
setReason(HttpStatus.SC_RESET_CONTENT, "Reset Content")202         setReason(HttpStatus.SC_RESET_CONTENT,
203                   "Reset Content");
setReason(HttpStatus.SC_PARTIAL_CONTENT, "Partial Content")204         setReason(HttpStatus.SC_PARTIAL_CONTENT,
205                   "Partial Content");
setReason(HttpStatus.SC_GATEWAY_TIMEOUT, "Gateway Timeout")206         setReason(HttpStatus.SC_GATEWAY_TIMEOUT,
207                   "Gateway Timeout");
setReason(HttpStatus.SC_HTTP_VERSION_NOT_SUPPORTED, "Http Version Not Supported")208         setReason(HttpStatus.SC_HTTP_VERSION_NOT_SUPPORTED,
209                   "Http Version Not Supported");
setReason(HttpStatus.SC_GONE, "Gone")210         setReason(HttpStatus.SC_GONE,
211                   "Gone");
setReason(HttpStatus.SC_LENGTH_REQUIRED, "Length Required")212         setReason(HttpStatus.SC_LENGTH_REQUIRED,
213                   "Length Required");
setReason(HttpStatus.SC_REQUESTED_RANGE_NOT_SATISFIABLE, "Requested Range Not Satisfiable")214         setReason(HttpStatus.SC_REQUESTED_RANGE_NOT_SATISFIABLE,
215                   "Requested Range Not Satisfiable");
setReason(HttpStatus.SC_EXPECTATION_FAILED, "Expectation Failed")216         setReason(HttpStatus.SC_EXPECTATION_FAILED,
217                   "Expectation Failed");
218 
219         // WebDAV Server-specific status codes
setReason(HttpStatus.SC_PROCESSING, "Processing")220         setReason(HttpStatus.SC_PROCESSING,
221                   "Processing");
setReason(HttpStatus.SC_MULTI_STATUS, "Multi-Status")222         setReason(HttpStatus.SC_MULTI_STATUS,
223                   "Multi-Status");
setReason(HttpStatus.SC_UNPROCESSABLE_ENTITY, "Unprocessable Entity")224         setReason(HttpStatus.SC_UNPROCESSABLE_ENTITY,
225                   "Unprocessable Entity");
setReason(HttpStatus.SC_INSUFFICIENT_SPACE_ON_RESOURCE, "Insufficient Space On Resource")226         setReason(HttpStatus.SC_INSUFFICIENT_SPACE_ON_RESOURCE,
227                   "Insufficient Space On Resource");
setReason(HttpStatus.SC_METHOD_FAILURE, "Method Failure")228         setReason(HttpStatus.SC_METHOD_FAILURE,
229                   "Method Failure");
setReason(HttpStatus.SC_LOCKED, "Locked")230         setReason(HttpStatus.SC_LOCKED,
231                   "Locked");
setReason(HttpStatus.SC_INSUFFICIENT_STORAGE, "Insufficient Storage")232         setReason(HttpStatus.SC_INSUFFICIENT_STORAGE,
233                   "Insufficient Storage");
setReason(HttpStatus.SC_FAILED_DEPENDENCY, "Failed Dependency")234         setReason(HttpStatus.SC_FAILED_DEPENDENCY,
235                   "Failed Dependency");
236     }
237 
238 
239 }
240