From 2170941cf6e1dd5d8cd5102d630bc1be38cc5b5c Mon Sep 17 00:00:00 2001 From: Moritz Halbritter Date: Wed, 23 Nov 2022 17:10:36 +0100 Subject: [PATCH] Update Kotlin example for Tomcat connector customization See gh-33331 --- .../MyTomcatConfiguration.kt | 28 ++++--------------- 1 file changed, 5 insertions(+), 23 deletions(-) diff --git a/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/howto/webserver/enablemultipleconnectorsintomcat/MyTomcatConfiguration.kt b/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/howto/webserver/enablemultipleconnectorsintomcat/MyTomcatConfiguration.kt index 7d6d01aaab..4f6a9a1558 100644 --- a/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/howto/webserver/enablemultipleconnectorsintomcat/MyTomcatConfiguration.kt +++ b/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/howto/webserver/enablemultipleconnectorsintomcat/MyTomcatConfiguration.kt @@ -17,45 +17,27 @@ package org.springframework.boot.docs.howto.webserver.enablemultipleconnectorsintomcat 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.server.WebServerFactoryCustomizer import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Configuration -import org.springframework.util.ResourceUtils -import java.io.IOException @Configuration(proxyBeanMethods = false) class MyTomcatConfiguration { @Bean - fun sslConnectorCustomizer(): WebServerFactoryCustomizer { + fun connectorCustomizer(): WebServerFactoryCustomizer { return WebServerFactoryCustomizer { tomcat: TomcatServletWebServerFactory -> tomcat.addAdditionalTomcatConnectors( - createSslConnector() + createConnector() ) } } - private fun createSslConnector(): Connector { + private fun createConnector(): Connector { val connector = Connector("org.apache.coyote.http11.Http11NioProtocol") - val protocol = connector.protocolHandler as Http11NioProtocol - return try { - val keystore = ResourceUtils.getURL("keystore") - val truststore = ResourceUtils.getURL("truststore") - connector.scheme = "https" - connector.secure = true - connector.port = 8443 - protocol.isSSLEnabled = true - protocol.keystoreFile = keystore.toString() - protocol.keystorePass = "changeit" - protocol.truststoreFile = truststore.toString() - protocol.truststorePass = "changeit" - protocol.keyAlias = "apitester" - connector - } catch (ex: IOException) { - throw IllegalStateException("Fail to create ssl connector", ex) - } + connector.port = 8081 + return connector } }