Allow multiple connectors with Tomcat
Update TomcatEmbeddedServletContainerFactory to allow for additional containers (e.g. SSL or AJP in addition to HTTP). Fixes gh-528
This commit is contained in:
committed by
Phillip Webb
parent
48636e3d6e
commit
8b77a0298f
@@ -453,6 +453,44 @@ that sets up the connector to be secure:
|
||||
}
|
||||
----
|
||||
|
||||
[[howto-enable-multiple-connectors-in-tomcat]]
|
||||
=== Enable Multiple Connectors Tomcat
|
||||
Add a `org.apache.catalina.connector.Connector` to the
|
||||
`TomcatEmbeddedServletContainerFactory` which can allow multiple connectors eg a HTTP and
|
||||
HTTPS connector:
|
||||
|
||||
[source,java,indent=0,subs="verbatim,quotes,attributes"]
|
||||
----
|
||||
@Bean
|
||||
public EmbeddedServletContainerFactory servletContainer() {
|
||||
TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory();
|
||||
tomcat.addAdditionalTomcatConnectors(createSslConnector());
|
||||
return tomcat;
|
||||
}
|
||||
|
||||
private Connector createSslConnector() {
|
||||
Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
|
||||
Http11NioProtocol protocol = (Http11NioProtocol) connector.getProtocolHandler();
|
||||
try {
|
||||
File keystore = new ClassPathResource("keystore").getFile();
|
||||
File truststore = new ClassPathResource("keystore").getFile();
|
||||
connector.setScheme("https");
|
||||
connector.setSecure(true);
|
||||
connector.setPort(8443);
|
||||
protocol.setSSLEnabled(true);
|
||||
protocol.setKeystoreFile(keystore.getAbsolutePath());
|
||||
protocol.setKeystorePass("changeit");
|
||||
protocol.setTruststoreFile(truststore.getAbsolutePath());
|
||||
protocol.setTruststorePass("changeit");
|
||||
protocol.setKeyAlias("apitester");
|
||||
return connector;
|
||||
}
|
||||
catch (IOException ex) {
|
||||
throw new IllegalStateException("can't access keystore: [" + "keystore"
|
||||
+ "] or truststore: [" + "keystore" + "]", ex);
|
||||
}
|
||||
}
|
||||
----
|
||||
|
||||
|
||||
[[howto-use-jetty-instead-of-tomcat]]
|
||||
|
||||
Reference in New Issue
Block a user