Search in sources :

Example 1 with TomcatConnectorCustomizer

use of org.springframework.boot.context.embedded.tomcat.TomcatConnectorCustomizer in project apollo by ctripcorp.

the class TomcatContainerCustomizer method customize.

@Override
public void customize(ConfigurableEmbeddedServletContainer container) {
    if (!(container instanceof TomcatEmbeddedServletContainerFactory)) {
        return;
    }
    if (!environment.containsProperty(TOMCAT_ACCEPTOR_COUNT)) {
        return;
    }
    TomcatEmbeddedServletContainerFactory tomcat = (TomcatEmbeddedServletContainerFactory) container;
    tomcat.addConnectorCustomizers(new TomcatConnectorCustomizer() {

        @Override
        public void customize(Connector connector) {
            ProtocolHandler handler = connector.getProtocolHandler();
            if (handler instanceof Http11NioProtocol) {
                Http11NioProtocol http = (Http11NioProtocol) handler;
                int acceptCount = Integer.parseInt(environment.getProperty(TOMCAT_ACCEPTOR_COUNT));
                http.setBacklog(acceptCount);
                logger.info("Setting tomcat accept count to {}", acceptCount);
            }
        }
    });
}
Also used : ProtocolHandler(org.apache.coyote.ProtocolHandler) Connector(org.apache.catalina.connector.Connector) Http11NioProtocol(org.apache.coyote.http11.Http11NioProtocol) TomcatEmbeddedServletContainerFactory(org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory) TomcatConnectorCustomizer(org.springframework.boot.context.embedded.tomcat.TomcatConnectorCustomizer)

Example 2 with TomcatConnectorCustomizer

use of org.springframework.boot.context.embedded.tomcat.TomcatConnectorCustomizer in project spring-boot-examples by ityouknow.

the class FileUploadWebApplication method tomcatEmbedded.

// Tomcat large file upload connection reset
@Bean
public TomcatEmbeddedServletContainerFactory tomcatEmbedded() {
    TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory();
    tomcat.addConnectorCustomizers((TomcatConnectorCustomizer) connector -> {
        if ((connector.getProtocolHandler() instanceof AbstractHttp11Protocol<?>)) {
            ((AbstractHttp11Protocol<?>) connector.getProtocolHandler()).setMaxSwallowSize(-1);
        }
    });
    return tomcat;
}
Also used : SpringApplication(org.springframework.boot.SpringApplication) TomcatEmbeddedServletContainerFactory(org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory) SpringBootApplication(org.springframework.boot.autoconfigure.SpringBootApplication) AbstractHttp11Protocol(org.apache.coyote.http11.AbstractHttp11Protocol) Bean(org.springframework.context.annotation.Bean) TomcatConnectorCustomizer(org.springframework.boot.context.embedded.tomcat.TomcatConnectorCustomizer) TomcatEmbeddedServletContainerFactory(org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory) AbstractHttp11Protocol(org.apache.coyote.http11.AbstractHttp11Protocol) Bean(org.springframework.context.annotation.Bean)

Example 3 with TomcatConnectorCustomizer

use of org.springframework.boot.context.embedded.tomcat.TomcatConnectorCustomizer in project spring-boot-examples by ityouknow.

the class FastDFSApplication method tomcatEmbedded.

// Tomcat large file upload connection reset
@Bean
public TomcatEmbeddedServletContainerFactory tomcatEmbedded() {
    TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory();
    tomcat.addConnectorCustomizers((TomcatConnectorCustomizer) connector -> {
        if ((connector.getProtocolHandler() instanceof AbstractHttp11Protocol<?>)) {
            ((AbstractHttp11Protocol<?>) connector.getProtocolHandler()).setMaxSwallowSize(-1);
        }
    });
    return tomcat;
}
Also used : SpringApplication(org.springframework.boot.SpringApplication) TomcatEmbeddedServletContainerFactory(org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory) SpringBootApplication(org.springframework.boot.autoconfigure.SpringBootApplication) AbstractHttp11Protocol(org.apache.coyote.http11.AbstractHttp11Protocol) Bean(org.springframework.context.annotation.Bean) TomcatConnectorCustomizer(org.springframework.boot.context.embedded.tomcat.TomcatConnectorCustomizer) TomcatEmbeddedServletContainerFactory(org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory) AbstractHttp11Protocol(org.apache.coyote.http11.AbstractHttp11Protocol) Bean(org.springframework.context.annotation.Bean)

Example 4 with TomcatConnectorCustomizer

use of org.springframework.boot.context.embedded.tomcat.TomcatConnectorCustomizer in project metasfresh-webui-api by metasfresh.

the class WebRestApiApplication method servletContainerCustomizer.

@Bean
public EmbeddedServletContainerCustomizer servletContainerCustomizer() {
    return new EmbeddedServletContainerCustomizer() {

        @Override
        public void customize(final ConfigurableEmbeddedServletContainer servletContainer) {
            final TomcatEmbeddedServletContainerFactory tomcatContainerFactory = (TomcatEmbeddedServletContainerFactory) servletContainer;
            tomcatContainerFactory.addConnectorCustomizers(new TomcatConnectorCustomizer() {

                @Override
                public void customize(final Connector connector) {
                    final AbstractHttp11Protocol<?> httpProtocol = (AbstractHttp11Protocol<?>) connector.getProtocolHandler();
                    httpProtocol.setCompression("on");
                    httpProtocol.setCompressionMinSize(256);
                    final String mimeTypes = httpProtocol.getCompressibleMimeType();
                    final String mimeTypesWithJson = mimeTypes + "," + MediaType.APPLICATION_JSON_VALUE + ",application/javascript";
                    httpProtocol.setCompressibleMimeType(mimeTypesWithJson);
                }
            });
        }
    };
}
Also used : Connector(org.apache.catalina.connector.Connector) ConfigurableEmbeddedServletContainer(org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer) TomcatEmbeddedServletContainerFactory(org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory) TomcatConnectorCustomizer(org.springframework.boot.context.embedded.tomcat.TomcatConnectorCustomizer) EmbeddedServletContainerCustomizer(org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer) AbstractHttp11Protocol(org.apache.coyote.http11.AbstractHttp11Protocol) Bean(org.springframework.context.annotation.Bean)

Aggregations

TomcatConnectorCustomizer (org.springframework.boot.context.embedded.tomcat.TomcatConnectorCustomizer)4 TomcatEmbeddedServletContainerFactory (org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory)4 AbstractHttp11Protocol (org.apache.coyote.http11.AbstractHttp11Protocol)3 Bean (org.springframework.context.annotation.Bean)3 Connector (org.apache.catalina.connector.Connector)2 SpringApplication (org.springframework.boot.SpringApplication)2 SpringBootApplication (org.springframework.boot.autoconfigure.SpringBootApplication)2 ProtocolHandler (org.apache.coyote.ProtocolHandler)1 Http11NioProtocol (org.apache.coyote.http11.Http11NioProtocol)1 ConfigurableEmbeddedServletContainer (org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer)1 EmbeddedServletContainerCustomizer (org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer)1