本文整理汇总了Scala中org.scalatra.servlet.ScalatraListener类的典型用法代码示例。如果您正苦于以下问题:Scala ScalatraListener类的具体用法?Scala ScalatraListener怎么用?Scala ScalatraListener使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ScalatraListener类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: probeForCycleClass
//设置package包名称以及导入依赖的类
#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
package ${package}
import javax.servlet.ServletContext
import nl.knaw.dans.lib.logging.DebugEnhancedLogging
import org.eclipse.jetty.ajp.Ajp13SocketConnector
import org.eclipse.jetty.server.Server
import org.eclipse.jetty.servlet.ServletContextHandler
import org.scalatra._
import org.scalatra.servlet.ScalatraListener
import scala.util.Try
class ${javaName}Service(serverPort: Int, app: ${javaName}App) extends DebugEnhancedLogging {
import logger._
private val server = new Server(serverPort)
private val context = new ServletContextHandler(ServletContextHandler.NO_SESSIONS)
context.addEventListener(new ScalatraListener() {
override def probeForCycleClass(classLoader: ClassLoader): (String, LifeCycle) = {
("anonymous", new LifeCycle {
override def init(context: ServletContext): Unit = {
context.mount(new ${javaName}Servlet(app), "/")
}
})
}
})
server.setHandler(context)
info(s"HTTP port is ${symbol_dollar}{serverPort}")
def start(): Try[Unit] = Try {
info("Starting service...")
server.start()
}
def stop(): Try[Unit] = Try {
info("Stopping service...")
server.stop()
}
def destroy(): Try[Unit] = Try {
server.destroy()
app.close()
}
}
示例2: AdminHttpServer
//设置package包名称以及导入依赖的类
package com.pagerduty.scheduler.admin.http.standalone
import com.pagerduty.scheduler.admin.AdminService
import com.pagerduty.scheduler.admin.http.Settings
import org.eclipse.jetty.server.Server
import org.eclipse.jetty.servlet.DefaultServlet
import org.eclipse.jetty.webapp.WebAppContext
import org.scalatra.servlet.ScalatraListener
class AdminHttpServer(settings: Settings, adminService: AdminService) {
import AdminHttpServer._
val ScalatraBootstrapClass = "com.pagerduty.scheduler.admin.http.standalone.ScalatraBootstrap"
private val server = new Server(settings.httpPort)
def start(): Unit = {
val context = new WebAppContext()
context.setContextPath("/")
context.setResourceBase("/dev/null") // don't have any static resources to serve
context.setInitParameter(ScalatraListener.LifeCycleKey, ScalatraBootstrapClass)
context.setAttribute(AdminServiceAttributeKey, adminService)
context.setAttribute(SettingsAttributeKey, settings)
context.addEventListener(new ScalatraListener)
context.addServlet(classOf[DefaultServlet], "/")
server.setHandler(context)
server.start
}
def running: Boolean = server.isRunning
def stop(): Unit = {
server.stop()
}
}
object AdminHttpServer {
val AdminServiceAttributeKey = "adminService"
val SettingsAttributeKey = "settings"
}
示例3: JettyLauncher
//设置package包名称以及导入依赖的类
package com.github.twinra.lendmanager
import com.github.twinra.lendmanager.rest.ScalatraBootstrap
import com.typesafe.config.ConfigFactory
import com.typesafe.scalalogging.LazyLogging
import org.eclipse.jetty.server.Server
import org.eclipse.jetty.servlet.DefaultServlet
import org.eclipse.jetty.webapp.WebAppContext
import org.scalatra.servlet.ScalatraListener
object JettyLauncher extends LazyLogging {
def main(args: Array[String]): Unit = {
val cfg = ConfigFactory.load("application.conf")
val server = new Server(cfg.getInt("cfg.http.port"))
val handler = new WebAppContext("src/main/webapp", "/") {
addEventListener(new ScalatraListener)
setInitParameter(ScalatraListener.LifeCycleKey, classOf[ScalatraBootstrap].getCanonicalName)
addServlet(classOf[DefaultServlet], "/")
}
server.setHandler(handler)
server.start()
server.join()
}
}
示例4: 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()
}
示例5: Jetty
//设置package包名称以及导入依赖的类
// http://scalatra.org//guides/2.5/deployment/standalone.
package com.eddsteel.feedfilter.net
import org.eclipse.jetty.server.Server
import org.eclipse.jetty.servlet.DefaultServlet
import org.eclipse.jetty.webapp.WebAppContext
import org.scalatra.servlet.ScalatraListener
object Jetty {
def main(args: Array[String]): Unit = {
val port = Option(System.getenv("PORT")).map(_.toInt).getOrElse(8080)
val server = new Server(port)
val context = {
val ctx = new WebAppContext()
ctx.setContextPath("/")
ctx.setResourceBase("src/main/resources")
ctx.setResourceBase(getClass.getClassLoader.getResource("WEB-INF").toExternalForm)
ctx.setInitParameter(
ScalatraListener.LifeCycleKey,
"com.eddsteel.feedfilter.net.ScalatraBootstrap")
ctx.addEventListener(new ScalatraListener)
ctx.addServlet(classOf[DefaultServlet], "/")
ctx
}
server.setHandler(context)
server.start
server.join
}
}
示例6: Main
//设置package包名称以及导入依赖的类
package io.github.shogowada.scala.jsonrpc.example.e2e
import org.eclipse.jetty.server.Server
import org.eclipse.jetty.servlet.DefaultServlet
import org.eclipse.jetty.util.resource.Resource
import org.eclipse.jetty.webapp.WebAppContext
import org.scalatra.servlet.ScalatraListener
object Main {
def main(args: Array[String]): Unit = {
val port = System.getProperty("port", "8080").toInt
println(s"Running server at port $port")
val server = new Server(port)
val context = new WebAppContext()
context.setContextPath("/")
context.setResourceBase(
Resource.newResource(ClassLoader.getSystemResource("public"))
.getURI
.toASCIIString
)
context.setInitParameter(ScalatraListener.LifeCycleKey, classOf[ScalatraBootstrap].getCanonicalName)
context.addEventListener(new ScalatraListener)
context.addServlet(classOf[DefaultServlet], "/")
server.setHandler(context)
server.start()
server.join()
}
}
示例7: JettyLauncher
//设置package包名称以及导入依赖的类
package proxy
import org.eclipse.jetty.server.Server
import org.eclipse.jetty.webapp.WebAppContext
import org.scalatra.servlet.ScalatraListener
object JettyLauncher extends App {
val port = 8082
val server: Server = new Server(port)
val context = new WebAppContext()
context.setContextPath("/")
context.setResourceBase("src/main/webapp")
context.addEventListener(new ScalatraListener)
context.addServlet(classOf[ProxyServlet], "/")
server.setHandler(context)
server.start()
server.join()
}
示例8: JettyLauncher
//设置package包名称以及导入依赖的类
import org.eclipse.jetty.server.Server
import org.eclipse.jetty.servlet.DefaultServlet
import org.eclipse.jetty.webapp.WebAppContext
import org.scalatra.servlet.ScalatraListener
object JettyLauncher {
def main(args: Array[String]) {
val port = if(System.getenv("PORT") != null) System.getenv("PORT").toInt else 8080
val server = new Server(port)
val context = new WebAppContext()
context setContextPath "/"
context.setResourceBase("src/main/webapp")
context.addEventListener(new ScalatraListener)
context.addServlet(classOf[DefaultServlet], "/")
server.setHandler(context)
server.start()
server.join()
}
}