Search in sources :

Example 61 with TomcatServletWebServerFactory

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

the class ServletWebServerFactoryAutoConfigurationTests method tomcatProtocolHandlerCustomizerRegisteredAsBeanAndViaFactoryIsOnlyCalledOnce.

@Test
void tomcatProtocolHandlerCustomizerRegisteredAsBeanAndViaFactoryIsOnlyCalledOnce() {
    WebApplicationContextRunner runner = new WebApplicationContextRunner(AnnotationConfigServletWebServerApplicationContext::new).withConfiguration(AutoConfigurations.of(ServletWebServerFactoryAutoConfiguration.class)).withUserConfiguration(DoubleRegistrationTomcatProtocolHandlerCustomizerConfiguration.class).withPropertyValues("server.port: 0");
    runner.run((context) -> {
        TomcatServletWebServerFactory factory = context.getBean(TomcatServletWebServerFactory.class);
        TomcatProtocolHandlerCustomizer<?> customizer = context.getBean("protocolHandlerCustomizer", TomcatProtocolHandlerCustomizer.class);
        assertThat(factory.getTomcatProtocolHandlerCustomizers()).contains(customizer);
        then(customizer).should().customize(any());
    });
}
Also used : WebApplicationContextRunner(org.springframework.boot.test.context.runner.WebApplicationContextRunner) TomcatServletWebServerFactory(org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory) Test(org.junit.jupiter.api.Test)

Example 62 with TomcatServletWebServerFactory

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

the class ServletWebServerFactoryAutoConfigurationTests method tomcatContextCustomizerRegisteredAsBeanAndViaFactoryIsOnlyCalledOnce.

@Test
void tomcatContextCustomizerRegisteredAsBeanAndViaFactoryIsOnlyCalledOnce() {
    WebApplicationContextRunner runner = new WebApplicationContextRunner(AnnotationConfigServletWebServerApplicationContext::new).withConfiguration(AutoConfigurations.of(ServletWebServerFactoryAutoConfiguration.class)).withUserConfiguration(DoubleRegistrationTomcatContextCustomizerConfiguration.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 63 with TomcatServletWebServerFactory

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

the class ServletWebServerFactoryAutoConfigurationTests method tomcatConnectorCustomizerRegisteredAsBeanAndViaFactoryIsOnlyCalledOnce.

@Test
void tomcatConnectorCustomizerRegisteredAsBeanAndViaFactoryIsOnlyCalledOnce() {
    WebApplicationContextRunner runner = new WebApplicationContextRunner(AnnotationConfigServletWebServerApplicationContext::new).withConfiguration(AutoConfigurations.of(ServletWebServerFactoryAutoConfiguration.class)).withUserConfiguration(DoubleRegistrationTomcatConnectorCustomizerConfiguration.class).withPropertyValues("server.port: 0");
    runner.run((context) -> {
        TomcatServletWebServerFactory factory = context.getBean(TomcatServletWebServerFactory.class);
        TomcatConnectorCustomizer customizer = context.getBean("connectorCustomizer", TomcatConnectorCustomizer.class);
        assertThat(factory.getTomcatConnectorCustomizers()).contains(customizer);
        then(customizer).should().customize(any(Connector.class));
    });
}
Also used : Connector(org.apache.catalina.connector.Connector) WebApplicationContextRunner(org.springframework.boot.test.context.runner.WebApplicationContextRunner) TomcatServletWebServerFactory(org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory) TomcatConnectorCustomizer(org.springframework.boot.web.embedded.tomcat.TomcatConnectorCustomizer) Test(org.junit.jupiter.api.Test)

Example 64 with TomcatServletWebServerFactory

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

the class MyCloudFoundryConfiguration method servletWebServerFactory.

@Bean
public TomcatServletWebServerFactory servletWebServerFactory() {
    return new TomcatServletWebServerFactory() {

        @Override
        protected void prepareContext(Host host, ServletContextInitializer[] initializers) {
            super.prepareContext(host, initializers);
            StandardContext child = new StandardContext();
            child.addLifecycleListener(new Tomcat.FixContextListener());
            child.setPath("/cloudfoundryapplication");
            ServletContainerInitializer initializer = getServletContextInitializer(getContextPath());
            child.addServletContainerInitializer(initializer, Collections.emptySet());
            child.setCrossContext(true);
            host.addChild(child);
        }
    };
}
Also used : ServletContainerInitializer(jakarta.servlet.ServletContainerInitializer) Tomcat(org.apache.catalina.startup.Tomcat) TomcatServletWebServerFactory(org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory) StandardContext(org.apache.catalina.core.StandardContext) Host(org.apache.catalina.Host) Bean(org.springframework.context.annotation.Bean)

Example 65 with TomcatServletWebServerFactory

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

the class SampleTomcatTwoConnectorsApplication method servletContainer.

@Bean
public ServletWebServerFactory servletContainer() {
    TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory();
    tomcat.addAdditionalTomcatConnectors(createStandardConnector());
    return tomcat;
}
Also used : TomcatServletWebServerFactory(org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory) Bean(org.springframework.context.annotation.Bean)

Aggregations

TomcatServletWebServerFactory (org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory)66 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)9 WebApplicationContextRunner (org.springframework.boot.test.context.runner.WebApplicationContextRunner)6 TomcatWebServer (org.springframework.boot.web.embedded.tomcat.TomcatWebServer)6 Connector (org.apache.catalina.connector.Connector)5 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