Skip to content

Commit 68b4c7d

Browse files
committed
SPR-6752 - RestTemplate throws IllegalArgumentException when HTTP status is not in the HttpStatus enum
1 parent 103ac03 commit 68b4c7d

File tree

3 files changed

+297
-2
lines changed

3 files changed

+297
-2
lines changed

build-spring-framework/resources/changelog.txt

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ http://www.springsource.org
66
Changes in version 3.0.1 (2010-02-18)
77
-------------------------------------
88

9+
* changed HttpStatus.REQUEST_TOO_LONG constant to REQUEST_ENTITY_TOO_LARGE
910
* upgraded to AspectJ 1.6.8
1011
* full support for JPA 2.0 persistence schema and PersistenceUnitInfo SPI
1112
* support for JPA PersistenceContext/Unit injection on Google App Engine

org.springframework.web/src/main/java/org/springframework/http/HttpStatus.java

+243-2
Original file line numberDiff line numberDiff line change
@@ -23,63 +23,304 @@
2323
*
2424
* @author Arjen Poutsma
2525
* @see HttpStatus.Series
26+
* @see <a href="http://www.iana.org/assignments/http-status-codes">HTTP Status Code Registry</a>
2627
*/
2728
public enum HttpStatus {
2829

2930
// 1xx Informational
3031

32+
/**
33+
* {@code 100 Continue}.
34+
* @see <a href="http://tools.ietf.org/html/rfc2616#section-10.1.1">HTTP/1.1</a>
35+
*/
3136
CONTINUE(100),
37+
/**
38+
* {@code 101 Switching Protocols}.
39+
* @see <a href="http://tools.ietf.org/html/rfc2616#section-10.1.2">HTTP/1.1</a>
40+
*/
3241
SWITCHING_PROTOCOLS(101),
42+
/**
43+
* {@code 102 Processing}.
44+
* @see <a href="http://tools.ietf.org/html/rfc2518#section-10.1">WebDAV</a>
45+
*/
46+
PROCESSING(102),
3347

3448
// 2xx Success
3549

50+
/**
51+
* {@code 200 OK}.
52+
* @see <a href="http://tools.ietf.org/html/rfc2616#section-10.2.1">HTTP/1.1</a>
53+
*/
3654
OK(200),
55+
/**
56+
* {@code 201 Created}.
57+
* @see <a href="http://tools.ietf.org/html/rfc2616#section-10.2.2">HTTP/1.1</a>
58+
*/
3759
CREATED(201),
60+
/**
61+
* {@code 202 Accepted}.
62+
* @see <a href="http://tools.ietf.org/html/rfc2616#section-10.2.3">HTTP/1.1</a>
63+
*/
3864
ACCEPTED(202),
65+
/**
66+
* {@code 203 Non-Authoritative Information}.
67+
* @see <a href="http://tools.ietf.org/html/rfc2616#section-10.2.4">HTTP/1.1</a>
68+
*/
3969
NON_AUTHORITATIVE_INFORMATION(203),
70+
/**
71+
* {@code 204 No Content}.
72+
* @see <a href="http://tools.ietf.org/html/rfc2616#section-10.2.5">HTTP/1.1</a>
73+
*/
4074
NO_CONTENT(204),
75+
/**
76+
* {@code 205 Reset Content}.
77+
* @see <a href="http://tools.ietf.org/html/rfc2616#section-10.2.6">HTTP/1.1</a>
78+
*/
4179
RESET_CONTENT(205),
80+
/**
81+
* {@code 206 Partial Content}.
82+
* @see <a href="http://tools.ietf.org/html/rfc2616#section-10.2.7">HTTP/1.1</a>
83+
*/
4284
PARTIAL_CONTENT(206),
85+
/**
86+
* {@code 207 Multi-Status}.
87+
* @see <a href="http://tools.ietf.org/html/rfc4918#section-13">WebDAV</a>
88+
*/
89+
MULTI_STATUS(207),
90+
/**
91+
* {@code 208 Already Reported}.
92+
* @see <a href="http://tools.ietf.org/html/draft-ietf-webdav-bind-27#section-7.1">WebDAV Binding Extensions</a>
93+
*/
94+
ALREADY_REPORTED(208),
95+
/**
96+
* {@code 226 IM Used}.
97+
* @see <a href="http://tools.ietf.org/html/rfc3229#section-10.4.1">Delta encoding in HTTP</a>
98+
*/
99+
IM_USED(226),
43100

44101
// 3xx Redirection
45102

103+
/**
104+
* {@code 300 Multiple Choices}.
105+
* @see <a href="http://tools.ietf.org/html/rfc2616#section-10.3.1">HTTP/1.1</a>
106+
*/
46107
MULTIPLE_CHOICES(300),
108+
/**
109+
* {@code 301 Moved Permanently}.
110+
* @see <a href="http://tools.ietf.org/html/rfc2616#section-10.3.2">HTTP/1.1</a>
111+
*/
47112
MOVED_PERMANENTLY(301),
113+
/**
114+
* {@code 302 Found}.
115+
* @see <a href="http://tools.ietf.org/html/rfc2616#section-10.3.3">HTTP/1.1</a>
116+
*/
117+
FOUND(302),
118+
/**
119+
* {@code 302 Moved Temporarily}.
120+
* @see <a href="http://tools.ietf.org/html/rfc1945#section-9.3">HTTP/1.0</a>
121+
*/
48122
MOVED_TEMPORARILY(302),
123+
/**
124+
* {@code 303 See Other}.
125+
* @see <a href="http://tools.ietf.org/html/rfc2616#section-10.3.4">HTTP/1.1</a>
126+
*/
49127
SEE_OTHER(303),
128+
/**
129+
* {@code 304 Not Modified}.
130+
* @see <a href="http://tools.ietf.org/html/rfc2616#section-10.3.5">HTTP/1.1</a>
131+
*/
50132
NOT_MODIFIED(304),
133+
/**
134+
* {@code 305 Use Proxy}.
135+
* @see <a href="http://tools.ietf.org/html/rfc2616#section-10.3.6">HTTP/1.1</a>
136+
*/
51137
USE_PROXY(305),
138+
/**
139+
* {@code 307 Temporary Redirect}.
140+
* @see <a href="http://tools.ietf.org/html/rfc2616#section-10.3.8">HTTP/1.1</a>
141+
*/
52142
TEMPORARY_REDIRECT(307),
53143

54144
// --- 4xx Client Error ---
55145

146+
/**
147+
* {@code 400 Bad Request}.
148+
* @see <a href="http://tools.ietf.org/html/rfc2616#section-10.4.1">HTTP/1.1</a>
149+
*/
56150
BAD_REQUEST(400),
151+
/**
152+
* {@code 401 Unauthorized}.
153+
* @see <a href="http://tools.ietf.org/html/rfc2616#section-10.4.2">HTTP/1.1</a>
154+
*/
57155
UNAUTHORIZED(401),
156+
/**
157+
* {@code 402 Payment Required}.
158+
* @see <a href="http://tools.ietf.org/html/rfc2616#section-10.4.3">HTTP/1.1</a>
159+
*/
58160
PAYMENT_REQUIRED(402),
161+
/**
162+
* {@code 403 Forbidden}.
163+
* @see <a href="http://tools.ietf.org/html/rfc2616#section-10.4.4">HTTP/1.1</a>
164+
*/
59165
FORBIDDEN(403),
166+
/**
167+
* {@code 404 Not Found}.
168+
* @see <a href="http://tools.ietf.org/html/rfc2616#section-10.4.5">HTTP/1.1</a>
169+
*/
60170
NOT_FOUND(404),
171+
/**
172+
* {@code 405 Method Not Allowed}.
173+
* @see <a href="http://tools.ietf.org/html/rfc2616#section-10.4.6">HTTP/1.1</a>
174+
*/
61175
METHOD_NOT_ALLOWED(405),
176+
/**
177+
* {@code 406 Not Acceptable}.
178+
* @see <a href="http://tools.ietf.org/html/rfc2616#section-10.4.7">HTTP/1.1</a>
179+
*/
62180
NOT_ACCEPTABLE(406),
181+
/**
182+
* {@code 407 Proxy Authentication Required}.
183+
* @see <a href="http://tools.ietf.org/html/rfc2616#section-10.4.8">HTTP/1.1</a>
184+
*/
63185
PROXY_AUTHENTICATION_REQUIRED(407),
186+
/**
187+
* {@code 408 Request Timeout}.
188+
* @see <a href="http://tools.ietf.org/html/rfc2616#section-10.4.9">HTTP/1.1</a>
189+
*/
64190
REQUEST_TIMEOUT(408),
191+
/**
192+
* {@code 409 Conflict}.
193+
* @see <a href="http://tools.ietf.org/html/rfc2616#section-10.4.10">HTTP/1.1</a>
194+
*/
65195
CONFLICT(409),
196+
/**
197+
* {@code 410 Gone}.
198+
* @see <a href="http://tools.ietf.org/html/rfc2616#section-10.4.11">HTTP/1.1</a>
199+
*/
66200
GONE(410),
201+
/**
202+
* {@code 411 Length Required}.
203+
* @see <a href="http://tools.ietf.org/html/rfc2616#section-10.4.12">HTTP/1.1</a>
204+
*/
67205
LENGTH_REQUIRED(411),
206+
/**
207+
* {@code 412 Precondition failed}.
208+
* @see <a href="http://tools.ietf.org/html/rfc2616#section-10.4.13">HTTP/1.1</a>
209+
*/
68210
PRECONDITION_FAILED(412),
69-
REQUEST_TOO_LONG(413),
211+
/**
212+
* {@code 413 Request Entity Too Large}.
213+
* @see <a href="http://tools.ietf.org/html/rfc2616#section-10.4.14">HTTP/1.1</a>
214+
*/
215+
REQUEST_ENTITY_TOO_LARGE(413),
216+
/**
217+
* {@code 414 Request-URI Too Long}.
218+
* @see <a href="http://tools.ietf.org/html/rfc2616#section-10.4.15">HTTP/1.1</a>
219+
*/
70220
REQUEST_URI_TOO_LONG(414),
221+
/**
222+
* {@code 415 Unsupported Media Type}.
223+
* @see <a href="http://tools.ietf.org/html/rfc2616#section-10.4.16">HTTP/1.1</a>
224+
*/
71225
UNSUPPORTED_MEDIA_TYPE(415),
226+
/**
227+
* {@code 416 Requested Range Not Satisfiable}.
228+
* @see <a href="http://tools.ietf.org/html/rfc2616#section-10.4.17">HTTP/1.1</a>
229+
*/
72230
REQUESTED_RANGE_NOT_SATISFIABLE(416),
231+
/**
232+
* {@code 417 Expectation Failed}.
233+
* @see <a href="http://tools.ietf.org/html/rfc2616#section-10.4.18">HTTP/1.1</a>
234+
*/
73235
EXPECTATION_FAILED(417),
236+
/**
237+
* {@code 419 Insufficient Space on Resource}.
238+
* @see <a href="http://tools.ietf.org/html/draft-ietf-webdav-protocol-05#section-10.4">WebDAV Draft</a>
239+
*/
240+
INSUFFICIENT_SPACE_ON_RESOURCE(419),
241+
/**
242+
* {@code 420 Method Failure}.
243+
* @see <a href="http://tools.ietf.org/html/draft-ietf-webdav-protocol-05#section-10.5">WebDAV Draft</a>
244+
*/
245+
METHOD_FAILURE(420),
246+
/**
247+
* {@code 421 Destination Locked}.
248+
* @see <a href="http://tools.ietf.org/html/draft-ietf-webdav-protocol-05#section-10.6">WebDAV Draft</a>
249+
*/
250+
DESTINATION_LOCKED(421),
251+
/**
252+
* {@code 422 Unprocessable Entity}.
253+
* @see <a href="http://tools.ietf.org/html/rfc4918#section-11.2">WebDAV</a>
254+
*/
255+
UNPROCESSABLE_ENTITY(422),
256+
/**
257+
* {@code 423 Locked}.
258+
* @see <a href="http://tools.ietf.org/html/rfc4918#section-11.3">WebDAV</a>
259+
*/
260+
LOCKED(423),
261+
/**
262+
* {@code 424 Failed Dependency}.
263+
* @see <a href="http://tools.ietf.org/html/rfc4918#section-11.4">WebDAV</a>
264+
*/
265+
FAILED_DEPENDENCY(424),
266+
/**
267+
* {@code 426 Upgrade Required}.
268+
* @see <a href="http://tools.ietf.org/html/rfc2817#section-6">Upgrading to TLS Within HTTP/1.1</a>
269+
*/
270+
UPGRADE_REQUIRED(426),
74271

75272
// --- 5xx Server Error ---
76273

274+
/**
275+
* {@code 500 Internal Server Error}.
276+
* @see <a href="http://tools.ietf.org/html/rfc2616#section-10.5.1">HTTP/1.1</a>
277+
*/
77278
INTERNAL_SERVER_ERROR(500),
279+
/**
280+
* {@code 501 Not Implemented}.
281+
* @see <a href="http://tools.ietf.org/html/rfc2616#section-10.5.2">HTTP/1.1</a>
282+
*/
78283
NOT_IMPLEMENTED(501),
284+
/**
285+
* {@code 502 Bad Gateway}.
286+
* @see <a href="http://tools.ietf.org/html/rfc2616#section-10.5.3">HTTP/1.1</a>
287+
*/
79288
BAD_GATEWAY(502),
289+
/**
290+
* {@code 503 Service Unavailable}.
291+
* @see <a href="http://tools.ietf.org/html/rfc2616#section-10.5.4">HTTP/1.1</a>
292+
*/
80293
SERVICE_UNAVAILABLE(503),
294+
/**
295+
* {@code 504 Gateway Timeout}.
296+
* @see <a href="http://tools.ietf.org/html/rfc2616#section-10.5.5">HTTP/1.1</a>
297+
*/
81298
GATEWAY_TIMEOUT(504),
82-
HTTP_VERSION_NOT_SUPPORTED(505);
299+
/**
300+
* {@code 505 HTTP Version Not Supported}.
301+
* @see <a href="http://tools.ietf.org/html/rfc2616#section-10.5.6">HTTP/1.1</a>
302+
*/
303+
HTTP_VERSION_NOT_SUPPORTED(505),
304+
/**
305+
* {@code 506 Variant Also Negotiates}
306+
* @see <a href="http://tools.ietf.org/html/rfc2295#section-8.1">Transparent Content Negotiation</a>
307+
*/
308+
VARIANT_ALSO_NEGOTIATES(506),
309+
/**
310+
* {@code 507 Insufficient Storage}
311+
* @see <a href="http://tools.ietf.org/html/rfc4918#section-11.5">WebDAV</a>
312+
*/
313+
INSUFFICIENT_STORAGE(507),
314+
/**
315+
* {@code 508 Loop Detected}
316+
* @see <a href="http://tools.ietf.org/html/draft-ietf-webdav-bind-27#section-7.2">WebDAV Binding Extensions</a>
317+
*/
318+
LOOP_DETECTED(508),
319+
/**
320+
* {@code 510 Not Extended}
321+
* @see <a href="http://tools.ietf.org/html/rfc2774#section-7">HTTP Extension Framework</a>
322+
*/
323+
NOT_EXTENDED(510);
83324

84325

85326
private final int value;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright 2002-2010 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.http;
18+
19+
import static org.junit.Assert.*;
20+
import org.junit.Test;
21+
22+
/** @author Arjen Poutsma */
23+
public class HttpStatusTests {
24+
25+
private int[] registryValues =
26+
new int[]{100, 101, 102, 200, 201, 202, 203, 204, 205, 206, 207, 208, 226, 300, 301, 302, 303, 304, 305,
27+
307, 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, 422,
28+
423, 424, 426, 500, 501, 502, 503, 504, 505, 506, 507, 508, 510,};
29+
30+
private String[] registryDescriptions =
31+
new String[]{"CONTINUE", "SWITCHING_PROTOCOLS", "PROCESSING", "OK", "CREATED", "ACCEPTED",
32+
"NON_AUTHORITATIVE_INFORMATION", "NO_CONTENT", "RESET_CONTENT", "PARTIAL_CONTENT", "MULTI_STATUS",
33+
"ALREADY_REPORTED", "IM_USED", "MULTIPLE_CHOICES", "MOVED_PERMANENTLY", "FOUND", "SEE_OTHER",
34+
"NOT_MODIFIED", "USE_PROXY", "TEMPORARY_REDIRECT", "BAD_REQUEST", "UNAUTHORIZED",
35+
"PAYMENT_REQUIRED", "FORBIDDEN", "NOT_FOUND", "METHOD_NOT_ALLOWED", "NOT_ACCEPTABLE",
36+
"PROXY_AUTHENTICATION_REQUIRED", "REQUEST_TIMEOUT", "CONFLICT", "GONE", "LENGTH_REQUIRED",
37+
"PRECONDITION_FAILED", "REQUEST_ENTITY_TOO_LARGE", "REQUEST_URI_TOO_LONG", "UNSUPPORTED_MEDIA_TYPE",
38+
"REQUESTED_RANGE_NOT_SATISFIABLE", "EXPECTATION_FAILED", "UNPROCESSABLE_ENTITY", "LOCKED",
39+
"FAILED_DEPENDENCY", "UPGRADE_REQUIRED", "INTERNAL_SERVER_ERROR", "NOT_IMPLEMENTED", "BAD_GATEWAY",
40+
"SERVICE_UNAVAILABLE", "GATEWAY_TIMEOUT", "HTTP_VERSION_NOT_SUPPORTED", "VARIANT_ALSO_NEGOTIATES",
41+
"INSUFFICIENT_STORAGE", "LOOP_DETECTED", "NOT_EXTENDED",};
42+
43+
@Test
44+
public void registryValues() {
45+
for (int i = 0; i < registryValues.length; i++) {
46+
HttpStatus status = HttpStatus.valueOf(registryValues[i]);
47+
assertEquals("Invalid value", registryValues[i], status.value());
48+
assertEquals("Invalid descripion", registryDescriptions[i], status.name());
49+
}
50+
51+
}
52+
53+
}

0 commit comments

Comments
 (0)