Search in sources :

Example 11 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)

Example 12 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)

Example 13 with TomcatServletWebServerFactory

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

the class DefaultServletWebServerFactoryCustomizerTests method customTomcatAcceptCount.

@Test
public void customTomcatAcceptCount() {
    Map<String, String> map = new HashMap<>();
    map.put("server.tomcat.accept-count", "10");
    bindProperties(map);
    TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory(0);
    this.customizer.customize(factory);
    TomcatWebServer embeddedFactory = (TomcatWebServer) factory.getWebServer();
    embeddedFactory.start();
    try {
        assertThat(((AbstractProtocol<?>) embeddedFactory.getTomcat().getConnector().getProtocolHandler()).getBacklog()).isEqualTo(10);
    } finally {
        embeddedFactory.stop();
    }
}
Also used : TomcatServletWebServerFactory(org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory) AbstractProtocol(org.apache.coyote.AbstractProtocol) TomcatWebServer(org.springframework.boot.web.embedded.tomcat.TomcatWebServer) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 14 with TomcatServletWebServerFactory

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

the class DefaultServletWebServerFactoryCustomizerTests method tomcatAccessLogCanBeEnabled.

@Test
public void tomcatAccessLogCanBeEnabled() {
    TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory();
    Map<String, String> map = new HashMap<>();
    map.put("server.tomcat.accesslog.enabled", "true");
    bindProperties(map);
    this.customizer.customize(factory);
    assertThat(factory.getEngineValves()).hasSize(1);
    assertThat(factory.getEngineValves()).first().isInstanceOf(AccessLogValve.class);
}
Also used : TomcatServletWebServerFactory(org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 15 with TomcatServletWebServerFactory

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

the class DefaultServletWebServerFactoryCustomizerTests method tomcatAccessLogBufferingCanBeDisabled.

@Test
public void tomcatAccessLogBufferingCanBeDisabled() {
    TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory();
    Map<String, String> map = new HashMap<>();
    map.put("server.tomcat.accesslog.enabled", "true");
    map.put("server.tomcat.accesslog.buffered", "false");
    bindProperties(map);
    this.customizer.customize(factory);
    assertThat(((AccessLogValve) factory.getEngineValves().iterator().next()).isBuffered()).isFalse();
}
Also used : TomcatServletWebServerFactory(org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory) HashMap(java.util.HashMap) AccessLogValve(org.apache.catalina.valves.AccessLogValve) Test(org.junit.Test)

Aggregations

TomcatServletWebServerFactory (org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory)21 Test (org.junit.Test)16 HashMap (java.util.HashMap)13 AccessLogValve (org.apache.catalina.valves.AccessLogValve)7 TomcatWebServer (org.springframework.boot.web.embedded.tomcat.TomcatWebServer)5 Valve (org.apache.catalina.Valve)2 RemoteIpValve (org.apache.catalina.valves.RemoteIpValve)2 AbstractProtocol (org.apache.coyote.AbstractProtocol)2 UndertowServletWebServerFactory (org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory)2 ServletContext (javax.servlet.ServletContext)1 Context (org.apache.catalina.Context)1 ServerProperties (org.springframework.boot.autoconfigure.web.ServerProperties)1 JettyServletWebServerFactory (org.springframework.boot.web.embedded.jetty.JettyServletWebServerFactory)1 TomcatContextCustomizer (org.springframework.boot.web.embedded.tomcat.TomcatContextCustomizer)1 WebServer (org.springframework.boot.web.server.WebServer)1 AnnotationConfigServletWebServerApplicationContext (org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext)1 ExampleServlet (org.springframework.boot.web.servlet.server.ExampleServlet)1 InitParameterConfiguringServletContextInitializer (org.springframework.boot.web.servlet.server.InitParameterConfiguringServletContextInitializer)1 ServletWebServerFactory (org.springframework.boot.web.servlet.server.ServletWebServerFactory)1 ApplicationContext (org.springframework.context.ApplicationContext)1