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


Scala Handler类代码示例

本文整理汇总了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)
  }

} 
开发者ID:agile-lab-dev,项目名称:wasp,代码行数:58,代码来源:Global.scala

示例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
    }
  }
} 
开发者ID:springnz,项目名称:play-app-base,代码行数:40,代码来源:RequestHandler.scala

示例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))
} 
开发者ID:Sharecare,项目名称:health-profile-social-history-play,代码行数:29,代码来源:XFlowRequestHandler.scala

示例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)
        )
    )
  }
} 
开发者ID:UKHomeOffice,项目名称:mercury,代码行数:56,代码来源:MercuryServicesContext.scala


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