当前位置: 首页>>代码示例>>Scala>>正文


Scala DefaultServlet类代码示例

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


在下文中一共展示了DefaultServlet类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。

示例1: PublicServlet

//设置package包名称以及导入依赖的类
package mesosphere.marathon.api

import org.eclipse.jetty.servlet.DefaultServlet
import org.eclipse.jetty.util.resource.Resource

class PublicServlet extends DefaultServlet {

  private[this] val path = "public"
  private[this] val pathWithSlash = s"^/$path/"

  // Set resource base to serve resources from classpath available under /public/*.
  override def getInitParameter(name: String): String = name match {
    case "resourceBase" => Option(getClass.getClassLoader.getResource(path)).fold(null: String)(_.toExternalForm)
    case _ => super.getInitParameter(name)
  }

  // The resource requested is /public/{path}
  // Since the resource base already is public, we strip public from the path
  @SuppressWarnings(Array("all"))
  override def getResource(pathInContext: String): Resource = {
    super.getResource(pathInContext.replaceFirst(pathWithSlash, ""))
  }
} 
开发者ID:xiaozai512,项目名称:marathon,代码行数:24,代码来源:PublicServlet.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: 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

示例5: 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

示例6: Main

//设置package包名称以及导入依赖的类
package io.github.shogowada.scala.jsonrpc.example.e2e.websocket

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

object Main {
  def main(args: Array[String]): Unit = {
    val port = System.getProperty("port", "8080").toInt
    val server = new Server(port)

    val context = new WebAppContext()
    context.setContextPath("/")
    context.setResourceBase(
      Resource.newResource(ClassLoader.getSystemResource("public"))
          .getURI
          .toASCIIString
    )
    context.addServlet(classOf[DefaultServlet], "/")
    context.addServlet(classOf[JSONRPCWebSocketServlet], "/jsonrpc")

    server.setHandler(context)

    server.start()
    server.join()
  }
} 
开发者ID:shogowada,项目名称:scala-json-rpc,代码行数:29,代码来源:Main.scala

示例7: 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.eclipse.jetty.servlet.DefaultServlet类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。