本文整理汇总了Scala中play.api.mvc.EssentialFilter类的典型用法代码示例。如果您正苦于以下问题:Scala EssentialFilter类的具体用法?Scala EssentialFilter怎么用?Scala EssentialFilter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了EssentialFilter类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。
示例1: AppLoader
//设置package包名称以及导入依赖的类
import models.{AuthorizeStoreCache, PendingContentStoreCache}
import play.api.ApplicationLoader.Context
import play.api.cache.EhCacheComponents
import play.api.mvc.EssentialFilter
import play.api.routing.Router
import play.api._
import play.filters.gzip.GzipFilter
import router.Routes
class AppLoader extends ApplicationLoader {
override def load(context: Context): Application = {
LoggerConfigurator(context.environment.classLoader)
.foreach(_.configure(context.environment))
new AppComponents(context).application
}
}
class AppComponents(context: Context)
extends BuiltInComponentsFromContext(context)
with EhCacheComponents {
implicit val executionContext =
play.api.libs.concurrent.Execution.Implicits.defaultContext
implicit lazy val authorizeStoreCache = AuthorizeStoreCache(
cacheApi("authorizeStore"))
implicit lazy val pendingConsentStoreCache = PendingContentStoreCache(
cacheApi("pendingConsentStore"))
implicit val config = configuration.underlying
lazy val applicationController = new controllers.Application
lazy val assets = new controllers.Assets(httpErrorHandler)
// Routes is a generated class
override def router: Router =
new Routes(httpErrorHandler, applicationController, assets)
val gzipFilter = new GzipFilter(shouldGzip = (request, response) => {
val contentType = response.header.headers.get("Content-Type")
contentType.exists(_.startsWith("text/html")) ||
request.path.endsWith("jsroutes.js")
})
override lazy val httpFilters: Seq[EssentialFilter] = Seq(gzipFilter)
}
开发者ID:zalando-incubator,项目名称:OAuth2-mock-play,代码行数:45,代码来源:AppLoader.scala
示例2: AppShutdown
//设置package包名称以及导入依赖的类
package org.andrewconner.spot.modules
import com.sun.media.sound.ModelSource
import org.andrewconner.spot.AppComponents
import org.andrewconner.spot.playapp.TarpitFilter
import play.api.Logger
import play.api.inject.ApplicationLifecycle
import play.api.libs.ws.WSClient
import play.api.libs.ws.ahc.AhcWSClient
import play.api.mvc.EssentialFilter
import com.softwaremill.macwire._
import scala.concurrent.{ ExecutionContext, Future }
import scala.util.{ Failure, Success }
trait PlayAppModule { self: AppComponents =>
lazy val appShutdown: AppShutdown = new AppShutdown(applicationLifecycle)
override lazy val httpFilters: Seq[EssentialFilter] = if (environment.mode == play.api.Mode.Test) {
Seq()
} else {
Seq(wire[TarpitFilter])
}
}
class AppShutdown(applicationLifecycle: ApplicationLifecycle)(implicit val ec: ExecutionContext) {
// On app shutdown, calls `f` on a separate thread, not blocking the rest of application shutdown.
// Useful when we really don't care about the result.
def onStopAsync(f: => Unit): Unit = {
applicationLifecycle.addStopHook { () =>
Future { f }(ec).onComplete {
case Success(s) =>
Logger.info("Success stopping")
case Failure(ex) =>
Logger.error("Error executing stop hook", ex)
}
Future.successful(())
}
}
def onStopBlock(f: => Unit) = {
applicationLifecycle.addStopHook { () =>
Future.successful(f)
}
}
def onStartAsync(f: => Unit) = {
println("")
}
}
开发者ID:andrewconner,项目名称:spotsy,代码行数:53,代码来源:PlayAppModule.scala
示例3: GriffinApiLoader
//设置package包名称以及导入依赖的类
import com.softwaremill.macwire._
import controllers.Assets
import filters.LoggingFilter
import play.api.ApplicationLoader.Context
import play.api._
import play.api.i18n._
import play.api.libs.ws.ahc.AhcWSComponents
import play.api.mvc.EssentialFilter
import play.api.routing.Router
import play.filters.cors.{CORSConfig, CORSFilter}
import router.Routes
import services.ServicesModule
class GriffinApiLoader extends ApplicationLoader {
def load(context: Context): Application = new GriffinComponents(context).application
}
class GriffinComponents(context: Context)
extends BuiltInComponentsFromContext(context)
with ServicesModule
with I18nComponents
with AhcWSComponents
{
// set up logger
LoggerConfigurator(context.environment.classLoader).foreach {
_.configure(context.environment)
}
lazy val assets: Assets = wire[Assets]
lazy val router: Router = {
// add the prefix string in local scope for the Routes constructor
val prefix: String = "/"
wire[Routes]
}
lazy val corsFilter = CORSFilter(CORSConfig.fromConfiguration(configuration))
lazy val loggingFilter = new LoggingFilter
lazy val filters = wire[Filters]
override lazy val httpFilters: Seq[EssentialFilter] =
Seq(loggingFilter,corsFilter)
}
开发者ID:yarshad,项目名称:griffin-api,代码行数:48,代码来源:GriffinApiLoader.scala
示例4: SilhouetteMacwireApplicationLoader
//设置package包名称以及导入依赖的类
package com.github.jacobono
import _root_.controllers.Assets
import _root_.controllers.WebJarAssets
import com.softwaremill.macwire._
import org.flywaydb.play.FlywayPlayComponents
import play.api._
import play.api.ApplicationLoader.Context
import play.api.cache.EhCacheComponents
import play.api.db.slick.SlickComponents
import play.api.i18n.I18nComponents
import play.api.libs.openid.OpenIDComponents
import play.api.libs.ws.ning.NingWSComponents
import play.api.mvc.EssentialFilter
import play.api.routing.Router
import play.filters.csrf.CSRFComponents
import play.filters.headers.SecurityHeadersComponents
import router.Routes
import com.github.jacobono.modules._
class SilhouetteMacwireApplicationLoader extends ApplicationLoader {
def load(context: Context): Application = {
Logger.configure(context.environment)
new SilhouetteMacwireComponents(context).application
}
}
class SilhouetteMacwireComponents(context: Context) extends BuiltInComponentsFromContext(context)
with ControllerModule with UtilModule with UserModule with SilhouetteModule
with DAOModule with DatabaseModule
with I18nComponents with NingWSComponents with CSRFComponents with SecurityHeadersComponents
with SlickComponents with EhCacheComponents with OpenIDComponents with FlywayPlayComponents {
flywayPlayInitializer
// for the optional Router param in error handler
// if this is trying to use the Router value from BuiltInComponentsFromContext
// it results in a circular dependency between the Router and the HttpErrorHandler
// the application obviously won't start if this happens
lazy val routerOption = None
override lazy val httpErrorHandler = errorHandler
override lazy val httpFilters: Seq[EssentialFilter] = filters.filters
lazy val webJarAssets: WebJarAssets = wire[WebJarAssets]
lazy val assets: Assets = wire[Assets]
lazy val router: Router = {
lazy val prefix = "/"
wire[Routes]
}
}
开发者ID:jacobono,项目名称:silhouette-macwire,代码行数:52,代码来源:SilhouetteMacwireApplicationLoader.scala
示例5: KamonFilter
//设置package包名称以及导入依赖的类
package kamon.play
import akka.util.ByteString
import kamon.trace.Tracer
import kamon.util.SameThreadExecutionContext
import play.api.libs.streams.Accumulator
import play.api.mvc.{ EssentialAction, EssentialFilter, RequestHeader, Result }
class KamonFilter extends EssentialFilter {
override def apply(next: EssentialAction): EssentialAction = new EssentialAction {
override def apply(requestHeader: RequestHeader): Accumulator[ByteString, Result] = {
def onResult(result: Result): Result = {
Tracer.currentContext.collect { ctx ?
ctx.finish()
PlayExtension.httpServerMetrics.recordResponse(ctx.name, result.header.status.toString)
if (PlayExtension.includeTraceToken) result.withHeaders(PlayExtension.traceTokenHeaderName -> ctx.token)
else result
} getOrElse result
}
//override the current trace name
Tracer.currentContext.rename(PlayExtension.generateTraceName(requestHeader))
val nextAccumulator = next.apply(requestHeader)
nextAccumulator.map(onResult)(SameThreadExecutionContext)
}
}
}
开发者ID:agiledigital,项目名称:kamon-play-2.5.x,代码行数:32,代码来源:KamonFilter.scala
示例6: DapperApplicationLoader
//设置package包名称以及导入依赖的类
package me.dapperware
import play.api.mvc.EssentialFilter
import play.api.routing.Router
import play.api.{Application, ApplicationLoader, BuiltInComponentsFromContext}
import com.softwaremill.macwire._
import me.dapperware.config.{MongoConfig, Neo4jConfig}
import me.dapperware.controllers.DapperController
import me.dapperware.module.{MongoModule, Neo4jModule}
import me.dapperware.schema.DapperSchemaBuilder
import play.filters.cors.CORSComponents
import router.Routes
class DapperApplicationLoader extends ApplicationLoader {
override def load(context: ApplicationLoader.Context): Application =
new DapperComponents(context).application
}
class DapperComponents(context: ApplicationLoader.Context)
extends BuiltInComponentsFromContext(context)
with CORSComponents {
// Configs
lazy val mongoConfig = wire[MongoConfig]
lazy val neo4jConfig = wire[Neo4jConfig]
// DBs
lazy val mongoModule: MongoModule = wire[MongoModule]
lazy val neo4jModule: Neo4jModule = wire[Neo4jModule]
// GraphQL Schema
lazy val schema = wire[DapperSchemaBuilder]
// Controllers
lazy val dapperController = wire[DapperController]
// Routes
lazy val router: Router = {
val prefix = "/"
wire[Routes]
}
override def httpFilters: Seq[EssentialFilter] = Seq(corsFilter)
}
开发者ID:paulpdaniels,项目名称:play-sangria-starter,代码行数:48,代码来源:DapperApplicationLoader.scala
示例7: ServerModule
//设置package包名称以及导入依赖的类
package uk.co.telegraph.utils.server
import akka.actor.ActorSystem
import com.google.inject.{AbstractModule, Provides}
import com.google.inject.Key.get
import com.google.inject.multibindings.Multibinder.newSetBinder
import play.api.mvc.EssentialFilter
import play.filters.cors.CORSFilter
import uk.co.telegraph.utils.server.filters.{AuthFilter, EventIdFilter}
import java.util.{Set => JSet}
import scala.language.postfixOps
import scala.collection.convert.WrapAsScala._
import uk.co.telegraph.utils.client.GenericClient
import uk.co.telegraph.utils.client.monitor.Monitor
class ServerModule extends AbstractModule {
override def configure(): Unit = {
val filterBinder = newSetBinder(binder(), get(classOf[EssentialFilter]))
filterBinder.addBinding().to(classOf[CORSFilter])
filterBinder.addBinding().to(classOf[EventIdFilter])
filterBinder.addBinding().to(classOf[AuthFilter])
}
@Provides
def monitorProvider(clientsSet:JSet[GenericClient])(implicit system:ActorSystem): Monitor = {
Monitor(clientsSet.toSeq)
}
}
开发者ID:telegraph,项目名称:tmg-utils,代码行数:30,代码来源:ServerModule.scala
示例8: CORSFilter
//设置package包名称以及导入依赖的类
package utils.play
import javax.inject.Inject
import controllers.Default
import play.api.Logger
import play.api.http.HttpFilters
import play.api.mvc.{ EssentialFilter, Filter, RequestHeader, Result }
import play.filters.csrf.CSRFFilter
import play.filters.headers.SecurityHeadersFilter
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent._
case class CORSFilter() extends Filter {
lazy val allowedDomain = play.api.Play.current.configuration.getString("cors.allowed.domain")
def apply(f: (RequestHeader) => Future[Result])(request: RequestHeader): Future[Result] = {
Logger.trace("[cors] filtering request to add cors")
if (isPreFlight(request)) {
Logger.trace("[cors] request is preflight")
Logger.trace(s"[cors] default allowed domain is $allowedDomain")
Future.successful(Default.Ok.withHeaders(
"Access-Control-Allow-Origin" -> allowedDomain.orElse(request.headers.get("Origin")).getOrElse(""),
"Access-Control-Allow-Methods" -> request.headers.get("Access-Control-Request-Method").getOrElse("*"),
"Access-Control-Allow-Headers" -> request.headers.get("Access-Control-Request-Headers").getOrElse(""),
"Access-Control-Expose-Headers" -> "WWW-Authenticate, Server-Authorization, X-Auth-Token",
"Access-Control-Allow-Credentials" -> "true"))
} else {
Logger.trace("[cors] request is normal")
Logger.trace(s"[cors] default allowed domain is $allowedDomain")
f(request).map {
_.withHeaders(
"Access-Control-Allow-Origin" -> allowedDomain.orElse(request.headers.get("Origin")).getOrElse(""),
"Access-Control-Allow-Methods" -> request.headers.get("Access-Control-Request-Method").getOrElse("*"),
"Access-Control-Allow-Headers" -> request.headers.get("Access-Control-Request-Headers").getOrElse(""),
"Access-Control-Expose-Headers" -> "WWW-Authenticate, Server-Authorization, X-Auth-Token, Authorization, Proxy-Authorization, Content-Type",
"Access-Control-Allow-Credentials" -> "true")
}
}
}
def isPreFlight(r: RequestHeader) = (
r.method.toLowerCase.equals("options")
&&
r.headers.get("Access-Control-Request-Method").nonEmpty)
}
class Filters @Inject() (csrfFilter: CSRFFilter, securityHeadersFilter: SecurityHeadersFilter) extends HttpFilters {
override def filters: Seq[EssentialFilter] = Seq(csrfFilter, securityHeadersFilter, CORSFilter())
}
开发者ID:rossanthony,项目名称:play-travel,代码行数:54,代码来源:Filters.scala
注:本文中的play.api.mvc.EssentialFilter类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论