当前位置: 首页>>代码示例>>Java>>正文


Java MultipartResolver类代码示例

本文整理汇总了Java中org.springframework.web.multipart.MultipartResolver的典型用法代码示例。如果您正苦于以下问题:Java MultipartResolver类的具体用法?Java MultipartResolver怎么用?Java MultipartResolver使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


MultipartResolver类属于org.springframework.web.multipart包,在下文中一共展示了MultipartResolver类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: multipartResolver

import org.springframework.web.multipart.MultipartResolver; //导入依赖的package包/类
@Bean
public MultipartResolver multipartResolver() {
	return new StandardServletMultipartResolver() {
		@Override
		public boolean isMultipart(HttpServletRequest request) {
			String method = request.getMethod().toLowerCase();
			// By default, only POST is allowed. Since this is an 'update'
			// we should accept PUT.
			if (!Arrays.asList("put", "post").contains(method)) {
				return false;
			}
			String contentType = request.getContentType();
			return (contentType != null && contentType.toLowerCase().startsWith("multipart/"));
		}
	};
}
 
开发者ID:scarabsoft,项目名称:jrest,代码行数:17,代码来源:JRestTestApplication.java

示例2: initMultipartResolver

import org.springframework.web.multipart.MultipartResolver; //导入依赖的package包/类
/**
 * 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");
		}
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:22,代码来源:DispatcherServlet.java

示例3: multipartResolver

import org.springframework.web.multipart.MultipartResolver; //导入依赖的package包/类
@Bean
public MultipartResolver multipartResolver(WikiConfig wikiConfig) {
    final String UPLOAD_TEMP_DIR = wikiConfig.getUploadTempDir();
    //
    CommonsMultipartResolver mr = new CommonsMultipartResolver();
    mr.setMaxUploadSize(MAX_UPLOAD_SIZE);
    mr.setDefaultEncoding(DEFAULT_ENCODING);
    try {
        Resource uploadTempDir = resourceLoader
                .getResource(UPLOAD_TEMP_DIR);
        mr.setUploadTempDir(uploadTempDir);
        LOG.debug(String.format("UPLOAD TEMP DIR = %s", uploadTempDir));
    } catch (IOException e) {
        LOG.error(String.format("#getResource(%s) FAIL, FALLBACK.",
                UPLOAD_TEMP_DIR), e);
    }
    return mr;
}
 
开发者ID:ageldama,项目名称:glados-wiki,代码行数:19,代码来源:MultipartResolverContext.java

示例4: multipartResolver

import org.springframework.web.multipart.MultipartResolver; //导入依赖的package包/类
@Bean(name = "multipartResolver")
public MultipartResolver multipartResolver() {
    CommonsMultipartResolver resolver = new CommonsMultipartResolver();
    resolver.setDefaultEncoding("UTF-8");
    resolver.setMaxInMemorySize(40960);
    resolver.setMaxUploadSize(50 * 1024 * 1024);//上传文件大小 50M 50*1024*1024
    return resolver;
}
 
开发者ID:lemon-china,项目名称:lemon-fileservice,代码行数:9,代码来源:SpringConfiguration.java

示例5: doFilterInternal

import org.springframework.web.multipart.MultipartResolver; //导入依赖的package包/类
/**
 * 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 {
		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);
		}
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:38,代码来源:MultipartFilter.java

示例6: lookupMultipartResolver

import org.springframework.web.multipart.MultipartResolver; //导入依赖的package包/类
/**
 * 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;
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:22,代码来源:MultipartFilter.java

示例7: dispatcherServletRefresh

import org.springframework.web.multipart.MultipartResolver; //导入依赖的package包/类
@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();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:31,代码来源:DispatcherServletTests.java

示例8: dispatcherServletContextRefresh

import org.springframework.web.multipart.MultipartResolver; //导入依赖的package包/类
@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();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:31,代码来源:DispatcherServletTests.java

示例9: doFilterInternal

import org.springframework.web.multipart.MultipartResolver; //导入依赖的package包/类
/**
 * 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);
		}
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:39,代码来源:MultipartFilter.java

示例10: multipartResolver

import org.springframework.web.multipart.MultipartResolver; //导入依赖的package包/类
@Bean
@ConditionalOnBean(MultipartResolver.class)
@ConditionalOnMissingBean(name = DispatcherServlet.MULTIPART_RESOLVER_BEAN_NAME)
public MultipartResolver multipartResolver(MultipartResolver resolver) {
	// Detect if the user has created a MultipartResolver but named it incorrectly
	return resolver;
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:8,代码来源:DispatcherServletAutoConfiguration.java

示例11: containerWithNothing

import org.springframework.web.multipart.MultipartResolver; //导入依赖的package包/类
@Test
public void containerWithNothing() throws Exception {
	this.context = new AnnotationConfigEmbeddedWebApplicationContext(
			ContainerWithNothing.class, BaseConfiguration.class);
	DispatcherServlet servlet = this.context.getBean(DispatcherServlet.class);
	verify404();
	assertThat(servlet.getMultipartResolver()).isNotNull();
	assertThat(this.context.getBeansOfType(StandardServletMultipartResolver.class))
			.hasSize(1);
	assertThat(this.context.getBeansOfType(MultipartResolver.class)).hasSize(1);
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:12,代码来源:MultipartAutoConfigurationTests.java

示例12: containerWithNoMultipartJettyConfiguration

import org.springframework.web.multipart.MultipartResolver; //导入依赖的package包/类
@Test
public void containerWithNoMultipartJettyConfiguration() {
	this.context = new AnnotationConfigEmbeddedWebApplicationContext(
			ContainerWithNoMultipartJetty.class, BaseConfiguration.class);
	DispatcherServlet servlet = this.context.getBean(DispatcherServlet.class);
	assertThat(servlet.getMultipartResolver()).isNotNull();
	assertThat(this.context.getBeansOfType(StandardServletMultipartResolver.class))
			.hasSize(1);
	assertThat(this.context.getBeansOfType(MultipartResolver.class)).hasSize(1);
	verifyServletWorks();
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:12,代码来源:MultipartAutoConfigurationTests.java

示例13: containerWithNoMultipartUndertowConfiguration

import org.springframework.web.multipart.MultipartResolver; //导入依赖的package包/类
@Test
public void containerWithNoMultipartUndertowConfiguration() {
	this.context = new AnnotationConfigEmbeddedWebApplicationContext(
			ContainerWithNoMultipartUndertow.class, BaseConfiguration.class);
	DispatcherServlet servlet = this.context.getBean(DispatcherServlet.class);
	verifyServletWorks();
	assertThat(servlet.getMultipartResolver()).isNotNull();
	assertThat(this.context.getBeansOfType(StandardServletMultipartResolver.class))
			.hasSize(1);
	assertThat(this.context.getBeansOfType(MultipartResolver.class)).hasSize(1);
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:12,代码来源:MultipartAutoConfigurationTests.java

示例14: containerWithNoMultipartTomcatConfiguration

import org.springframework.web.multipart.MultipartResolver; //导入依赖的package包/类
@Test
public void containerWithNoMultipartTomcatConfiguration() {
	this.context = new AnnotationConfigEmbeddedWebApplicationContext(
			ContainerWithNoMultipartTomcat.class, BaseConfiguration.class);
	DispatcherServlet servlet = this.context.getBean(DispatcherServlet.class);
	assertThat(servlet.getMultipartResolver()).isNull();
	assertThat(this.context.getBeansOfType(StandardServletMultipartResolver.class))
			.hasSize(1);
	assertThat(this.context.getBeansOfType(MultipartResolver.class)).hasSize(1);
	verifyServletWorks();
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:12,代码来源:MultipartAutoConfigurationTests.java

示例15: containerWithCustomMultipartResolver

import org.springframework.web.multipart.MultipartResolver; //导入依赖的package包/类
@Test
public void containerWithCustomMultipartResolver() throws Exception {
	this.context = new AnnotationConfigEmbeddedWebApplicationContext(
			ContainerWithCustomMultipartResolver.class, BaseConfiguration.class);
	MultipartResolver multipartResolver = this.context
			.getBean(MultipartResolver.class);
	assertThat(multipartResolver)
			.isNotInstanceOf(StandardServletMultipartResolver.class);
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:10,代码来源:MultipartAutoConfigurationTests.java


注:本文中的org.springframework.web.multipart.MultipartResolver类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。