@Bean public WebServerFactoryCustomizer tomcatFactoryCustomizer() { return server -> { if (server instanceof TomcatServletWebServerFactory) { ((TomcatServletWebServerFactory) server).addConnectorCustomizers(tomcatGracefulShutdown()); } }; }
/** * Create a Tomcat customizer bean to allow Tomcat to speak http2. * @return the TomcatServletWebServerFactory */ @Bean public TomcatServletWebServerFactory tomcatCustomizer() { TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory(); factory.addConnectorCustomizers((connector -> { connector.addUpgradeProtocol(new Http2Protocol()); })); return factory; }
@Test public void testTomcatCustomizer() { TomcatServletWebServerFactory factory = sut.tomcatCustomizer(); @SuppressWarnings("unchecked") List<TomcatConnectorCustomizer> tomcatConnectorCustomizers = new ArrayList(factory.getTomcatConnectorCustomizers()); assertTrue(tomcatConnectorCustomizers.size() == 1); }
@Test public void testCustomize() { TomcatServletWebServerFactory factory = sut.tomcatCustomizer(); @SuppressWarnings("unchecked") List<TomcatConnectorCustomizer> tomcatConnectorCustomizers = new ArrayList(factory.getTomcatConnectorCustomizers()); TomcatConnectorCustomizer customizer = tomcatConnectorCustomizers.get(0); assertNotNull(customizer); customizer.customize(connector); verify(connector, times(1)).addUpgradeProtocol(any(Http2Protocol.class)); }
@Test public void customize() throws MalformedURLException { TomcatServletWebServerFactory tomcatFactory = new TomcatServletWebServerFactory(); TomcatSpringBootAutoConfiguration tomcatSpringBootAutoConfiguration = new TomcatSpringBootAutoConfiguration(); tomcatSpringBootAutoConfiguration.customize(tomcatFactory); assertThat(tomcatFactory.getTomcatContextCustomizers()) .isNotEmpty(); }
@Test public void doNotCustomize() throws MalformedURLException { TomcatServletWebServerFactory tomcatFactory = new TomcatServletWebServerFactory(); TomcatSpringBootAutoConfiguration tomcatSpringBootAutoConfiguration = new TomcatSpringBootAutoConfiguration(); tomcatSpringBootAutoConfiguration.customize(tomcatFactory); assertThat(tomcatFactory.getTomcatConnectorCustomizers()) .isEmpty(); }
/** {@inheritDoc} */ @Override protected void installLogbackAccess(TomcatServletWebServerFactory container) { LogbackAccessTomcatValve valve = new LogbackAccessTomcatValve( logbackAccessProperties, environment, applicationEventPublisher); container.addEngineValves(valve); log.debug("Installed Logback-access: container=[{}]", container); }
@Bean TomcatServletWebServerFactory webServerFactory() { return new TomcatServletWebServerFactory(0); }
@Override public void customize(TomcatServletWebServerFactory container) { container.addContextCustomizers(this.customizer); }
@Bean public TomcatServletWebServerFactory tomcatServletWebServerFactory() { return new TomcatServletWebServerFactory(); }