SPR-6709 Update changelog and add one test

This commit is contained in:
Rossen Stoyanchev 2011-06-03 09:38:22 +00:00
parent d2a99de9fc
commit f1ad53d570
4 changed files with 23 additions and 4 deletions

View File

@ -17,6 +17,7 @@ Changes in version 3.1 M2 (2011-05-31)
* support for including @PathVariables in data binding * support for including @PathVariables in data binding
* support for URI template variables in view names with the "redirect:" prefix * support for URI template variables in view names with the "redirect:" prefix
* added a flag for extracting the value from single-key models in MappingJacksonJsonView * added a flag for extracting the value from single-key models in MappingJacksonJsonView
* added support for @Valid with @RequestBody arguments
* allow bean references in mvc:interceptor namespace elements * allow bean references in mvc:interceptor namespace elements
* consolidated the initialization and use of MappedInterceptors in AbstractHandlerMapping * consolidated the initialization and use of MappedInterceptors in AbstractHandlerMapping
* added Servlet 3.0 based WebApplicationInitializer mechanism for programmatic bootstrapping * added Servlet 3.0 based WebApplicationInitializer mechanism for programmatic bootstrapping

View File

@ -49,6 +49,7 @@ import org.springframework.web.servlet.mvc.multiaction.NoSuchRequestHandlingMeth
* <p>This exception resolver is enabled by default in the {@link org.springframework.web.servlet.DispatcherServlet}. * <p>This exception resolver is enabled by default in the {@link org.springframework.web.servlet.DispatcherServlet}.
* *
* @author Arjen Poutsma * @author Arjen Poutsma
* @author Rossen Stoyanchev
* @since 3.0 * @since 3.0
* @see #handleNoSuchRequestHandlingMethod * @see #handleNoSuchRequestHandlingMethod
* @see #handleHttpRequestMethodNotSupported * @see #handleHttpRequestMethodNotSupported
@ -321,7 +322,7 @@ public class DefaultHandlerExceptionResolver extends AbstractHandlerExceptionRes
/** /**
* Handle the case where the object created from the body of a request has failed validation. The default * Handle the case where the object created from the body of a request has failed validation. The default
* implementation sends an HTTP 500 error along with a message containing the errors. * implementation sends an HTTP 400 error along with a message containing the errors.
* @param request current HTTP request * @param request current HTTP request
* @param response current HTTP response * @param response current HTTP response
* @param handler the executed handler, or <code>null</code> if none chosen * @param handler the executed handler, or <code>null</code> if none chosen

View File

@ -16,22 +16,27 @@
package org.springframework.web.servlet.mvc.support; package org.springframework.web.servlet.mvc.support;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.util.Collections; import java.util.Collections;
import static org.junit.Assert.*;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.springframework.beans.TestBean;
import org.springframework.beans.TypeMismatchException; import org.springframework.beans.TypeMismatchException;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageNotReadableException; import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.http.converter.HttpMessageNotWritableException; import org.springframework.http.converter.HttpMessageNotWritableException;
import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse; import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.validation.BeanPropertyBindingResult;
import org.springframework.web.HttpMediaTypeNotSupportedException; import org.springframework.web.HttpMediaTypeNotSupportedException;
import org.springframework.web.HttpRequestMethodNotSupportedException; import org.springframework.web.HttpRequestMethodNotSupportedException;
import org.springframework.web.bind.MissingServletRequestParameterException; import org.springframework.web.bind.MissingServletRequestParameterException;
import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.method.annotation.support.RequestBodyNotValidException;
import org.springframework.web.servlet.mvc.multiaction.NoSuchRequestHandlingMethodException; import org.springframework.web.servlet.mvc.multiaction.NoSuchRequestHandlingMethodException;
/** @author Arjen Poutsma */ /** @author Arjen Poutsma */
@ -118,5 +123,17 @@ public class DefaultHandlerExceptionResolverTests {
assertEquals("Invalid status code", 500, response.getStatus()); assertEquals("Invalid status code", 500, response.getStatus());
} }
@Test
public void handleRequestBodyNotValid() {
BeanPropertyBindingResult errors = new BeanPropertyBindingResult(new TestBean(), "testBean");
errors.rejectValue("name", "invalid");
RequestBodyNotValidException ex = new RequestBodyNotValidException(errors);
ModelAndView mav = exceptionResolver.resolveException(request, response, null, ex);
assertNotNull("No ModelAndView returned", mav);
assertTrue("No Empty ModelAndView returned", mav.isEmpty());
assertEquals("Invalid status code", 400, response.getStatus());
assertTrue(response.getErrorMessage().startsWith("Request body content validation failed"));
assertTrue(response.getErrorMessage().contains("Field error in object 'testBean' on field 'name'"));
}
} }

View File

@ -94,7 +94,7 @@ import java.lang.annotation.Target;
* the Servlet request HTTP contents. The request stream will be * the Servlet request HTTP contents. The request stream will be
* converted to the declared method argument type using * converted to the declared method argument type using
* {@linkplain org.springframework.http.converter.HttpMessageConverter message * {@linkplain org.springframework.http.converter.HttpMessageConverter message
* converters}. * converters}. Such parameters may optionally be annotated with {@code @Valid}.
* <li>{@link org.springframework.http.HttpEntity HttpEntity&lt;?&gt;} parameters * <li>{@link org.springframework.http.HttpEntity HttpEntity&lt;?&gt;} parameters
* for access to the Servlet request HTTP headers and contents. The request stream will be * for access to the Servlet request HTTP headers and contents. The request stream will be
* converted to the entity body using * converted to the entity body using