1 // ======================================================================== 2 // Copyright (c) 2004-2009 Mort Bay Consulting Pty. Ltd. 3 // ------------------------------------------------------------------------ 4 // All rights reserved. This program and the accompanying materials 5 // are made available under the terms of the Eclipse Public License v1.0 6 // and Apache License v2.0 which accompanies this distribution. 7 // The Eclipse Public License is available at 8 // http://www.eclipse.org/legal/epl-v10.html 9 // The Apache License v2.0 is available at 10 // http://www.opensource.org/licenses/apache2.0.php 11 // You may elect to redistribute this code under either of these licenses. 12 // ======================================================================== 13 14 package org.eclipse.jetty.http; 15 16 import org.eclipse.jetty.util.TypeUtil; 17 18 /** 19 * <p> 20 * HttpStatusCode enum class, for status codes based on various HTTP RFCs. (see 21 * table below) 22 * </p> 23 * 24 * <table border="1" cellpadding="5"> 25 * <tr> 26 * <th>Enum</th> 27 * <th>Code</th> 28 * <th>Message</th> 29 * <th> 30 * <a href="http://tools.ietf.org/html/rfc1945">RFC 1945 - HTTP/1.0</a></th> 31 * <th> 32 * <a href="http://tools.ietf.org/html/rfc2616">RFC 2616 - HTTP/1.1</a></th> 33 * <th> 34 * <a href="http://tools.ietf.org/html/rfc2518">RFC 2518 - WEBDAV</a></th> 35 * </tr> 36 * 37 * <tr> 38 * <td><strong><code>Informational - 1xx</code></strong></td> 39 * <td colspan="5">{@link #isInformational(int)}</td> 40 * </tr> 41 * 42 * <tr> 43 * <td>{@link #CONTINUE}</td> 44 * <td>100</td> 45 * <td>Continue</td> 46 * <td> </td> 47 * <td> 48 * <a href="http://tools.ietf.org/html/rfc2616#section-10.1.1">Sec. 10.1.1</a></td> 49 * <td> </td> 50 * </tr> 51 * <tr> 52 * <td>{@link #SWITCHING_PROTOCOLS}</td> 53 * <td>101</td> 54 * <td>Switching Protocols</td> 55 * <td> </td> 56 * <td> 57 * <a href="http://tools.ietf.org/html/rfc2616#section-10.1.2">Sec. 10.1.2</a></td> 58 * <td> </td> 59 * </tr> 60 * <tr> 61 * <td>{@link #PROCESSING}</td> 62 * <td>102</td> 63 * <td>Processing</td> 64 * <td> </td> 65 * <td> </td> 66 * <td> 67 * <a href="http://tools.ietf.org/html/rfc2518#section-10.1">Sec. 10.1</a></td> 68 * </tr> 69 * 70 * <tr> 71 * <td><strong><code>Success - 2xx</code></strong></td> 72 * <td colspan="5">{@link #isSuccess(int)}</td> 73 * </tr> 74 * 75 * <tr> 76 * <td>{@link #OK}</td> 77 * <td>200</td> 78 * <td>OK</td> 79 * <td> 80 * <a href="http://tools.ietf.org/html/rfc1945#section-9.2">Sec. 9.2</a></td> 81 * <td> 82 * <a href="http://tools.ietf.org/html/rfc2616#section-10.2.1">Sec. 10.2.1</a></td> 83 * <td> </td> 84 * </tr> 85 * <tr> 86 * <td>{@link #CREATED}</td> 87 * <td>201</td> 88 * <td>Created</td> 89 * <td> 90 * <a href="http://tools.ietf.org/html/rfc1945#section-9.2">Sec. 9.2</a></td> 91 * <td> 92 * <a href="http://tools.ietf.org/html/rfc2616#section-10.2.2">Sec. 10.2.2</a></td> 93 * <td> </td> 94 * </tr> 95 * <tr> 96 * <td>{@link #ACCEPTED}</td> 97 * <td>202</td> 98 * <td>Accepted</td> 99 * <td> 100 * <a href="http://tools.ietf.org/html/rfc1945#section-9.2">Sec. 9.2</a></td> 101 * <td> 102 * <a href="http://tools.ietf.org/html/rfc2616#section-10.2.3">Sec. 10.2.3</a></td> 103 * <td> </td> 104 * </tr> 105 * <tr> 106 * <td>{@link #NON_AUTHORITATIVE_INFORMATION}</td> 107 * <td>203</td> 108 * <td>Non Authoritative Information</td> 109 * <td> </td> 110 * <td> 111 * <a href="http://tools.ietf.org/html/rfc2616#section-10.2.4">Sec. 10.2.4</a></td> 112 * <td> </td> 113 * </tr> 114 * <tr> 115 * <td>{@link #NO_CONTENT}</td> 116 * <td>204</td> 117 * <td>No Content</td> 118 * <td> 119 * <a href="http://tools.ietf.org/html/rfc1945#section-9.2">Sec. 9.2</a></td> 120 * <td> 121 * <a href="http://tools.ietf.org/html/rfc2616#section-10.2.5">Sec. 10.2.5</a></td> 122 * <td> </td> 123 * </tr> 124 * <tr> 125 * <td>{@link #RESET_CONTENT}</td> 126 * <td>205</td> 127 * <td>Reset Content</td> 128 * <td> </td> 129 * <td> 130 * <a href="http://tools.ietf.org/html/rfc2616#section-10.2.6">Sec. 10.2.6</a></td> 131 * <td> </td> 132 * </tr> 133 * <tr> 134 * <td>{@link #PARTIAL_CONTENT}</td> 135 * <td>206</td> 136 * <td>Partial Content</td> 137 * <td> </td> 138 * <td> 139 * <a href="http://tools.ietf.org/html/rfc2616#section-10.2.7">Sec. 10.2.7</a></td> 140 * <td> </td> 141 * </tr> 142 * <tr> 143 * <td>{@link #MULTI_STATUS}</td> 144 * <td>207</td> 145 * <td>Multi-Status</td> 146 * <td> </td> 147 * <td> </td> 148 * <td> 149 * <a href="http://tools.ietf.org/html/rfc2518#section-10.2">Sec. 10.2</a></td> 150 * </tr> 151 * <tr> 152 * <td> </td> 153 * <td><strike>207</strike></td> 154 * <td><strike>Partial Update OK</strike></td> 155 * <td> </td> 156 * <td> 157 * <a href= 158 * "http://www.w3.org/Protocols/HTTP/1.1/draft-ietf-http-v11-spec-rev-01.txt" 159 * >draft/01</a></td> 160 * <td> </td> 161 * </tr> 162 * 163 * <tr> 164 * <td><strong><code>Redirection - 3xx</code></strong></td> 165 * <td colspan="5">{@link #isRedirection(int)}</td> 166 * </tr> 167 * 168 * <tr> 169 * <td>{@link #MULTIPLE_CHOICES}</td> 170 * <td>300</td> 171 * <td>Multiple Choices</td> 172 * <td> 173 * <a href="http://tools.ietf.org/html/rfc1945#section-9.3">Sec. 9.3</a></td> 174 * <td> 175 * <a href="http://tools.ietf.org/html/rfc2616#section-10.3.1">Sec. 10.3.1</a></td> 176 * <td> </td> 177 * </tr> 178 * <tr> 179 * <td>{@link #MOVED_PERMANENTLY}</td> 180 * <td>301</td> 181 * <td>Moved Permanently</td> 182 * <td> 183 * <a href="http://tools.ietf.org/html/rfc1945#section-9.3">Sec. 9.3</a></td> 184 * <td> 185 * <a href="http://tools.ietf.org/html/rfc2616#section-10.3.2">Sec. 10.3.2</a></td> 186 * <td> </td> 187 * </tr> 188 * <tr> 189 * <td>{@link #MOVED_TEMPORARILY}</td> 190 * <td>302</td> 191 * <td>Moved Temporarily</td> 192 * <td> 193 * <a href="http://tools.ietf.org/html/rfc1945#section-9.3">Sec. 9.3</a></td> 194 * <td>(now "<code>302 Found</code>")</td> 195 * <td> </td> 196 * </tr> 197 * <tr> 198 * <td>{@link #FOUND}</td> 199 * <td>302</td> 200 * <td>Found</td> 201 * <td>(was "<code>302 Moved Temporarily</code>")</td> 202 * <td> 203 * <a href="http://tools.ietf.org/html/rfc2616#section-10.3.3">Sec. 10.3.3</a></td> 204 * <td> </td> 205 * </tr> 206 * <tr> 207 * <td>{@link #SEE_OTHER}</td> 208 * <td>303</td> 209 * <td>See Other</td> 210 * <td> </td> 211 * <td> 212 * <a href="http://tools.ietf.org/html/rfc2616#section-10.3.4">Sec. 10.3.4</a></td> 213 * <td> </td> 214 * </tr> 215 * <tr> 216 * <td>{@link #NOT_MODIFIED}</td> 217 * <td>304</td> 218 * <td>Not Modified</td> 219 * <td> 220 * <a href="http://tools.ietf.org/html/rfc1945#section-9.3">Sec. 9.3</a></td> 221 * <td> 222 * <a href="http://tools.ietf.org/html/rfc2616#section-10.3.5">Sec. 10.3.5</a></td> 223 * <td> </td> 224 * </tr> 225 * <tr> 226 * <td>{@link #USE_PROXY}</td> 227 * <td>305</td> 228 * <td>Use Proxy</td> 229 * <td> </td> 230 * <td> 231 * <a href="http://tools.ietf.org/html/rfc2616#section-10.3.6">Sec. 10.3.6</a></td> 232 * <td> </td> 233 * </tr> 234 * <tr> 235 * <td> </td> 236 * <td>306</td> 237 * <td><em>(Unused)</em></td> 238 * <td> </td> 239 * <td> 240 * <a href="http://tools.ietf.org/html/rfc2616#section-10.3.7">Sec. 10.3.7</a></td> 241 * <td> </td> 242 * </tr> 243 * <tr> 244 * <td>{@link #TEMPORARY_REDIRECT}</td> 245 * <td>307</td> 246 * <td>Temporary Redirect</td> 247 * <td> </td> 248 * <td> 249 * <a href="http://tools.ietf.org/html/rfc2616#section-10.3.8">Sec. 10.3.8</a></td> 250 * <td> </td> 251 * </tr> 252 * 253 * <tr> 254 * <td><strong><code>Client Error - 4xx</code></strong></td> 255 * <td colspan="5">{@link #isClientError(int)}</td> 256 * </tr> 257 * 258 * <tr> 259 * <td>{@link #BAD_REQUEST}</td> 260 * <td>400</td> 261 * <td>Bad Request</td> 262 * <td> 263 * <a href="http://tools.ietf.org/html/rfc1945#section-9.4">Sec. 9.4</a></td> 264 * <td> 265 * <a href="http://tools.ietf.org/html/rfc2616#section-10.4.1">Sec. 10.4.1</a></td> 266 * <td> </td> 267 * </tr> 268 * <tr> 269 * <td>{@link #UNAUTHORIZED}</td> 270 * <td>401</td> 271 * <td>Unauthorized</td> 272 * <td> 273 * <a href="http://tools.ietf.org/html/rfc1945#section-9.4">Sec. 9.4</a></td> 274 * <td> 275 * <a href="http://tools.ietf.org/html/rfc2616#section-10.4.2">Sec. 10.4.2</a></td> 276 * <td> </td> 277 * </tr> 278 * <tr> 279 * <td>{@link #PAYMENT_REQUIRED}</td> 280 * <td>402</td> 281 * <td>Payment Required</td> 282 * <td> 283 * <a href="http://tools.ietf.org/html/rfc1945#section-9.4">Sec. 9.4</a></td> 284 * <td> 285 * <a href="http://tools.ietf.org/html/rfc2616#section-10.4.3">Sec. 10.4.3</a></td> 286 * <td> </td> 287 * </tr> 288 * <tr> 289 * <td>{@link #FORBIDDEN}</td> 290 * <td>403</td> 291 * <td>Forbidden</td> 292 * <td> 293 * <a href="http://tools.ietf.org/html/rfc1945#section-9.4">Sec. 9.4</a></td> 294 * <td> 295 * <a href="http://tools.ietf.org/html/rfc2616#section-10.4.4">Sec. 10.4.4</a></td> 296 * <td> </td> 297 * </tr> 298 * <tr> 299 * <td>{@link #NOT_FOUND}</td> 300 * <td>404</td> 301 * <td>Not Found</td> 302 * <td> 303 * <a href="http://tools.ietf.org/html/rfc1945#section-9.4">Sec. 9.4</a></td> 304 * <td> 305 * <a href="http://tools.ietf.org/html/rfc2616#section-10.4.5">Sec. 10.4.5</a></td> 306 * <td> </td> 307 * </tr> 308 * <tr> 309 * <td>{@link #METHOD_NOT_ALLOWED}</td> 310 * <td>405</td> 311 * <td>Method Not Allowed</td> 312 * <td> </td> 313 * <td> 314 * <a href="http://tools.ietf.org/html/rfc2616#section-10.4.6">Sec. 10.4.6</a></td> 315 * <td> </td> 316 * </tr> 317 * <tr> 318 * <td>{@link #NOT_ACCEPTABLE}</td> 319 * <td>406</td> 320 * <td>Not Acceptable</td> 321 * <td> </td> 322 * <td> 323 * <a href="http://tools.ietf.org/html/rfc2616#section-10.4.7">Sec. 10.4.7</a></td> 324 * <td> </td> 325 * </tr> 326 * <tr> 327 * <td>{@link #PROXY_AUTHENTICATION_REQUIRED}</td> 328 * <td>407</td> 329 * <td>Proxy Authentication Required</td> 330 * <td> </td> 331 * <td> 332 * <a href="http://tools.ietf.org/html/rfc2616#section-10.4.8">Sec. 10.4.8</a></td> 333 * <td> </td> 334 * </tr> 335 * <tr> 336 * <td>{@link #REQUEST_TIMEOUT}</td> 337 * <td>408</td> 338 * <td>Request Timeout</td> 339 * <td> </td> 340 * <td> 341 * <a href="http://tools.ietf.org/html/rfc2616#section-10.4.9">Sec. 10.4.9</a></td> 342 * <td> </td> 343 * </tr> 344 * <tr> 345 * <td>{@link #CONFLICT}</td> 346 * <td>409</td> 347 * <td>Conflict</td> 348 * <td> </td> 349 * <td> 350 * <a href="http://tools.ietf.org/html/rfc2616#section-10.4.10">Sec. 10.4.10</a> 351 * </td> 352 * <td> </td> 353 * </tr> 354 * <tr> 355 * <td>{@link #GONE}</td> 356 * <td>410</td> 357 * <td>Gone</td> 358 * <td> </td> 359 * <td> 360 * <a href="http://tools.ietf.org/html/rfc2616#section-10.4.11">Sec. 10.4.11</a> 361 * </td> 362 * <td> </td> 363 * </tr> 364 * <tr> 365 * <td>{@link #LENGTH_REQUIRED}</td> 366 * <td>411</td> 367 * <td>Length Required</td> 368 * <td> </td> 369 * <td> 370 * <a href="http://tools.ietf.org/html/rfc2616#section-10.4.12">Sec. 10.4.12</a> 371 * </td> 372 * <td> </td> 373 * </tr> 374 * <tr> 375 * <td>{@link #PRECONDITION_FAILED}</td> 376 * <td>412</td> 377 * <td>Precondition Failed</td> 378 * <td> </td> 379 * <td> 380 * <a href="http://tools.ietf.org/html/rfc2616#section-10.4.13">Sec. 10.4.13</a> 381 * </td> 382 * <td> </td> 383 * </tr> 384 * <tr> 385 * <td>{@link #REQUEST_ENTITY_TOO_LARGE}</td> 386 * <td>413</td> 387 * <td>Request Entity Too Large</td> 388 * <td> </td> 389 * <td> 390 * <a href="http://tools.ietf.org/html/rfc2616#section-10.4.14">Sec. 10.4.14</a> 391 * </td> 392 * <td> </td> 393 * </tr> 394 * <tr> 395 * <td>{@link #REQUEST_URI_TOO_LONG}</td> 396 * <td>414</td> 397 * <td>Request-URI Too Long</td> 398 * <td> </td> 399 * <td> 400 * <a href="http://tools.ietf.org/html/rfc2616#section-10.4.15">Sec. 10.4.15</a> 401 * </td> 402 * <td> </td> 403 * </tr> 404 * <tr> 405 * <td>{@link #UNSUPPORTED_MEDIA_TYPE}</td> 406 * <td>415</td> 407 * <td>Unsupported Media Type</td> 408 * <td> </td> 409 * <td> 410 * <a href="http://tools.ietf.org/html/rfc2616#section-10.4.16">Sec. 10.4.16</a> 411 * </td> 412 * <td> </td> 413 * </tr> 414 * <tr> 415 * <td>{@link #REQUESTED_RANGE_NOT_SATISFIABLE}</td> 416 * <td>416</td> 417 * <td>Requested Range Not Satisfiable</td> 418 * <td> </td> 419 * <td> 420 * <a href="http://tools.ietf.org/html/rfc2616#section-10.4.17">Sec. 10.4.17</a> 421 * </td> 422 * <td> </td> 423 * </tr> 424 * <tr> 425 * <td>{@link #EXPECTATION_FAILED}</td> 426 * <td>417</td> 427 * <td>Expectation Failed</td> 428 * <td> </td> 429 * <td> 430 * <a href="http://tools.ietf.org/html/rfc2616#section-10.4.18">Sec. 10.4.18</a> 431 * </td> 432 * <td> </td> 433 * </tr> 434 * <tr> 435 * <td> </td> 436 * <td><strike>418</strike></td> 437 * <td><strike>Reauthentication Required</strike></td> 438 * <td> </td> 439 * <td> 440 * <a href= 441 * "http://tools.ietf.org/html/draft-ietf-http-v11-spec-rev-01#section-10.4.19" 442 * >draft/01</a></td> 443 * <td> </td> 444 * </tr> 445 * <tr> 446 * <td> </td> 447 * <td><strike>418</strike></td> 448 * <td><strike>Unprocessable Entity</strike></td> 449 * <td> </td> 450 * <td> </td> 451 * <td> 452 * <a href= 453 * "http://tools.ietf.org/html/draft-ietf-webdav-protocol-05#section-10.3" 454 * >draft/05</a></td> 455 * </tr> 456 * <tr> 457 * <td> </td> 458 * <td><strike>419</strike></td> 459 * <td><strike>Proxy Reauthentication Required</stike></td> 460 * <td> </td> 461 * <td> 462 * <a href= 463 * "http://tools.ietf.org/html/draft-ietf-http-v11-spec-rev-01#section-10.4.20" 464 * >draft/01</a></td> 465 * <td> </td> 466 * </tr> 467 * <tr> 468 * <td> </td> 469 * <td><strike>419</strike></td> 470 * <td><strike>Insufficient Space on Resource</stike></td> 471 * <td> </td> 472 * <td> </td> 473 * <td> 474 * <a href= 475 * "http://tools.ietf.org/html/draft-ietf-webdav-protocol-05#section-10.4" 476 * >draft/05</a></td> 477 * </tr> 478 * <tr> 479 * <td> </td> 480 * <td><strike>420</strike></td> 481 * <td><strike>Method Failure</strike></td> 482 * <td> </td> 483 * <td> </td> 484 * <td> 485 * <a href= 486 * "http://tools.ietf.org/html/draft-ietf-webdav-protocol-05#section-10.5" 487 * >draft/05</a></td> 488 * </tr> 489 * <tr> 490 * <td> </td> 491 * <td>421</td> 492 * <td><em>(Unused)</em></td> 493 * <td> </td> 494 * <td> </td> 495 * <td> </td> 496 * </tr> 497 * <tr> 498 * <td>{@link #UNPROCESSABLE_ENTITY}</td> 499 * <td>422</td> 500 * <td>Unprocessable Entity</td> 501 * <td> </td> 502 * <td> </td> 503 * <td> 504 * <a href="http://tools.ietf.org/html/rfc2518#section-10.3">Sec. 10.3</a></td> 505 * </tr> 506 * <tr> 507 * <td>{@link #LOCKED}</td> 508 * <td>423</td> 509 * <td>Locked</td> 510 * <td> </td> 511 * <td> </td> 512 * <td> 513 * <a href="http://tools.ietf.org/html/rfc2518#section-10.4">Sec. 10.4</a></td> 514 * </tr> 515 * <tr> 516 * <td>{@link #FAILED_DEPENDENCY}</td> 517 * <td>424</td> 518 * <td>Failed Dependency</td> 519 * <td> </td> 520 * <td> </td> 521 * <td> 522 * <a href="http://tools.ietf.org/html/rfc2518#section-10.5">Sec. 10.5</a></td> 523 * </tr> 524 * 525 * <tr> 526 * <td><strong><code>Server Error - 5xx</code></strong></td> 527 * <td colspan="5">{@link #isServerError(int)}</td> 528 * </tr> 529 * 530 * <tr> 531 * <td>{@link #INTERNAL_SERVER_ERROR}</td> 532 * <td>500</td> 533 * <td>Internal Server Error</td> 534 * <td> 535 * <a href="http://tools.ietf.org/html/rfc1945#section-9.5">Sec. 9.5</a></td> 536 * <td> 537 * <a href="http://tools.ietf.org/html/rfc2616#section-10.5.1">Sec. 10.5.1</a></td> 538 * <td> </td> 539 * </tr> 540 * <tr> 541 * <td>{@link #NOT_IMPLEMENTED}</td> 542 * <td>501</td> 543 * <td>Not Implemented</td> 544 * <td> 545 * <a href="http://tools.ietf.org/html/rfc1945#section-9.5">Sec. 9.5</a></td> 546 * <td> 547 * <a href="http://tools.ietf.org/html/rfc2616#section-10.5.2">Sec. 10.5.2</a></td> 548 * <td> </td> 549 * </tr> 550 * <tr> 551 * <td>{@link #BAD_GATEWAY}</td> 552 * <td>502</td> 553 * <td>Bad Gateway</td> 554 * <td> 555 * <a href="http://tools.ietf.org/html/rfc1945#section-9.5">Sec. 9.5</a></td> 556 * <td> 557 * <a href="http://tools.ietf.org/html/rfc2616#section-10.5.3">Sec. 10.5.3</a></td> 558 * <td> </td> 559 * </tr> 560 * <tr> 561 * <td>{@link #SERVICE_UNAVAILABLE}</td> 562 * <td>503</td> 563 * <td>Service Unavailable</td> 564 * <td> 565 * <a href="http://tools.ietf.org/html/rfc1945#section-9.5">Sec. 9.5</a></td> 566 * <td> 567 * <a href="http://tools.ietf.org/html/rfc2616#section-10.5.4">Sec. 10.5.4</a></td> 568 * <td> </td> 569 * </tr> 570 * <tr> 571 * <td>{@link #GATEWAY_TIMEOUT}</td> 572 * <td>504</td> 573 * <td>Gateway Timeout</td> 574 * <td> </td> 575 * <td> 576 * <a href="http://tools.ietf.org/html/rfc2616#section-10.5.5">Sec. 10.5.5</a></td> 577 * <td> </td> 578 * </tr> 579 * <tr> 580 * <td>{@link #HTTP_VERSION_NOT_SUPPORTED}</td> 581 * <td>505</td> 582 * <td>HTTP Version Not Supported</td> 583 * <td> </td> 584 * <td> 585 * <a href="http://tools.ietf.org/html/rfc2616#section-10.5.6">Sec. 10.5.6</a></td> 586 * <td> </td> 587 * </tr> 588 * <tr> 589 * <td> </td> 590 * <td>506</td> 591 * <td><em>(Unused)</em></td> 592 * <td> </td> 593 * <td> </td> 594 * <td> </td> 595 * </tr> 596 * <tr> 597 * <td>{@link #INSUFFICIENT_STORAGE}</td> 598 * <td>507</td> 599 * <td>Insufficient Storage</td> 600 * <td> </td> 601 * <td> </td> 602 * <td> 603 * <a href="http://tools.ietf.org/html/rfc2518#section-10.6">Sec. 10.6</a></td> 604 * </tr> 605 * 606 * </table> 607 * 608 * @version $Id$ 609 */ 610 public class HttpStatus 611 { 612 public final static int CONTINUE_100 = 100; 613 public final static int SWITCHING_PROTOCOLS_101 = 101; 614 public final static int PROCESSING_102 = 102; 615 616 public final static int OK_200 = 200; 617 public final static int CREATED_201 = 201; 618 public final static int ACCEPTED_202 = 202; 619 public final static int NON_AUTHORITATIVE_INFORMATION_203 = 203; 620 public final static int NO_CONTENT_204 = 204; 621 public final static int RESET_CONTENT_205 = 205; 622 public final static int PARTIAL_CONTENT_206 = 206; 623 public final static int MULTI_STATUS_207 = 207; 624 625 public final static int MULTIPLE_CHOICES_300 = 300; 626 public final static int MOVED_PERMANENTLY_301 = 301; 627 public final static int MOVED_TEMPORARILY_302 = 302; 628 public final static int FOUND_302 = 302; 629 public final static int SEE_OTHER_303 = 303; 630 public final static int NOT_MODIFIED_304 = 304; 631 public final static int USE_PROXY_305 = 305; 632 public final static int TEMPORARY_REDIRECT_307 = 307; 633 634 public final static int BAD_REQUEST_400 = 400; 635 public final static int UNAUTHORIZED_401 = 401; 636 public final static int PAYMENT_REQUIRED_402 = 402; 637 public final static int FORBIDDEN_403 = 403; 638 public final static int NOT_FOUND_404 = 404; 639 public final static int METHOD_NOT_ALLOWED_405 = 405; 640 public final static int NOT_ACCEPTABLE_406 = 406; 641 public final static int PROXY_AUTHENTICATION_REQUIRED_407 = 407; 642 public final static int REQUEST_TIMEOUT_408 = 408; 643 public final static int CONFLICT_409 = 409; 644 public final static int GONE_410 = 410; 645 public final static int LENGTH_REQUIRED_411 = 411; 646 public final static int PRECONDITION_FAILED_412 = 412; 647 public final static int REQUEST_ENTITY_TOO_LARGE_413 = 413; 648 public final static int REQUEST_URI_TOO_LONG_414 = 414; 649 public final static int UNSUPPORTED_MEDIA_TYPE_415 = 415; 650 public final static int REQUESTED_RANGE_NOT_SATISFIABLE_416 = 416; 651 public final static int EXPECTATION_FAILED_417 = 417; 652 public final static int UNPROCESSABLE_ENTITY_422 = 422; 653 public final static int LOCKED_423 = 423; 654 public final static int FAILED_DEPENDENCY_424 = 424; 655 656 public final static int INTERNAL_SERVER_ERROR_500 = 500; 657 public final static int NOT_IMPLEMENTED_501 = 501; 658 public final static int BAD_GATEWAY_502 = 502; 659 public final static int SERVICE_UNAVAILABLE_503 = 503; 660 public final static int GATEWAY_TIMEOUT_504 = 504; 661 public final static int HTTP_VERSION_NOT_SUPPORTED_505 = 505; 662 public final static int INSUFFICIENT_STORAGE_507 = 507; 663 664 public static final int MAX_CODE = 507; 665 666 667 private static final Code[] codeMap = new Code[MAX_CODE+1]; 668 669 static 670 { 671 for (Code code : Code.values()) 672 { 673 codeMap[code._code] = code; 674 } 675 } 676 677 678 public enum Code 679 { 680 /* 681 * -------------------------------------------------------------------- 682 * Informational messages in 1xx series. As defined by ... RFC 1945 - 683 * HTTP/1.0 RFC 2616 - HTTP/1.1 RFC 2518 - WebDAV 684 */ 685 686 /** <code>100 Continue</code> */ 687 CONTINUE(CONTINUE_100, "Continue"), 688 /** <code>101 Switching Protocols</code> */ 689 SWITCHING_PROTOCOLS(SWITCHING_PROTOCOLS_101, "Switching Protocols"), 690 /** <code>102 Processing</code> */ 691 PROCESSING(PROCESSING_102, "Processing"), 692 693 /* 694 * -------------------------------------------------------------------- 695 * Success messages in 2xx series. As defined by ... RFC 1945 - HTTP/1.0 696 * RFC 2616 - HTTP/1.1 RFC 2518 - WebDAV 697 */ 698 699 /** <code>200 OK</code> */ 700 OK(OK_200, "OK"), 701 /** <code>201 Created</code> */ 702 CREATED(CREATED_201, "Created"), 703 /** <code>202 Accepted</code> */ 704 ACCEPTED(ACCEPTED_202, "Accepted"), 705 /** <code>203 Non Authoritative Information</code> */ 706 NON_AUTHORITATIVE_INFORMATION(NON_AUTHORITATIVE_INFORMATION_203, "Non Authoritative Information"), 707 /** <code>204 No Content</code> */ 708 NO_CONTENT(NO_CONTENT_204, "No Content"), 709 /** <code>205 Reset Content</code> */ 710 RESET_CONTENT(RESET_CONTENT_205, "Reset Content"), 711 /** <code>206 Partial Content</code> */ 712 PARTIAL_CONTENT(PARTIAL_CONTENT_206, "Partial Content"), 713 /** <code>207 Multi-Status</code> */ 714 MULTI_STATUS(MULTI_STATUS_207, "Multi-Status"), 715 716 /* 717 * -------------------------------------------------------------------- 718 * Redirection messages in 3xx series. As defined by ... RFC 1945 - 719 * HTTP/1.0 RFC 2616 - HTTP/1.1 720 */ 721 722 /** <code>300 Mutliple Choices</code> */ 723 MULTIPLE_CHOICES(MULTIPLE_CHOICES_300, "Multiple Choices"), 724 /** <code>301 Moved Permanently</code> */ 725 MOVED_PERMANENTLY(MOVED_PERMANENTLY_301, "Moved Permanently"), 726 /** <code>302 Moved Temporarily</code> */ 727 MOVED_TEMPORARILY(MOVED_TEMPORARILY_302, "Moved Temporarily"), 728 /** <code>302 Found</code> */ 729 FOUND(FOUND_302, "Found"), 730 /** <code>303 See Other</code> */ 731 SEE_OTHER(SEE_OTHER_303, "See Other"), 732 /** <code>304 Not Modified</code> */ 733 NOT_MODIFIED(NOT_MODIFIED_304, "Not Modified"), 734 /** <code>305 Use Proxy</code> */ 735 USE_PROXY(USE_PROXY_305, "Use Proxy"), 736 /** <code>307 Temporary Redirect</code> */ 737 TEMPORARY_REDIRECT(TEMPORARY_REDIRECT_307, "Temporary Redirect"), 738 739 /* 740 * -------------------------------------------------------------------- 741 * Client Error messages in 4xx series. As defined by ... RFC 1945 - 742 * HTTP/1.0 RFC 2616 - HTTP/1.1 RFC 2518 - WebDAV 743 */ 744 745 /** <code>400 Bad Request</code> */ 746 BAD_REQUEST(BAD_REQUEST_400, "Bad Request"), 747 /** <code>401 Unauthorized</code> */ 748 UNAUTHORIZED(UNAUTHORIZED_401, "Unauthorized"), 749 /** <code>402 Payment Required</code> */ 750 PAYMENT_REQUIRED(PAYMENT_REQUIRED_402, "Payment Required"), 751 /** <code>403 Forbidden</code> */ 752 FORBIDDEN(FORBIDDEN_403, "Forbidden"), 753 /** <code>404 Not Found</code> */ 754 NOT_FOUND(NOT_FOUND_404, "Not Found"), 755 /** <code>405 Method Not Allowed</code> */ 756 METHOD_NOT_ALLOWED(METHOD_NOT_ALLOWED_405, "Method Not Allowed"), 757 /** <code>406 Not Acceptable</code> */ 758 NOT_ACCEPTABLE(NOT_ACCEPTABLE_406, "Not Acceptable"), 759 /** <code>407 Proxy Authentication Required</code> */ 760 PROXY_AUTHENTICATION_REQUIRED(PROXY_AUTHENTICATION_REQUIRED_407, "Proxy Authentication Required"), 761 /** <code>408 Request Timeout</code> */ 762 REQUEST_TIMEOUT(REQUEST_TIMEOUT_408, "Request Timeout"), 763 /** <code>409 Conflict</code> */ 764 CONFLICT(CONFLICT_409, "Conflict"), 765 /** <code>410 Gone</code> */ 766 GONE(GONE_410, "Gone"), 767 /** <code>411 Length Required</code> */ 768 LENGTH_REQUIRED(LENGTH_REQUIRED_411, "Length Required"), 769 /** <code>412 Precondition Failed</code> */ 770 PRECONDITION_FAILED(PRECONDITION_FAILED_412, "Precondition Failed"), 771 /** <code>413 Request Entity Too Large</code> */ 772 REQUEST_ENTITY_TOO_LARGE(REQUEST_ENTITY_TOO_LARGE_413, "Request Entity Too Large"), 773 /** <code>414 Request-URI Too Long</code> */ 774 REQUEST_URI_TOO_LONG(REQUEST_URI_TOO_LONG_414, "Request-URI Too Long"), 775 /** <code>415 Unsupported Media Type</code> */ 776 UNSUPPORTED_MEDIA_TYPE(UNSUPPORTED_MEDIA_TYPE_415, "Unsupported Media Type"), 777 /** <code>416 Requested Range Not Satisfiable</code> */ 778 REQUESTED_RANGE_NOT_SATISFIABLE(REQUESTED_RANGE_NOT_SATISFIABLE_416, "Requested Range Not Satisfiable"), 779 /** <code>417 Expectation Failed</code> */ 780 EXPECTATION_FAILED(EXPECTATION_FAILED_417, "Expectation Failed"), 781 /** <code>422 Unprocessable Entity</code> */ 782 UNPROCESSABLE_ENTITY(UNPROCESSABLE_ENTITY_422, "Unprocessable Entity"), 783 /** <code>423 Locked</code> */ 784 LOCKED(LOCKED_423, "Locked"), 785 /** <code>424 Failed Dependency</code> */ 786 FAILED_DEPENDENCY(FAILED_DEPENDENCY_424, "Failed Dependency"), 787 788 /* 789 * -------------------------------------------------------------------- 790 * Server Error messages in 5xx series. As defined by ... RFC 1945 - 791 * HTTP/1.0 RFC 2616 - HTTP/1.1 RFC 2518 - WebDAV 792 */ 793 794 /** <code>500 Server Error</code> */ 795 INTERNAL_SERVER_ERROR(INTERNAL_SERVER_ERROR_500, "Server Error"), 796 /** <code>501 Not Implemented</code> */ 797 NOT_IMPLEMENTED(NOT_IMPLEMENTED_501, "Not Implemented"), 798 /** <code>502 Bad Gateway</code> */ 799 BAD_GATEWAY(BAD_GATEWAY_502, "Bad Gateway"), 800 /** <code>503 Service Unavailable</code> */ 801 SERVICE_UNAVAILABLE(SERVICE_UNAVAILABLE_503, "Service Unavailable"), 802 /** <code>504 Gateway Timeout</code> */ 803 GATEWAY_TIMEOUT(GATEWAY_TIMEOUT_504, "Gateway Timeout"), 804 /** <code>505 HTTP Version Not Supported</code> */ 805 HTTP_VERSION_NOT_SUPPORTED(HTTP_VERSION_NOT_SUPPORTED_505, "HTTP Version Not Supported"), 806 /** <code>507 Insufficient Storage</code> */ 807 INSUFFICIENT_STORAGE(INSUFFICIENT_STORAGE_507, "Insufficient Storage"); 808 809 private final int _code; 810 private final String _message; 811 812 private Code(int code, String message) 813 { 814 this._code = code; 815 _message=message; 816 } 817 818 public int getCode() 819 { 820 return _code; 821 } 822 823 public String getMessage() 824 { 825 return _message; 826 } 827 828 829 public boolean equals(int code) 830 { 831 return (this._code == code); 832 } 833 834 @Override 835 public String toString() 836 { 837 return String.format("[%03d %s]",this._code,this.getMessage()); 838 } 839 840 /** 841 * Simple test against an code to determine if it falls into the 842 * <code>Informational</code> message category as defined in the <a 843 * href="http://tools.ietf.org/html/rfc1945">RFC 1945 - HTTP/1.0</a>, 844 * and <a href="http://tools.ietf.org/html/rfc2616">RFC 2616 - 845 * HTTP/1.1</a>. 846 * 847 * @return true if within range of codes that belongs to 848 * <code>Informational</code> messages. 849 */ 850 public boolean isInformational() 851 { 852 return HttpStatus.isInformational(this._code); 853 } 854 855 /** 856 * Simple test against an code to determine if it falls into the 857 * <code>Success</code> message category as defined in the <a 858 * href="http://tools.ietf.org/html/rfc1945">RFC 1945 - HTTP/1.0</a>, 859 * and <a href="http://tools.ietf.org/html/rfc2616">RFC 2616 - 860 * HTTP/1.1</a>. 861 * 862 * @return true if within range of codes that belongs to 863 * <code>Success</code> messages. 864 */ 865 public boolean isSuccess() 866 { 867 return HttpStatus.isSuccess(this._code); 868 } 869 870 /** 871 * Simple test against an code to determine if it falls into the 872 * <code>Redirection</code> message category as defined in the <a 873 * href="http://tools.ietf.org/html/rfc1945">RFC 1945 - HTTP/1.0</a>, 874 * and <a href="http://tools.ietf.org/html/rfc2616">RFC 2616 - 875 * HTTP/1.1</a>. 876 * 877 * @return true if within range of codes that belongs to 878 * <code>Redirection</code> messages. 879 */ 880 public boolean isRedirection() 881 { 882 return HttpStatus.isRedirection(this._code); 883 } 884 885 /** 886 * Simple test against an code to determine if it falls into the 887 * <code>Client Error</code> message category as defined in the <a 888 * href="http://tools.ietf.org/html/rfc1945">RFC 1945 - HTTP/1.0</a>, 889 * and <a href="http://tools.ietf.org/html/rfc2616">RFC 2616 - 890 * HTTP/1.1</a>. 891 * 892 * @return true if within range of codes that belongs to 893 * <code>Client Error</code> messages. 894 */ 895 public boolean isClientError() 896 { 897 return HttpStatus.isClientError(this._code); 898 } 899 900 /** 901 * Simple test against an code to determine if it falls into the 902 * <code>Server Error</code> message category as defined in the <a 903 * href="http://tools.ietf.org/html/rfc1945">RFC 1945 - HTTP/1.0</a>, 904 * and <a href="http://tools.ietf.org/html/rfc2616">RFC 2616 - 905 * HTTP/1.1</a>. 906 * 907 * @return true if within range of codes that belongs to 908 * <code>Server Error</code> messages. 909 */ 910 public boolean isServerError() 911 { 912 return HttpStatus.isServerError(this._code); 913 } 914 } 915 916 917 /** 918 * Get the HttpStatusCode for a specific code 919 * 920 * @param code 921 * the code to lookup. 922 * @return the {@link HttpStatus} if found, or null if not found. 923 */ 924 public static Code getCode(int code) 925 { 926 if (code <= MAX_CODE) 927 { 928 return codeMap[code]; 929 } 930 return null; 931 } 932 933 /** 934 * Get the status message for a specific code. 935 * 936 * @param code 937 * the code to look up 938 * @return the specific message, or the code number itself if code 939 * does not match known list. 940 */ 941 public static String getMessage(int code) 942 { 943 Code codeEnum = getCode(code); 944 if (codeEnum != null) 945 { 946 return codeEnum.getMessage(); 947 } 948 else 949 { 950 return TypeUtil.toString(code); 951 } 952 } 953 954 /** 955 * Simple test against an code to determine if it falls into the 956 * <code>Informational</code> message category as defined in the <a 957 * href="http://tools.ietf.org/html/rfc1945">RFC 1945 - HTTP/1.0</a>, and <a 958 * href="http://tools.ietf.org/html/rfc2616">RFC 2616 - HTTP/1.1</a>. 959 * 960 * @param code 961 * the code to test. 962 * @return true if within range of codes that belongs to 963 * <code>Informational</code> messages. 964 */ 965 public static boolean isInformational(int code) 966 { 967 return ((100 <= code) && (code <= 199)); 968 } 969 970 /** 971 * Simple test against an code to determine if it falls into the 972 * <code>Success</code> message category as defined in the <a 973 * href="http://tools.ietf.org/html/rfc1945">RFC 1945 - HTTP/1.0</a>, and <a 974 * href="http://tools.ietf.org/html/rfc2616">RFC 2616 - HTTP/1.1</a>. 975 * 976 * @param code 977 * the code to test. 978 * @return true if within range of codes that belongs to 979 * <code>Success</code> messages. 980 */ 981 public static boolean isSuccess(int code) 982 { 983 return ((200 <= code) && (code <= 299)); 984 } 985 986 /** 987 * Simple test against an code to determine if it falls into the 988 * <code>Redirection</code> message category as defined in the <a 989 * href="http://tools.ietf.org/html/rfc1945">RFC 1945 - HTTP/1.0</a>, and <a 990 * href="http://tools.ietf.org/html/rfc2616">RFC 2616 - HTTP/1.1</a>. 991 * 992 * @param code 993 * the code to test. 994 * @return true if within range of codes that belongs to 995 * <code>Redirection</code> messages. 996 */ 997 public static boolean isRedirection(int code) 998 { 999 return ((300 <= code) && (code <= 399)); 1000 } 1001 1002 /** 1003 * Simple test against an code to determine if it falls into the 1004 * <code>Client Error</code> message category as defined in the <a 1005 * href="http://tools.ietf.org/html/rfc1945">RFC 1945 - HTTP/1.0</a>, and <a 1006 * href="http://tools.ietf.org/html/rfc2616">RFC 2616 - HTTP/1.1</a>. 1007 * 1008 * @param code 1009 * the code to test. 1010 * @return true if within range of codes that belongs to 1011 * <code>Client Error</code> messages. 1012 */ 1013 public static boolean isClientError(int code) 1014 { 1015 return ((400 <= code) && (code <= 499)); 1016 } 1017 1018 /** 1019 * Simple test against an code to determine if it falls into the 1020 * <code>Server Error</code> message category as defined in the <a 1021 * href="http://tools.ietf.org/html/rfc1945">RFC 1945 - HTTP/1.0</a>, and <a 1022 * href="http://tools.ietf.org/html/rfc2616">RFC 2616 - HTTP/1.1</a>. 1023 * 1024 * @param code 1025 * the code to test. 1026 * @return true if within range of codes that belongs to 1027 * <code>Server Error</code> messages. 1028 */ 1029 public static boolean isServerError(int code) 1030 { 1031 return ((500 <= code) && (code <= 599)); 1032 } 1033 }