NativeWebRequest detects native MultipartRequest even when decorated (SPR-6594)
This commit is contained in:
@@ -427,8 +427,9 @@ public class HandlerMethodInvoker {
|
||||
paramName = getRequiredParameterName(methodParam);
|
||||
}
|
||||
Object paramValue = null;
|
||||
if (webRequest.getNativeRequest() instanceof MultipartRequest) {
|
||||
paramValue = ((MultipartRequest) webRequest.getNativeRequest()).getFile(paramName);
|
||||
MultipartRequest multipartRequest = webRequest.getNativeRequest(MultipartRequest.class);
|
||||
if (multipartRequest != null) {
|
||||
paramValue = multipartRequest.getFile(paramName);
|
||||
}
|
||||
if (paramValue == null) {
|
||||
String[] paramValues = webRequest.getParameterValues(paramName);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
* Copyright 2002-2010 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.
|
||||
@@ -101,9 +101,9 @@ public class WebRequestDataBinder extends WebDataBinder {
|
||||
public void bind(WebRequest request) {
|
||||
MutablePropertyValues mpvs = new MutablePropertyValues(request.getParameterMap());
|
||||
if (request instanceof NativeWebRequest) {
|
||||
Object nativeRequest = ((NativeWebRequest) request).getNativeRequest();
|
||||
if (nativeRequest instanceof MultipartRequest) {
|
||||
bindMultipartFiles(((MultipartRequest) nativeRequest).getFileMap(), mpvs);
|
||||
MultipartRequest multipartRequest = ((NativeWebRequest) request).getNativeRequest(MultipartRequest.class);
|
||||
if (multipartRequest != null) {
|
||||
bindMultipartFiles(multipartRequest.getFileMap(), mpvs);
|
||||
}
|
||||
}
|
||||
doBind(mpvs);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
* Copyright 2002-2010 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.
|
||||
@@ -51,6 +51,28 @@ public class FacesWebRequest extends FacesRequestAttributes implements NativeWeb
|
||||
return getExternalContext().getResponse();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T getNativeRequest(Class<T> requiredType) {
|
||||
if (requiredType != null) {
|
||||
Object request = getExternalContext().getRequest();
|
||||
if (requiredType.isInstance(request)) {
|
||||
return (T) request;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T getNativeResponse(Class<T> requiredType) {
|
||||
if (requiredType != null) {
|
||||
Object response = getExternalContext().getResponse();
|
||||
if (requiredType.isInstance(response)) {
|
||||
return (T) response;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public String getHeader(String headerName) {
|
||||
return getExternalContext().getRequestHeaderMap().get(headerName);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
* Copyright 2002-2010 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.
|
||||
@@ -44,4 +44,26 @@ public interface NativeWebRequest extends WebRequest {
|
||||
*/
|
||||
Object getNativeResponse();
|
||||
|
||||
/**
|
||||
* Return the underlying native request object, if available.
|
||||
* @param requiredType the desired type of request object
|
||||
* @return the matching request object, or <code>null</code> if none
|
||||
* of that type is available
|
||||
* @see javax.servlet.http.HttpServletRequest
|
||||
* @see javax.portlet.ActionRequest
|
||||
* @see javax.portlet.RenderRequest
|
||||
*/
|
||||
<T> T getNativeRequest(Class<T> requiredType);
|
||||
|
||||
/**
|
||||
* Return the underlying native request object, if available.
|
||||
* @param requiredType the desired type of response object
|
||||
* @return the matching response object, or <code>null</code> if none
|
||||
* of that type is available
|
||||
* @see javax.servlet.http.HttpServletRequest
|
||||
* @see javax.portlet.ActionRequest
|
||||
* @see javax.portlet.RenderRequest
|
||||
*/
|
||||
<T> T getNativeResponse(Class<T> requiredType);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
* Copyright 2002-2010 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.
|
||||
@@ -20,6 +20,10 @@ import java.security.Principal;
|
||||
import java.util.Iterator;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletRequestWrapper;
|
||||
import javax.servlet.ServletResponse;
|
||||
import javax.servlet.ServletResponseWrapper;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
@@ -80,6 +84,44 @@ public class ServletWebRequest extends ServletRequestAttributes implements Nativ
|
||||
return getResponse();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T getNativeRequest(Class<T> requiredType) {
|
||||
if (requiredType != null) {
|
||||
ServletRequest request = getRequest();
|
||||
while (request != null) {
|
||||
if (requiredType.isInstance(request)) {
|
||||
return (T) request;
|
||||
}
|
||||
else if (request instanceof ServletRequestWrapper) {
|
||||
request = ((ServletRequestWrapper) request).getRequest();
|
||||
}
|
||||
else {
|
||||
request = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T getNativeResponse(Class<T> requiredType) {
|
||||
if (requiredType != null) {
|
||||
ServletResponse response = getResponse();
|
||||
while (response != null) {
|
||||
if (requiredType.isInstance(response)) {
|
||||
return (T) response;
|
||||
}
|
||||
else if (response instanceof ServletResponseWrapper) {
|
||||
response = ((ServletResponseWrapper) response).getResponse();
|
||||
}
|
||||
else {
|
||||
response = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public String getHeader(String headerName) {
|
||||
return getRequest().getHeader(headerName);
|
||||
|
||||
Reference in New Issue
Block a user