本文整理汇总了Scala中org.eclipse.jetty.webapp.WebAppContext类的典型用法代码示例。如果您正苦于以下问题:Scala WebAppContext类的具体用法?Scala WebAppContext怎么用?Scala WebAppContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了WebAppContext类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: RunWebApp
//设置package包名称以及导入依赖的类
import org.eclipse.jetty.server.handler.ContextHandler
import org.eclipse.jetty.server.nio.SelectChannelConnector
import org.eclipse.jetty.server.{Handler, Server}
import org.eclipse.jetty.webapp.WebAppContext
object RunWebApp extends App {
val server = new Server
val scc = new SelectChannelConnector
scc.setPort(8080)
server.setConnectors(Array(scc))
val context = new WebAppContext()
context.setServer(server)
context.setWar("src/main/webapp")
val context0: ContextHandler = new ContextHandler();
context0.setHandler(context)
server.setHandler(context0)
try {
println(">>> STARTING EMBEDDED JETTY SERVER, PRESS ANY KEY TO STOP")
server.start()
while (System.in.available() == 0) {
Thread.sleep(5000)
}
server.stop()
server.join()
} catch {
case exc: Exception => {
exc.printStackTrace()
System.exit(100)
}
}
}
示例2: Web
//设置package包名称以及导入依赖的类
import java.io.File
import java.util
import java.util.Locale
import javax.servlet.DispatcherType
import org.eclipse.jetty.server.Server
import org.eclipse.jetty.servlet.FilterHolder
import org.eclipse.jetty.util.resource.{Resource, ResourceCollection}
import org.eclipse.jetty.webapp.WebAppContext
import refpay.RefPayPlan
import unfiltered.filter.Plan
import scala.util.Properties
object Web extends App{
Locale.setDefault(new Locale("no_NO"))
val port = Properties.envOrElse("PORT", "9998").toInt
val resources = new ResourceCollection(
Resource.newResource(new File("src/main/webapp"))
)
val server = new Server(port)
val context = new WebAppContext()
// context.setContextPath("/api")
context.setBaseResource(resources)
registerPlan(new RefPayPlan, "Dommerbetaling", context)
server.setHandler(context)
server.setSendDateHeader(true)
server.setStopAtShutdown(true)
server.start()
def registerPlan(plan: Plan, name: String, context: WebAppContext) {
val holder = new FilterHolder(plan)
holder.setName(name)
context.addFilter(holder, "/*", util.EnumSet.of(DispatcherType.REQUEST,DispatcherType.ASYNC,DispatcherType.ERROR,DispatcherType.FORWARD,DispatcherType.INCLUDE))
}
}
示例3: 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"
}
示例4: 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()
}
}
示例5: 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()
}
示例6: 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
}
}
示例7: 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()
}
}
示例8: 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()
}
}
示例9: EmbeddedWebapp
//设置package包名称以及导入依赖的类
package etape3
object EmbeddedWebapp {
import org.eclipse.jetty.server.Server
import org.eclipse.jetty.server.ServerConnector
import org.eclipse.jetty.webapp.WebAppContext
import org.eclipse.jetty.servlet.ServletHolder;
def main(args: Array[String]): Unit = {
val port = 8080;
val contextPath = "/";
val server = new Server()
val connector = new ServerConnector(server)
connector.setPort(port)
server.addConnector(connector)
val context = new WebAppContext()
context.setResourceBase("web")
context.setContextPath(contextPath)
context.addServlet(new ServletHolder(TimeTableServlet), "/solver/*");
context.setWelcomeFiles( Array("index.html") );
server.setHandler(context)
server.start();
}
}
示例10: 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()
}
示例11: 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()
}
}
示例12: ApplicationStarter
//设置package包名称以及导入依赖的类
import java.net.InetSocketAddress
import org.eclipse.jetty.server.Server
import org.eclipse.jetty.servlet.ServletHolder
import org.eclipse.jetty.webapp.WebAppContext
import org.scalatra.servlet.ScalatraListener
import web.{EndpointInfo, ProxyModel, ProxyServlet}
object ApplicationStarter extends App {
def buildJettyServer() = {
val socketAddress = new InetSocketAddress(8080)
val server = new Server(socketAddress)
val context = new WebAppContext()
context.setContextPath("/")
context.setResourceBase("src/main/webapp")
context.addEventListener(new ScalatraListener)
server.setHandler(context)
server
}
val model = ProxyModel.defaultProxyModel
val server = buildJettyServer()
server.start()
server.join()
}