|
|
@ -16,46 +16,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
package org.springframework.boot.docs.howto.webserver.enablemultipleconnectorsintomcat;
|
|
|
|
package org.springframework.boot.docs.howto.webserver.enablemultipleconnectorsintomcat;
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
import java.net.URL;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.apache.catalina.connector.Connector;
|
|
|
|
import org.apache.catalina.connector.Connector;
|
|
|
|
import org.apache.coyote.http11.Http11NioProtocol;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
|
|
|
|
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
|
|
|
|
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
|
|
|
|
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
|
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
import org.springframework.util.ResourceUtils;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Configuration(proxyBeanMethods = false)
|
|
|
|
@Configuration(proxyBeanMethods = false)
|
|
|
|
public class MyTomcatConfiguration {
|
|
|
|
public class MyTomcatConfiguration {
|
|
|
|
|
|
|
|
|
|
|
|
@Bean
|
|
|
|
@Bean
|
|
|
|
public WebServerFactoryCustomizer<TomcatServletWebServerFactory> sslConnectorCustomizer() {
|
|
|
|
public WebServerFactoryCustomizer<TomcatServletWebServerFactory> connectorCustomizer() {
|
|
|
|
return (tomcat) -> tomcat.addAdditionalTomcatConnectors(createSslConnector());
|
|
|
|
return (tomcat) -> tomcat.addAdditionalTomcatConnectors(createConnector());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private Connector createSslConnector() {
|
|
|
|
private Connector createConnector() {
|
|
|
|
Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
|
|
|
|
Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
|
|
|
|
Http11NioProtocol protocol = (Http11NioProtocol) connector.getProtocolHandler();
|
|
|
|
connector.setPort(8081);
|
|
|
|
try {
|
|
|
|
return connector;
|
|
|
|
URL keystore = ResourceUtils.getURL("keystore");
|
|
|
|
|
|
|
|
URL truststore = ResourceUtils.getURL("truststore");
|
|
|
|
|
|
|
|
connector.setScheme("https");
|
|
|
|
|
|
|
|
connector.setSecure(true);
|
|
|
|
|
|
|
|
connector.setPort(8443);
|
|
|
|
|
|
|
|
protocol.setSSLEnabled(true);
|
|
|
|
|
|
|
|
protocol.setKeystoreFile(keystore.toString());
|
|
|
|
|
|
|
|
protocol.setKeystorePass("changeit");
|
|
|
|
|
|
|
|
protocol.setTruststoreFile(truststore.toString());
|
|
|
|
|
|
|
|
protocol.setTruststorePass("changeit");
|
|
|
|
|
|
|
|
protocol.setKeyAlias("apitester");
|
|
|
|
|
|
|
|
return connector;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (IOException ex) {
|
|
|
|
|
|
|
|
throw new IllegalStateException("Fail to create ssl connector", ex);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|