Skip to content

Commit f1ad53d

Browse files
committed
SPR-6709 Update changelog and add one test
1 parent d2a99de commit f1ad53d

File tree

4 files changed

+23
-4
lines changed

4 files changed

+23
-4
lines changed

build-spring-framework/resources/changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Changes in version 3.1 M2 (2011-05-31)
1717
* support for including @PathVariables in data binding
1818
* support for URI template variables in view names with the "redirect:" prefix
1919
* added a flag for extracting the value from single-key models in MappingJacksonJsonView
20+
* added support for @Valid with @RequestBody arguments
2021
* allow bean references in mvc:interceptor namespace elements
2122
* consolidated the initialization and use of MappedInterceptors in AbstractHandlerMapping
2223
* added Servlet 3.0 based WebApplicationInitializer mechanism for programmatic bootstrapping

org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/support/DefaultHandlerExceptionResolver.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
* <p>This exception resolver is enabled by default in the {@link org.springframework.web.servlet.DispatcherServlet}.
5050
*
5151
* @author Arjen Poutsma
52+
* @author Rossen Stoyanchev
5253
* @since 3.0
5354
* @see #handleNoSuchRequestHandlingMethod
5455
* @see #handleHttpRequestMethodNotSupported
@@ -321,7 +322,7 @@ protected ModelAndView handleHttpMessageNotWritable(HttpMessageNotWritableExcept
321322

322323
/**
323324
* Handle the case where the object created from the body of a request has failed validation. The default
324-
* implementation sends an HTTP 500 error along with a message containing the errors.
325+
* implementation sends an HTTP 400 error along with a message containing the errors.
325326
* @param request current HTTP request
326327
* @param response current HTTP response
327328
* @param handler the executed handler, or <code>null</code> if none chosen

org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/support/DefaultHandlerExceptionResolverTests.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,27 @@
1616

1717
package org.springframework.web.servlet.mvc.support;
1818

19+
import static org.junit.Assert.assertEquals;
20+
import static org.junit.Assert.assertNotNull;
21+
import static org.junit.Assert.assertTrue;
22+
1923
import java.util.Collections;
2024

21-
import static org.junit.Assert.*;
2225
import org.junit.Before;
2326
import org.junit.Test;
24-
27+
import org.springframework.beans.TestBean;
2528
import org.springframework.beans.TypeMismatchException;
2629
import org.springframework.http.MediaType;
2730
import org.springframework.http.converter.HttpMessageNotReadableException;
2831
import org.springframework.http.converter.HttpMessageNotWritableException;
2932
import org.springframework.mock.web.MockHttpServletRequest;
3033
import org.springframework.mock.web.MockHttpServletResponse;
34+
import org.springframework.validation.BeanPropertyBindingResult;
3135
import org.springframework.web.HttpMediaTypeNotSupportedException;
3236
import org.springframework.web.HttpRequestMethodNotSupportedException;
3337
import org.springframework.web.bind.MissingServletRequestParameterException;
3438
import org.springframework.web.servlet.ModelAndView;
39+
import org.springframework.web.servlet.mvc.method.annotation.support.RequestBodyNotValidException;
3540
import org.springframework.web.servlet.mvc.multiaction.NoSuchRequestHandlingMethodException;
3641

3742
/** @author Arjen Poutsma */
@@ -118,5 +123,17 @@ public void handleHttpMessageNotWritable() {
118123
assertEquals("Invalid status code", 500, response.getStatus());
119124
}
120125

126+
@Test
127+
public void handleRequestBodyNotValid() {
128+
BeanPropertyBindingResult errors = new BeanPropertyBindingResult(new TestBean(), "testBean");
129+
errors.rejectValue("name", "invalid");
130+
RequestBodyNotValidException ex = new RequestBodyNotValidException(errors);
131+
ModelAndView mav = exceptionResolver.resolveException(request, response, null, ex);
132+
assertNotNull("No ModelAndView returned", mav);
133+
assertTrue("No Empty ModelAndView returned", mav.isEmpty());
134+
assertEquals("Invalid status code", 400, response.getStatus());
135+
assertTrue(response.getErrorMessage().startsWith("Request body content validation failed"));
136+
assertTrue(response.getErrorMessage().contains("Field error in object 'testBean' on field 'name'"));
137+
}
121138

122139
}

org.springframework.web/src/main/java/org/springframework/web/bind/annotation/RequestMapping.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
* the Servlet request HTTP contents. The request stream will be
9595
* converted to the declared method argument type using
9696
* {@linkplain org.springframework.http.converter.HttpMessageConverter message
97-
* converters}.
97+
* converters}. Such parameters may optionally be annotated with {@code @Valid}.
9898
* <li>{@link org.springframework.http.HttpEntity HttpEntity&lt;?&gt;} parameters
9999
* for access to the Servlet request HTTP headers and contents. The request stream will be
100100
* converted to the entity body using

0 commit comments

Comments
 (0)