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


Scala OptionalSourceMapper类代码示例

本文整理汇总了Scala中play.api.OptionalSourceMapper的典型用法代码示例。如果您正苦于以下问题:Scala OptionalSourceMapper类的具体用法?Scala OptionalSourceMapper怎么用?Scala OptionalSourceMapper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了OptionalSourceMapper类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。

示例1: ErrorHandler

//设置package包名称以及导入依赖的类
import javax.inject.{ Inject, Provider }
import play.api.{ Configuration, Environment, Logger, OptionalSourceMapper, UsefulException }
import play.api.http.DefaultHttpErrorHandler
import play.api.mvc.RequestHeader
import play.api.mvc.Results._
import play.api.routing.Router
import scala.concurrent.Future

class ErrorHandler @Inject() (
    env: Environment,
    config: Configuration,
    sourceMapper: OptionalSourceMapper,
    router: Provider[Router]
  ) extends DefaultHttpErrorHandler(env, config, sourceMapper, router) {

  override def onProdServerError(request: RequestHeader, exception: UsefulException) =
    Future.successful(InternalServerError("A server error occurred: " + exception.getMessage))

  override def onClientError(request: RequestHeader, statusCode: Int, message: String) = {
    if (statusCode == 413)      // Request entity too large
      Future.successful(EntityTooLarge("Could not upload the file - too large"))
    else if (statusCode == 404) // Not Found
      Future.successful(NotFound(views.html.error404()))
    else
      super.onClientError(request, statusCode, message)
  }

} 
开发者ID:pelagios,项目名称:recogito2,代码行数:29,代码来源:ErrorHandler.scala

示例2: ErrorHandler

//设置package包名称以及导入依赖的类
package utils

import javax.inject.{Inject, Provider}

import com.mohiva.play.silhouette.api.actions.SecuredErrorHandler
import play.api.http.DefaultHttpErrorHandler
import play.api.i18n.{I18nSupport, Messages, MessagesApi}
import play.api.mvc.Results._
import play.api.mvc.{RequestHeader, Result}
import play.api.routing.Router
import play.api.{Configuration, OptionalSourceMapper}

import scala.concurrent.Future
import controllers.{WebJarAssets, routes}

class ErrorHandler @Inject() (
                               val messagesApi: MessagesApi,
                               env: play.api.Environment,
                               config: Configuration,
                               sourceMapper: OptionalSourceMapper,
                               router: javax.inject.Provider[Router],
                               p: Provider[WebJarAssets])
  extends DefaultHttpErrorHandler(env, config, sourceMapper, router)
    with SecuredErrorHandler with I18nSupport {

  // https://www.playframework.com/documentation/2.5.x/Migration25#Handling-legacy-components
  implicit lazy val webJarAssets = p.get()

  override def onNotAuthenticated(implicit request: RequestHeader): Future[Result] =
    Future.successful(Redirect(routes.Auth.signIn()))

  override def onNotAuthorized(implicit request: RequestHeader): Future[Result] =
    Future.successful(Redirect(routes.Auth.signIn()).flashing("error" -> Messages("error.accessDenied")))

  override def onNotFound(request: RequestHeader, message: String): Future[Result] =
    Future.successful(Ok(views.html.errors.notFound(request)))

  override def onServerError(request:RequestHeader, exception:Throwable):Future[Result] =
    Future.successful(Ok(views.html.errors.serverError(request, exception)))
} 
开发者ID:tm-sukehiro,项目名称:play-hands-on,代码行数:41,代码来源:ErrorHandler.scala

示例3: ErrorHandler

//设置package包名称以及导入依赖的类
package utils

import javax.inject.Inject

import com.mohiva.play.silhouette.api.SecuredErrorHandler

import play.api.http.DefaultHttpErrorHandler
import play.api.i18n.{I18nSupport,Messages,MessagesApi}
import play.api.mvc.Results._
import play.api.mvc.{Result,RequestHeader}
import play.api.routing.Router
import play.api.{OptionalSourceMapper,Configuration}

import scala.concurrent.Future

class ErrorHandler @Inject() (
  val messagesApi: MessagesApi,
  env: play.api.Environment,
  config: Configuration,
  sourceMapper: OptionalSourceMapper,
  router: javax.inject.Provider[Router])
  extends DefaultHttpErrorHandler(env, config, sourceMapper, router)
  with SecuredErrorHandler with I18nSupport {

  override def onNotAuthenticated(request: RequestHeader, messages: Messages): Option[Future[Result]] =
    Some(Future.successful(Ok("please sign in")))

  override def onNotAuthorized(request: RequestHeader, messages: Messages): Option[Future[Result]] =
    Some(Future.successful(Ok(Messages("error.accessDenied")(messages))))

  override def onNotFound(request: RequestHeader, message: String): Future[Result] = 
    Future.successful(Ok("not found"))

  override def onServerError(request:RequestHeader, exception:Throwable):Future[Result] = 
    Future.successful(Ok("server error"))
} 
开发者ID:k19862217,项目名称:book-shoes-api,代码行数:37,代码来源:ErrorHandler.scala

示例4: ErrorHandler

//设置package包名称以及导入依赖的类
package utils

import javax.inject.Inject

import com.mohiva.play.silhouette.api.SecuredErrorHandler

import play.api.http.DefaultHttpErrorHandler
import play.api.i18n.{I18nSupport,Messages,MessagesApi}
import play.api.mvc.Results._
import play.api.mvc.{Result,RequestHeader}
import play.api.routing.Router
import play.api.{OptionalSourceMapper,Configuration}

import scala.concurrent.Future

import controllers.routes

class ErrorHandler @Inject() (
  val messagesApi: MessagesApi,
  env: play.api.Environment,
  config: Configuration,
  sourceMapper: OptionalSourceMapper,
  router: javax.inject.Provider[Router])
  extends DefaultHttpErrorHandler(env, config, sourceMapper, router)
  with SecuredErrorHandler with I18nSupport {

  override def onNotAuthenticated(request: RequestHeader, messages: Messages): Option[Future[Result]] =
    Some(Future.successful(Redirect(routes.Auth.signIn())))

  override def onNotAuthorized(request: RequestHeader, messages: Messages): Option[Future[Result]] =
    Some(Future.successful(Redirect(routes.Auth.signIn()).flashing("error" -> Messages("error.accessDenied")(messages))))

  override def onNotFound(request: RequestHeader, message: String): Future[Result] = 
    Future.successful(Ok(views.html.errors.notFound(request)))

  override def onServerError(request:RequestHeader, exception:Throwable):Future[Result] = 
    Future.successful(Ok(views.html.errors.serverError(request, exception)))
} 
开发者ID:Viva-con-Agua,项目名称:drops,代码行数:39,代码来源:ErrorHandler.scala

示例5: ErrorHandler

//设置package包名称以及导入依赖的类
package ylabs.play.common

import java.io.{PrintWriter, StringWriter}
import javax.inject.{Inject, Provider}

import play.api.http.DefaultHttpErrorHandler
import play.api.libs.json.{JsObject, JsString, Json, Writes}
import play.api.mvc.RequestHeader
import play.api.mvc.Results._
import play.api.routing.Router
import play.api.{Configuration, Environment, OptionalSourceMapper, UsefulException}
import ylabs.play.common.models.Helpers.ApiFailure.Failed
import ylabs.play.common.models.ValidationError.{Field, Invalid, Reason}

import scala.concurrent.Future

class ErrorHandler @Inject() (
    env: Environment,
    config: Configuration,
    sourceMapper: OptionalSourceMapper,
    router: Provider[Router]) extends DefaultHttpErrorHandler(env, config, sourceMapper, router) {

  def prettyTrace(t: Throwable) = {
    val sw = new StringWriter
    t.printStackTrace(new PrintWriter(sw))
    sw.toString
  }

  implicit def exceptionWrites: Writes[Throwable] = new Writes[Throwable] {
    def writes(t: Throwable) = JsObject(Seq(
      "message" -> JsString(t.getMessage),
      "trace" -> JsString(prettyTrace(t))))
  }

  override def onDevServerError(request: RequestHeader, exception: UsefulException) = {
    Future.successful(InternalServerError(Json.toJson(exception)))
  }

  override def onProdServerError(request: RequestHeader, exception: UsefulException) = {
    Future.successful(InternalServerError(Json.toJson("Internal Error")))
  }

  override def onBadRequest(request: RequestHeader, message: String) = {
    def errorToMessage(error: String) = error match {
      case "error.path.missing" ? "Value missing"
      case _                    ? error
    }

    //This is a bit of a mess because play doesn't allow invalid json to get to our client code
    //Message will be something like "Json validation error List((obj.name,List(ValidationError(List(error.path.missing),WrappedArray()))))"
    //So this extracts the field and reason
    val errorRegex = """\(obj.([^,]+),List\(ValidationError\(List\(([^\)]+)""".r
    val errors = errorRegex.findAllMatchIn(message) map { m ? Invalid(Field(m.group(1)), Reason(errorToMessage(m.group(2)))) }
    val list = if(errors.nonEmpty) errors.toList else List(Invalid(Field("Unknown"), Reason(message)))

    val failed = Failed(list)
    Future.successful(BadRequest(Json.toJson(failed)))
  }
} 
开发者ID:springnz,项目名称:play-app-base,代码行数:60,代码来源:ErrorHandler.scala

示例6: ErrorHandler

//设置package包名称以及导入依赖的类
package sc.ript.cgmlms.fw.handlers

import javax.inject.{Inject, Singleton}

import com.google.inject.Provider
import com.typesafe.scalalogging.LazyLogging
import play.api.http.DefaultHttpErrorHandler
import play.api.mvc.Results.{InternalServerError, Status}
import play.api.mvc.{RequestHeader, Result}
import play.api.routing.Router
import play.api.{Configuration, Environment, OptionalSourceMapper}

import scala.concurrent.Future

@Singleton
private class ErrorHandler @Inject()(env: Environment, config: Configuration, sourceMapper: OptionalSourceMapper, router: Provider[Router]) extends DefaultHttpErrorHandler(env, config, sourceMapper, router) with LazyLogging {

  override def onClientError(request: RequestHeader, statusCode: Int, message: String): Future[Result] = {
    logger.info("statusCode = {}, message = {}", statusCode.toString, message)
    Future.successful(Status(statusCode)("A client error occurred: " + message))
  }

  override def onServerError(request: RequestHeader, exception: Throwable): Future[Result] = {
    logger.error(s"message = ${exception.getMessage}", exception)
    Future.successful(InternalServerError("A server error occurred: " + exception.getMessage))
  }

} 
开发者ID:brightgenerous,项目名称:cgm-lms,代码行数:29,代码来源:ErrorHandler.scala

示例7: ErrorHandler

//设置package包名称以及导入依赖的类
package com.clemble.loveit.common.controller

import com.clemble.loveit.common.error.ThankException
import javax.inject.{Singleton, Inject, Provider}
import play.api.http.DefaultHttpErrorHandler
import play.api.mvc.Results._
import play.api.mvc._
import play.api.routing.Router
import play.api.{Configuration, Environment, OptionalSourceMapper}

import scala.concurrent._

@Singleton
class ErrorHandler @Inject() (
                               env: Environment,
                               config: Configuration,
                               sourceMapper: OptionalSourceMapper,
                               router: Provider[Router]
                             ) extends DefaultHttpErrorHandler(env, config, sourceMapper, router) {

  override def onServerError(request: RequestHeader, exception: Throwable): Future[Result] = {
    exception match {
      case te: ThankException =>
        Future.successful(BadRequest(te))
      case exc =>
        super.onServerError(request, exc)
    }
  }

} 
开发者ID:thankyo,项目名称:thank,代码行数:31,代码来源:ErrorHandler.scala

示例8: ErrorHandler

//设置package包名称以及导入依赖的类
import play.api.http.DefaultHttpErrorHandler
import daos.SubjectDao
import be.objectify.deadbolt.scala.AuthenticatedRequest
import play.api.OptionalSourceMapper
import play.api.Environment
import javax.inject.Inject
import models.Notification
import play.api.Configuration
import play.api.Logger
import play.api.i18n.{ I18nSupport, MessagesApi }
import play.api.mvc._
import play.api.mvc.Results._
import play.api.routing.Router
import scala.concurrent._
import javax.inject._

@Singleton
class ErrorHandler @Inject() (
  subjectDao: SubjectDao,
  env: Environment,
  config: Configuration,
  sourceMapper: OptionalSourceMapper,
  router: Provider[Router],
  val messagesApi: MessagesApi
)
    extends DefaultHttpErrorHandler(env, config, sourceMapper, router) with I18nSupport {

  def onProdServerError(request: RequestHeader, exception: Throwable) = {
    Logger.error("Error no manejado", exception)
    val req: Request[Any] = Request(request, 1)
    val subject = subjectDao.subjectByIdentifier(request.session("login"))

    implicit val authReq: AuthenticatedRequest[_] = AuthenticatedRequest(req, subject)
    implicit val nots = Notification.error(messagesApi("ErrorHandler.error"))
    Future.successful(
      Ok(views.html.index())
    )
  }
} 
开发者ID:kdoomsday,项目名称:kaminalapp,代码行数:40,代码来源:ErrorHandler.scala

示例9: ErrorHandler

//设置package包名称以及导入依赖的类
import javax.inject.{Inject, Provider, Singleton}

import play.api.http.DefaultHttpErrorHandler
import play.api.i18n.{I18nSupport, Messages, MessagesApi}
import play.api.libs.concurrent.Execution.Implicits.defaultContext
import play.api.mvc.Results._
import play.api.mvc.{RequestHeader, Result}
import play.api.routing.Router
import play.api.{Configuration, Environment, OptionalSourceMapper, UsefulException}
import views.ErrorView

import scala.concurrent.Future
import play.api.libs.concurrent.Execution.Implicits.defaultContext

@Singleton
class ErrorHandler @Inject()(env: Environment,
                             config: Configuration,
                             sourceMapper: OptionalSourceMapper,
                             router: Provider[Router],
                             val messagesApi: MessagesApi
                            ) extends DefaultHttpErrorHandler(env, config, sourceMapper, router) with I18nSupport {

  override def onProdServerError(request: RequestHeader, exception: UsefulException): Future[Result] = {
    implicit val requestHeader = request
    Future.successful(InternalServerError(ErrorView(Messages("error.server"), exception.getMessage, "server_error")))
  }

  override def onForbidden(request: RequestHeader, message: String): Future[Result] = {
    implicit val requestHeader = request
    Future.successful(Forbidden(ErrorView(Messages("error.forbidden_access"), message, "unauthorized_error")))
  }
} 
开发者ID:rusins,项目名称:pusdieno,代码行数:33,代码来源:ErrorHandler.scala


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