本文整理汇总了Scala中org.eclipse.jetty.server.handler.ResourceHandler类的典型用法代码示例。如果您正苦于以下问题:Scala ResourceHandler类的具体用法?Scala ResourceHandler怎么用?Scala ResourceHandler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ResourceHandler类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: StaticServer
//设置package包名称以及导入依赖的类
package com.appliedscala.generator
import org.eclipse.jetty.server.Server
import org.eclipse.jetty.server.handler.{DefaultHandler, HandlerList, ResourceHandler}
import org.slf4j.LoggerFactory
case class StaticServer(path: String, port: Int, fakeServer: Boolean) {
val logger = LoggerFactory.getLogger("S2HttpServer")
val server = {
if (fakeServer) {
None
} else {
logger.info(s"Starting the HTTP server")
val jettyServer = new Server(port)
val resource_handler = new ResourceHandler()
resource_handler.setWelcomeFiles(Array("index.html"))
resource_handler.setResourceBase(path)
resource_handler.setDirectoriesListed(true)
val handlers = new HandlerList()
handlers.setHandlers(Array(resource_handler, new DefaultHandler()))
jettyServer.setHandler(handlers)
Some(jettyServer)
}
}
def start(): Unit = {
try {
server.foreach {
s => s.start()
logger.info(s"The HTTP server has been started on port $port")
}
} catch {
case e: Exception =>
logger.error("Error occurred while trying to start the HTTP server", e)
}
}
def stop(): Unit = {
try {
server.foreach { s =>
s.stop()
logger.info("The HTTP server has been stopped")
}
} catch {
case e: Exception =>
logger.error("Error occurred while trying to stop the HTTP server", e)
}
}
}
示例2: FileUploadServerMain
//设置package包名称以及导入依赖的类
package jp.seraphr.fileupload.main
import org.eclipse.jetty.server.{ Handler, Server }
import org.eclipse.jetty.server.handler.{ DefaultHandler, HandlerList, ResourceHandler }
import org.eclipse.jetty.webapp.WebAppContext
import org.scalatra.servlet.ScalatraListener
object FileUploadServerMain extends App {
val tPort = 8080
val tServer = new Server(tPort)
val tContext = new WebAppContext()
tContext.setContextPath("/")
tContext.setResourceBase("src/main/webapp")
tContext.addEventListener(new ScalatraListener)
tContext.setInitParameter(ScalatraListener.LifeCycleKey, classOf[ScalatraBootstrap].getName)
val tResourceHandler = new ResourceHandler()
tResourceHandler.setDirectoriesListed(true)
tResourceHandler.setWelcomeFiles(Array("index.html"))
// tResourceHandler.setResourceBase("..")
tResourceHandler.setResourceBase("../webapp/assets/")
val tHandlers = new HandlerList()
tHandlers.setHandlers(Array[Handler](tResourceHandler, tContext, new DefaultHandler()))
tServer.setHandler(tHandlers)
tServer.start()
tServer.join()
}