Search in sources :

Example 1 with AccessLogValve

use of org.apache.catalina.valves.AccessLogValve in project tomcat by apache.

the class TomcatBaseTest method setUp.

@Before
@Override
public void setUp() throws Exception {
    super.setUp();
    // Trigger loading of catalina.properties
    CatalinaProperties.getProperty("foo");
    File appBase = new File(getTemporaryDirectory(), "webapps");
    if (!appBase.exists() && !appBase.mkdir()) {
        fail("Unable to create appBase for test");
    }
    tomcat = new TomcatWithFastSessionIDs();
    String protocol = getProtocol();
    Connector connector = new Connector(protocol);
    // Listen only on localhost
    connector.setAttribute("address", InetAddress.getByName("localhost").getHostAddress());
    // Use random free port
    connector.setPort(0);
    // Mainly set to reduce timeouts during async tests
    connector.setAttribute("connectionTimeout", "3000");
    tomcat.getService().addConnector(connector);
    tomcat.setConnector(connector);
    // Add AprLifecycleListener if we are using the Apr connector
    if (protocol.contains("Apr")) {
        StandardServer server = (StandardServer) tomcat.getServer();
        AprLifecycleListener listener = new AprLifecycleListener();
        listener.setSSLRandomSeed("/dev/urandom");
        server.addLifecycleListener(listener);
        connector.setAttribute("pollerThreadCount", Integer.valueOf(1));
    }
    File catalinaBase = getTemporaryDirectory();
    tomcat.setBaseDir(catalinaBase.getAbsolutePath());
    tomcat.getHost().setAppBase(appBase.getAbsolutePath());
    accessLogEnabled = Boolean.parseBoolean(System.getProperty("tomcat.test.accesslog", "false"));
    if (accessLogEnabled) {
        String accessLogDirectory = System.getProperty("tomcat.test.reports");
        if (accessLogDirectory == null) {
            accessLogDirectory = new File(getBuildDirectory(), "logs").toString();
        }
        AccessLogValve alv = new AccessLogValve();
        alv.setDirectory(accessLogDirectory);
        alv.setPattern("%h %l %u %t \"%r\" %s %b %I %D");
        tomcat.getHost().getPipeline().addValve(alv);
    }
    // Cannot delete the whole tempDir, because logs are there,
    // but delete known subdirectories of it.
    addDeleteOnTearDown(new File(catalinaBase, "webapps"));
    addDeleteOnTearDown(new File(catalinaBase, "work"));
}
Also used : Connector(org.apache.catalina.connector.Connector) AprLifecycleListener(org.apache.catalina.core.AprLifecycleListener) StandardServer(org.apache.catalina.core.StandardServer) File(java.io.File) AccessLogValve(org.apache.catalina.valves.AccessLogValve) Before(org.junit.Before)

Example 2 with AccessLogValve

use of org.apache.catalina.valves.AccessLogValve in project spring-boot by spring-projects.

the class DefaultServletWebServerFactoryCustomizerTests method tomcatAccessLogFileDateFormatByDefault.

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

use of org.apache.catalina.valves.AccessLogValve in project spring-boot by spring-projects.

the class DefaultServletWebServerFactoryCustomizerTests method tomcatAccessLogIsBufferedByDefault.

@Test
public void tomcatAccessLogIsBufferedByDefault() {
    TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory();
    Map<String, String> map = new HashMap<>();
    map.put("server.tomcat.accesslog.enabled", "true");
    bindProperties(map);
    this.customizer.customize(factory);
    assertThat(((AccessLogValve) factory.getEngineValves().iterator().next()).isBuffered()).isTrue();
}
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 4 with AccessLogValve

use of org.apache.catalina.valves.AccessLogValve 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 5 with AccessLogValve

use of org.apache.catalina.valves.AccessLogValve 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

AccessLogValve (org.apache.catalina.valves.AccessLogValve)6 Test (org.junit.Test)5 TomcatServletWebServerFactory (org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory)5 HashMap (java.util.HashMap)4 File (java.io.File)1 Connector (org.apache.catalina.connector.Connector)1 AprLifecycleListener (org.apache.catalina.core.AprLifecycleListener)1 StandardServer (org.apache.catalina.core.StandardServer)1 Before (org.junit.Before)1 UndertowServletWebServerFactory (org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory)1 AnnotationConfigServletWebServerApplicationContext (org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext)1 ServletWebServerFactory (org.springframework.boot.web.servlet.server.ServletWebServerFactory)1 ApplicationContext (org.springframework.context.ApplicationContext)1 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)1