Search in sources :

Example 51 with Connector

use of org.apache.catalina.connector.Connector in project tomcat by apache.

the class TestCustomSsl method testCustomSslImplementation.

@Test
public void testCustomSslImplementation() throws Exception {
    TesterSupport.configureClientSsl();
    Tomcat tomcat = getTomcatInstance();
    Connector connector = tomcat.getConnector();
    Assume.assumeFalse("This test is only for JSSE based SSL connectors", connector.getProtocolHandlerClassName().contains("Apr"));
    connector.setProperty("sslImplementationName", "org.apache.tomcat.util.net.jsse.TesterBug50640SslImpl");
    // This setting will break ssl configuration unless the custom
    // implementation is used.
    connector.setProperty(TesterBug50640SslImpl.PROPERTY_NAME, TesterBug50640SslImpl.PROPERTY_VALUE);
    connector.setProperty("sslProtocol", "tls");
    File keystoreFile = new File("test/org/apache/tomcat/util/net/localhost.jks");
    connector.setAttribute("keystoreFile", keystoreFile.getAbsolutePath());
    connector.setSecure(true);
    connector.setProperty("SSLEnabled", "true");
    File appDir = new File(getBuildDirectory(), "webapps/examples");
    Context ctxt = tomcat.addWebapp(null, "/examples", appDir.getAbsolutePath());
    ctxt.addApplicationListener(WsContextListener.class.getName());
    tomcat.start();
    ByteChunk res = getUrl("https://localhost:" + getPort() + "/examples/servlets/servlet/HelloWorldExample");
    assertTrue(res.toString().indexOf("<a href=\"../helloworld.html\">") > 0);
}
Also used : Context(org.apache.catalina.Context) Connector(org.apache.catalina.connector.Connector) Tomcat(org.apache.catalina.startup.Tomcat) WsContextListener(org.apache.tomcat.websocket.server.WsContextListener) ByteChunk(org.apache.tomcat.util.buf.ByteChunk) File(java.io.File) TomcatBaseTest(org.apache.catalina.startup.TomcatBaseTest) Test(org.junit.Test)

Example 52 with Connector

use of org.apache.catalina.connector.Connector in project spring-boot by spring-projects.

the class TomcatServletWebServerFactoryTests method uriEncoding.

@Test
public void uriEncoding() throws Exception {
    TomcatServletWebServerFactory factory = getFactory();
    factory.setUriEncoding(Charset.forName("US-ASCII"));
    Tomcat tomcat = getTomcat(factory);
    Connector connector = ((TomcatWebServer) this.webServer).getServiceConnectors().get(tomcat.getService())[0];
    assertThat(connector.getURIEncoding()).isEqualTo("US-ASCII");
}
Also used : Connector(org.apache.catalina.connector.Connector) Tomcat(org.apache.catalina.startup.Tomcat) Test(org.junit.Test)

Example 53 with Connector

use of org.apache.catalina.connector.Connector in project spring-boot by spring-projects.

the class TomcatServletWebServerFactoryTests method sslEnabledProtocolsConfiguration.

@Test
public void sslEnabledProtocolsConfiguration() throws Exception {
    Ssl ssl = getSsl(null, "password", "src/test/resources/test.jks");
    ssl.setEnabledProtocols(new String[] { "TLSv1.2" });
    ssl.setCiphers(new String[] { "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256", "BRAVO" });
    TomcatServletWebServerFactory factory = getFactory();
    factory.setSsl(ssl);
    this.webServer = factory.getWebServer(sessionServletRegistration());
    Tomcat tomcat = ((TomcatWebServer) this.webServer).getTomcat();
    this.webServer.start();
    Connector connector = tomcat.getConnector();
    SSLHostConfig sslHostConfig = connector.getProtocolHandler().findSslHostConfigs()[0];
    assertThat(sslHostConfig.getSslProtocol()).isEqualTo("TLS");
    assertThat(sslHostConfig.getEnabledProtocols()).containsExactly("TLSv1.2");
}
Also used : Connector(org.apache.catalina.connector.Connector) Tomcat(org.apache.catalina.startup.Tomcat) Ssl(org.springframework.boot.web.server.Ssl) SSLHostConfig(org.apache.tomcat.util.net.SSLHostConfig) Test(org.junit.Test)

Example 54 with Connector

use of org.apache.catalina.connector.Connector in project spring-boot by spring-projects.

the class TomcatServletWebServerFactoryTests method tomcatAdditionalConnectors.

@Test
public void tomcatAdditionalConnectors() throws Exception {
    TomcatServletWebServerFactory factory = getFactory();
    Connector[] listeners = new Connector[4];
    for (int i = 0; i < listeners.length; i++) {
        Connector connector = mock(Connector.class);
        given(connector.getState()).willReturn(LifecycleState.STOPPED);
        listeners[i] = connector;
    }
    factory.addAdditionalTomcatConnectors(listeners);
    this.webServer = factory.getWebServer();
    Map<Service, Connector[]> connectors = ((TomcatWebServer) this.webServer).getServiceConnectors();
    assertThat(connectors.values().iterator().next().length).isEqualTo(listeners.length + 1);
}
Also used : Connector(org.apache.catalina.connector.Connector) Service(org.apache.catalina.Service) Test(org.junit.Test)

Example 55 with Connector

use of org.apache.catalina.connector.Connector in project spring-boot by spring-projects.

the class TomcatServletWebServerFactoryTests method sslEnabledMultipleProtocolsConfiguration.

@Test
public void sslEnabledMultipleProtocolsConfiguration() throws Exception {
    Ssl ssl = getSsl(null, "password", "src/test/resources/test.jks");
    ssl.setEnabledProtocols(new String[] { "TLSv1.1", "TLSv1.2" });
    ssl.setCiphers(new String[] { "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256", "BRAVO" });
    TomcatServletWebServerFactory factory = getFactory();
    factory.setSsl(ssl);
    this.webServer = factory.getWebServer(sessionServletRegistration());
    this.webServer.start();
    Tomcat tomcat = ((TomcatWebServer) this.webServer).getTomcat();
    Connector connector = tomcat.getConnector();
    SSLHostConfig sslHostConfig = connector.getProtocolHandler().findSslHostConfigs()[0];
    assertThat(sslHostConfig.getSslProtocol()).isEqualTo("TLS");
    assertThat(sslHostConfig.getEnabledProtocols()).containsExactlyInAnyOrder("TLSv1.1", "TLSv1.2");
}
Also used : Connector(org.apache.catalina.connector.Connector) Tomcat(org.apache.catalina.startup.Tomcat) Ssl(org.springframework.boot.web.server.Ssl) SSLHostConfig(org.apache.tomcat.util.net.SSLHostConfig) Test(org.junit.Test)

Aggregations

Connector (org.apache.catalina.connector.Connector)70 Test (org.junit.Test)16 Service (org.apache.catalina.Service)15 File (java.io.File)12 Tomcat (org.apache.catalina.startup.Tomcat)11 Properties (java.util.Properties)8 Context (org.apache.catalina.Context)7 HashMap (java.util.HashMap)6 Engine (org.apache.catalina.Engine)6 SSLHostConfig (org.apache.tomcat.util.net.SSLHostConfig)6 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 Map (java.util.Map)5 StandardService (org.apache.catalina.core.StandardService)5 URI (java.net.URI)4 Executor (org.apache.catalina.Executor)4 LifecycleException (org.apache.catalina.LifecycleException)4 Server (org.apache.catalina.Server)4 Http2Protocol (org.apache.coyote.http2.Http2Protocol)4 ObjectName (javax.management.ObjectName)3