複数の JVM を介してリモート機能をテストする必要があるシナリオが 1 つあります。2 つの異なるポートで JettyTestServer を実行しようとしています。しかし、2 番目のポートで Jetty を実行しているときにエラーが発生します。
ERROR - Failed to Boot! Your application may not run properly
java.lang.IllegalStateException: Cannot modify after boot.
しかし、私のテストケースは成功しています。リモート機能は正常に動作しています。
これが私のコードです:-
object JettyTestServer {
private val serverPort = System.getProperty("SERVLET_PORT", "8989").toInt
private var baseUrl = "http://localhost:" + serverPort
private val server: Server = {
val server = new Server(8989)
val context = getContext
server.setHandler(context)
context.addServlet("org.eclipse.jetty.servlet.DefaultServlet", "/")
val connector: SelectChannelConnector = getConnector(8989)
val connList: List[Connector] = List(connector)
server.setConnectors(connList.toArray);
server
}
private val remoteServer: Server = {
val server = new Server(8991)
val context = getContext
server.setHandler(context)
context.addServlet("org.eclipse.jetty.servlet.DefaultServlet", "/")
val connector: SelectChannelConnector = getConnector(8991)
val connList: List[Connector] = List(connector)
server.setConnectors(connList.toArray);
server
}
private def getContext: WebAppContext = {
val context = new WebAppContext()
context.setContextPath("/")
context.setDescriptor("src/main/webapp/WEB-INF/web.xml")
context.setResourceBase("src/main/webapp")
context.setParentLoaderPriority(true)
context
}
private def getConnector(port: Int): SelectChannelConnector = {
val connector: SelectChannelConnector = new SelectChannelConnector()
connector.setPort(port)
connector.setConfidentialPort(8443)
connector.setAcceptors(2)
connector.setMaxIdleTime(30000)
connector
}
def urlFor(path: String) = baseUrl + path
lazy val start = {
server.start()
}
lazy val startRemoteServer = {
remoteServer.start()
}
私のテストケースでは、以下の行を使用して桟橋を開始しています。
com.test.api.JettyTestServer.start
com.test.api.JettyTestServer.startRemoteServer
構成で何か不足している場合はお知らせください。
前もって感謝します。