Search in sources :

Example 36 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 37 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 38 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)

Example 39 with TomcatServletWebServerFactory

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

the class DefaultServletWebServerFactoryCustomizerTests method customTomcatMaxConnections.

@Test
public void customTomcatMaxConnections() {
    Map<String, String> map = new HashMap<>();
    map.put("server.tomcat.max-connections", "5");
    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()).getMaxConnections()).isEqualTo(5);
    } 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 40 with TomcatServletWebServerFactory

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

the class DefaultServletWebServerFactoryCustomizerTests method customTomcatRemoteIpValve.

@Test
public void customTomcatRemoteIpValve() throws Exception {
    Map<String, String> map = new HashMap<>();
    map.put("server.tomcat.remote_ip_header", "x-my-remote-ip-header");
    map.put("server.tomcat.protocol_header", "x-my-protocol-header");
    map.put("server.tomcat.internal_proxies", "192.168.0.1");
    map.put("server.tomcat.port-header", "x-my-forward-port");
    map.put("server.tomcat.protocol-header-https-value", "On");
    bindProperties(map);
    TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory();
    this.customizer.customize(factory);
    assertThat(factory.getEngineValves()).hasSize(1);
    Valve valve = factory.getEngineValves().iterator().next();
    assertThat(valve).isInstanceOf(RemoteIpValve.class);
    RemoteIpValve remoteIpValve = (RemoteIpValve) valve;
    assertThat(remoteIpValve.getProtocolHeader()).isEqualTo("x-my-protocol-header");
    assertThat(remoteIpValve.getProtocolHeaderHttpsValue()).isEqualTo("On");
    assertThat(remoteIpValve.getRemoteIpHeader()).isEqualTo("x-my-remote-ip-header");
    assertThat(remoteIpValve.getPortHeader()).isEqualTo("x-my-forward-port");
    assertThat(remoteIpValve.getInternalProxies()).isEqualTo("192.168.0.1");
}
Also used : TomcatServletWebServerFactory(org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory) HashMap(java.util.HashMap) Valve(org.apache.catalina.Valve) AccessLogValve(org.apache.catalina.valves.AccessLogValve) RemoteIpValve(org.apache.catalina.valves.RemoteIpValve) RemoteIpValve(org.apache.catalina.valves.RemoteIpValve) 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