diff --git a/spring-web/src/main/java/org/springframework/web/multipart/support/MissingServletRequestPartException.java b/spring-web/src/main/java/org/springframework/web/multipart/support/MissingServletRequestPartException.java index 0ee85e75cc64d5726a31d1c831ccbb5a61ce474e..422517bd63d721a1e1be8bf2cb9e1798f41349d9 100644 --- a/spring-web/src/main/java/org/springframework/web/multipart/support/MissingServletRequestPartException.java +++ b/spring-web/src/main/java/org/springframework/web/multipart/support/MissingServletRequestPartException.java @@ -22,13 +22,13 @@ import org.springframework.web.multipart.MultipartResolver; /** * Raised when the part of a "multipart/form-data" request identified by its - * name cannot be found. - * - *
This may be because the request is not a multipart/form-data - * - * either because the part is not present in the request, or - * because the web application is not configured correctly for processing - * multipart requests -- e.g. no {@link MultipartResolver}. + * name cannot be found. + * + *
This may be because the request is not a multipart/form-data + * + * either because the part is not present in the request, or + * because the web application is not configured correctly for processing + * multipart requests -- e.g. no {@link MultipartResolver}. * * @author Rossen Stoyanchev * @since 3.1 @@ -40,7 +40,7 @@ public class MissingServletRequestPartException extends ServletException { private final String partName; public MissingServletRequestPartException(String partName) { - super("Request part '" + partName + "' not found."); + super("Required request part '" + partName + "' is not present."); this.partName = partName; } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/support/DefaultHandlerExceptionResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/support/DefaultHandlerExceptionResolver.java index 104d9da3515854e749885b9531cd753d874bb20b..bf0e69649f622aed1dd2fd95e082d652391220e2 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/support/DefaultHandlerExceptionResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/support/DefaultHandlerExceptionResolver.java @@ -258,7 +258,7 @@ public class DefaultHandlerExceptionResolver extends AbstractHandlerExceptionRes protected ModelAndView handleMissingServletRequestParameter(MissingServletRequestParameterException ex, HttpServletRequest request, HttpServletResponse response, Object handler) throws IOException { - response.sendError(HttpServletResponse.SC_BAD_REQUEST); + response.sendError(HttpServletResponse.SC_BAD_REQUEST, ex.getMessage()); return new ModelAndView(); } @@ -384,7 +384,7 @@ public class DefaultHandlerExceptionResolver extends AbstractHandlerExceptionRes */ protected ModelAndView handleMissingServletRequestPartException(MissingServletRequestPartException ex, HttpServletRequest request, HttpServletResponse response, Object handler) throws IOException { - response.sendError(HttpServletResponse.SC_BAD_REQUEST); + response.sendError(HttpServletResponse.SC_BAD_REQUEST, ex.getMessage()); return new ModelAndView(); } diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/support/DefaultHandlerExceptionResolverTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/support/DefaultHandlerExceptionResolverTests.java index 0ef1163958c2154d200db08892aaf6016cc971ce..9fdc1bdc7f8e5db913ffa744dcf83c0096d379ac 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/support/DefaultHandlerExceptionResolverTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/support/DefaultHandlerExceptionResolverTests.java @@ -98,6 +98,7 @@ public class DefaultHandlerExceptionResolverTests { assertNotNull("No ModelAndView returned", mav); assertTrue("No Empty ModelAndView returned", mav.isEmpty()); assertEquals("Invalid status code", 400, response.getStatus()); + assertEquals("Required bar parameter 'foo' is not present", response.getErrorMessage()); } @Test @@ -156,6 +157,7 @@ public class DefaultHandlerExceptionResolverTests { assertNotNull("No ModelAndView returned", mav); assertTrue("No Empty ModelAndView returned", mav.isEmpty()); assertEquals("Invalid status code", 400, response.getStatus()); + assertEquals("Required request part 'name' is not present.", response.getErrorMessage()); } @Test