• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Scala ScalatraListener类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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()
  }
} 
开发者ID:DANS-KNAW,项目名称:easy-module-archetype,代码行数:49,代码来源:__javaName__Service.scala


示例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"
} 
开发者ID:PagerDuty,项目名称:scheduler,代码行数:45,代码来源:AdminHttpServer.scala


示例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()
  }
} 
开发者ID:twinra,项目名称:lending-manager,代码行数:28,代码来源:JettyLauncher.scala


示例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()
} 
开发者ID:seraphr,项目名称:scalatra-reactjs-fileupload,代码行数:32,代码来源:FileuploadServerMain.scala


示例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
  }
} 
开发者ID:eddsteel,项目名称:feed-filter,代码行数:31,代码来源:Jetty.scala


示例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()
  }
} 
开发者ID:shogowada,项目名称:scala-json-rpc,代码行数:34,代码来源:Main.scala


示例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()
} 
开发者ID:salimfadhley,项目名称:megaproxy,代码行数:22,代码来源:JettyLauncher.scala


示例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()
  }

} 
开发者ID:rferrerme,项目名称:scalatra-minimal,代码行数:25,代码来源:JettyLauncher.scala



注:本文中的org.scalatra.servlet.ScalatraListener类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Scala AttributeSet类代码示例发布时间:2022-05-23
下一篇:
Scala Positional类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap