org.springframework.web.multipart.MultipartResolver Java Examples

The following examples show how to use org.springframework.web.multipart.MultipartResolver. 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: DispatcherServlet.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Initialize the MultipartResolver used by this class.
 * <p>If no bean is defined with the given name in the BeanFactory for this namespace,
 * no multipart handling is provided.
 */
private void initMultipartResolver(ApplicationContext context) {
	try {
		this.multipartResolver = context.getBean(MULTIPART_RESOLVER_BEAN_NAME, MultipartResolver.class);
		if (logger.isTraceEnabled()) {
			logger.trace("Detected " + this.multipartResolver);
		}
		else if (logger.isDebugEnabled()) {
			logger.debug("Detected " + this.multipartResolver.getClass().getSimpleName());
		}
	}
	catch (NoSuchBeanDefinitionException ex) {
		// Default is no multipart resolver.
		this.multipartResolver = null;
		if (logger.isTraceEnabled()) {
			logger.trace("No MultipartResolver '" + MULTIPART_RESOLVER_BEAN_NAME + "' declared");
		}
	}
}
 
Example #2
Source File: WebUtil.java    From hdw-dubbo with Apache License 2.0 6 votes vote down vote up
/**
 * 从request中获得参数,并返回可读的Map
 * application/x-www-form-urlencode
 * application/json
 * application/json;charset=UTF-8
 * multipart/form-data
 *
 * @param request
 * @return
 */
public static Map<String, String> getParameterMap(HttpServletRequest request) {
    String contentType = request.getHeader(org.springframework.http.HttpHeaders.CONTENT_TYPE);
    Map<String, String> returnMap = new HashMap();
    if (contentType != null && contentType.contains(MediaType.MULTIPART_FORM_DATA_VALUE)) {
        // form-data表单
        MultipartResolver multipartResolver = SpringUtil.getBean(MultipartResolver.class);
        MultipartHttpServletRequest multiReq = multipartResolver.resolveMultipart(request);
        returnMap = conventMap(multiReq.getParameterMap());
    } else if (MediaType.APPLICATION_JSON_VALUE.equals(contentType) || MediaType.APPLICATION_JSON_UTF8_VALUE.equals(contentType)) {
        // json表单
        String body = getBodyString(request);
        if (StringUtils.isNoneBlank(body)) {
            try {
                returnMap = JSONObject.parseObject(body, Map.class);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    } else {
        // 普通表单
        returnMap = conventMap(request.getParameterMap());
    }
    // 参数Map
    return returnMap;
}
 
Example #3
Source File: MultipartConfig.java    From api-layer with Eclipse Public License 2.0 6 votes vote down vote up
@Bean
public MultipartResolver multipartResolver() {
    return new StandardServletMultipartResolver() {
        @Override
        public boolean isMultipart(HttpServletRequest request) {
            String method = request.getMethod().toLowerCase();
            if (!Arrays.asList("put", "post").contains(method)) {
                return false;
            }
            String contentType = request.getContentType();
            return (contentType != null && contentType.toLowerCase().startsWith("multipart/"));
        }
    };
}
 
Example #4
Source File: DispatcherServlet.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Initialize the MultipartResolver used by this class.
 * <p>If no bean is defined with the given name in the BeanFactory for this namespace,
 * no multipart handling is provided.
 */
private void initMultipartResolver(ApplicationContext context) {
	try {
		this.multipartResolver = context.getBean(MULTIPART_RESOLVER_BEAN_NAME, MultipartResolver.class);
		if (logger.isDebugEnabled()) {
			logger.debug("Using MultipartResolver [" + this.multipartResolver + "]");
		}
	}
	catch (NoSuchBeanDefinitionException ex) {
		// Default is no multipart resolver.
		this.multipartResolver = null;
		if (logger.isDebugEnabled()) {
			logger.debug("Unable to locate MultipartResolver with name '" + MULTIPART_RESOLVER_BEAN_NAME +
					"': no multipart request handling provided");
		}
	}
}
 
Example #5
Source File: DispatcherServlet.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Initialize the MultipartResolver used by this class.
 * <p>If no bean is defined with the given name in the BeanFactory for this namespace,
 * no multipart handling is provided.
 */
private void initMultipartResolver(ApplicationContext context) {
	try {
		this.multipartResolver = context.getBean(MULTIPART_RESOLVER_BEAN_NAME, MultipartResolver.class);
		if (logger.isTraceEnabled()) {
			logger.trace("Detected " + this.multipartResolver);
		}
		else if (logger.isDebugEnabled()) {
			logger.debug("Detected " + this.multipartResolver.getClass().getSimpleName());
		}
	}
	catch (NoSuchBeanDefinitionException ex) {
		// Default is no multipart resolver.
		this.multipartResolver = null;
		if (logger.isTraceEnabled()) {
			logger.trace("No MultipartResolver '" + MULTIPART_RESOLVER_BEAN_NAME + "' declared");
		}
	}
}
 
Example #6
Source File: WebUtils.java    From open-cloud with MIT License 6 votes vote down vote up
/**
 * 从request中获得参数,并返回可读的Map
 * application/x-www-form-urlencode
 * application/json
 * application/json;charset=UTF-8
 * multipart/form-data
 *
 * @param request
 * @return
 */
public static Map<String, String> getParameterMap(HttpServletRequest request) {
    String contentType = request.getHeader(org.springframework.http.HttpHeaders.CONTENT_TYPE);
    Map<String, String> returnMap = new HashMap();
    if (contentType != null && contentType.contains(MediaType.MULTIPART_FORM_DATA_VALUE)) {
        // form-data表单
        MultipartResolver multipartResolver = SpringContextHolder.getBean(MultipartResolver.class);
        MultipartHttpServletRequest multiReq = multipartResolver.resolveMultipart(request);
        returnMap = conventMap(multiReq.getParameterMap());
    } else if (MediaType.APPLICATION_JSON_VALUE.equals(contentType) || MediaType.APPLICATION_JSON_UTF8_VALUE.equals(contentType)) {
        // json表单
        String body = getBodyString(request);
        if (StringUtils.isNotBlank(body)) {
            try {
                returnMap = JSONObject.parseObject(body, Map.class);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    } else {
        // 普通表单
        returnMap = conventMap(request.getParameterMap());
    }
    // 参数Map
    return returnMap;
}
 
Example #7
Source File: DispatcherServlet.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * Initialize the MultipartResolver used by this class.
 * <p>If no bean is defined with the given name in the BeanFactory for this namespace,
 * no multipart handling is provided.
 */
private void initMultipartResolver(ApplicationContext context) {
	try {
		this.multipartResolver = context.getBean(MULTIPART_RESOLVER_BEAN_NAME, MultipartResolver.class);
		if (logger.isDebugEnabled()) {
			logger.debug("Using MultipartResolver [" + this.multipartResolver + "]");
		}
	}
	catch (NoSuchBeanDefinitionException ex) {
		// Default is no multipart resolver.
		this.multipartResolver = null;
		if (logger.isDebugEnabled()) {
			logger.debug("Unable to locate MultipartResolver with name '" + MULTIPART_RESOLVER_BEAN_NAME +
					"': no multipart request handling provided");
		}
	}
}
 
Example #8
Source File: DispatcherServletTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void dispatcherServletRefresh() throws ServletException {
	MockServletContext servletContext = new MockServletContext("org/springframework/web/context");
	DispatcherServlet servlet = new DispatcherServlet();

	servlet.init(new MockServletConfig(servletContext, "empty"));
	ServletContextAwareBean contextBean =
			(ServletContextAwareBean) servlet.getWebApplicationContext().getBean("servletContextAwareBean");
	ServletConfigAwareBean configBean =
			(ServletConfigAwareBean) servlet.getWebApplicationContext().getBean("servletConfigAwareBean");
	assertSame(servletContext, contextBean.getServletContext());
	assertSame(servlet.getServletConfig(), configBean.getServletConfig());
	MultipartResolver multipartResolver = servlet.getMultipartResolver();
	assertNotNull(multipartResolver);

	servlet.refresh();

	ServletContextAwareBean contextBean2 =
			(ServletContextAwareBean) servlet.getWebApplicationContext().getBean("servletContextAwareBean");
	ServletConfigAwareBean configBean2 =
			(ServletConfigAwareBean) servlet.getWebApplicationContext().getBean("servletConfigAwareBean");
	assertSame(servletContext, contextBean2.getServletContext());
	assertSame(servlet.getServletConfig(), configBean2.getServletConfig());
	assertNotSame(contextBean, contextBean2);
	assertNotSame(configBean, configBean2);
	MultipartResolver multipartResolver2 = servlet.getMultipartResolver();
	assertNotSame(multipartResolver, multipartResolver2);

	servlet.destroy();
}
 
Example #9
Source File: DispatcherServletTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void dispatcherServletRefresh() throws ServletException {
	MockServletContext servletContext = new MockServletContext("org/springframework/web/context");
	DispatcherServlet servlet = new DispatcherServlet();

	servlet.init(new MockServletConfig(servletContext, "empty"));
	ServletContextAwareBean contextBean =
			(ServletContextAwareBean) servlet.getWebApplicationContext().getBean("servletContextAwareBean");
	ServletConfigAwareBean configBean =
			(ServletConfigAwareBean) servlet.getWebApplicationContext().getBean("servletConfigAwareBean");
	assertSame(servletContext, contextBean.getServletContext());
	assertSame(servlet.getServletConfig(), configBean.getServletConfig());
	MultipartResolver multipartResolver = servlet.getMultipartResolver();
	assertNotNull(multipartResolver);

	servlet.refresh();

	ServletContextAwareBean contextBean2 =
			(ServletContextAwareBean) servlet.getWebApplicationContext().getBean("servletContextAwareBean");
	ServletConfigAwareBean configBean2 =
			(ServletConfigAwareBean) servlet.getWebApplicationContext().getBean("servletConfigAwareBean");
	assertSame(servletContext, contextBean2.getServletContext());
	assertSame(servlet.getServletConfig(), configBean2.getServletConfig());
	assertNotSame(contextBean, contextBean2);
	assertNotSame(configBean, configBean2);
	MultipartResolver multipartResolver2 = servlet.getMultipartResolver();
	assertNotSame(multipartResolver, multipartResolver2);

	servlet.destroy();
}
 
Example #10
Source File: DispatcherServletTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void dispatcherServletContextRefresh() throws ServletException {
	MockServletContext servletContext = new MockServletContext("org/springframework/web/context");
	DispatcherServlet servlet = new DispatcherServlet();

	servlet.init(new MockServletConfig(servletContext, "empty"));
	ServletContextAwareBean contextBean =
			(ServletContextAwareBean) servlet.getWebApplicationContext().getBean("servletContextAwareBean");
	ServletConfigAwareBean configBean =
			(ServletConfigAwareBean) servlet.getWebApplicationContext().getBean("servletConfigAwareBean");
	assertSame(servletContext, contextBean.getServletContext());
	assertSame(servlet.getServletConfig(), configBean.getServletConfig());
	MultipartResolver multipartResolver = servlet.getMultipartResolver();
	assertNotNull(multipartResolver);

	((ConfigurableApplicationContext) servlet.getWebApplicationContext()).refresh();

	ServletContextAwareBean contextBean2 =
			(ServletContextAwareBean) servlet.getWebApplicationContext().getBean("servletContextAwareBean");
	ServletConfigAwareBean configBean2 =
			(ServletConfigAwareBean) servlet.getWebApplicationContext().getBean("servletConfigAwareBean");
	assertSame(servletContext, contextBean2.getServletContext());
	assertSame(servlet.getServletConfig(), configBean2.getServletConfig());
	assertTrue(contextBean != contextBean2);
	assertTrue(configBean != configBean2);
	MultipartResolver multipartResolver2 = servlet.getMultipartResolver();
	assertTrue(multipartResolver != multipartResolver2);

	servlet.destroy();
}
 
Example #11
Source File: MultipartFilter.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Look for a MultipartResolver bean in the root web application context.
 * Supports a "multipartResolverBeanName" filter init param; the default
 * bean name is "filterMultipartResolver".
 * <p>This can be overridden to use a custom MultipartResolver instance,
 * for example if not using a Spring web application context.
 * @return the MultipartResolver instance
 */
protected MultipartResolver lookupMultipartResolver() {
	WebApplicationContext wac = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
	String beanName = getMultipartResolverBeanName();
	if (wac != null && wac.containsBean(beanName)) {
		if (logger.isDebugEnabled()) {
			logger.debug("Using MultipartResolver '" + beanName + "' for MultipartFilter");
		}
		return wac.getBean(beanName, MultipartResolver.class);
	}
	else {
		return this.defaultMultipartResolver;
	}
}
 
Example #12
Source File: DispatcherServletTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void dispatcherServletRefresh() throws ServletException {
	MockServletContext servletContext = new MockServletContext("org/springframework/web/context");
	DispatcherServlet servlet = new DispatcherServlet();

	servlet.init(new MockServletConfig(servletContext, "empty"));
	ServletContextAwareBean contextBean =
			(ServletContextAwareBean) servlet.getWebApplicationContext().getBean("servletContextAwareBean");
	ServletConfigAwareBean configBean =
			(ServletConfigAwareBean) servlet.getWebApplicationContext().getBean("servletConfigAwareBean");
	assertSame(servletContext, contextBean.getServletContext());
	assertSame(servlet.getServletConfig(), configBean.getServletConfig());
	MultipartResolver multipartResolver = servlet.getMultipartResolver();
	assertNotNull(multipartResolver);

	servlet.refresh();

	ServletContextAwareBean contextBean2 =
			(ServletContextAwareBean) servlet.getWebApplicationContext().getBean("servletContextAwareBean");
	ServletConfigAwareBean configBean2 =
			(ServletConfigAwareBean) servlet.getWebApplicationContext().getBean("servletConfigAwareBean");
	assertSame(servletContext, contextBean2.getServletContext());
	assertSame(servlet.getServletConfig(), configBean2.getServletConfig());
	assertNotSame(contextBean, contextBean2);
	assertNotSame(configBean, configBean2);
	MultipartResolver multipartResolver2 = servlet.getMultipartResolver();
	assertNotSame(multipartResolver, multipartResolver2);

	servlet.destroy();
}
 
Example #13
Source File: MultipartFilter.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Check for a multipart request via this filter's MultipartResolver,
 * and wrap the original request with a MultipartHttpServletRequest if appropriate.
 * <p>All later elements in the filter chain, most importantly servlets, benefit
 * from proper parameter extraction in the multipart case, and are able to cast to
 * MultipartHttpServletRequest if they need to.
 */
@Override
protected void doFilterInternal(
		HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
		throws ServletException, IOException {

	MultipartResolver multipartResolver = lookupMultipartResolver(request);

	HttpServletRequest processedRequest = request;
	if (multipartResolver.isMultipart(processedRequest)) {
		if (logger.isTraceEnabled()) {
			logger.trace("Resolving multipart request");
		}
		processedRequest = multipartResolver.resolveMultipart(processedRequest);
	}
	else {
		// A regular request...
		if (logger.isTraceEnabled()) {
			logger.trace("Not a multipart request");
		}
	}

	try {
		filterChain.doFilter(processedRequest, response);
	}
	finally {
		if (processedRequest instanceof MultipartHttpServletRequest) {
			multipartResolver.cleanupMultipart((MultipartHttpServletRequest) processedRequest);
		}
	}
}
 
Example #14
Source File: DispatcherServletTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void dispatcherServletContextRefresh() throws ServletException {
	MockServletContext servletContext = new MockServletContext("org/springframework/web/context");
	DispatcherServlet servlet = new DispatcherServlet();

	servlet.init(new MockServletConfig(servletContext, "empty"));
	ServletContextAwareBean contextBean =
			(ServletContextAwareBean) servlet.getWebApplicationContext().getBean("servletContextAwareBean");
	ServletConfigAwareBean configBean =
			(ServletConfigAwareBean) servlet.getWebApplicationContext().getBean("servletConfigAwareBean");
	assertSame(servletContext, contextBean.getServletContext());
	assertSame(servlet.getServletConfig(), configBean.getServletConfig());
	MultipartResolver multipartResolver = servlet.getMultipartResolver();
	assertNotNull(multipartResolver);

	((ConfigurableApplicationContext) servlet.getWebApplicationContext()).refresh();

	ServletContextAwareBean contextBean2 =
			(ServletContextAwareBean) servlet.getWebApplicationContext().getBean("servletContextAwareBean");
	ServletConfigAwareBean configBean2 =
			(ServletConfigAwareBean) servlet.getWebApplicationContext().getBean("servletConfigAwareBean");
	assertSame(servletContext, contextBean2.getServletContext());
	assertSame(servlet.getServletConfig(), configBean2.getServletConfig());
	assertTrue(contextBean != contextBean2);
	assertTrue(configBean != configBean2);
	MultipartResolver multipartResolver2 = servlet.getMultipartResolver();
	assertTrue(multipartResolver != multipartResolver2);

	servlet.destroy();
}
 
Example #15
Source File: MultipartFilter.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Check for a multipart request via this filter's MultipartResolver,
 * and wrap the original request with a MultipartHttpServletRequest if appropriate.
 * <p>All later elements in the filter chain, most importantly servlets, benefit
 * from proper parameter extraction in the multipart case, and are able to cast to
 * MultipartHttpServletRequest if they need to.
 */
@Override
protected void doFilterInternal(
		HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
		throws ServletException, IOException {

	MultipartResolver multipartResolver = lookupMultipartResolver(request);

	HttpServletRequest processedRequest = request;
	if (multipartResolver.isMultipart(processedRequest)) {
		if (logger.isTraceEnabled()) {
			logger.trace("Resolving multipart request");
		}
		processedRequest = multipartResolver.resolveMultipart(processedRequest);
	}
	else {
		// A regular request...
		if (logger.isTraceEnabled()) {
			logger.trace("Not a multipart request");
		}
	}

	try {
		filterChain.doFilter(processedRequest, response);
	}
	finally {
		if (processedRequest instanceof MultipartHttpServletRequest) {
			multipartResolver.cleanupMultipart((MultipartHttpServletRequest) processedRequest);
		}
	}
}
 
Example #16
Source File: MultipartFilter.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Look for a MultipartResolver bean in the root web application context.
 * Supports a "multipartResolverBeanName" filter init param; the default
 * bean name is "filterMultipartResolver".
 * <p>This can be overridden to use a custom MultipartResolver instance,
 * for example if not using a Spring web application context.
 * @return the MultipartResolver instance
 */
protected MultipartResolver lookupMultipartResolver() {
	WebApplicationContext wac = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
	String beanName = getMultipartResolverBeanName();
	if (wac != null && wac.containsBean(beanName)) {
		if (logger.isDebugEnabled()) {
			logger.debug("Using MultipartResolver '" + beanName + "' for MultipartFilter");
		}
		return wac.getBean(beanName, MultipartResolver.class);
	}
	else {
		return this.defaultMultipartResolver;
	}
}
 
Example #17
Source File: MultipartResolverFactoryBean.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
public MultipartResolver getMultipartResolver() throws Exception {
	String indicator = (String) tsh.getTokenState(HelperHandlerHookBean.IN_HELPER_INDICATOR);
	if (indicator != null && indicator.equals(HelperHandlerHookBean.IN_HELPER_INDICATOR))
		return blankMultipartResolver;
	else
		return commonsMultipartResolver;
}
 
Example #18
Source File: ExtZuulContextConfig.java    From onetwo with Apache License 2.0 5 votes vote down vote up
@Bean(name=MultipartFilter.DEFAULT_MULTIPART_RESOLVER_BEAN_NAME)
@ConditionalOnMissingBean(name={MultipartFilter.DEFAULT_MULTIPART_RESOLVER_BEAN_NAME})
public MultipartResolver filterMultipartResolver(){
	BootStandardServletMultipartResolver resolver = new BootStandardServletMultipartResolver();
	resolver.setMaxUploadSize(FileUtils.parseSize(multipartProperties.getMaxRequestSize()));
	return resolver;
}
 
Example #19
Source File: MultipartFilter.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Look for a MultipartResolver bean in the root web application context.
 * Supports a "multipartResolverBeanName" filter init param; the default
 * bean name is "filterMultipartResolver".
 * <p>This can be overridden to use a custom MultipartResolver instance,
 * for example if not using a Spring web application context.
 * @return the MultipartResolver instance, or {@code null} if none found
 */
protected MultipartResolver lookupMultipartResolver() {
	WebApplicationContext wac = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
	String beanName = getMultipartResolverBeanName();
	if (wac != null && wac.containsBean(beanName)) {
		if (logger.isDebugEnabled()) {
			logger.debug("Using MultipartResolver '" + beanName + "' for MultipartFilter");
		}
		return wac.getBean(beanName, MultipartResolver.class);
	}
	else {
		return this.defaultMultipartResolver;
	}
}
 
Example #20
Source File: MultipartFilter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Check for a multipart request via this filter's MultipartResolver,
 * and wrap the original request with a MultipartHttpServletRequest if appropriate.
 * <p>All later elements in the filter chain, most importantly servlets, benefit
 * from proper parameter extraction in the multipart case, and are able to cast to
 * MultipartHttpServletRequest if they need to.
 */
@Override
protected void doFilterInternal(
		HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
		throws ServletException, IOException {

	MultipartResolver multipartResolver = lookupMultipartResolver(request);

	HttpServletRequest processedRequest = request;
	if (multipartResolver.isMultipart(processedRequest)) {
		if (logger.isDebugEnabled()) {
			logger.debug("Resolving multipart request [" + processedRequest.getRequestURI() +
					"] with MultipartFilter");
		}
		processedRequest = multipartResolver.resolveMultipart(processedRequest);
	}
	else {
		// A regular request...
		if (logger.isDebugEnabled()) {
			logger.debug("Request [" + processedRequest.getRequestURI() + "] is not a multipart request");
		}
	}

	try {
		filterChain.doFilter(processedRequest, response);
	}
	finally {
		if (processedRequest instanceof MultipartHttpServletRequest) {
			multipartResolver.cleanupMultipart((MultipartHttpServletRequest) processedRequest);
		}
	}
}
 
Example #21
Source File: MultipartFilter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Look for a MultipartResolver bean in the root web application context.
 * Supports a "multipartResolverBeanName" filter init param; the default
 * bean name is "filterMultipartResolver".
 * <p>This can be overridden to use a custom MultipartResolver instance,
 * for example if not using a Spring web application context.
 * @return the MultipartResolver instance, or {@code null} if none found
 */
protected MultipartResolver lookupMultipartResolver() {
	WebApplicationContext wac = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
	String beanName = getMultipartResolverBeanName();
	if (wac != null && wac.containsBean(beanName)) {
		if (logger.isDebugEnabled()) {
			logger.debug("Using MultipartResolver '" + beanName + "' for MultipartFilter");
		}
		return wac.getBean(beanName, MultipartResolver.class);
	}
	else {
		return this.defaultMultipartResolver;
	}
}
 
Example #22
Source File: MultipartFilter.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Check for a multipart request via this filter's MultipartResolver,
 * and wrap the original request with a MultipartHttpServletRequest if appropriate.
 * <p>All later elements in the filter chain, most importantly servlets, benefit
 * from proper parameter extraction in the multipart case, and are able to cast to
 * MultipartHttpServletRequest if they need to.
 */
@Override
protected void doFilterInternal(
		HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
		throws ServletException, IOException {

	MultipartResolver multipartResolver = lookupMultipartResolver(request);

	HttpServletRequest processedRequest = request;
	if (multipartResolver.isMultipart(processedRequest)) {
		if (logger.isDebugEnabled()) {
			logger.debug("Resolving multipart request [" + processedRequest.getRequestURI() +
					"] with MultipartFilter");
		}
		processedRequest = multipartResolver.resolveMultipart(processedRequest);
	}
	else {
		// A regular request...
		if (logger.isDebugEnabled()) {
			logger.debug("Request [" + processedRequest.getRequestURI() + "] is not a multipart request");
		}
	}

	try {
		filterChain.doFilter(processedRequest, response);
	}
	finally {
		if (processedRequest instanceof MultipartHttpServletRequest) {
			multipartResolver.cleanupMultipart((MultipartHttpServletRequest) processedRequest);
		}
	}
}
 
Example #23
Source File: DispatcherServletTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void dispatcherServletContextRefresh() throws ServletException {
	MockServletContext servletContext = new MockServletContext("org/springframework/web/context");
	DispatcherServlet servlet = new DispatcherServlet();

	servlet.init(new MockServletConfig(servletContext, "empty"));
	ServletContextAwareBean contextBean =
			(ServletContextAwareBean) servlet.getWebApplicationContext().getBean("servletContextAwareBean");
	ServletConfigAwareBean configBean =
			(ServletConfigAwareBean) servlet.getWebApplicationContext().getBean("servletConfigAwareBean");
	assertSame(servletContext, contextBean.getServletContext());
	assertSame(servlet.getServletConfig(), configBean.getServletConfig());
	MultipartResolver multipartResolver = servlet.getMultipartResolver();
	assertNotNull(multipartResolver);

	((ConfigurableApplicationContext) servlet.getWebApplicationContext()).refresh();

	ServletContextAwareBean contextBean2 =
			(ServletContextAwareBean) servlet.getWebApplicationContext().getBean("servletContextAwareBean");
	ServletConfigAwareBean configBean2 =
			(ServletConfigAwareBean) servlet.getWebApplicationContext().getBean("servletConfigAwareBean");
	assertSame(servletContext, contextBean2.getServletContext());
	assertSame(servlet.getServletConfig(), configBean2.getServletConfig());
	assertTrue(contextBean != contextBean2);
	assertTrue(configBean != configBean2);
	MultipartResolver multipartResolver2 = servlet.getMultipartResolver();
	assertTrue(multipartResolver != multipartResolver2);

	servlet.destroy();
}
 
Example #24
Source File: MultipartResolverFactoryBean.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
public MultipartResolver getMultipartResolver() throws Exception {
	String indicator = (String) tsh.getTokenState(HelperHandlerHookBean.IN_HELPER_INDICATOR);
	if (indicator != null && indicator.equals(HelperHandlerHookBean.IN_HELPER_INDICATOR))
		return blankMultipartResolver;
	else
		return commonsMultipartResolver;
}
 
Example #25
Source File: FormDataController.java    From lemon with Apache License 2.0 4 votes vote down vote up
@Resource
public void setMultipartResolver(MultipartResolver multipartResolver) {
    this.multipartResolver = multipartResolver;
}
 
Example #26
Source File: DispatcherServletConfiguration.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@Bean
public MultipartResolver multipartResolver() {
    return new PutAwareStandardServletMultiPartResolver();
}
 
Example #27
Source File: MultipartResolverFactoryBean.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
public void setBlankMultipartResolver(MultipartResolver resolver) {
	blankMultipartResolver = resolver;
}
 
Example #28
Source File: OssRestController.java    From lemon with Apache License 2.0 4 votes vote down vote up
@Resource
public void setMultipartResolver(MultipartResolver multipartResolver) {
    this.multipartResolver = multipartResolver;
}
 
Example #29
Source File: BootFixedConfiguration.java    From onetwo with Apache License 2.0 4 votes vote down vote up
@Bean(name=MultipartFilter.DEFAULT_MULTIPART_RESOLVER_BEAN_NAME)
public MultipartResolver filterMultipartResolver(){
	BootStandardServletMultipartResolver resolver = new BootStandardServletMultipartResolver();
	resolver.setMaxUploadSize(FileUtils.parseSize(multipartProperties.getMaxRequestSize()));
	return resolver;
}
 
Example #30
Source File: DispatcherServletConfiguration.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@Bean
public MultipartResolver multipartResolver() {
    return new PutAwareStandardServletMultiPartResolver();
}