Search in sources :

Example 6 with TomcatServletWebServerFactory

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

the class DefaultServletWebServerFactoryCustomizerTests method defaultTomcatBackgroundProcessorDelay.

@Test
public void defaultTomcatBackgroundProcessorDelay() throws Exception {
    TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory();
    this.customizer.customize(factory);
    assertThat(((TomcatWebServer) factory.getWebServer()).getTomcat().getEngine().getBackgroundProcessorDelay()).isEqualTo(30);
}
Also used : TomcatServletWebServerFactory(org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory) TomcatWebServer(org.springframework.boot.web.embedded.tomcat.TomcatWebServer) Test(org.junit.Test)

Example 7 with TomcatServletWebServerFactory

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

the class DefaultServletWebServerFactoryCustomizerTests method testRemoteIpValveConfigured.

private void testRemoteIpValveConfigured() {
    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-Forwarded-Proto");
    assertThat(remoteIpValve.getProtocolHeaderHttpsValue()).isEqualTo("https");
    assertThat(remoteIpValve.getRemoteIpHeader()).isEqualTo("X-Forwarded-For");
    String expectedInternalProxies = // 10/8
    "10\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}|" + // 192.168/16
    "192\\.168\\.\\d{1,3}\\.\\d{1,3}|" + // 169.254/16
    "169\\.254\\.\\d{1,3}\\.\\d{1,3}|" + // 127/8
    "127\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}|" + // 172.16/12
    "172\\.1[6-9]{1}\\.\\d{1,3}\\.\\d{1,3}|" + "172\\.2[0-9]{1}\\.\\d{1,3}\\.\\d{1,3}|" + "172\\.3[0-1]{1}\\.\\d{1,3}\\.\\d{1,3}";
    assertThat(remoteIpValve.getInternalProxies()).isEqualTo(expectedInternalProxies);
}
Also used : TomcatServletWebServerFactory(org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory) Valve(org.apache.catalina.Valve) AccessLogValve(org.apache.catalina.valves.AccessLogValve) RemoteIpValve(org.apache.catalina.valves.RemoteIpValve) RemoteIpValve(org.apache.catalina.valves.RemoteIpValve)

Example 8 with TomcatServletWebServerFactory

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

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

the class DefaultServletWebServerFactoryCustomizerTests method tomcatAccessLogIsDisabledByDefault.

@Test
public void tomcatAccessLogIsDisabledByDefault() {
    TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory();
    this.customizer.customize(factory);
    assertThat(factory.getEngineValves()).isEmpty();
}
Also used : TomcatServletWebServerFactory(org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory) Test(org.junit.Test)

Example 10 with TomcatServletWebServerFactory

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

the class DefaultServletWebServerFactoryCustomizerTests method disableTomcatRemoteIpValve.

@Test
public void disableTomcatRemoteIpValve() throws Exception {
    Map<String, String> map = new HashMap<>();
    map.put("server.tomcat.remote_ip_header", "");
    map.put("server.tomcat.protocol_header", "");
    bindProperties(map);
    TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory();
    this.customizer.customize(factory);
    assertThat(factory.getEngineValves()).isEmpty();
}
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