Search in sources :

Example 16 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 17 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)

Example 18 with TomcatServletWebServerFactory

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

the class DefaultServletWebServerFactoryCustomizer method customize.

@Override
public void customize(ConfigurableServletWebServerFactory factory) {
    if (this.serverProperties.getPort() != null) {
        factory.setPort(this.serverProperties.getPort());
    }
    if (this.serverProperties.getAddress() != null) {
        factory.setAddress(this.serverProperties.getAddress());
    }
    if (this.serverProperties.getServlet().getContextPath() != null) {
        factory.setContextPath(this.serverProperties.getServlet().getContextPath());
    }
    if (this.serverProperties.getDisplayName() != null) {
        factory.setDisplayName(this.serverProperties.getDisplayName());
    }
    if (this.serverProperties.getSession().getTimeout() != null) {
        factory.setSessionTimeout(this.serverProperties.getSession().getTimeout());
    }
    factory.setPersistSession(this.serverProperties.getSession().isPersistent());
    factory.setSessionStoreDir(this.serverProperties.getSession().getStoreDir());
    if (this.serverProperties.getSsl() != null) {
        factory.setSsl(this.serverProperties.getSsl());
    }
    if (this.serverProperties.getServlet() != null) {
        factory.setJsp(this.serverProperties.getServlet().getJsp());
    }
    if (this.serverProperties.getCompression() != null) {
        factory.setCompression(this.serverProperties.getCompression());
    }
    factory.setServerHeader(this.serverProperties.getServerHeader());
    if (factory instanceof TomcatServletWebServerFactory) {
        TomcatCustomizer.customizeTomcat(this.serverProperties, this.environment, (TomcatServletWebServerFactory) factory);
    }
    if (factory instanceof JettyServletWebServerFactory) {
        JettyCustomizer.customizeJetty(this.serverProperties, this.environment, (JettyServletWebServerFactory) factory);
    }
    if (factory instanceof UndertowServletWebServerFactory) {
        UndertowCustomizer.customizeUndertow(this.serverProperties, this.environment, (UndertowServletWebServerFactory) factory);
    }
    factory.addInitializers(new SessionConfiguringInitializer(this.serverProperties.getSession()));
    factory.addInitializers(new InitParameterConfiguringServletContextInitializer(this.serverProperties.getServlet().getContextParameters()));
}
Also used : TomcatServletWebServerFactory(org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory) JettyServletWebServerFactory(org.springframework.boot.web.embedded.jetty.JettyServletWebServerFactory) UndertowServletWebServerFactory(org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory) InitParameterConfiguringServletContextInitializer(org.springframework.boot.web.servlet.server.InitParameterConfiguringServletContextInitializer)

Example 19 with TomcatServletWebServerFactory

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

the class DefaultServletWebServerFactoryCustomizerTests method tomcatAccessLogFileDateFormatCanBeRedefined.

@Test
public void tomcatAccessLogFileDateFormatCanBeRedefined() {
    TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory();
    Map<String, String> map = new HashMap<String, String>();
    map.put("server.tomcat.accesslog.enabled", "true");
    map.put("server.tomcat.accesslog.file-date-format", "yyyy-MM-dd.HH");
    bindProperties(map);
    this.customizer.customize(factory);
    assertThat(((AccessLogValve) factory.getEngineValves().iterator().next()).getFileDateFormat()).isEqualTo("yyyy-MM-dd.HH");
}
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 20 with TomcatServletWebServerFactory

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

the class DefaultServletWebServerFactoryCustomizerTests method customizeTomcatDisplayName.

@Test
public void customizeTomcatDisplayName() throws Exception {
    Map<String, String> map = new HashMap<>();
    map.put("server.display-name", "MyBootApp");
    bindProperties(map);
    TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory();
    this.customizer.customize(factory);
    assertThat(factory.getDisplayName()).isEqualTo("MyBootApp");
}
Also used : TomcatServletWebServerFactory(org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory) HashMap(java.util.HashMap) 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