1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31 package edu.internet2.middleware.grouperClientExt.org.apache.commons.httpclient;
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47 public class HttpStatus {
48
49
50
51
52
53 private static final String[][] REASON_PHRASES = new String[][]{
54 new String[0],
55 new String[3],
56 new String[8],
57 new String[8],
58 new String[25],
59 new String[8]
60 };
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77 public static String getStatusText(int statusCode) {
78
79 if (statusCode < 0) {
80 throw new IllegalArgumentException("status code may not be negative");
81 }
82 int classIndex = statusCode / 100;
83 int codeIndex = statusCode - classIndex * 100;
84 if (classIndex < 1 || classIndex > (REASON_PHRASES.length - 1)
85 || codeIndex < 0 || codeIndex > (REASON_PHRASES[classIndex].length - 1)) {
86 return null;
87 }
88 return REASON_PHRASES[classIndex][codeIndex];
89 }
90
91
92
93
94
95
96
97
98
99 private static void addStatusCodeMap(int statusCode, String reasonPhrase) {
100 int classIndex = statusCode / 100;
101 REASON_PHRASES[classIndex][statusCode - classIndex * 100] = reasonPhrase;
102 }
103
104
105
106
107
108
109
110 public static final int SC_CONTINUE = 100;
111
112 public static final int SC_SWITCHING_PROTOCOLS = 101;
113
114 public static final int SC_PROCESSING = 102;
115
116
117
118
119 public static final int SC_OK = 200;
120
121 public static final int SC_CREATED = 201;
122
123 public static final int SC_ACCEPTED = 202;
124
125 public static final int SC_NON_AUTHORITATIVE_INFORMATION = 203;
126
127 public static final int SC_NO_CONTENT = 204;
128
129 public static final int SC_RESET_CONTENT = 205;
130
131 public static final int SC_PARTIAL_CONTENT = 206;
132
133
134
135
136 public static final int SC_MULTI_STATUS = 207;
137
138
139
140
141 public static final int SC_MULTIPLE_CHOICES = 300;
142
143 public static final int SC_MOVED_PERMANENTLY = 301;
144
145 public static final int SC_MOVED_TEMPORARILY = 302;
146
147 public static final int SC_SEE_OTHER = 303;
148
149 public static final int SC_NOT_MODIFIED = 304;
150
151 public static final int SC_USE_PROXY = 305;
152
153 public static final int SC_TEMPORARY_REDIRECT = 307;
154
155
156
157
158 public static final int SC_BAD_REQUEST = 400;
159
160 public static final int SC_UNAUTHORIZED = 401;
161
162 public static final int SC_PAYMENT_REQUIRED = 402;
163
164 public static final int SC_FORBIDDEN = 403;
165
166 public static final int SC_NOT_FOUND = 404;
167
168 public static final int SC_METHOD_NOT_ALLOWED = 405;
169
170 public static final int SC_NOT_ACCEPTABLE = 406;
171
172 public static final int SC_PROXY_AUTHENTICATION_REQUIRED = 407;
173
174 public static final int SC_REQUEST_TIMEOUT = 408;
175
176 public static final int SC_CONFLICT = 409;
177
178 public static final int SC_GONE = 410;
179
180 public static final int SC_LENGTH_REQUIRED = 411;
181
182 public static final int SC_PRECONDITION_FAILED = 412;
183
184 public static final int SC_REQUEST_TOO_LONG = 413;
185
186 public static final int SC_REQUEST_URI_TOO_LONG = 414;
187
188 public static final int SC_UNSUPPORTED_MEDIA_TYPE = 415;
189
190 public static final int SC_REQUESTED_RANGE_NOT_SATISFIABLE = 416;
191
192 public static final int SC_EXPECTATION_FAILED = 417;
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209 public static final int SC_INSUFFICIENT_SPACE_ON_RESOURCE = 419;
210
211
212
213
214
215 public static final int SC_METHOD_FAILURE = 420;
216
217 public static final int SC_UNPROCESSABLE_ENTITY = 422;
218
219 public static final int SC_LOCKED = 423;
220
221 public static final int SC_FAILED_DEPENDENCY = 424;
222
223
224
225
226 public static final int SC_INTERNAL_SERVER_ERROR = 500;
227
228 public static final int SC_NOT_IMPLEMENTED = 501;
229
230 public static final int SC_BAD_GATEWAY = 502;
231
232 public static final int SC_SERVICE_UNAVAILABLE = 503;
233
234 public static final int SC_GATEWAY_TIMEOUT = 504;
235
236 public static final int SC_HTTP_VERSION_NOT_SUPPORTED = 505;
237
238
239 public static final int SC_INSUFFICIENT_STORAGE = 507;
240
241
242
243
244
245 static {
246
247 addStatusCodeMap(SC_OK, "OK");
248 addStatusCodeMap(SC_CREATED, "Created");
249 addStatusCodeMap(SC_ACCEPTED, "Accepted");
250 addStatusCodeMap(SC_NO_CONTENT, "No Content");
251 addStatusCodeMap(SC_MOVED_PERMANENTLY, "Moved Permanently");
252 addStatusCodeMap(SC_MOVED_TEMPORARILY, "Moved Temporarily");
253 addStatusCodeMap(SC_NOT_MODIFIED, "Not Modified");
254 addStatusCodeMap(SC_BAD_REQUEST, "Bad Request");
255 addStatusCodeMap(SC_UNAUTHORIZED, "Unauthorized");
256 addStatusCodeMap(SC_FORBIDDEN, "Forbidden");
257 addStatusCodeMap(SC_NOT_FOUND, "Not Found");
258 addStatusCodeMap(SC_INTERNAL_SERVER_ERROR, "Internal Server Error");
259 addStatusCodeMap(SC_NOT_IMPLEMENTED, "Not Implemented");
260 addStatusCodeMap(SC_BAD_GATEWAY, "Bad Gateway");
261 addStatusCodeMap(SC_SERVICE_UNAVAILABLE, "Service Unavailable");
262
263
264 addStatusCodeMap(SC_CONTINUE, "Continue");
265 addStatusCodeMap(SC_TEMPORARY_REDIRECT, "Temporary Redirect");
266 addStatusCodeMap(SC_METHOD_NOT_ALLOWED, "Method Not Allowed");
267 addStatusCodeMap(SC_CONFLICT, "Conflict");
268 addStatusCodeMap(SC_PRECONDITION_FAILED, "Precondition Failed");
269 addStatusCodeMap(SC_REQUEST_TOO_LONG, "Request Too Long");
270 addStatusCodeMap(SC_REQUEST_URI_TOO_LONG, "Request-URI Too Long");
271 addStatusCodeMap(SC_UNSUPPORTED_MEDIA_TYPE, "Unsupported Media Type");
272 addStatusCodeMap(SC_MULTIPLE_CHOICES, "Multiple Choices");
273 addStatusCodeMap(SC_SEE_OTHER, "See Other");
274 addStatusCodeMap(SC_USE_PROXY, "Use Proxy");
275 addStatusCodeMap(SC_PAYMENT_REQUIRED, "Payment Required");
276 addStatusCodeMap(SC_NOT_ACCEPTABLE, "Not Acceptable");
277 addStatusCodeMap(SC_PROXY_AUTHENTICATION_REQUIRED,
278 "Proxy Authentication Required");
279 addStatusCodeMap(SC_REQUEST_TIMEOUT,
280 "Request Timeout");
281
282 addStatusCodeMap(SC_SWITCHING_PROTOCOLS, "Switching Protocols");
283 addStatusCodeMap(SC_NON_AUTHORITATIVE_INFORMATION,
284 "Non Authoritative Information");
285 addStatusCodeMap(SC_RESET_CONTENT, "Reset Content");
286 addStatusCodeMap(SC_PARTIAL_CONTENT, "Partial Content");
287 addStatusCodeMap(SC_GATEWAY_TIMEOUT, "Gateway Timeout");
288 addStatusCodeMap(SC_HTTP_VERSION_NOT_SUPPORTED,
289 "Http Version Not Supported");
290 addStatusCodeMap(SC_GONE,
291 "Gone");
292 addStatusCodeMap(SC_LENGTH_REQUIRED,
293 "Length Required");
294 addStatusCodeMap(SC_REQUESTED_RANGE_NOT_SATISFIABLE,
295 "Requested Range Not Satisfiable");
296 addStatusCodeMap(SC_EXPECTATION_FAILED,
297 "Expectation Failed");
298
299
300 addStatusCodeMap(SC_PROCESSING, "Processing");
301 addStatusCodeMap(SC_MULTI_STATUS, "Multi-Status");
302 addStatusCodeMap(SC_UNPROCESSABLE_ENTITY, "Unprocessable Entity");
303 addStatusCodeMap(SC_INSUFFICIENT_SPACE_ON_RESOURCE,
304 "Insufficient Space On Resource");
305 addStatusCodeMap(SC_METHOD_FAILURE, "Method Failure");
306 addStatusCodeMap(SC_LOCKED, "Locked");
307 addStatusCodeMap(SC_INSUFFICIENT_STORAGE , "Insufficient Storage");
308 addStatusCodeMap(SC_FAILED_DEPENDENCY, "Failed Dependency");
309 }
310
311
312 }