Search in sources :

Example 26 with TomcatServletWebServerFactory

use of org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory in project spring-boot by spring-projects.

the class ServletWebServerFactoryAutoConfigurationTests method tomcatContextCustomizerBeanIsAddedToFactory.

@Test
void tomcatContextCustomizerBeanIsAddedToFactory() {
    WebApplicationContextRunner runner = new WebApplicationContextRunner(AnnotationConfigServletWebServerApplicationContext::new).withConfiguration(AutoConfigurations.of(ServletWebServerFactoryAutoConfiguration.class)).withUserConfiguration(TomcatContextCustomizerConfiguration.class).withPropertyValues("server.port: 0");
    runner.run((context) -> {
        TomcatServletWebServerFactory factory = context.getBean(TomcatServletWebServerFactory.class);
        TomcatContextCustomizer customizer = context.getBean("contextCustomizer", TomcatContextCustomizer.class);
        assertThat(factory.getTomcatContextCustomizers()).contains(customizer);
        then(customizer).should().customize(any(Context.class));
    });
}
Also used : TomcatContextCustomizer(org.springframework.boot.web.embedded.tomcat.TomcatContextCustomizer) AnnotationConfigServletWebServerApplicationContext(org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext) AssertableWebApplicationContext(org.springframework.boot.test.context.assertj.AssertableWebApplicationContext) Context(org.apache.catalina.Context) ApplicationContext(org.springframework.context.ApplicationContext) ServletContext(jakarta.servlet.ServletContext) WebApplicationContextRunner(org.springframework.boot.test.context.runner.WebApplicationContextRunner) TomcatServletWebServerFactory(org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory) Test(org.junit.jupiter.api.Test)

Example 27 with TomcatServletWebServerFactory

use of org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory in project midpoint by Evolveum.

the class TestMidPointSpringApplication method tomcatEmbeddedServletContainerFactory.

@Bean
public TomcatServletWebServerFactory tomcatEmbeddedServletContainerFactory() {
    TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory();
    tomcat.setPort(DEFAULT_PORT);
    return tomcat;
}
Also used : TomcatServletWebServerFactory(org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory) Bean(org.springframework.context.annotation.Bean)

Example 28 with TomcatServletWebServerFactory

use of org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory in project cas by apereo.

the class CasTomcatServletWebServerFactoryCustomizer method customize.

@Override
public void customize(final ConfigurableServletWebServerFactory factory) {
    if (factory instanceof TomcatServletWebServerFactory) {
        val tomcat = (TomcatServletWebServerFactory) factory;
        configureAjp(tomcat);
        configureHttp(tomcat);
        configureHttpProxy(tomcat);
        configureExtendedAccessLogValve(tomcat);
        configureRewriteValve(tomcat);
        configureSSLValve(tomcat);
        configureBasicAuthn(tomcat);
        finalizeConnectors(tomcat);
    }
}
Also used : lombok.val(lombok.val) TomcatServletWebServerFactory(org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory)

Example 29 with TomcatServletWebServerFactory

use of org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory in project kork by spinnaker.

the class TomcatConfiguration method containerCustomizer.

/**
 * Setup multiple connectors: - an https connector requiring client auth that will service API
 * requests - an http connector that will service legacy non-https requests
 */
@Bean
@ConditionalOnExpression("${server.ssl.enabled:false}")
WebServerFactoryCustomizer containerCustomizer(DefaultTomcatConnectorCustomizer defaultTomcatConnectorCustomizer, TomcatConfigurationProperties tomcatConfigurationProperties) {
    System.setProperty("jdk.tls.rejectClientInitiatedRenegotiation", "true");
    System.setProperty("jdk.tls.ephemeralDHKeySize", "2048");
    return new WebServerFactoryCustomizer() {

        @Override
        public void customize(WebServerFactory factory) {
            TomcatServletWebServerFactory tomcat = (TomcatServletWebServerFactory) factory;
            // This will only handle the case where SSL is enabled on the main Tomcat connector
            tomcat.addConnectorCustomizers(defaultTomcatConnectorCustomizer);
            if (tomcatConfigurationProperties.getLegacyServerPort() > 0) {
                log.info("Creating legacy connector on port {}", tomcatConfigurationProperties.getLegacyServerPort());
                Connector httpConnector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
                httpConnector.setScheme("http");
                httpConnector.setPort(tomcatConfigurationProperties.getLegacyServerPort());
                applyCompressionSettings(httpConnector, tomcat);
                tomcat.addAdditionalTomcatConnectors(httpConnector);
            }
            if (tomcatConfigurationProperties.getApiPort() > 0) {
                log.info("Creating api connector on port {}", tomcatConfigurationProperties.getApiPort());
                Connector apiConnector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
                apiConnector.setScheme("https");
                apiConnector.setSecure(true);
                apiConnector.setPort(tomcatConfigurationProperties.getApiPort());
                applyCompressionSettings(apiConnector, tomcat);
                Ssl ssl = defaultTomcatConnectorCustomizer.copySslConfigurationWithClientAuth(tomcat);
                CustomizableTomcatServletWebServerFactory newFactory = new CustomizableTomcatServletWebServerFactory();
                BeanUtils.copyProperties(tomcat, newFactory);
                newFactory.setPort(tomcatConfigurationProperties.getApiPort());
                newFactory.setSsl(ssl);
                newFactory.customizeSslConnector(apiConnector);
                defaultTomcatConnectorCustomizer.customize(apiConnector);
                tomcat.addAdditionalTomcatConnectors(apiConnector);
            }
        }
    };
}
Also used : Connector(org.apache.catalina.connector.Connector) TomcatServletWebServerFactory(org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory) WebServerFactory(org.springframework.boot.web.server.WebServerFactory) TomcatServletWebServerFactory(org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory) WebServerFactoryCustomizer(org.springframework.boot.web.server.WebServerFactoryCustomizer) Ssl(org.springframework.boot.web.server.Ssl) ConditionalOnExpression(org.springframework.boot.autoconfigure.condition.ConditionalOnExpression) Bean(org.springframework.context.annotation.Bean)

Example 30 with TomcatServletWebServerFactory

use of org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory in project spring-boot by spring-projects.

the class EndpointWebMvcAutoConfigurationTests method tomcatManagementAccessLogUsesCustomPrefix.

@Test
public void tomcatManagementAccessLogUsesCustomPrefix() throws Exception {
    EnvironmentTestUtils.addEnvironment(this.applicationContext, "management.port=" + ports.get().management);
    this.applicationContext.register(TomcatWebServerConfig.class, RootConfig.class, EndpointConfig.class, DifferentPortConfig.class, BaseConfiguration.class, EndpointWebMvcAutoConfiguration.class, ErrorMvcAutoConfiguration.class);
    EnvironmentTestUtils.addEnvironment(this.applicationContext, "server.tomcat.accesslog.enabled: true");
    this.applicationContext.refresh();
    ApplicationContext managementContext = this.applicationContext.getBean(ManagementContextResolver.class).getApplicationContext();
    ServletWebServerFactory factory = managementContext.getBean(ServletWebServerFactory.class);
    assertThat(factory).isInstanceOf(TomcatServletWebServerFactory.class);
    AccessLogValve accessLogValve = findAccessLogValve(((TomcatServletWebServerFactory) factory));
    assertThat(accessLogValve).isNotNull();
    assertThat(accessLogValve.getPrefix()).isEqualTo("management_access_log");
}
Also used : AnnotationConfigServletWebServerApplicationContext(org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext) ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) TomcatServletWebServerFactory(org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory) TomcatServletWebServerFactory(org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory) ServletWebServerFactory(org.springframework.boot.web.servlet.server.ServletWebServerFactory) UndertowServletWebServerFactory(org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory) AccessLogValve(org.apache.catalina.valves.AccessLogValve) Test(org.junit.Test)

Aggregations

TomcatServletWebServerFactory (org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory)67 Test (org.junit.jupiter.api.Test)28 AccessLogValve (org.apache.catalina.valves.AccessLogValve)24 Test (org.junit.Test)18 HashMap (java.util.HashMap)13 Bean (org.springframework.context.annotation.Bean)10 Connector (org.apache.catalina.connector.Connector)6 WebApplicationContextRunner (org.springframework.boot.test.context.runner.WebApplicationContextRunner)6 TomcatWebServer (org.springframework.boot.web.embedded.tomcat.TomcatWebServer)6 Valve (org.apache.catalina.Valve)4 RemoteIpValve (org.apache.catalina.valves.RemoteIpValve)4 Context (org.apache.catalina.Context)3 TomcatContextCustomizer (org.springframework.boot.web.embedded.tomcat.TomcatContextCustomizer)3 UndertowServletWebServerFactory (org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory)3 AnnotationConfigServletWebServerApplicationContext (org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext)3 ApplicationContext (org.springframework.context.ApplicationContext)3 ServletContext (jakarta.servlet.ServletContext)2 lombok.val (lombok.val)2 ErrorReportValve (org.apache.catalina.valves.ErrorReportValve)2 AbstractProtocol (org.apache.coyote.AbstractProtocol)2