org.springframework.web.multipart.MultipartRequest Java Examples

The following examples show how to use org.springframework.web.multipart.MultipartRequest. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ServletRequestMethodArgumentResolver.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Override
public Object resolveArgument(MethodParameter parameter, @Nullable ModelAndViewContainer mavContainer,
		NativeWebRequest webRequest, @Nullable WebDataBinderFactory binderFactory) throws Exception {

	Class<?> paramType = parameter.getParameterType();

	// WebRequest / NativeWebRequest / ServletWebRequest
	if (WebRequest.class.isAssignableFrom(paramType)) {
		if (!paramType.isInstance(webRequest)) {
			throw new IllegalStateException(
					"Current request is not of type [" + paramType.getName() + "]: " + webRequest);
		}
		return webRequest;
	}

	// ServletRequest / HttpServletRequest / MultipartRequest / MultipartHttpServletRequest
	if (ServletRequest.class.isAssignableFrom(paramType) || MultipartRequest.class.isAssignableFrom(paramType)) {
		return resolveNativeRequest(webRequest, paramType);
	}

	// HttpServletRequest required for all further argument types
	return resolveArgument(paramType, resolveNativeRequest(webRequest, HttpServletRequest.class));
}
 
Example #2
Source File: UploadValidateInterceptor.java    From onetwo with Apache License 2.0 6 votes vote down vote up
public void doValidate(HttpServletRequest request, HttpServletResponse response, HandlerMethod handler) {
		UploadFileValidator validator = handler.getMethodAnnotation(UploadFileValidator.class);
		
		MultipartRequest mrequest = (MultipartRequest) request;
//		Collection<List<MultipartFile>> files = mrequest.getMultiFileMap().values();
		/*for(List<MultipartFile> mfiles : files){
			checkFileTypes(mfiles, allowed, validator.errorPostfixMessage());
		}*/
		List<MultipartFile> files = mrequest.getMultiFileMap().values()
					.stream()
					.flatMap(list->list.stream())
					.filter(f->StringUtils.isNotBlank(f.getOriginalFilename()))
					.collect(Collectors.toList());
		
		if(files.isEmpty() && validator!=null && !validator.nullable()){
			throw new ServiceException(validator.nullableErrorMessage());
		}
		this.checkFileTypes(files, validator);
	}
 
Example #3
Source File: ServletWebRequestTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void decoratedNativeRequest() {
	HttpServletRequest decoratedRequest = new HttpServletRequestWrapper(servletRequest);
	HttpServletResponse decoratedResponse = new HttpServletResponseWrapper(servletResponse);
	ServletWebRequest request = new ServletWebRequest(decoratedRequest, decoratedResponse);
	assertSame(decoratedRequest, request.getNativeRequest());
	assertSame(decoratedRequest, request.getNativeRequest(ServletRequest.class));
	assertSame(decoratedRequest, request.getNativeRequest(HttpServletRequest.class));
	assertSame(servletRequest, request.getNativeRequest(MockHttpServletRequest.class));
	assertNull(request.getNativeRequest(MultipartRequest.class));
	assertSame(decoratedResponse, request.getNativeResponse());
	assertSame(decoratedResponse, request.getNativeResponse(ServletResponse.class));
	assertSame(decoratedResponse, request.getNativeResponse(HttpServletResponse.class));
	assertSame(servletResponse, request.getNativeResponse(MockHttpServletResponse.class));
	assertNull(request.getNativeResponse(MultipartRequest.class));
}
 
Example #4
Source File: PortletWebRequestTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void testDecoratedNativeRequest() {
	MockRenderRequest portletRequest = new MockRenderRequest();
	MockRenderResponse portletResponse = new MockRenderResponse();
	PortletRequest decoratedRequest = new PortletRequestWrapper(portletRequest);
	PortletResponse decoratedResponse = new PortletResponseWrapper(portletResponse);
	PortletWebRequest request = new PortletWebRequest(decoratedRequest, decoratedResponse);
	assertSame(decoratedRequest, request.getNativeRequest());
	assertSame(decoratedRequest, request.getNativeRequest(PortletRequest.class));
	assertSame(portletRequest, request.getNativeRequest(RenderRequest.class));
	assertSame(portletRequest, request.getNativeRequest(MockRenderRequest.class));
	assertNull(request.getNativeRequest(MultipartRequest.class));
	assertSame(decoratedResponse, request.getNativeResponse());
	assertSame(decoratedResponse, request.getNativeResponse(PortletResponse.class));
	assertSame(portletResponse, request.getNativeResponse(RenderResponse.class));
	assertSame(portletResponse, request.getNativeResponse(MockRenderResponse.class));
	assertNull(request.getNativeResponse(MultipartRequest.class));
}
 
Example #5
Source File: PortletWebRequestTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void testNativeRequest() {
	MockRenderRequest portletRequest = new MockRenderRequest();
	MockRenderResponse portletResponse = new MockRenderResponse();
	PortletWebRequest request = new PortletWebRequest(portletRequest, portletResponse);
	assertSame(portletRequest, request.getNativeRequest());
	assertSame(portletRequest, request.getNativeRequest(PortletRequest.class));
	assertSame(portletRequest, request.getNativeRequest(RenderRequest.class));
	assertSame(portletRequest, request.getNativeRequest(MockRenderRequest.class));
	assertNull(request.getNativeRequest(MultipartRequest.class));
	assertSame(portletResponse, request.getNativeResponse());
	assertSame(portletResponse, request.getNativeResponse(PortletResponse.class));
	assertSame(portletResponse, request.getNativeResponse(RenderResponse.class));
	assertSame(portletResponse, request.getNativeResponse(MockRenderResponse.class));
	assertNull(request.getNativeResponse(MultipartRequest.class));
}
 
Example #6
Source File: ServletWebRequestTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void decoratedNativeRequest() {
	HttpServletRequest decoratedRequest = new HttpServletRequestWrapper(servletRequest);
	HttpServletResponse decoratedResponse = new HttpServletResponseWrapper(servletResponse);
	ServletWebRequest request = new ServletWebRequest(decoratedRequest, decoratedResponse);
	assertSame(decoratedRequest, request.getNativeRequest());
	assertSame(decoratedRequest, request.getNativeRequest(ServletRequest.class));
	assertSame(decoratedRequest, request.getNativeRequest(HttpServletRequest.class));
	assertSame(servletRequest, request.getNativeRequest(MockHttpServletRequest.class));
	assertNull(request.getNativeRequest(MultipartRequest.class));
	assertSame(decoratedResponse, request.getNativeResponse());
	assertSame(decoratedResponse, request.getNativeResponse(ServletResponse.class));
	assertSame(decoratedResponse, request.getNativeResponse(HttpServletResponse.class));
	assertSame(servletResponse, request.getNativeResponse(MockHttpServletResponse.class));
	assertNull(request.getNativeResponse(MultipartRequest.class));
}
 
Example #7
Source File: ServletRequestMethodArgumentResolver.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Override
public Object resolveArgument(MethodParameter parameter, @Nullable ModelAndViewContainer mavContainer,
		NativeWebRequest webRequest, @Nullable WebDataBinderFactory binderFactory) throws Exception {

	Class<?> paramType = parameter.getParameterType();

	// WebRequest / NativeWebRequest / ServletWebRequest
	if (WebRequest.class.isAssignableFrom(paramType)) {
		if (!paramType.isInstance(webRequest)) {
			throw new IllegalStateException(
					"Current request is not of type [" + paramType.getName() + "]: " + webRequest);
		}
		return webRequest;
	}

	// ServletRequest / HttpServletRequest / MultipartRequest / MultipartHttpServletRequest
	if (ServletRequest.class.isAssignableFrom(paramType) || MultipartRequest.class.isAssignableFrom(paramType)) {
		return resolveNativeRequest(webRequest, paramType);
	}

	// HttpServletRequest required for all further argument types
	return resolveArgument(paramType, resolveNativeRequest(webRequest, HttpServletRequest.class));
}
 
Example #8
Source File: ServletRequestMethodArgumentResolver.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Override
public boolean supportsParameter(MethodParameter parameter) {
	Class<?> paramType = parameter.getParameterType();
	return (WebRequest.class.isAssignableFrom(paramType) ||
			ServletRequest.class.isAssignableFrom(paramType) ||
			MultipartRequest.class.isAssignableFrom(paramType) ||
			HttpSession.class.isAssignableFrom(paramType) ||
			(pushBuilder != null && pushBuilder.isAssignableFrom(paramType)) ||
			Principal.class.isAssignableFrom(paramType) ||
			InputStream.class.isAssignableFrom(paramType) ||
			Reader.class.isAssignableFrom(paramType) ||
			HttpMethod.class == paramType ||
			Locale.class == paramType ||
			TimeZone.class == paramType ||
			ZoneId.class == paramType);
}
 
Example #9
Source File: ServletWebRequestTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void decoratedNativeRequest() {
	HttpServletRequest decoratedRequest = new HttpServletRequestWrapper(servletRequest);
	HttpServletResponse decoratedResponse = new HttpServletResponseWrapper(servletResponse);
	ServletWebRequest request = new ServletWebRequest(decoratedRequest, decoratedResponse);
	assertSame(decoratedRequest, request.getNativeRequest());
	assertSame(decoratedRequest, request.getNativeRequest(ServletRequest.class));
	assertSame(decoratedRequest, request.getNativeRequest(HttpServletRequest.class));
	assertSame(servletRequest, request.getNativeRequest(MockHttpServletRequest.class));
	assertNull(request.getNativeRequest(MultipartRequest.class));
	assertSame(decoratedResponse, request.getNativeResponse());
	assertSame(decoratedResponse, request.getNativeResponse(ServletResponse.class));
	assertSame(decoratedResponse, request.getNativeResponse(HttpServletResponse.class));
	assertSame(servletResponse, request.getNativeResponse(MockHttpServletResponse.class));
	assertNull(request.getNativeResponse(MultipartRequest.class));
}
 
Example #10
Source File: ServletRequestMethodArgumentResolver.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Override
public boolean supportsParameter(MethodParameter parameter) {
	Class<?> paramType = parameter.getParameterType();
	return (WebRequest.class.isAssignableFrom(paramType) ||
			ServletRequest.class.isAssignableFrom(paramType) ||
			MultipartRequest.class.isAssignableFrom(paramType) ||
			HttpSession.class.isAssignableFrom(paramType) ||
			(pushBuilder != null && pushBuilder.isAssignableFrom(paramType)) ||
			Principal.class.isAssignableFrom(paramType) ||
			InputStream.class.isAssignableFrom(paramType) ||
			Reader.class.isAssignableFrom(paramType) ||
			HttpMethod.class == paramType ||
			Locale.class == paramType ||
			TimeZone.class == paramType ||
			ZoneId.class == paramType);
}
 
Example #11
Source File: BinaryUploader.java    From kvf-admin with MIT License 5 votes vote down vote up
public State save(HttpServletRequest request, Map<String, Object> conf) {
    if (request instanceof MultipartRequest) {
        return doSave((MultipartRequest) request, conf);
    } else {
        return doSave(request, conf);
    }
}
 
Example #12
Source File: ServletRequestMethodArgumentResolverTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Before
public void setup() throws Exception {
	resolver = new ServletRequestMethodArgumentResolver();
	mavContainer = new ModelAndViewContainer();
	servletRequest = new MockHttpServletRequest("GET", "");
	webRequest = new ServletWebRequest(servletRequest, new MockHttpServletResponse());

	method = getClass().getMethod("supportedParams", ServletRequest.class, MultipartRequest.class,
			HttpSession.class, Principal.class, Locale.class, InputStream.class, Reader.class,
			WebRequest.class, TimeZone.class, ZoneId.class, HttpMethod.class, PushBuilder.class);
}
 
Example #13
Source File: ServletWebRequestTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void nativeRequest() {
	assertSame(servletRequest, request.getNativeRequest());
	assertSame(servletRequest, request.getNativeRequest(ServletRequest.class));
	assertSame(servletRequest, request.getNativeRequest(HttpServletRequest.class));
	assertSame(servletRequest, request.getNativeRequest(MockHttpServletRequest.class));
	assertNull(request.getNativeRequest(MultipartRequest.class));
	assertSame(servletResponse, request.getNativeResponse());
	assertSame(servletResponse, request.getNativeResponse(ServletResponse.class));
	assertSame(servletResponse, request.getNativeResponse(HttpServletResponse.class));
	assertSame(servletResponse, request.getNativeResponse(MockHttpServletResponse.class));
	assertNull(request.getNativeResponse(MultipartRequest.class));
}
 
Example #14
Source File: HandlerMethodInvoker.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private Object resolveRequestParam(String paramName, boolean required, String defaultValue,
		MethodParameter methodParam, NativeWebRequest webRequest, Object handlerForInitBinderCall)
		throws Exception {

	Class<?> paramType = methodParam.getParameterType();
	if (Map.class.isAssignableFrom(paramType) && paramName.length() == 0) {
		return resolveRequestParamMap((Class<? extends Map<?, ?>>) paramType, webRequest);
	}
	if (paramName.length() == 0) {
		paramName = getRequiredParameterName(methodParam);
	}
	Object paramValue = null;
	MultipartRequest multipartRequest = webRequest.getNativeRequest(MultipartRequest.class);
	if (multipartRequest != null) {
		List<MultipartFile> files = multipartRequest.getFiles(paramName);
		if (!files.isEmpty()) {
			paramValue = (files.size() == 1 ? files.get(0) : files);
		}
	}
	if (paramValue == null) {
		String[] paramValues = webRequest.getParameterValues(paramName);
		if (paramValues != null) {
			paramValue = (paramValues.length == 1 ? paramValues[0] : paramValues);
		}
	}
	if (paramValue == null) {
		if (defaultValue != null) {
			paramValue = resolveDefaultValue(defaultValue);
		}
		else if (required) {
			raiseMissingParameterException(paramName, paramType);
		}
		paramValue = checkValue(paramName, paramValue, paramType);
	}
	WebDataBinder binder = createBinder(webRequest, null, paramName);
	initBinder(handlerForInitBinderCall, paramName, binder, webRequest);
	return binder.convertIfNecessary(paramValue, paramType, methodParam);
}
 
Example #15
Source File: ServletRequestMethodArgumentResolverTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unused")
public void supportedParams(ServletRequest p0,
							MultipartRequest p1,
							HttpSession p2,
							Principal p3,
							Locale p4,
							InputStream p5,
							Reader p6,
							WebRequest p7,
							TimeZone p8,
							ZoneId p9,
							HttpMethod p10) {
}
 
Example #16
Source File: ServletRequestMethodArgumentResolverTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
	method = getClass().getMethod("supportedParams", ServletRequest.class, MultipartRequest.class,
			HttpSession.class, Principal.class, Locale.class, InputStream.class, Reader.class,
			WebRequest.class, TimeZone.class, ZoneId.class, HttpMethod.class);
	mavContainer = new ModelAndViewContainer();
	servletRequest = new MockHttpServletRequest("GET", "");
	webRequest = new ServletWebRequest(servletRequest, new MockHttpServletResponse());
}
 
Example #17
Source File: ServletRequestMethodArgumentResolver.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public boolean supportsParameter(MethodParameter parameter) {
	Class<?> paramType = parameter.getParameterType();
	return (WebRequest.class.isAssignableFrom(paramType) ||
			ServletRequest.class.isAssignableFrom(paramType) ||
			MultipartRequest.class.isAssignableFrom(paramType) ||
			HttpSession.class.isAssignableFrom(paramType) ||
			Principal.class.isAssignableFrom(paramType) ||
			Locale.class == paramType ||
			TimeZone.class == paramType ||
			"java.time.ZoneId".equals(paramType.getName()) ||
			InputStream.class.isAssignableFrom(paramType) ||
			Reader.class.isAssignableFrom(paramType) ||
			HttpMethod.class == paramType);
}
 
Example #18
Source File: ServletRequestMethodArgumentResolverTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@SuppressWarnings("unused")
public void supportedParams(ServletRequest p0,
							MultipartRequest p1,
							HttpSession p2,
							Principal p3,
							Locale p4,
							InputStream p5,
							Reader p6,
							WebRequest p7,
							TimeZone p8,
							ZoneId p9,
							HttpMethod p10,
							PushBuilder p11) {
}
 
Example #19
Source File: MultipartResolutionDelegate.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Nullable
public static MultipartRequest resolveMultipartRequest(NativeWebRequest webRequest) {
	MultipartRequest multipartRequest = webRequest.getNativeRequest(MultipartRequest.class);
	if (multipartRequest != null) {
		return multipartRequest;
	}
	HttpServletRequest servletRequest = webRequest.getNativeRequest(HttpServletRequest.class);
	if (servletRequest != null && isMultipartContent(servletRequest)) {
		return new StandardMultipartHttpServletRequest(servletRequest);
	}
	return null;
}
 
Example #20
Source File: HandlerMethodInvoker.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private Object resolveRequestParam(String paramName, boolean required, String defaultValue,
		MethodParameter methodParam, NativeWebRequest webRequest, Object handlerForInitBinderCall)
		throws Exception {

	Class<?> paramType = methodParam.getParameterType();
	if (Map.class.isAssignableFrom(paramType) && paramName.length() == 0) {
		return resolveRequestParamMap((Class<? extends Map<?, ?>>) paramType, webRequest);
	}
	if (paramName.length() == 0) {
		paramName = getRequiredParameterName(methodParam);
	}
	Object paramValue = null;
	MultipartRequest multipartRequest = webRequest.getNativeRequest(MultipartRequest.class);
	if (multipartRequest != null) {
		List<MultipartFile> files = multipartRequest.getFiles(paramName);
		if (!files.isEmpty()) {
			paramValue = (files.size() == 1 ? files.get(0) : files);
		}
	}
	if (paramValue == null) {
		String[] paramValues = webRequest.getParameterValues(paramName);
		if (paramValues != null) {
			paramValue = (paramValues.length == 1 ? paramValues[0] : paramValues);
		}
	}
	if (paramValue == null) {
		if (defaultValue != null) {
			paramValue = resolveDefaultValue(defaultValue);
		}
		else if (required) {
			raiseMissingParameterException(paramName, paramType);
		}
		paramValue = checkValue(paramName, paramValue, paramType);
	}
	WebDataBinder binder = createBinder(webRequest, null, paramName);
	initBinder(handlerForInitBinderCall, paramName, binder, webRequest);
	return binder.convertIfNecessary(paramValue, paramType, methodParam);
}
 
Example #21
Source File: ServletRequestMethodArgumentResolver.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean supportsParameter(MethodParameter parameter) {
	Class<?> paramType = parameter.getParameterType();
	return (WebRequest.class.isAssignableFrom(paramType) ||
			ServletRequest.class.isAssignableFrom(paramType) ||
			MultipartRequest.class.isAssignableFrom(paramType) ||
			HttpSession.class.isAssignableFrom(paramType) ||
			Principal.class.isAssignableFrom(paramType) ||
			InputStream.class.isAssignableFrom(paramType) ||
			Reader.class.isAssignableFrom(paramType) ||
			HttpMethod.class == paramType ||
			Locale.class == paramType ||
			TimeZone.class == paramType ||
			"java.time.ZoneId".equals(paramType.getName()));
}
 
Example #22
Source File: ServletWebRequestTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void nativeRequest() {
	assertSame(servletRequest, request.getNativeRequest());
	assertSame(servletRequest, request.getNativeRequest(ServletRequest.class));
	assertSame(servletRequest, request.getNativeRequest(HttpServletRequest.class));
	assertSame(servletRequest, request.getNativeRequest(MockHttpServletRequest.class));
	assertNull(request.getNativeRequest(MultipartRequest.class));
	assertSame(servletResponse, request.getNativeResponse());
	assertSame(servletResponse, request.getNativeResponse(ServletResponse.class));
	assertSame(servletResponse, request.getNativeResponse(HttpServletResponse.class));
	assertSame(servletResponse, request.getNativeResponse(MockHttpServletResponse.class));
	assertNull(request.getNativeResponse(MultipartRequest.class));
}
 
Example #23
Source File: ServletWebRequestTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void nativeRequest() {
	assertSame(servletRequest, request.getNativeRequest());
	assertSame(servletRequest, request.getNativeRequest(ServletRequest.class));
	assertSame(servletRequest, request.getNativeRequest(HttpServletRequest.class));
	assertSame(servletRequest, request.getNativeRequest(MockHttpServletRequest.class));
	assertNull(request.getNativeRequest(MultipartRequest.class));
	assertSame(servletResponse, request.getNativeResponse());
	assertSame(servletResponse, request.getNativeResponse(ServletResponse.class));
	assertSame(servletResponse, request.getNativeResponse(HttpServletResponse.class));
	assertSame(servletResponse, request.getNativeResponse(MockHttpServletResponse.class));
	assertNull(request.getNativeResponse(MultipartRequest.class));
}
 
Example #24
Source File: ServletRequestMethodArgumentResolverTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Before
public void setup() throws Exception {
	resolver = new ServletRequestMethodArgumentResolver();
	mavContainer = new ModelAndViewContainer();
	servletRequest = new MockHttpServletRequest("GET", "");
	webRequest = new ServletWebRequest(servletRequest, new MockHttpServletResponse());

	method = getClass().getMethod("supportedParams", ServletRequest.class, MultipartRequest.class,
			HttpSession.class, Principal.class, Locale.class, InputStream.class, Reader.class,
			WebRequest.class, TimeZone.class, ZoneId.class, HttpMethod.class, PushBuilder.class);
}
 
Example #25
Source File: ServletRequestMethodArgumentResolverTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@SuppressWarnings("unused")
public void supportedParams(ServletRequest p0,
							MultipartRequest p1,
							HttpSession p2,
							Principal p3,
							Locale p4,
							InputStream p5,
							Reader p6,
							WebRequest p7,
							TimeZone p8,
							ZoneId p9,
							HttpMethod p10,
							PushBuilder p11) {
}
 
Example #26
Source File: MultipartResolutionDelegate.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Nullable
public static MultipartRequest resolveMultipartRequest(NativeWebRequest webRequest) {
	MultipartRequest multipartRequest = webRequest.getNativeRequest(MultipartRequest.class);
	if (multipartRequest != null) {
		return multipartRequest;
	}
	HttpServletRequest servletRequest = webRequest.getNativeRequest(HttpServletRequest.class);
	if (servletRequest != null && isMultipartContent(servletRequest)) {
		return new StandardMultipartHttpServletRequest(servletRequest);
	}
	return null;
}
 
Example #27
Source File: RequestParamMethodArgumentResolver.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
@Nullable
protected Object resolveName(String name, MethodParameter parameter, NativeWebRequest request) throws Exception {
	HttpServletRequest servletRequest = request.getNativeRequest(HttpServletRequest.class);

	if (servletRequest != null) {
		Object mpArg = MultipartResolutionDelegate.resolveMultipartArgument(name, parameter, servletRequest);
		if (mpArg != MultipartResolutionDelegate.UNRESOLVABLE) {
			return mpArg;
		}
	}

	Object arg = null;
	MultipartRequest multipartRequest = request.getNativeRequest(MultipartRequest.class);
	if (multipartRequest != null) {
		List<MultipartFile> files = multipartRequest.getFiles(name);
		if (!files.isEmpty()) {
			arg = (files.size() == 1 ? files.get(0) : files);
		}
	}
	if (arg == null) {
		String[] paramValues = request.getParameterValues(name);
		if (paramValues != null) {
			arg = (paramValues.length == 1 ? paramValues[0] : paramValues);
		}
	}
	return arg;
}
 
Example #28
Source File: RequestParamMethodArgumentResolver.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
@Nullable
protected Object resolveName(String name, MethodParameter parameter, NativeWebRequest request) throws Exception {
	HttpServletRequest servletRequest = request.getNativeRequest(HttpServletRequest.class);

	if (servletRequest != null) {
		Object mpArg = MultipartResolutionDelegate.resolveMultipartArgument(name, parameter, servletRequest);
		if (mpArg != MultipartResolutionDelegate.UNRESOLVABLE) {
			return mpArg;
		}
	}

	Object arg = null;
	MultipartRequest multipartRequest = request.getNativeRequest(MultipartRequest.class);
	if (multipartRequest != null) {
		List<MultipartFile> files = multipartRequest.getFiles(name);
		if (!files.isEmpty()) {
			arg = (files.size() == 1 ? files.get(0) : files);
		}
	}
	if (arg == null) {
		String[] paramValues = request.getParameterValues(name);
		if (paramValues != null) {
			arg = (paramValues.length == 1 ? paramValues[0] : paramValues);
		}
	}
	return arg;
}
 
Example #29
Source File: AnnotationMethodHandlerAdapter.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
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) ||
			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;
		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();
	}
	else if (Principal.class.isAssignableFrom(parameterType)) {
		return request.getUserPrincipal();
	}
	else if (Locale.class == parameterType) {
		return RequestContextUtils.getLocale(request);
	}
	else if (InputStream.class.isAssignableFrom(parameterType)) {
		return request.getInputStream();
	}
	else if (Reader.class.isAssignableFrom(parameterType)) {
		return request.getReader();
	}
	else if (OutputStream.class.isAssignableFrom(parameterType)) {
		this.responseArgumentUsed = true;
		return response.getOutputStream();
	}
	else if (Writer.class.isAssignableFrom(parameterType)) {
		this.responseArgumentUsed = true;
		return response.getWriter();
	}
	return super.resolveStandardArgument(parameterType, webRequest);
}
 
Example #30
Source File: UploadValidateInterceptor.java    From onetwo with Apache License 2.0 4 votes vote down vote up
public boolean isSupport(HttpServletRequest request, HandlerMethod handler) {
		return MultipartRequest.class.isInstance(request);
//		return MultipartRequest.class.isInstance(request) && handler.getMethodAnnotation(UploadFileValidator.class)!=null;
	}