use of org.springframework.web.multipart.MultipartResolver in project spring-framework by spring-projects.
the class DispatcherServletTests method dispatcherServletContextRefresh.
@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");
assertThat(contextBean.getServletContext()).isSameAs(servletContext);
assertThat(configBean.getServletConfig()).isSameAs(servlet.getServletConfig());
MultipartResolver multipartResolver = servlet.getMultipartResolver();
assertThat(multipartResolver).isNotNull();
((ConfigurableApplicationContext) servlet.getWebApplicationContext()).refresh();
ServletContextAwareBean contextBean2 = (ServletContextAwareBean) servlet.getWebApplicationContext().getBean("servletContextAwareBean");
ServletConfigAwareBean configBean2 = (ServletConfigAwareBean) servlet.getWebApplicationContext().getBean("servletConfigAwareBean");
assertThat(contextBean2.getServletContext()).isSameAs(servletContext);
assertThat(configBean2.getServletConfig()).isSameAs(servlet.getServletConfig());
assertThat(contextBean != contextBean2).isTrue();
assertThat(configBean != configBean2).isTrue();
MultipartResolver multipartResolver2 = servlet.getMultipartResolver();
assertThat(multipartResolver != multipartResolver2).isTrue();
servlet.destroy();
}
use of org.springframework.web.multipart.MultipartResolver in project spring-framework by spring-projects.
the class MultipartFilter method doFilterInternal.
/**
* 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);
}
}
}
use of org.springframework.web.multipart.MultipartResolver in project spring-boot by spring-projects.
the class MultipartAutoConfigurationTests method webServerWithCustomMultipartResolver.
@Test
void webServerWithCustomMultipartResolver() {
this.context = new AnnotationConfigServletWebServerApplicationContext(WebServerWithCustomMultipartResolver.class, BaseConfiguration.class);
MultipartResolver multipartResolver = this.context.getBean(MultipartResolver.class);
assertThat(multipartResolver).isNotInstanceOf(StandardServletMultipartResolver.class);
assertThat(this.context.getBeansOfType(MultipartConfigElement.class)).hasSize(1);
}
use of org.springframework.web.multipart.MultipartResolver in project grails-core by grails.
the class DefaultUrlMappingInfo method tryMultipartParams.
private Enumeration<String> tryMultipartParams(HttpServletRequest request, Enumeration<String> originalParams) {
Enumeration<String> paramNames = originalParams;
boolean disabled = isMultipartDisabled();
if (!disabled) {
MultipartResolver resolver = getMultipartResolver();
if (resolver != null && resolver.isMultipart(request)) {
MultipartHttpServletRequest resolvedMultipartRequest = getResolvedRequest(request, resolver);
paramNames = resolvedMultipartRequest.getParameterNames();
}
}
return paramNames;
}
use of org.springframework.web.multipart.MultipartResolver in project spring-integration by spring-projects.
the class HttpRequestHandlingEndpointSupport method onInit.
/**
* Locates the {@link MultipartResolver} bean based on the default name defined by the
* {@link DispatcherServlet#MULTIPART_RESOLVER_BEAN_NAME} constant if available.
* Sets up default converters if no converters set, or {@link #setMergeWithDefaultConverters(boolean)}
* was called with true after the converters were set.
*/
@Override
protected void onInit() throws Exception {
super.onInit();
BeanFactory beanFactory = getBeanFactory();
if (this.multipartResolver == null && beanFactory != null) {
try {
MultipartResolver multipartResolver = beanFactory.getBean(DispatcherServlet.MULTIPART_RESOLVER_BEAN_NAME, MultipartResolver.class);
if (logger.isDebugEnabled()) {
logger.debug("Using MultipartResolver [" + multipartResolver + "]");
}
this.multipartResolver = multipartResolver;
} catch (NoSuchBeanDefinitionException e) {
if (logger.isDebugEnabled()) {
logger.debug("Unable to locate MultipartResolver with name '" + DispatcherServlet.MULTIPART_RESOLVER_BEAN_NAME + "': no multipart request handling will be supported.");
}
}
}
if (this.messageConverters.size() == 0 || (this.mergeWithDefaultConverters && !this.convertersMerged)) {
this.messageConverters.addAll(this.defaultMessageConverters);
}
}
Aggregations