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