Java 类org.springframework.web.multipart.MultipartResolver 实例源码

项目:jrest    文件:JRestTestApplication.java   
@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/"));
        }
    };
}
项目:spring4-understanding    文件:DispatcherServlet.java   
/**
 * 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");
        }
    }
}
项目:class-guard    文件:DispatcherServlet.java   
/**
 * 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");
        }
    }
}
项目:glados-wiki    文件:MultipartResolverContext.java   
@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;
}
项目:lemon-fileservice    文件:SpringConfiguration.java   
@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;
}
项目:lams    文件:MultipartFilter.java   
/**
 * 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);
        }
    }
}
项目:lams    文件:MultipartFilter.java   
/**
 * 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;
    }
}
项目:spring4-understanding    文件:DispatcherServletTests.java   
@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();
}
项目:spring4-understanding    文件:DispatcherServletTests.java   
@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();
}
项目:spring4-understanding    文件:MultipartFilter.java   
/**
 * 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);
        }
    }
}
项目:spring4-understanding    文件:MultipartFilter.java   
/**
 * 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;
    }
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:DispatcherServletAutoConfiguration.java   
@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;
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:MultipartAutoConfigurationTests.java   
@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);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:MultipartAutoConfigurationTests.java   
@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();
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:MultipartAutoConfigurationTests.java   
@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);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:MultipartAutoConfigurationTests.java   
@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();
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:MultipartAutoConfigurationTests.java   
@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);
}
项目:spring-boot-concourse    文件:DispatcherServletAutoConfiguration.java   
@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;
}
项目:spring-boot-concourse    文件:MultipartAutoConfigurationTests.java   
@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);
}
项目:spring-boot-concourse    文件:MultipartAutoConfigurationTests.java   
@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();
}
项目:spring-boot-concourse    文件:MultipartAutoConfigurationTests.java   
@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);
}
项目:spring-boot-concourse    文件:MultipartAutoConfigurationTests.java   
@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();
}
项目:spring-boot-concourse    文件:MultipartAutoConfigurationTests.java   
@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);
}
项目:contestparser    文件:DispatcherServletAutoConfiguration.java   
@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;
}
项目:contestparser    文件:MultipartAutoConfigurationTests.java   
@Test
public void containerWithNothing() throws Exception {
    this.context = new AnnotationConfigEmbeddedWebApplicationContext(
            ContainerWithNothing.class, BaseConfiguration.class);
    DispatcherServlet servlet = this.context.getBean(DispatcherServlet.class);
    verify404();
    assertNotNull(servlet.getMultipartResolver());
    assertThat(this.context.getBeansOfType(StandardServletMultipartResolver.class)
            .size(), equalTo(1));
    assertThat(this.context.getBeansOfType(MultipartResolver.class).size(),
            equalTo(1));
}
项目:contestparser    文件:MultipartAutoConfigurationTests.java   
@Test
public void containerWithNoMultipartJettyConfiguration() {
    this.context = new AnnotationConfigEmbeddedWebApplicationContext(
            ContainerWithNoMultipartJetty.class, BaseConfiguration.class);
    DispatcherServlet servlet = this.context.getBean(DispatcherServlet.class);
    assertNotNull(servlet.getMultipartResolver());
    assertThat(this.context.getBeansOfType(StandardServletMultipartResolver.class)
            .size(), equalTo(1));
    assertThat(this.context.getBeansOfType(MultipartResolver.class).size(),
            equalTo(1));
    verifyServletWorks();
}
项目:contestparser    文件:MultipartAutoConfigurationTests.java   
@Test
public void containerWithNoMultipartUndertowConfiguration() {
    this.context = new AnnotationConfigEmbeddedWebApplicationContext(
            ContainerWithNoMultipartUndertow.class, BaseConfiguration.class);
    DispatcherServlet servlet = this.context.getBean(DispatcherServlet.class);
    verifyServletWorks();
    assertNotNull(servlet.getMultipartResolver());
    assertThat(this.context.getBeansOfType(StandardServletMultipartResolver.class)
            .size(), equalTo(1));
    assertThat(this.context.getBeansOfType(MultipartResolver.class).size(),
            equalTo(1));
}
项目:contestparser    文件:MultipartAutoConfigurationTests.java   
@Test
public void containerWithNoMultipartTomcatConfiguration() {
    this.context = new AnnotationConfigEmbeddedWebApplicationContext(
            ContainerWithNoMultipartTomcat.class, BaseConfiguration.class);
    DispatcherServlet servlet = this.context.getBean(DispatcherServlet.class);
    assertNull(servlet.getMultipartResolver());
    assertThat(this.context.getBeansOfType(StandardServletMultipartResolver.class)
            .size(), equalTo(1));
    assertThat(this.context.getBeansOfType(MultipartResolver.class).size(),
            equalTo(1));
    verifyServletWorks();
}
项目:contestparser    文件:MultipartAutoConfigurationTests.java   
@Test
public void containerWithCustomMultipartResolver() throws Exception {
    this.context = new AnnotationConfigEmbeddedWebApplicationContext(
            ContainerWithCustomMultipartResolver.class, BaseConfiguration.class);
    MultipartResolver multipartResolver = this.context
            .getBean(MultipartResolver.class);
    assertThat(multipartResolver,
            not(instanceOf(StandardServletMultipartResolver.class)));
}
项目:onetwo    文件:ExtZuulContextConfig.java   
@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;
}
项目:onetwo    文件:BootWebCommonAutoConfig.java   
@Bean(name=MultipartFilter.DEFAULT_MULTIPART_RESOLVER_BEAN_NAME)
//  @ConditionalOnMissingBean(MultipartResolver.class)
    public MultipartResolver filterMultipartResolver(){
        BootStandardServletMultipartResolver resolver = new BootStandardServletMultipartResolver();
        resolver.setMaxUploadSize(FileUtils.parseSize(multipartProperties.getMaxRequestSize()));
        return resolver;
    }
项目:sakai    文件:MultipartResolverFactoryBean.java   
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;
}
项目:class-guard    文件:DispatcherServletTests.java   
public void testDispatcherServletRefresh() 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();
}
项目:class-guard    文件:DispatcherServletTests.java   
public void testDispatcherServletContextRefresh() 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();
}
项目:class-guard    文件:MultipartFilter.java   
/**
 * 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);
        }
    }
}
项目:class-guard    文件:MultipartFilter.java   
/**
 * 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;
    }
}
项目:sakai    文件:MultipartResolverFactoryBean.java   
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;
}
项目:mev    文件:MultipartUploadConfiguration.java   
@Bean
  public MultipartResolver multipartResolver () {
    final long DEFAULT_MAX_UPLOAD_SIZE = 1024L * 1024L * 200; // 200Mb

    //TODO: find a better way to bypass Spring controllers for OpenRefine
    CommonsMultipartResolver resolver = new CommonsMultipartResolver (){
      @Override
      public boolean isMultipart(HttpServletRequest request){        
        if(request.getServletPath().startsWith ("/annotations")){
          if(request.getServletPath().endsWith("/row/import") || request.getServletPath().endsWith("/column/import"))
            //annotation import is handled by AnnotationConroller
            return super.isMultipart (request);
          else
            //Let OpenRefine handle parsing of the multipart request
            return false;
        }else{
          return super.isMultipart (request);
        }

      }
    };
//    StandardServletMultipartResolver resolver = new StandardServletMultipartResolver ();
    resolver.setMaxUploadSize (environment.getProperty ("multipart.upload.max.size",
                                                        Long.class,
                                                        DEFAULT_MAX_UPLOAD_SIZE));
    resolver.setResolveLazily (true);
    return resolver;
  }
项目:spring-rythm    文件:MultipartFilter.java   
/**
 * 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
 */
@Override
protected MultipartResolver lookupMultipartResolver() {
    WebApplicationContext wac = (WebApplicationContext)RythmConfigurer.getInstance().getApplicationContext();
    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;
    }
}
项目:webapp-base    文件:WebConfig.java   
@Bean
public MultipartResolver multipartResolver() {
    final CommonsMultipartResolver resolver = new CommonsMultipartResolver();
    // Max upload size: 1 MB
    resolver.setMaxUploadSize(1048576);
    resolver.setDefaultEncoding(StandardCharsets.UTF_8.name());
    resolver.setResolveLazily(true);
    return resolver;
}