本文整理汇总了Scala中play.api.mvc.Handler类的典型用法代码示例。如果您正苦于以下问题:Scala Handler类的具体用法?Scala Handler怎么用?Scala Handler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Handler类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: Global
//设置package包名称以及导入依赖的类
package it.agilelab.bigdata.wasp.web
import _root_.controllers.Assets
import akka.actor.Props
import it.agilelab.bigdata.wasp.core.WaspSystem
import it.agilelab.bigdata.wasp.core.WaspSystem.{actorSystem, masterActor}
import it.agilelab.bigdata.wasp.core.bl.ConfigBL
import it.agilelab.bigdata.wasp.core.logging.LoggerInjector
import it.agilelab.bigdata.wasp.core.utils.{WaspDB, ActorSystemInjector}
import it.agilelab.bigdata.wasp.master.MasterGuardian
import it.agilelab.bigdata.wasp.producers.InternalLogProducerGuardian
import org.apache.log4j.Level
import play.api.mvc.{RequestHeader, Handler}
import play.api.{Application, GlobalSettings, Logger}
import play.api.routing._
import play.api.routing.sird._
import play.api.mvc._
object Global extends GlobalBase{
override def onRequestOverride(req: RequestHeader): Option[Handler] = {
Logger.info("Global onRequestOverride")
None
}
}
trait GlobalBase extends GlobalSettings with ActorSystemInjector with LoggerInjector {
org.apache.log4j.Logger.getLogger("org").setLevel(Level.WARN)
org.apache.log4j.Logger.getLogger("akka").setLevel(Level.WARN)
override def loggerActorProps : Props = Props(new InternalLogProducerGuardian(ConfigBL))
override def onStart(app : Application) {
Logger.info("starting app: " + app.configuration.getString("application.version").getOrElse("no version"))
val startMaster = app.configuration.getString("master.start").getOrElse("true")
val actorSystem = WaspSystem.actorSystem
WaspDB.DBInitialization(actorSystem)
WaspSystem.systemInitialization(actorSystem)
if(startMaster == "true") {
masterActor = WaspSystem.actorSystem.actorOf(Props(new MasterGuardian(ConfigBL)))
}
}
def onRequestOverride(req: RequestHeader): Option[Handler]
override def onRouteRequest(req: RequestHeader): Option[Handler] = {
Logger.info(s"onRouteRequest: ${req.toString()}")
onRequestOverride(req) orElse super.onRouteRequest(req)
}
}
示例2: RequestHandler
//设置package包名称以及导入依赖的类
package ylabs.play.common
import javax.inject.Inject
import play.api.http.{DefaultHttpRequestHandler, HttpConfiguration, HttpErrorHandler, HttpFilters}
import play.api.mvc.{Handler, RequestHeader}
import play.api.routing.Router
import ylabs.play.common.controllers.{FileUploadController, HealthcheckController, LocationController, UserController}
class RequestHandler @Inject() (
router: Router,
errorHandler: HttpErrorHandler,
configuration: HttpConfiguration,
filters: HttpFilters,
userController: UserController,
locationController: LocationController,
fileUploadController: FileUploadController,
healthcheckController: HealthcheckController
) extends DefaultHttpRequestHandler(router , errorHandler, configuration, filters) {
override def routeRequest(req: RequestHeader): Option[Handler] = {
(req.method, req.path) match {
case ("GET", "/auth") ? Some(userController.authenticate())
case ("POST", "/user") ? Some(userController.create())
case ("POST", "/user/code/request") => Some(userController.requestCode())
case ("POST", "/user/code/register") => Some(userController.registerDevice())
case ("PATCH", "/user") ? Some(userController.update())
case ("GET", "/user") ? Some(userController.get())
case ("POST", "/location") ? Some(locationController.update())
case ("GET", "/location") ? Some(locationController.list())
case ("GET", "/location/last") ? Some(locationController.last())
case ("POST", "/location/nearby") ? Some(locationController.nearby())
case ("POST", "/location/suggest") ? Some(locationController.suggest())
case ("POST", "/cloud") ? Some(fileUploadController.uploadFile())
case ("GET", "/healthcheck") ? Some(healthcheckController.check())
case _ ? None
}
}
}
示例3: XFlowRequestHandler
//设置package包名称以及导入依赖的类
import javax.inject.Inject
import play.api.http._
import play.api.mvc.{Handler, RequestHeader}
import play.api.routing.Router
class XFlowRequestHandler @Inject() (
config: play.api.Configuration,
errorHandler: HttpErrorHandler,
configuration: HttpConfiguration,
filters: HttpFilters,
router: Router)
extends DefaultHttpRequestHandler(router, errorHandler, configuration, filters) {
val X_FLOW_ID_HEADER = "X-Flow-ID"
def getXFlow(request: RequestHeader): RequestHeader = {
val appName = config.getString("application.name").getOrElse("scala-template")
val xflow = request.headers.get(X_FLOW_ID_HEADER).getOrElse(appName + "-" + java.util.UUID.randomUUID.toString)
request.copy(headers = request.headers.add((X_FLOW_ID_HEADER, xflow)))
}
override def handlerForRequest(request: RequestHeader): (RequestHeader, Handler) =
super.handlerForRequest(getXFlow(request))
}
示例4: param
//设置package包名称以及导入依赖的类
package uk.gov.homeoffice.mercury
import scala.collection.JavaConversions._
import play.api.libs.json.{JsValue, Json}
import play.api.mvc.BodyParsers.parse
import play.api.mvc.Results.{Ok, Unauthorized}
import play.api.mvc.{Action, Handler, Request, RequestHeader}
import play.api.routing.sird._
import org.json4s.JsonDSL._
import org.json4s._
import org.json4s.jackson.JsonMethods._
import uk.gov.homeoffice.aws.s3.S3.ResourceKey
import uk.gov.homeoffice.aws.s3.S3ServerEmbedded
import uk.gov.homeoffice.aws.sqs.{Message, SQSServerEmbedded}
trait MercuryServicesContext extends S3ServerEmbedded with SQSServerEmbedded with MercuryEvent {
val userName = "userName"
val password = "password"
val credentials = Credentials(userName, password)
val ticket = "TICKET"
s3Client.listBuckets().find(_.getName == bucket) getOrElse s3Client.createBucket(bucket)
val mercuryEventMessage: ResourceKey => Message = { key =>
createMessage(compact(render(mercuryEvent(key))))
}
val authorizeRoute: PartialFunction[RequestHeader, Handler] = {
case POST(p"/alfresco/s/api/login") => Action(parse.json) { implicit request =>
(param("username"), param("password")) match {
case (Some(`userName`), Some(`password`)) => Ok(Json.obj("data" -> Json.obj("ticket" -> ticket)))
case _ => Unauthorized
}
}
}
val authorizeCheck: PartialFunction[RequestHeader, Handler] = {
case rh if !rh.getQueryString("alf_ticket").contains(ticket) => Action {
Unauthorized
}
}
def param(key: String)(implicit request: Request[JsValue]): Option[String] = (request.body \ key).asOpt[String]
}
trait MercuryEvent {
val mercuryEvent: ResourceKey => JValue = { key =>
"Records" -> List(
"s3" ->
("object" ->
("key" -> key)
)
)
}
}