Search in sources :

Example 1 with TomcatContextCustomizer

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

the class DefaultServletWebServerFactoryCustomizerTests method redirectContextRootCanBeConfigured.

@Test
public void redirectContextRootCanBeConfigured() throws Exception {
    Map<String, String> map = new HashMap<>();
    map.put("server.tomcat.redirect-context-root", "false");
    bindProperties(map);
    ServerProperties.Tomcat tomcat = this.properties.getTomcat();
    assertThat(tomcat.getRedirectContextRoot()).isEqualTo(false);
    TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory();
    this.customizer.customize(factory);
    Context context = mock(Context.class);
    for (TomcatContextCustomizer customizer : factory.getTomcatContextCustomizers()) {
        customizer.customize(context);
    }
    verify(context).setMapperContextRootRedirectEnabled(false);
}
Also used : Context(org.apache.catalina.Context) ServletContext(javax.servlet.ServletContext) TomcatContextCustomizer(org.springframework.boot.web.embedded.tomcat.TomcatContextCustomizer) TomcatServletWebServerFactory(org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory) HashMap(java.util.HashMap) ServerProperties(org.springframework.boot.autoconfigure.web.ServerProperties) Test(org.junit.Test)

Example 2 with TomcatContextCustomizer

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

the class ReactiveWebServerFactoryAutoConfigurationTests method tomcatContextCustomizerRegisteredAsBeanAndViaFactoryIsOnlyCalledOnce.

@Test
void tomcatContextCustomizerRegisteredAsBeanAndViaFactoryIsOnlyCalledOnce() {
    ReactiveWebApplicationContextRunner runner = new ReactiveWebApplicationContextRunner(AnnotationConfigReactiveWebServerApplicationContext::new).withConfiguration(AutoConfigurations.of(ReactiveWebServerFactoryAutoConfiguration.class)).withUserConfiguration(HttpHandlerConfiguration.class, DoubleRegistrationTomcatContextCustomizerConfiguration.class).withPropertyValues("server.port: 0");
    runner.run((context) -> {
        TomcatReactiveWebServerFactory factory = context.getBean(TomcatReactiveWebServerFactory.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) AnnotationConfigReactiveWebServerApplicationContext(org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebServerApplicationContext) AnnotationConfigReactiveWebApplicationContext(org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebApplicationContext) Context(org.apache.catalina.Context) TomcatReactiveWebServerFactory(org.springframework.boot.web.embedded.tomcat.TomcatReactiveWebServerFactory) ReactiveWebApplicationContextRunner(org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner) Test(org.junit.jupiter.api.Test)

Example 3 with TomcatContextCustomizer

use of org.springframework.boot.web.embedded.tomcat.TomcatContextCustomizer 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 4 with TomcatContextCustomizer

use of org.springframework.boot.web.embedded.tomcat.TomcatContextCustomizer 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 5 with TomcatContextCustomizer

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

the class ReactiveWebServerFactoryAutoConfigurationTests method tomcatContextCustomizerBeanIsAddedToFactory.

@Test
void tomcatContextCustomizerBeanIsAddedToFactory() {
    ReactiveWebApplicationContextRunner runner = new ReactiveWebApplicationContextRunner(AnnotationConfigReactiveWebServerApplicationContext::new).withConfiguration(AutoConfigurations.of(ReactiveWebServerFactoryAutoConfiguration.class)).withUserConfiguration(HttpHandlerConfiguration.class, TomcatContextCustomizerConfiguration.class).withPropertyValues("server.port: 0");
    runner.run((context) -> {
        TomcatReactiveWebServerFactory factory = context.getBean(TomcatReactiveWebServerFactory.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) AnnotationConfigReactiveWebServerApplicationContext(org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebServerApplicationContext) AnnotationConfigReactiveWebApplicationContext(org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebApplicationContext) Context(org.apache.catalina.Context) TomcatReactiveWebServerFactory(org.springframework.boot.web.embedded.tomcat.TomcatReactiveWebServerFactory) ReactiveWebApplicationContextRunner(org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner) Test(org.junit.jupiter.api.Test)

Aggregations

Context (org.apache.catalina.Context)5 TomcatContextCustomizer (org.springframework.boot.web.embedded.tomcat.TomcatContextCustomizer)5 Test (org.junit.jupiter.api.Test)4 TomcatServletWebServerFactory (org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory)3 ServletContext (jakarta.servlet.ServletContext)2 AssertableWebApplicationContext (org.springframework.boot.test.context.assertj.AssertableWebApplicationContext)2 ReactiveWebApplicationContextRunner (org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner)2 WebApplicationContextRunner (org.springframework.boot.test.context.runner.WebApplicationContextRunner)2 TomcatReactiveWebServerFactory (org.springframework.boot.web.embedded.tomcat.TomcatReactiveWebServerFactory)2 AnnotationConfigReactiveWebApplicationContext (org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebApplicationContext)2 AnnotationConfigReactiveWebServerApplicationContext (org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebServerApplicationContext)2 AnnotationConfigServletWebServerApplicationContext (org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext)2 ApplicationContext (org.springframework.context.ApplicationContext)2 HashMap (java.util.HashMap)1 ServletContext (javax.servlet.ServletContext)1 Test (org.junit.Test)1 ServerProperties (org.springframework.boot.autoconfigure.web.ServerProperties)1