Update Kotlin example for Tomcat connector customization
See gh-33331
This commit is contained in:
parent
9af2a5712c
commit
2170941cf6
|
|
@ -17,45 +17,27 @@
|
||||||
package org.springframework.boot.docs.howto.webserver.enablemultipleconnectorsintomcat
|
package org.springframework.boot.docs.howto.webserver.enablemultipleconnectorsintomcat
|
||||||
|
|
||||||
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
|
|
||||||
import java.io.IOException
|
|
||||||
|
|
||||||
@Configuration(proxyBeanMethods = false)
|
@Configuration(proxyBeanMethods = false)
|
||||||
class MyTomcatConfiguration {
|
class MyTomcatConfiguration {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
fun sslConnectorCustomizer(): WebServerFactoryCustomizer<TomcatServletWebServerFactory> {
|
fun connectorCustomizer(): WebServerFactoryCustomizer<TomcatServletWebServerFactory> {
|
||||||
return WebServerFactoryCustomizer { tomcat: TomcatServletWebServerFactory ->
|
return WebServerFactoryCustomizer { tomcat: TomcatServletWebServerFactory ->
|
||||||
tomcat.addAdditionalTomcatConnectors(
|
tomcat.addAdditionalTomcatConnectors(
|
||||||
createSslConnector()
|
createConnector()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createSslConnector(): Connector {
|
private fun createConnector(): Connector {
|
||||||
val connector = Connector("org.apache.coyote.http11.Http11NioProtocol")
|
val connector = Connector("org.apache.coyote.http11.Http11NioProtocol")
|
||||||
val protocol = connector.protocolHandler as Http11NioProtocol
|
connector.port = 8081
|
||||||
return try {
|
return connector
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue