本文整理汇总了Scala中org.eclipse.jetty.server.Request类的典型用法代码示例。如果您正苦于以下问题:Scala Request类的具体用法?Scala Request怎么用?Scala Request使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Request类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: AppMock
//设置package包名称以及导入依赖的类
package mesosphere.marathon.integration.setup
import java.lang.management.ManagementFactory
import org.eclipse.jetty.server.{ Request, Server }
import org.eclipse.jetty.server.handler.AbstractHandler
import javax.servlet.http.{ HttpServletResponse, HttpServletRequest }
import akka.actor.ActorSystem
import spray.client.pipelining._
import scala.concurrent.Await._
import scala.concurrent.duration._
class AppMock(appId: String, version: String, url: String) extends AbstractHandler {
import scala.concurrent.ExecutionContext.Implicits.global
implicit val system = ActorSystem()
val pipeline = sendReceive
val waitTime = 30.seconds
val processId = ManagementFactory.getRuntimeMXBean.getName
def start(port: Int): Unit = {
val server = new Server(port)
server.setHandler(this)
server.start()
val taskId = System.getenv().getOrDefault("MESOS_TASK_ID", "<UNKNOWN>")
println(s"AppMock[$appId $version]: $taskId has taken the stage at port $port. Will query $url for health status.")
server.join()
println(s"AppMock[$appId $version]: says goodbye")
}
override def handle(
target: String,
baseRequest: Request,
request: HttpServletRequest,
response: HttpServletResponse): Unit = {
if (request.getMethod == "GET" && request.getPathInfo == "/ping") {
response.setStatus(200)
baseRequest.setHandled(true)
val marathonId = sys.env.getOrElse("MARATHON_APP_ID", "NO_MARATHON_APP_ID_SET")
response.getWriter.println(s"Pong $marathonId")
} else {
val res = result(pipeline(Get(url)), waitTime)
println(s"AppMock[$appId $version]: current health is $res")
response.setStatus(res.status.intValue)
baseRequest.setHandled(true)
response.getWriter.print(res.entity.asString)
}
}
}
object AppMock {
def main(args: Array[String]): Unit = {
val port = args(0).toInt
val appId = args(1)
val version = args(2)
val url = args(3) + "/" + port
new AppMock(appId, version, url).start(port)
}
}
示例2: Server
//设置package包名称以及导入依赖的类
package com.arangodb
import scala.beans.BeanProperty
import org.eclipse.jetty.server.Request
import org.eclipse.jetty.server.handler.AbstractHandler
import com.arangodb.Server.Movie
import com.arangodb.util.MapBuilder
import javax.servlet.http.HttpServletRequest
import javax.servlet.http.HttpServletResponse
object Server {
private val COLLECTION_NAME = "ring_movies"
class Handler(arangoDB: ArangoDB) extends AbstractHandler {
override def handle(target: String,
req: Request,
httpReq: HttpServletRequest,
httpRes: HttpServletResponse) = {
httpRes.setContentType("text/html")
httpRes.setStatus(HttpServletResponse.SC_OK)
httpRes.getWriter().println("<h1>all movies that have \"Lord.*Rings\" in their title</h1>")
val cursor = getMovies(arangoDB)
while (cursor.hasNext()) {
httpRes.getWriter().println(cursor.next().title + "<br />")
}
req.setHandled(true)
}
}
def main(args: Array[String]): Unit = {
val arangoDB = new ArangoDB.Builder().host("arangodb-proxy.marathon.mesos").user("root").build();
val server = new org.eclipse.jetty.server.Server(8080)
server.setHandler(new Handler(arangoDB))
server.start
}
def getMovies(arangoDB: ArangoDB): ArangoCursor[Movie] = {
arangoDB.db().query("for doc in @@col return doc", new MapBuilder().put("@col", COLLECTION_NAME).get(), null, classOf[Movie])
}
case class Movie(@BeanProperty title: String) {
def this() = this(title = null)
}
}
示例3: Param
//设置package包名称以及导入依赖的类
package org.cddcore.website
import javax.servlet.http.{HttpServletRequest, HttpServletResponse}
import org.cddcore.engine.Engine
import org.cddcore.rendering.{RenderConfiguration, RenderContext, Renderer, WebsiteUrlManipulators}
import org.eclipse.jetty.server.handler.AbstractHandler
import org.eclipse.jetty.server.{Handler, Request, Server}
case class Param(name: String, valueAsString: String, value: Any)
object WebServer {
def defaultPort = {
val portString = System.getenv("PORT")
println("PortString[" + portString + "]")
val port = portString match {
case null => 8080;
case _ => portString.toInt
}
println("Port[" + port + "]")
port
}
def resourceHandlers = List(new ResourcesHandler("/images"), new ResourcesHandler("/stylesheets"))
def defaultPathHandlers = List(new FavIconHandler, new RootPathHandler, new EngineComponentPathHandler)
def apply(engines: List[Engine[_, _]], title: String = "Engines and Documents", port: Int = defaultPort, handlers: List[PathHandler] = defaultPathHandlers)(implicit renderConfiguration: RenderConfiguration) =
new WebServer(port, new AggregateHandler(title, engines, resourceHandlers, handlers)(renderConfiguration.copy(urlBase = "/", urlManipulations = new WebsiteUrlManipulators)))
// def withPreHandlers(port: Int, engines: List[Engine], preHandlers: CddPathHandler*)(implicit ldp: CddDisplayProcessor): WebServer =
// new WebServer(port, new CddHandler("Engines and Documents", engines, preHandlers.toList ::: defaultPathHandlers)(ldp))
//
// def defaultCddHandler(engines: List[Engine])(implicit ldp: CddDisplayProcessor) = new CddHandler("Engines and Documents", engines, defaultPathHandlers)(ldp)
}
class WebServer(val port: Int, val handler: Handler) {
val server = new Server(port);
server.setHandler(handler)
def launch {
start;
server.join
}
def start = server.start
def stop = server.stop
}