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