diff --git a/org.springframework.web/src/main/java/org/springframework/http/HttpStatus.java b/org.springframework.web/src/main/java/org/springframework/http/HttpStatus.java index 79a2bbd00c8b1cd73ac8f2f09ca8fa54a449bfa2..1de14c2884a578f0d741412e84922b05d1cf633a 100644 --- a/org.springframework.web/src/main/java/org/springframework/http/HttpStatus.java +++ b/org.springframework.web/src/main/java/org/springframework/http/HttpStatus.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2012 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,6 +24,7 @@ package org.springframework.http; * @author Arjen Poutsma * @see HttpStatus.Series * @see HTTP Status Code Registry + * @see List of HTTP status codes - Wikipedia */ public enum HttpStatus { @@ -44,6 +45,12 @@ public enum HttpStatus { * @see WebDAV */ PROCESSING(102, "Processing"), + /** + * {@code 103 Checkpoint}. + * @see A proposal for supporting + * resumable POST/PUT HTTP requests in HTTP/1.0 + */ + CHECKPOINT(103, "Checkpoint"), // 2xx Success @@ -140,6 +147,12 @@ public enum HttpStatus { * @see HTTP/1.1 */ TEMPORARY_REDIRECT(307, "Temporary Redirect"), + /** + * {@code 308 Resume Incomplete}. + * @see A proposal for supporting + * resumable POST/PUT HTTP requests in HTTP/1.0 + */ + RESUME_INCOMPLETE(308, "Resume Incomplete"), // --- 4xx Client Error --- @@ -187,7 +200,7 @@ public enum HttpStatus { * {@code 408 Request Timeout}. * @see HTTP/1.1 */ - REQUEST_TIMEOUT(408, "Request Time-out"), + REQUEST_TIMEOUT(408, "Request Timeout"), /** * {@code 409 Conflict}. * @see HTTP/1.1 @@ -217,7 +230,7 @@ public enum HttpStatus { * {@code 414 Request-URI Too Long}. * @see HTTP/1.1 */ - REQUEST_URI_TOO_LONG(414, "Request-URI Too Large"), + REQUEST_URI_TOO_LONG(414, "Request-URI Too Long"), /** * {@code 415 Unsupported Media Type}. * @see HTTP/1.1 @@ -233,6 +246,11 @@ public enum HttpStatus { * @see HTTP/1.1 */ EXPECTATION_FAILED(417, "Expectation Failed"), + /** + * {@code 418 I'm a teapot}. + * @see HTCPCP/1.0 + */ + I_AM_A_TEAPOT(418, "I'm a teapot"), /** * {@code 419 Insufficient Space on Resource}. * @see WebDAV Draft @@ -268,6 +286,24 @@ public enum HttpStatus { * @see Upgrading to TLS Within HTTP/1.1 */ UPGRADE_REQUIRED(426, "Upgrade Required"), + /** + * {@code 428 Precondition Required}. + * @see Additional HTTP Status + * Codes + */ + PRECONDITION_REQUIRED(428, "Precondition Required"), + /** + * {@code 429 Too Many Requests}. + * @see Additional HTTP Status + * Codes + */ + TOO_MANY_REQUESTS(429, "Too Many Requests"), + /** + * {@code 431 Request Header Fields Too Large}. + * @see Additional HTTP Status + * Codes + */ + REQUEST_HEADER_FIELDS_TOO_LARGE(431, "Request Header Fields Too Large"), // --- 5xx Server Error --- @@ -295,7 +331,7 @@ public enum HttpStatus { * {@code 504 Gateway Timeout}. * @see HTTP/1.1 */ - GATEWAY_TIMEOUT(504, "Gateway Time-out"), + GATEWAY_TIMEOUT(504, "Gateway Timeout"), /** * {@code 505 HTTP Version Not Supported}. * @see HTTP/1.1 @@ -316,11 +352,22 @@ public enum HttpStatus { * @see WebDAV Binding Extensions */ LOOP_DETECTED(508, "Loop Detected"), + /** + * {@code 509 Bandwidth Limit Exceeded} + */ + BANDWIDTH_LIMIT_EXCEEDED(509, "Bandwidth Limit Exceeded"), /** * {@code 510 Not Extended} * @see HTTP Extension Framework */ - NOT_EXTENDED(510, "Not Extended"); + NOT_EXTENDED(510, "Not Extended"), + /** + * {@code 511 Network Authentication Required}. + * @see Additional HTTP Status + * Codes + */ + NETWORK_AUTHENTICATION_REQUIRED(511, "Network Authentication Required"); + private final int value; diff --git a/org.springframework.web/src/test/java/org/springframework/http/HttpStatusTests.java b/org.springframework.web/src/test/java/org/springframework/http/HttpStatusTests.java index 4fbe093e7691aa3da0502c027950aac8a1096afb..15fd54740281a30930748f8e39f59179e05400ce 100644 --- a/org.springframework.web/src/test/java/org/springframework/http/HttpStatusTests.java +++ b/org.springframework.web/src/test/java/org/springframework/http/HttpStatusTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2012 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,38 +16,110 @@ package org.springframework.http; -import static org.junit.Assert.*; +import java.util.LinkedHashMap; +import java.util.Map; + +import org.junit.Before; import org.junit.Test; +import static org.junit.Assert.*; + /** @author Arjen Poutsma */ public class HttpStatusTests { - private int[] registryValues = - new int[]{100, 101, 102, 200, 201, 202, 203, 204, 205, 206, 207, 208, 226, 300, 301, 302, 303, 304, 305, - 307, 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, 422, - 423, 424, 426, 500, 501, 502, 503, 504, 505, 506, 507, 508, 510,}; - - private String[] registryDescriptions = - new String[]{"CONTINUE", "SWITCHING_PROTOCOLS", "PROCESSING", "OK", "CREATED", "ACCEPTED", - "NON_AUTHORITATIVE_INFORMATION", "NO_CONTENT", "RESET_CONTENT", "PARTIAL_CONTENT", "MULTI_STATUS", - "ALREADY_REPORTED", "IM_USED", "MULTIPLE_CHOICES", "MOVED_PERMANENTLY", "FOUND", "SEE_OTHER", - "NOT_MODIFIED", "USE_PROXY", "TEMPORARY_REDIRECT", "BAD_REQUEST", "UNAUTHORIZED", - "PAYMENT_REQUIRED", "FORBIDDEN", "NOT_FOUND", "METHOD_NOT_ALLOWED", "NOT_ACCEPTABLE", - "PROXY_AUTHENTICATION_REQUIRED", "REQUEST_TIMEOUT", "CONFLICT", "GONE", "LENGTH_REQUIRED", - "PRECONDITION_FAILED", "REQUEST_ENTITY_TOO_LARGE", "REQUEST_URI_TOO_LONG", "UNSUPPORTED_MEDIA_TYPE", - "REQUESTED_RANGE_NOT_SATISFIABLE", "EXPECTATION_FAILED", "UNPROCESSABLE_ENTITY", "LOCKED", - "FAILED_DEPENDENCY", "UPGRADE_REQUIRED", "INTERNAL_SERVER_ERROR", "NOT_IMPLEMENTED", "BAD_GATEWAY", - "SERVICE_UNAVAILABLE", "GATEWAY_TIMEOUT", "HTTP_VERSION_NOT_SUPPORTED", "VARIANT_ALSO_NEGOTIATES", - "INSUFFICIENT_STORAGE", "LOOP_DETECTED", "NOT_EXTENDED",}; + private Map statusCodes = new LinkedHashMap(); + + @Before + public void createStatusCodes() { + statusCodes.put(100, "CONTINUE"); + statusCodes.put(101, "SWITCHING_PROTOCOLS"); + statusCodes.put(102, "PROCESSING"); + statusCodes.put(103, "CHECKPOINT"); + + statusCodes.put(200, "OK"); + statusCodes.put(201, "CREATED"); + statusCodes.put(202, "ACCEPTED"); + statusCodes.put(203, "NON_AUTHORITATIVE_INFORMATION"); + statusCodes.put(204, "NO_CONTENT"); + statusCodes.put(205, "RESET_CONTENT"); + statusCodes.put(206, "PARTIAL_CONTENT"); + statusCodes.put(207, "MULTI_STATUS"); + statusCodes.put(208, "ALREADY_REPORTED"); + statusCodes.put(226, "IM_USED"); + + statusCodes.put(300, "MULTIPLE_CHOICES"); + statusCodes.put(301, "MOVED_PERMANENTLY"); + statusCodes.put(302, "FOUND"); + statusCodes.put(303, "SEE_OTHER"); + statusCodes.put(304, "NOT_MODIFIED"); + statusCodes.put(305, "USE_PROXY"); + statusCodes.put(307, "TEMPORARY_REDIRECT"); + statusCodes.put(308, "RESUME_INCOMPLETE"); + + statusCodes.put(400, "BAD_REQUEST"); + statusCodes.put(401, "UNAUTHORIZED"); + statusCodes.put(402, "PAYMENT_REQUIRED"); + statusCodes.put(403, "FORBIDDEN"); + statusCodes.put(404, "NOT_FOUND"); + statusCodes.put(405, "METHOD_NOT_ALLOWED"); + statusCodes.put(406, "NOT_ACCEPTABLE"); + statusCodes.put(407, "PROXY_AUTHENTICATION_REQUIRED"); + statusCodes.put(408, "REQUEST_TIMEOUT"); + statusCodes.put(409, "CONFLICT"); + statusCodes.put(410, "GONE"); + statusCodes.put(411, "LENGTH_REQUIRED"); + statusCodes.put(412, "PRECONDITION_FAILED"); + statusCodes.put(413, "REQUEST_ENTITY_TOO_LARGE"); + statusCodes.put(414, "REQUEST_URI_TOO_LONG"); + statusCodes.put(415, "UNSUPPORTED_MEDIA_TYPE"); + statusCodes.put(416, "REQUESTED_RANGE_NOT_SATISFIABLE"); + statusCodes.put(417, "EXPECTATION_FAILED"); + statusCodes.put(418, "I_AM_A_TEAPOT"); + statusCodes.put(419, "INSUFFICIENT_SPACE_ON_RESOURCE"); + statusCodes.put(420, "METHOD_FAILURE"); + statusCodes.put(421, "DESTINATION_LOCKED"); + statusCodes.put(422, "UNPROCESSABLE_ENTITY"); + statusCodes.put(423, "LOCKED"); + statusCodes.put(424, "FAILED_DEPENDENCY"); + statusCodes.put(426, "UPGRADE_REQUIRED"); + statusCodes.put(428, "PRECONDITION_REQUIRED"); + statusCodes.put(429, "TOO_MANY_REQUESTS"); + statusCodes.put(431, "REQUEST_HEADER_FIELDS_TOO_LARGE"); + + statusCodes.put(500, "INTERNAL_SERVER_ERROR"); + statusCodes.put(501, "NOT_IMPLEMENTED"); + statusCodes.put(502, "BAD_GATEWAY"); + statusCodes.put(503, "SERVICE_UNAVAILABLE"); + statusCodes.put(504, "GATEWAY_TIMEOUT"); + statusCodes.put(505, "HTTP_VERSION_NOT_SUPPORTED"); + statusCodes.put(506, "VARIANT_ALSO_NEGOTIATES"); + statusCodes.put(507, "INSUFFICIENT_STORAGE"); + statusCodes.put(508, "LOOP_DETECTED"); + statusCodes.put(509, "BANDWIDTH_LIMIT_EXCEEDED"); + statusCodes.put(510, "NOT_EXTENDED"); + statusCodes.put(511, "NETWORK_AUTHENTICATION_REQUIRED"); + } @Test - public void registryValues() { - for (int i = 0; i < registryValues.length; i++) { - HttpStatus status = HttpStatus.valueOf(registryValues[i]); - assertEquals("Invalid value", registryValues[i], status.value()); - assertEquals("Invalid descripion", registryDescriptions[i], status.name()); + public void fromMapToEnum() { + for (Map.Entry entry : statusCodes.entrySet()) { + int value = entry.getKey(); + HttpStatus status = HttpStatus.valueOf(value); + assertEquals("Invalid value", value, status.value()); + assertEquals("Invalid name for [" + value + "]", entry.getValue(), status.name()); } - } + @Test + public void fromEnumToMap() { + + for (HttpStatus status : HttpStatus.values()) { + int value = status.value(); + if (value == 302) { + continue; + } + assertTrue("Map has no value for [" + value + "]", statusCodes.containsKey(value)); + assertEquals("Invalid name for [" + value + "]", statusCodes.get(value), status.name()); + } + } }