Skip to content

Commit 2170941

Browse files
committed
Update Kotlin example for Tomcat connector customization
See gh-33331
1 parent 9af2a57 commit 2170941

File tree

1 file changed

+5
-23
lines changed
  • spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/howto/webserver/enablemultipleconnectorsintomcat

1 file changed

+5
-23
lines changed

spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/howto/webserver/enablemultipleconnectorsintomcat/MyTomcatConfiguration.kt

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,45 +17,27 @@
1717
package org.springframework.boot.docs.howto.webserver.enablemultipleconnectorsintomcat
1818

1919
import org.apache.catalina.connector.Connector
20-
import org.apache.coyote.http11.Http11NioProtocol
2120
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory
2221
import org.springframework.boot.web.server.WebServerFactoryCustomizer
2322
import org.springframework.context.annotation.Bean
2423
import org.springframework.context.annotation.Configuration
25-
import org.springframework.util.ResourceUtils
26-
import java.io.IOException
2724

2825
@Configuration(proxyBeanMethods = false)
2926
class MyTomcatConfiguration {
3027

3128
@Bean
32-
fun sslConnectorCustomizer(): WebServerFactoryCustomizer<TomcatServletWebServerFactory> {
29+
fun connectorCustomizer(): WebServerFactoryCustomizer<TomcatServletWebServerFactory> {
3330
return WebServerFactoryCustomizer { tomcat: TomcatServletWebServerFactory ->
3431
tomcat.addAdditionalTomcatConnectors(
35-
createSslConnector()
32+
createConnector()
3633
)
3734
}
3835
}
3936

40-
private fun createSslConnector(): Connector {
37+
private fun createConnector(): Connector {
4138
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
5941
}
6042

6143
}

0 commit comments

Comments
 (0)