Search in sources :

Example 1 with AprLifecycleListener

use of org.apache.catalina.core.AprLifecycleListener 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 AprLifecycleListener

use of org.apache.catalina.core.AprLifecycleListener in project tomcat by apache.

the class TesterSupport method initSsl.

protected static void initSsl(Tomcat tomcat, String keystore, String keystorePass, String keyPass) {
    String protocol = tomcat.getConnector().getProtocolHandlerClassName();
    if (protocol.indexOf("Apr") == -1) {
        Connector connector = tomcat.getConnector();
        String sslImplementation = System.getProperty("tomcat.test.sslImplementation");
        if (sslImplementation != null && !"${test.sslImplementation}".equals(sslImplementation)) {
            StandardServer server = (StandardServer) tomcat.getServer();
            AprLifecycleListener listener = new AprLifecycleListener();
            listener.setSSLRandomSeed("/dev/urandom");
            server.addLifecycleListener(listener);
            tomcat.getConnector().setAttribute("sslImplementationName", sslImplementation);
        }
        connector.setProperty("sslProtocol", "tls");
        File keystoreFile = new File("test/org/apache/tomcat/util/net/" + keystore);
        connector.setAttribute("keystoreFile", keystoreFile.getAbsolutePath());
        File truststoreFile = new File("test/org/apache/tomcat/util/net/ca.jks");
        connector.setAttribute("truststoreFile", truststoreFile.getAbsolutePath());
        if (keystorePass != null) {
            connector.setAttribute("keystorePass", keystorePass);
        }
        if (keyPass != null) {
            connector.setAttribute("keyPass", keyPass);
        }
    } else {
        File keystoreFile = new File("test/org/apache/tomcat/util/net/localhost-cert.pem");
        tomcat.getConnector().setAttribute("SSLCertificateFile", keystoreFile.getAbsolutePath());
        keystoreFile = new File("test/org/apache/tomcat/util/net/localhost-key.pem");
        tomcat.getConnector().setAttribute("SSLCertificateKeyFile", keystoreFile.getAbsolutePath());
    }
    tomcat.getConnector().setSecure(true);
    tomcat.getConnector().setProperty("SSLEnabled", "true");
}
Also used : Connector(org.apache.catalina.connector.Connector) AprLifecycleListener(org.apache.catalina.core.AprLifecycleListener) StandardServer(org.apache.catalina.core.StandardServer) File(java.io.File)

Aggregations

File (java.io.File)2 Connector (org.apache.catalina.connector.Connector)2 AprLifecycleListener (org.apache.catalina.core.AprLifecycleListener)2 StandardServer (org.apache.catalina.core.StandardServer)2 AccessLogValve (org.apache.catalina.valves.AccessLogValve)1 Before (org.junit.Before)1