Spring-Cloud Zuul breaks UTF-8 symbols in forwarded multipart request filename

后端 未结 1 896
灰色年华
灰色年华 2021-01-13 14:31

this is first time for me on SO, so please be patient for my first question.

I think i have some kind of configuration problem, but after a day of experiments i\'m s

相关标签:
1条回答
  • 2021-01-13 15:02

    I just ran into the same issue myself, and created the following issue:

    https://jira.spring.io/browse/SPR-15396

    Hopefully this is getting configurable in Spring 4.3.8.

    In the meantime, you have to create a bean of type FormBodyWrapperFilter (that overrides the one in ZuulConfiguration). In the constructor, you pass a copy of FormHttpMessageConverter, which extends from FormHttpMessageConverter, and you change the encoding used in FormHttpMessageConverter.MultipartHttpOutputMessage#getAsciiBytes(String) to UTF-8 (you might also want to delete any references to javax-mail, unless you have that on classpath). You need a pretty recent version of Spring Cloud Netflix to do this.

    Example:

    @Bean
    FormBodyWrapperFilter formBodyWrapperFilter() {
        return new FormBodyWrapperFilter(new MyFormHttpMessageConverter());
    }
    

    Then you create a copy of FormHttpMessageConverter, and change the following method:

        private byte[] getAsciiBytes(String name) {
            try {
                // THIS IS THE ONLY MODIFICATION:
                return name.getBytes("UTF-8");
            } catch (UnsupportedEncodingException ex) {
                // Should not happen - US-ASCII is always supported.
                throw new IllegalStateException(ex);
            }
        }
    
    0 讨论(0)
提交回复
热议问题