本文整理汇总了Scala中play.api.mvc.Results.Ok类的典型用法代码示例。如果您正苦于以下问题:Scala Ok类的具体用法?Scala Ok怎么用?Scala Ok使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Ok类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。
示例1: ResultMessage
//设置package包名称以及导入依赖的类
package services
import play.api.libs.json.{JsValue, Json}
import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global
import play.api.mvc.Results.{Ok, BadRequest}
import play.api.mvc.Result
object ResultMessage {
val MESSAGE_INVALID_JSON = "Invalid json"
val MESSAGE_DB_ERROR = "DB error"
val MESSAGE_API_NOT_FOUND = "Api is not found"
val MESSAGE_SOME_IDS_HAVE_NOT_REGISTERED = "Some ids have not registered"
val MESSAGE_VALUE_IS_NOT_FOUND = (value: String) => s"$value is not found"
val MESSAGE_TABLE_REPOSITORY_ERROR = (message: String) => s"$message"
case class ErrorMessage(json: JsValue)
private val keyErrorMessage = "errorMessage"
sealed trait ApiResult {
def getAsFuture: Future[Result]
}
case class ApiSuccess(future: Future[String]) extends ApiResult {
override def getAsFuture: Future[Result] = future.map{Ok(_)}
}
case class ApiError(errorMessage: ErrorMessage) extends ApiResult {
override def getAsFuture: Future[Result] = Future[Result]{BadRequest(errorMessage.json.toString)}
}
def generateError(errorMessage: String): ErrorMessage = {
ErrorMessage(
Json.obj(keyErrorMessage -> errorMessage)
)
}
}
开发者ID:misoton665,项目名称:ibuki,代码行数:40,代码来源:ResultMessage.scala
示例2: RecoveryPolicy
//设置package包名称以及导入依赖的类
// The MIT License (MIT)
// Copyright (c) 2016 Paul Lavery
//
// See the LICENCE.txt file distributed with this work for additional information regarding copyright ownership.
package utils
import play.api.Logger
import play.api.mvc.Result
import play.api.mvc.Results.{InternalServerError, Ok}
import play.api.libs.json.Json
import reactivemongo.api.commands.WriteResult
object RecoveryPolicy {
val defaultRecoveryPolicy: PartialFunction[Throwable, Result] = {
// If the result from Mongo is defined with the error code 11000 (duplicate error)
case duplicateResult: WriteResult if (duplicateResult.code contains 11000) =>
Ok(Json.obj("status" ->"KO", "message" -> "An object with same ID already exists"))
case errorResult: WriteResult =>
Logger.error(s"An error happened while trying to write to the DB: $errorResult.message")
InternalServerError(Json.obj("status" ->"KO", "message" -> "Oops something went wrong"))
case genericError =>
Logger.error(genericError.toString)
InternalServerError(Json.obj("status" ->"KO", "message" -> "Oops something went wrong"))
}
}
开发者ID:paulporu,项目名称:Play-User-Queue,代码行数:29,代码来源:RecoveryPolicy.scala
示例3: 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.Results.Ok类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论