本文整理汇总了Scala中play.core.SourceMapper类的典型用法代码示例。如果您正苦于以下问题:Scala SourceMapper类的具体用法?Scala SourceMapper怎么用?Scala SourceMapper使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SourceMapper类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: ServerErrorHandler
//设置package包名称以及导入依赖的类
package utils.web
import org.slf4j.LoggerFactory
import play.api._
import play.api.http.DefaultHttpErrorHandler
import play.api.mvc.Results._
import play.api.mvc._
import play.api.routing.Router
import play.core.SourceMapper
import scala.concurrent.Future
class ServerErrorHandler(
env: play.api.Environment, config: Configuration,
sourceMapper: Option[SourceMapper], router: Option[Router]
) extends DefaultHttpErrorHandler(env, config, sourceMapper, router) {
private val log = LoggerFactory.getLogger(classOf[ServerErrorHandler])
override def onClientError(request: RequestHeader, statusCode: Int, message: String) = {
Future.successful(
Status(statusCode)("A client error occurred: " + message)
)
}
override def onServerError(request: RequestHeader, exception: Throwable) = {
log.error("Server error " + exception.getMessage + "for uri" + request.uri)
Future.successful(
InternalServerError("A server error occurred: " + exception.getMessage)
)
}
}
示例2: environment
//设置package包名称以及导入依赖的类
package com.github.jacobono.modules
import play.api.{ Configuration, Environment }
import play.api.http.HttpErrorHandler
import play.api.routing.Router
import play.core.SourceMapper
import play.filters.csrf.{ CSRFConfig, CSRFFilter }
import play.filters.headers.SecurityHeadersFilter
import com.softwaremill.macwire._
import com.github.jacobono.utils._
trait UtilModule {
def environment: Environment
def configuration: Configuration
def sourceMapper: Option[SourceMapper]
def routerOption: Option[Router]
def csrfFilter: CSRFFilter
def csrfConfig: CSRFConfig
def securityHeadersFilter: SecurityHeadersFilter
lazy val filters = wire[Filters]
lazy val csrfHelper = wire[CSRFHelper]
lazy val errorHandler: HttpErrorHandler = wire[ErrorHandler]
}
示例3: run
//设置package包名称以及导入依赖的类
package controllers
import java.io.File
import loader.{AppApplicationLoader, AppComponents}
import mqtt.MqttConnector
import play.api.test.Helpers._
import play.api.ApplicationLoader.Context
import play.api._
import play.api.test.FakeRequest
import play.api.test.Helpers.{GET, contentAsString, route}
import play.core.{DefaultWebCommands, SourceMapper, WebCommands}
import play.filters.csrf.CSRF.Token
trait IntegrationTest {
var appComponents:BuiltInComponentsFromContext with WithoutMqttAppComponents = null
trait WithoutMqttAppComponents extends AppComponents {
override lazy val mqttConnector = new MqttConnector(null, null, actorSystem) {
override val reconnect = new Runnable {
override def run() = {}
}
}
}
class WithoutMqttApp extends AppApplicationLoader {
override def createApp(context: Context) = {
appComponents = new BuiltInComponentsFromContext(context) with WithoutMqttAppComponents
appComponents
}
}
implicit val app = new WithoutMqttApp()
.load(ApplicationLoader.Context(environment, sourceMapper, webCommands, configuration))
Play.start(app)
def getCsrfToken() = {
val request = FakeRequest(GET, "/data").withHeaders()
val page = route(app, request).get
val content = contentAsString(page)
val name = ("""<input type="hidden" id="csrf_token_name" value="([\w]+)">""".r).findFirstMatchIn(content).get.group(1)
val value = ("""<input type="hidden" id="csrf_token_value" value="([\w-]+)">""".r).findFirstMatchIn(content).get.group(1)
Token(name, value)
}
def sourceMapper: Option[SourceMapper] = None
def environment: Environment = Environment(new File("."), ClassLoader.getSystemClassLoader, Mode.Test)
def webCommands: WebCommands = new DefaultWebCommands
def configuration: Configuration = Configuration.load(Environment(new File("."), ClassLoader.getSystemClassLoader, Mode.Test))
}
示例4: ProdErrorHandler
//设置package包名称以及导入依赖的类
package services
import play.api.routing.Router
import play.api.{Configuration, Environment, Logger}
import play.api.http.DefaultHttpErrorHandler
import play.api.mvc._
import play.core.SourceMapper
import scala.concurrent._
class ProdErrorHandler(environment: Environment, configuration: Configuration,
sourceMapper: Option[SourceMapper] = None,
router: => Option[Router] = None)
extends DefaultHttpErrorHandler (
environment, configuration, sourceMapper, router) {
override protected def onNotFound(request: RequestHeader, message: String):
Future[Result] = {
implicit val req = request
Future.successful(Results.NotFound(views.html.errorPage()))
}
override def onServerError(request: RequestHeader, exception: Throwable):
Future[Result] = {
Logger.error("Exception occurred", exception)
implicit val req = request
Future.successful(Results.InternalServerError(views.html.errorPage()))
}
override protected def onBadRequest(request: RequestHeader, message: String):
Future[Result] = {
super.onBadRequest(request, message)
}
}
示例5: WebGatewayErrorHandler
//设置package包名称以及导入依赖的类
import javax.inject._
import javax.inject._
import org.slf4j.LoggerFactory
import play.api._
import play.api.http.DefaultHttpErrorHandler
import play.api.mvc.Results._
import play.api.mvc._
import play.api.routing.Router
import play.core.SourceMapper
import scala.concurrent.Future
class WebGatewayErrorHandler @Inject()(
env: play.api.Environment, config: Configuration,
sourceMapper: Option[SourceMapper], router: Option[Router]
) extends DefaultHttpErrorHandler(env, config, sourceMapper, router) {
private val log = LoggerFactory.getLogger(classOf[WebGatewayErrorHandler])
override def onClientError(request: RequestHeader, statusCode: Int, message: String) = {
Future.successful(
Status(statusCode)("A client error occurred: " + message)
)
}
override def onServerError(request: RequestHeader, exception: Throwable) = {
log.error("Server error " + exception.getMessage + "for uri" + request.uri)
Future.successful(
InternalServerError("A server error occurred: " + exception.getMessage)
)
}
}