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 f19d587f5e..539ec6a5ea 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 @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2022 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,8 +16,7 @@ package org.springframework.web.multipart.support; -import jakarta.servlet.ServletException; - +import org.springframework.web.bind.ServletRequestBindingException; import org.springframework.web.multipart.MultipartResolver; /** @@ -30,10 +29,11 @@ import org.springframework.web.multipart.MultipartResolver; * e.g. no {@link MultipartResolver}. * * @author Rossen Stoyanchev + * @author Wonchul Heo * @since 3.1 */ @SuppressWarnings("serial") -public class MissingServletRequestPartException extends ServletException { +public class MissingServletRequestPartException extends ServletRequestBindingException { private final String requestPartName; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ResponseEntityExceptionHandler.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ResponseEntityExceptionHandler.java index c4f3076efa..6c9e70c8e4 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ResponseEntityExceptionHandler.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ResponseEntityExceptionHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2022 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. @@ -73,6 +73,7 @@ import org.springframework.web.util.WebUtils; * detected, {@link ExceptionHandlerExceptionResolver} must be configured. * * @author Rossen Stoyanchev + * @author Wonchul Heo * @since 3.2 * @see #handleException(Exception, WebRequest) * @see org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver @@ -108,13 +109,13 @@ public abstract class ResponseEntityExceptionHandler { HttpMediaTypeNotAcceptableException.class, MissingPathVariableException.class, MissingServletRequestParameterException.class, + MissingServletRequestPartException.class, ServletRequestBindingException.class, ConversionNotSupportedException.class, TypeMismatchException.class, HttpMessageNotReadableException.class, HttpMessageNotWritableException.class, MethodArgumentNotValidException.class, - MissingServletRequestPartException.class, BindException.class, NoHandlerFoundException.class, AsyncRequestTimeoutException.class @@ -143,6 +144,10 @@ public abstract class ResponseEntityExceptionHandler { HttpStatus status = HttpStatus.BAD_REQUEST; return handleMissingServletRequestParameter((MissingServletRequestParameterException) ex, headers, status, request); } + else if (ex instanceof MissingServletRequestPartException) { + HttpStatus status = HttpStatus.BAD_REQUEST; + return handleMissingServletRequestPart((MissingServletRequestPartException) ex, headers, status, request); + } else if (ex instanceof ServletRequestBindingException) { HttpStatus status = HttpStatus.BAD_REQUEST; return handleServletRequestBindingException((ServletRequestBindingException) ex, headers, status, request); @@ -167,10 +172,6 @@ public abstract class ResponseEntityExceptionHandler { HttpStatus status = HttpStatus.BAD_REQUEST; return handleMethodArgumentNotValid((MethodArgumentNotValidException) ex, headers, status, request); } - else if (ex instanceof MissingServletRequestPartException) { - HttpStatus status = HttpStatus.BAD_REQUEST; - return handleMissingServletRequestPart((MissingServletRequestPartException) ex, headers, status, request); - } else if (ex instanceof BindException) { HttpStatus status = HttpStatus.BAD_REQUEST; return handleBindException((BindException) ex, headers, status, request); 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 dfd379d7ac..4aa1b2b664 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 @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2022 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. @@ -90,6 +90,10 @@ import org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver; *

400 (SC_BAD_REQUEST)

* * + *

MissingServletRequestPartException

+ *

400 (SC_BAD_REQUEST)

+ * + * *

ServletRequestBindingException

*

400 (SC_BAD_REQUEST)

* @@ -113,10 +117,6 @@ import org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver; *

MethodArgumentNotValidException

*

400 (SC_BAD_REQUEST)

* - * - *

MissingServletRequestPartException

- *

400 (SC_BAD_REQUEST)

- * * *

BindException

*

400 (SC_BAD_REQUEST)

@@ -135,6 +135,7 @@ import org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver; * @author Arjen Poutsma * @author Rossen Stoyanchev * @author Juergen Hoeller + * @author Wonchul Heo * @since 3.0 * @see org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler */ @@ -188,6 +189,10 @@ public class DefaultHandlerExceptionResolver extends AbstractHandlerExceptionRes return handleMissingServletRequestParameter( (MissingServletRequestParameterException) ex, request, response, handler); } + else if (ex instanceof MissingServletRequestPartException) { + return handleMissingServletRequestPartException( + (MissingServletRequestPartException) ex, request, response, handler); + } else if (ex instanceof ServletRequestBindingException) { return handleServletRequestBindingException( (ServletRequestBindingException) ex, request, response, handler); @@ -212,10 +217,6 @@ public class DefaultHandlerExceptionResolver extends AbstractHandlerExceptionRes return handleMethodArgumentNotValidException( (MethodArgumentNotValidException) ex, request, response, handler); } - else if (ex instanceof MissingServletRequestPartException) { - return handleMissingServletRequestPartException( - (MissingServletRequestPartException) ex, request, response, handler); - } else if (ex instanceof BindException) { return handleBindException((BindException) ex, request, response, handler); }