ScalaInterceptors - opensas/Play20Es GitHub Wiki

Intercepting requests

Esta página todavía no ha sido traducida al castellano. Puedes ayudarnos con la tarea simplemente presionando el botón Edit Page. Para más información puedes leer esta guía para el traductor. Aquí puedes ver cuánto nos falta para terminar la traducción.

Overriding onRouteRequest

One another important aspect of the Global object is that it provides a way to intercept requests and execute business logic before a request is dispatched to an Action.

Tip This hook can be also used for hijacking requests, allowing developers to plug-in their own request routing mechanism.

Let’s see how this works in practice:

import play.api._

// Note: this is in the default package.
object Global extends GlobalSettings {

  def onRouteRequest(request: RequestHeader): Option[Handler] = {
     println("executed before every request:" + request.toString)
     super.onRouteRequest(request)
  }

}

It’s also possible to intercept a specific Action method, using Action composition.

Next: Testing your application

⚠️ **GitHub.com Fallback** ⚠️