@@ -8,7 +8,6 @@ import org.eclipse.jetty.util.ssl.SslContextFactory
8
8
import org.eclipse.jetty.util.thread.QueuedThreadPool
9
9
import org.slf4j.LoggerFactory
10
10
import ua.com.lavi.komock.engine.model.SslKeyStore
11
- import java.util.*
12
11
import java.util.concurrent.TimeUnit
13
12
14
13
@@ -32,19 +31,17 @@ internal class JettyServer(val serverName: String,
32
31
33
32
init {
34
33
jettyServer = Server (QueuedThreadPool (maxThreads, minThreads, idleTimeout))
34
+ val contextHandler = buildContextHandler()
35
+ val handlerList: HandlerList = HandlerList ()
36
+ handlerList.handlers = arrayOf(contextHandler)
37
+ jettyServer.handler = handlerList
35
38
}
36
39
37
40
fun start () {
38
41
log.debug(" $serverName - initializing on $host :$port " )
39
- val contextHandler = buildContextHandler()
40
42
val serverConnector: ServerConnector = buildServerConnector(jettyServer, host, port, sslKeyStore)
41
-
42
43
jettyServer = serverConnector.server
43
44
jettyServer.connectors = arrayOf(serverConnector)
44
- val handlerList: HandlerList = HandlerList ()
45
- handlerList.handlers = arrayOf(contextHandler)
46
- jettyServer.handler = handlerList
47
-
48
45
jettyServer.start()
49
46
log.debug(" $serverName - listening on $host :$port " )
50
47
}
@@ -58,19 +55,15 @@ internal class JettyServer(val serverName: String,
58
55
/* *
59
56
* Add virtual hosts to the running server
60
57
*/
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())
65
60
}
66
61
67
62
/* *
68
63
* Remove virtual host from the running server
69
64
*/
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())
74
67
}
75
68
76
69
private fun buildContextHandler (): ContextHandler {
@@ -80,6 +73,12 @@ internal class JettyServer(val serverName: String,
80
73
return contextHandler
81
74
}
82
75
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
+
83
82
private fun buildServerConnector (server : Server ,
84
83
host : String ,
85
84
port : Int ,
0 commit comments