Browse Source

@MVC handler methods reliably resolve MultipartRequest arguments with HiddenHttpMethodFilter (SPR-7296)

pull/1234/head
Juergen Hoeller 15 years ago
parent
commit
037c277351
  1. 20
      org.springframework.web.portlet/src/main/java/org/springframework/web/portlet/mvc/annotation/AnnotationMethodHandlerAdapter.java
  2. 20
      org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/annotation/AnnotationMethodHandlerAdapter.java
  3. 2
      org.springframework.web/src/main/java/org/springframework/web/bind/annotation/support/HandlerMethodInvoker.java

20
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; @@ -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 @@ -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();

20
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; @@ -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 @@ -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();

2
org.springframework.web/src/main/java/org/springframework/web/bind/annotation/support/HandlerMethodInvoker.java

@ -862,7 +862,7 @@ public class HandlerMethodInvoker { @@ -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;
}

Loading…
Cancel
Save