2

I'm trying to set max-swallow-size property of tomcat to -1 in springboot microservice while upgrading to springboot version 2; my earlier code was working but in upgrade some classes have changed so it stopped working.

I tried to set property in two ways but both are not working;

  1. with service configuration
@Bean
public ServletWebServerFactory servletContainerFactory() {

        TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory();

        factory.addConnectorCustomizers(new TomcatConnectorCustomizer() {
            @Override
            public void customize(Connector connector) {
                if(connector.getProtocolHandler() instanceof AbstractHttp11Protocol) {
                    logger.debug("Setting maxSwallowSize for server connector as "+maxSwallowSize);
                    ((AbstractHttp11Protocol <?>) connector.getProtocolHandler()).setMaxSwallowSize(maxSwallowSize);
                }
            }
        });

        return factory;
    }

In control flow, I can see the debug line printed but it have not taken effect as end -point response is 502(Bad gateway) instead of 400

Second way : 2. through application.properties file with property

server.tomcat.max-swallow-size=-1

This is also not honored.

Now, How can I verify the property value whether it is actually set or not ? or Am I setting the value in correct way ?

YoB
  • 61
  • 1
  • 6

1 Answers1

4

This New class has resolved my issue

@Component
public class TomcatCustomizer implements
WebServerFactoryCustomizer<TomcatServletWebServerFactory> {

    @Override
    public void customize(TomcatServletWebServerFactory factory) {

        factory.addConnectorCustomizers(new TomcatConnectorCustomizer() {
            @Override
            public void customize(Connector connector) {
                if(connector.getProtocolHandler() instanceof AbstractHttp11Protocol) {
                    ((AbstractHttp11Protocol <?>) connector.getProtocolHandler()).setMaxSwallowSize(maxSwallowSize);
                }
            }
        });
    }
}

and I have used updated properties in spring boot 2.0

spring.servlet.multipart.max-file-size= XX MB
spring.servlet.multipart.max-request-size= YY MB

YoB
  • 61
  • 1
  • 6