[logback-dev] [JIRA] (LOGBACK-1503) TeeFilter breaks multipart processing on Spring Boot 2.2+

QOS.CH (JIRA) noreply-jira at qos.ch
Sun Feb 9 12:25:00 CET 2020


Gediminas Rimsa created LOGBACK-1503:
----------------------------------------

             Summary: TeeFilter breaks multipart processing on Spring Boot 2.2+
                 Key: LOGBACK-1503
                 URL: https://jira.qos.ch/browse/LOGBACK-1503
             Project: logback
          Issue Type: Bug
          Components: logback-access
    Affects Versions: 1.2.3
         Environment: Spring Boot 2.2.4, Tomcat 9.0.30, Logback 1.2.3

 

TeeFilter registered like this:

{{ {color:#808000}@Bean
{color} {color:#000080}public {color}FilterRegistrationBean<TeeFilter> requestResponseFilter2() \{}}
{{    FilterRegistrationBean<TeeFilter> filterRegBean = {color:#000080}new {color}FilterRegistrationBean<>();}}
{{    filterRegBean.setFilter({color:#000080}new {color}TeeFilter());}}
{{    filterRegBean.setName({color:#008000}"Logback access-logging request response filter"{color});}}
{{    {color:#000080}return {color}filterRegBean;}}
{{ }}}
            Reporter: Gediminas Rimsa
            Assignee: Logback dev list
            Priority: Minor


*Symptom*

Webapp fails to process multipart HTTP requests with the following exception:
{quote}
org.springframework.web.multipart.MultipartException: Failed to parse multipart servlet request; nested exception is java.io.IOException: org.apache.tomcat.util.http.fileupload.FileUploadException: Stream closed
{quote}
*Troubleshooting*

- Multipart requests work when TeeFilter is disabled.
- Multipart requests work when Spring Boot is downgraded to 2.1.12 (Tomcat still 9.0.30, Logback still 1.2.3)

*Root cause*
`TeeFilter` decorates incoming request with `TeeHttpServletRequest` that reads the input stream and closes it (see `TeeServletInputStream#duplicateInputStream`). Everything works as expected here.

However, when `HttpServletRequest#getParts` is called later, `TeeHttpServletRequest` delegates it to the original request, which has its stream closed already, which results in the exception.

*Workaround*

Force loading of parts before request passes through `TeeFilter`. With Tomcat this is as simple as:

{{{color:#000080}private static class {color}MultipartSafeTeeFilter {color:#000080}extends {color}TeeFilter \{}}
{{    {color:#808000}@Override
{color}    {color:#000080}public void {color}doFilter(}}
{{        ServletRequest request,}}
{{        ServletResponse response,}}
{{        FilterChain filterChain}}
{{    ) {color:#000080}throws {color}IOException, ServletException \{}}
{{        request.getParameter({color:#008000}"whatever"{color});}}
{{        {color:#000080}super{color}.doFilter(request, response, filterChain);}}
{{    }}}
{{}}}

 



--
This message was sent by Atlassian JIRA
(v7.3.1#73012)


More information about the logback-dev mailing list