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

Scala ServletContextHandler类代码示例

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

本文整理汇总了Scala中org.eclipse.jetty.servlet.ServletContextHandler的典型用法代码示例。如果您正苦于以下问题:Scala ServletContextHandler类的具体用法?Scala ServletContextHandler怎么用?Scala ServletContextHandler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了ServletContextHandler类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: Arguments

//设置package包名称以及导入依赖的类
package net.sayuan.kafka

import java.io.File
import java.util.concurrent.{Executors, TimeUnit}

import io.prometheus.client.exporter.MetricsServlet
import org.apache.log4j.{Level, Logger}
import org.eclipse.jetty.server.Server
import org.eclipse.jetty.servlet.{ServletContextHandler, ServletHolder}
import org.json4s._
import org.json4s.jackson.JsonMethods._

case class Arguments(config: String = "config.json")

object KafkaOffsetExporter {
  def main(args: Array[String]) {
    implicit val formats = DefaultFormats
    val parser = new scopt.OptionParser[Arguments]("kafka-offset-exporter") {
      head("kafka-offset-exporter")
      opt[String]("config") action { (x,c) => c.copy(config = x) } text("config file.")
      help("help") text("prints this usage text")
    }
    parser.parse(args, Arguments()) match {
      case Some(args) => {
        val config = parse(new File(args.config)).extract[Config]
        start(config)
      }
      case _ =>
    }
  }

  def start(config: Config) {
    val server = new Server(config.port)
    val context = new ServletContextHandler()
    context.setContextPath("/")
    server.setHandler(context)
    context.addServlet(new ServletHolder(
      new MetricsServlet()), "/metrics")

    val scheduler = Executors.newScheduledThreadPool(1)
    scheduler.scheduleAtFixedRate(new KafkaOffsetUpdater(config), 0, config.interval, TimeUnit.SECONDS)

    server.start()
    server.join()
  }
} 
开发者ID:sayuan,项目名称:kafka-offset-exporter,代码行数:47,代码来源:KafkaOffsetExporter.scala


示例3: RackServer

//设置package包名称以及导入依赖的类
package coder36.rack

import javax.servlet.http.{HttpServlet, HttpServletRequest, HttpServletResponse}

import com.typesafe.scalalogging.LazyLogging
import org.eclipse.jetty.server.Server
import org.eclipse.jetty.servlet.{ServletContextHandler, ServletHolder}

import scala.collection.mutable.Map

class RackServer extends LazyLogging {

  val port : Int = 8080
  var path : String = ""

  val apps = scala.collection.mutable.Map[String,RackServlet]()

  def map(path: String) : RackServer = {
    this.path = path
    this
  }

  def onto(rack: Rack) = {
    apps(path) = new RackServlet(rack, path)
  }

  def start() : RackServer = {
    val context = new ServletContextHandler(ServletContextHandler.SESSIONS)
    context.setContextPath("/")
    val server = new Server(port)
    server.setHandler(context)
    apps.foreach( app => context.addServlet(new ServletHolder(app._2), (app._1 + "/*").replaceAll("//", "/")) )
    println(s"\u001B[34mRack started... listening for HTTP on /0.0.0.0:${port}")
    server.start
    this
  }

}

class RackServlet(val rack: Rack, val path: String)  extends HttpServlet {

  override def service(request: HttpServletRequest, response: HttpServletResponse) {
    val res = Middleware.BaseRack( rack, request, response ).call(Map('base_path -> path))
    val status = res._1
    val headers = res._2
    val body = res._3
    response.setStatus(status)
    headers.foreach( (h) => response.addHeader(h._1, h._2))
    if( body != null ) response.getWriter().write(body)
  }
} 
开发者ID:coder36,项目名称:scalarack,代码行数:52,代码来源:Rackup.scala


示例4: Server

//设置package包名称以及导入依赖的类
package works.weave.socks.aws.orders.main

import org.eclipse.jetty
import org.eclipse.jetty.servlet.ServletContextHandler
import org.eclipse.jetty.servlet.ServletHolder
import org.glassfish.jersey.servlet.ServletContainer
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Component
import scala.collection.JavaConverters._
import scala.util.control.NonFatal
import Server._
import org.eclipse.jetty.util.log.Slf4jLog

@Component
class Server(val jerseyApp : JerseyApp) {

  def run() : Unit = {

    jetty.util.log.Log.setLog(new Slf4jLog())

    val port = System.getenv().asScala.getOrElse("PORT", "80").toInt

    val context = new ServletContextHandler(ServletContextHandler.SESSIONS)
    context.setContextPath("/")

    val jettyServer = new jetty.server.Server(port)
    jettyServer.setHandler(context)

    val servletContainer = new ServletContainer(jerseyApp)
    val servletHolder = new ServletHolder(servletContainer)
    context.addServlet(servletHolder, "/*")
    val jerseyServlet = servletHolder
    jerseyServlet.setInitOrder(0)

    try {
      Log.info("Starting jetty")
      jettyServer.start()
      Log.info("Jetty started")
      jettyServer.join()
      Log.info("Jetty exited")
    } finally {
      Log.info("Destroying jetty")
      try {
        jettyServer.destroy()
      } catch {
        case NonFatal(e) => Log.error("Error during Jetty shutdown", e)
      }
    }
  }
}

object Server {
  val Log = LoggerFactory.getLogger(classOf[Server])
} 
开发者ID:Compositional,项目名称:orders-aws,代码行数:55,代码来源:Server.scala



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Scala Color类代码示例发布时间:2022-05-23
下一篇:
Scala Job类代码示例发布时间: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