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