本文整理汇总了Scala中org.eclipse.jetty.server.handler.HandlerList类的典型用法代码示例。如果您正苦于以下问题:Scala HandlerList类的具体用法?Scala HandlerList怎么用?Scala HandlerList使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了HandlerList类的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)
}
}
}
开发者ID:denisftw,项目名称:s2gen,代码行数:52,代码来源:StaticServer.scala
示例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()
}
开发者ID:seraphr,项目名称:scalatra-reactjs-fileupload,代码行数:32,代码来源:FileuploadServerMain.scala
注:本文中的org.eclipse.jetty.server.handler.HandlerList类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论