Skip to content

Commit fcb5c36

Browse files
OleksandrOleksandr
Oleksandr
authored and
Oleksandr
committed
Fix add virtualhost before router start
1 parent d3843fe commit fcb5c36

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

gradle.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version=1.2.3
1+
version=1.2.4

komock-core/src/main/kotlin/ua/com/lavi/komock/engine/JettyServer.kt

+14-15
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import org.eclipse.jetty.util.ssl.SslContextFactory
88
import org.eclipse.jetty.util.thread.QueuedThreadPool
99
import org.slf4j.LoggerFactory
1010
import ua.com.lavi.komock.engine.model.SslKeyStore
11-
import java.util.*
1211
import java.util.concurrent.TimeUnit
1312

1413

@@ -32,19 +31,17 @@ internal class JettyServer(val serverName: String,
3231

3332
init {
3433
jettyServer = Server(QueuedThreadPool(maxThreads, minThreads, idleTimeout))
34+
val contextHandler = buildContextHandler()
35+
val handlerList: HandlerList = HandlerList()
36+
handlerList.handlers = arrayOf(contextHandler)
37+
jettyServer.handler = handlerList
3538
}
3639

3740
fun start() {
3841
log.debug("$serverName - initializing on $host:$port")
39-
val contextHandler = buildContextHandler()
4042
val serverConnector: ServerConnector = buildServerConnector(jettyServer, host, port, sslKeyStore)
41-
4243
jettyServer = serverConnector.server
4344
jettyServer.connectors = arrayOf(serverConnector)
44-
val handlerList: HandlerList = HandlerList()
45-
handlerList.handlers = arrayOf(contextHandler)
46-
jettyServer.handler = handlerList
47-
4845
jettyServer.start()
4946
log.debug("$serverName - listening on $host:$port")
5047
}
@@ -58,19 +55,15 @@ internal class JettyServer(val serverName: String,
5855
/**
5956
* Add virtual hosts to the running server
6057
*/
61-
fun addVirtualHosts(virtualHosts: ArrayList<String>) {
62-
val handlerList = jettyServer.handler as HandlerList
63-
val contextHandler = handlerList.handlers[0] as ContextHandler
64-
contextHandler.addVirtualHosts(virtualHosts.toTypedArray())
58+
fun addVirtualHosts(virtualHosts: List<String>) {
59+
getContextHabdler().addVirtualHosts(virtualHosts.toTypedArray())
6560
}
6661

6762
/**
6863
* Remove virtual host from the running server
6964
*/
70-
fun removeVirtualHosts(virtualHosts: ArrayList<String>) {
71-
val handlerList = jettyServer.handler as HandlerList
72-
val contextHandler = handlerList.handlers[0] as ContextHandler
73-
contextHandler.removeVirtualHosts(virtualHosts.toTypedArray())
65+
fun removeVirtualHosts(virtualHosts: List<String>) {
66+
getContextHabdler().removeVirtualHosts(virtualHosts.toTypedArray())
7467
}
7568

7669
private fun buildContextHandler(): ContextHandler {
@@ -80,6 +73,12 @@ internal class JettyServer(val serverName: String,
8073
return contextHandler
8174
}
8275

76+
private fun getContextHabdler(): ContextHandler {
77+
val handlerList = jettyServer.handler as HandlerList
78+
val contextHandler = handlerList.handlers[0] as ContextHandler
79+
return contextHandler
80+
}
81+
8382
private fun buildServerConnector(server: Server,
8483
host: String,
8584
port: Int,

0 commit comments

Comments
 (0)