Search in sources :

Example 21 with Connector

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

the class TomcatServletWebServerFactory method getWebServer.

@Override
public WebServer getWebServer(ServletContextInitializer... initializers) {
    Tomcat tomcat = new Tomcat();
    File baseDir = (this.baseDirectory != null ? this.baseDirectory : createTempDir("tomcat"));
    tomcat.setBaseDir(baseDir.getAbsolutePath());
    Connector connector = new Connector(this.protocol);
    tomcat.getService().addConnector(connector);
    customizeConnector(connector);
    tomcat.setConnector(connector);
    tomcat.getHost().setAutoDeploy(false);
    configureEngine(tomcat.getEngine());
    for (Connector additionalConnector : this.additionalTomcatConnectors) {
        tomcat.getService().addConnector(additionalConnector);
    }
    prepareContext(tomcat.getHost(), initializers);
    return getTomcatWebServer(tomcat);
}
Also used : Connector(org.apache.catalina.connector.Connector) Tomcat(org.apache.catalina.startup.Tomcat) File(java.io.File)

Example 22 with Connector

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

the class TomcatWebServer method start.

@Override
public void start() throws WebServerException {
    synchronized (this.monitor) {
        if (this.started) {
            return;
        }
        try {
            addPreviouslyRemovedConnectors();
            Connector connector = this.tomcat.getConnector();
            if (connector != null && this.autoStart) {
                startConnector(connector);
            }
            checkThatConnectorsHaveStarted();
            this.started = true;
            TomcatWebServer.logger.info("Tomcat started on port(s): " + getPortsDescription(true));
        } catch (ConnectorStartFailedException ex) {
            stopSilently();
            throw ex;
        } catch (Exception ex) {
            throw new WebServerException("Unable to start embedded Tomcat server", ex);
        } finally {
            Context context = findContext();
            ContextBindings.unbindClassLoader(context, context.getNamingToken(), getClass().getClassLoader());
        }
    }
}
Also used : Context(org.apache.catalina.Context) Connector(org.apache.catalina.connector.Connector) WebServerException(org.springframework.boot.web.server.WebServerException) LifecycleException(org.apache.catalina.LifecycleException) WebServerException(org.springframework.boot.web.server.WebServerException) NamingException(javax.naming.NamingException)

Example 23 with Connector

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

the class TomcatWebServer method removeServiceConnectors.

private void removeServiceConnectors() {
    for (Service service : this.tomcat.getServer().findServices()) {
        Connector[] connectors = service.findConnectors().clone();
        this.serviceConnectors.put(service, connectors);
        for (Connector connector : connectors) {
            service.removeConnector(connector);
        }
    }
}
Also used : Connector(org.apache.catalina.connector.Connector) Service(org.apache.catalina.Service)

Example 24 with Connector

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

the class TomcatServletWebServerFactoryTests method defaultUriEncoding.

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

Example 25 with Connector

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

the class TomcatServletWebServerFactoryTests method sslCiphersConfiguration.

@Test
public void sslCiphersConfiguration() throws Exception {
    Ssl ssl = new Ssl();
    ssl.setKeyStore("test.jks");
    ssl.setKeyStorePassword("secret");
    ssl.setCiphers(new String[] { "ALPHA", "BRAVO", "CHARLIE" });
    TomcatServletWebServerFactory factory = getFactory();
    factory.setSsl(ssl);
    Tomcat tomcat = getTomcat(factory);
    Connector connector = ((TomcatWebServer) this.webServer).getServiceConnectors().get(tomcat.getService())[0];
    SSLHostConfig[] sslHostConfigs = connector.getProtocolHandler().findSslHostConfigs();
    assertThat(sslHostConfigs[0].getCiphers()).isEqualTo("ALPHA:BRAVO:CHARLIE");
}
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)66 Test (org.junit.Test)16 Service (org.apache.catalina.Service)14 File (java.io.File)10 Tomcat (org.apache.catalina.startup.Tomcat)10 Context (org.apache.catalina.Context)6 Engine (org.apache.catalina.Engine)6 Properties (java.util.Properties)5 StandardService (org.apache.catalina.core.StandardService)5 SSLHostConfig (org.apache.tomcat.util.net.SSLHostConfig)5 IOException (java.io.IOException)4 URI (java.net.URI)4 ArrayList (java.util.ArrayList)4 Executor (org.apache.catalina.Executor)4 HashMap (java.util.HashMap)3 ObjectName (javax.management.ObjectName)3 Container (org.apache.catalina.Container)3 LifecycleException (org.apache.catalina.LifecycleException)3 Wrapper (org.apache.catalina.Wrapper)3 InetAddress (java.net.InetAddress)2