|
16 | 16 |
|
17 | 17 | package org.springframework.boot.docs.howto.webserver.enablemultipleconnectorsintomcat;
|
18 | 18 |
|
19 |
| -import java.io.IOException; |
20 |
| -import java.net.URL; |
21 |
| - |
22 | 19 | import org.apache.catalina.connector.Connector;
|
23 |
| -import org.apache.coyote.http11.Http11NioProtocol; |
24 | 20 |
|
25 | 21 | import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
|
26 | 22 | import org.springframework.boot.web.server.WebServerFactoryCustomizer;
|
27 | 23 | import org.springframework.context.annotation.Bean;
|
28 | 24 | import org.springframework.context.annotation.Configuration;
|
29 |
| -import org.springframework.util.ResourceUtils; |
30 | 25 |
|
31 | 26 | @Configuration(proxyBeanMethods = false)
|
32 | 27 | public class MyTomcatConfiguration {
|
33 | 28 |
|
34 | 29 | @Bean
|
35 |
| - public WebServerFactoryCustomizer<TomcatServletWebServerFactory> sslConnectorCustomizer() { |
36 |
| - return (tomcat) -> tomcat.addAdditionalTomcatConnectors(createSslConnector()); |
| 30 | + public WebServerFactoryCustomizer<TomcatServletWebServerFactory> connectorCustomizer() { |
| 31 | + return (tomcat) -> tomcat.addAdditionalTomcatConnectors(createConnector()); |
37 | 32 | }
|
38 | 33 |
|
39 |
| - private Connector createSslConnector() { |
| 34 | + private Connector createConnector() { |
40 | 35 | Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
|
41 |
| - Http11NioProtocol protocol = (Http11NioProtocol) connector.getProtocolHandler(); |
42 |
| - try { |
43 |
| - URL keystore = ResourceUtils.getURL("keystore"); |
44 |
| - URL truststore = ResourceUtils.getURL("truststore"); |
45 |
| - connector.setScheme("https"); |
46 |
| - connector.setSecure(true); |
47 |
| - connector.setPort(8443); |
48 |
| - protocol.setSSLEnabled(true); |
49 |
| - protocol.setKeystoreFile(keystore.toString()); |
50 |
| - protocol.setKeystorePass("changeit"); |
51 |
| - protocol.setTruststoreFile(truststore.toString()); |
52 |
| - protocol.setTruststorePass("changeit"); |
53 |
| - protocol.setKeyAlias("apitester"); |
54 |
| - return connector; |
55 |
| - } |
56 |
| - catch (IOException ex) { |
57 |
| - throw new IllegalStateException("Fail to create ssl connector", ex); |
58 |
| - } |
| 36 | + connector.setPort(8081); |
| 37 | + return connector; |
59 | 38 | }
|
60 | 39 |
|
61 | 40 | }
|
0 commit comments