From 037c277351fb2260ee7c15c54bf5c599c7bb998d Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Sun, 20 Jun 2010 18:45:42 +0000 Subject: [PATCH] @MVC handler methods reliably resolve MultipartRequest arguments with HiddenHttpMethodFilter (SPR-7296) --- .../AnnotationMethodHandlerAdapter.java | 20 +++++++++++++++---- .../AnnotationMethodHandlerAdapter.java | 20 +++++++++++++++---- .../support/HandlerMethodInvoker.java | 2 +- 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/org.springframework.web.portlet/src/main/java/org/springframework/web/portlet/mvc/annotation/AnnotationMethodHandlerAdapter.java b/org.springframework.web.portlet/src/main/java/org/springframework/web/portlet/mvc/annotation/AnnotationMethodHandlerAdapter.java index 6fbe0333fe..3c8bf99227 100644 --- a/org.springframework.web.portlet/src/main/java/org/springframework/web/portlet/mvc/annotation/AnnotationMethodHandlerAdapter.java +++ b/org.springframework.web.portlet/src/main/java/org/springframework/web/portlet/mvc/annotation/AnnotationMethodHandlerAdapter.java @@ -85,6 +85,7 @@ import org.springframework.web.bind.support.WebArgumentResolver; import org.springframework.web.bind.support.WebBindingInitializer; import org.springframework.web.context.request.NativeWebRequest; import org.springframework.web.context.request.RequestScope; +import org.springframework.web.multipart.MultipartRequest; import org.springframework.web.portlet.HandlerAdapter; import org.springframework.web.portlet.ModelAndView; import org.springframework.web.portlet.bind.MissingPortletRequestParameterException; @@ -582,17 +583,28 @@ public class AnnotationMethodHandlerAdapter extends PortletContentGenerator } @Override - protected Object resolveStandardArgument(Class parameterType, NativeWebRequest webRequest) + protected Object resolveStandardArgument(Class parameterType, NativeWebRequest webRequest) throws Exception { PortletRequest request = webRequest.getNativeRequest(PortletRequest.class); PortletResponse response = webRequest.getNativeResponse(PortletResponse.class); - if (PortletRequest.class.isAssignableFrom(parameterType)) { - return request; + if (PortletRequest.class.isAssignableFrom(parameterType) || + MultipartRequest.class.isAssignableFrom(parameterType)) { + Object nativeRequest = webRequest.getNativeRequest(parameterType); + if (nativeRequest == null) { + throw new IllegalStateException( + "Current request is not of type [" + parameterType.getName() + "]: " + request); + } + return nativeRequest; } else if (PortletResponse.class.isAssignableFrom(parameterType)) { - return response; + Object nativeResponse = webRequest.getNativeResponse(parameterType); + if (nativeResponse == null) { + throw new IllegalStateException( + "Current response is not of type [" + parameterType.getName() + "]: " + response); + } + return nativeResponse; } else if (PortletSession.class.isAssignableFrom(parameterType)) { return request.getPortletSession(); diff --git a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/annotation/AnnotationMethodHandlerAdapter.java b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/annotation/AnnotationMethodHandlerAdapter.java index d1c556d0e5..8b4c85ec71 100644 --- a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/annotation/AnnotationMethodHandlerAdapter.java +++ b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/annotation/AnnotationMethodHandlerAdapter.java @@ -103,6 +103,7 @@ import org.springframework.web.bind.support.WebBindingInitializer; import org.springframework.web.context.request.NativeWebRequest; import org.springframework.web.context.request.RequestScope; import org.springframework.web.context.request.ServletWebRequest; +import org.springframework.web.multipart.MultipartRequest; import org.springframework.web.servlet.HandlerAdapter; import org.springframework.web.servlet.HandlerMapping; import org.springframework.web.servlet.ModelAndView; @@ -770,16 +771,27 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator } @Override - protected Object resolveStandardArgument(Class parameterType, NativeWebRequest webRequest) throws Exception { + protected Object resolveStandardArgument(Class parameterType, NativeWebRequest webRequest) throws Exception { HttpServletRequest request = webRequest.getNativeRequest(HttpServletRequest.class); HttpServletResponse response = webRequest.getNativeResponse(HttpServletResponse.class); - if (ServletRequest.class.isAssignableFrom(parameterType)) { - return request; + if (ServletRequest.class.isAssignableFrom(parameterType) || + MultipartRequest.class.isAssignableFrom(parameterType)) { + Object nativeRequest = webRequest.getNativeRequest(parameterType); + if (nativeRequest == null) { + throw new IllegalStateException( + "Current request is not of type [" + parameterType.getName() + "]: " + request); + } + return nativeRequest; } else if (ServletResponse.class.isAssignableFrom(parameterType)) { this.responseArgumentUsed = true; - return response; + Object nativeResponse = webRequest.getNativeResponse(parameterType); + if (nativeResponse == null) { + throw new IllegalStateException( + "Current response is not of type [" + parameterType.getName() + "]: " + response); + } + return nativeResponse; } else if (HttpSession.class.isAssignableFrom(parameterType)) { return request.getSession(); diff --git a/org.springframework.web/src/main/java/org/springframework/web/bind/annotation/support/HandlerMethodInvoker.java b/org.springframework.web/src/main/java/org/springframework/web/bind/annotation/support/HandlerMethodInvoker.java index baeb4606f2..d678588476 100644 --- a/org.springframework.web/src/main/java/org/springframework/web/bind/annotation/support/HandlerMethodInvoker.java +++ b/org.springframework.web/src/main/java/org/springframework/web/bind/annotation/support/HandlerMethodInvoker.java @@ -862,7 +862,7 @@ public class HandlerMethodInvoker { return value; } - protected Object resolveStandardArgument(Class parameterType, NativeWebRequest webRequest) throws Exception { + protected Object resolveStandardArgument(Class parameterType, NativeWebRequest webRequest) throws Exception { if (WebRequest.class.isAssignableFrom(parameterType)) { return webRequest; }