forked from playframework/playframework
-
Notifications
You must be signed in to change notification settings - Fork 0
ScalaInterceptors
pk11 edited this page Feb 10, 2012
·
7 revisions
One another important aspect of the Global object is that it provides a way to intercept requests and execute some business logic before a request is being dispatched to an Action.
Tip: this hook can be also used for hijacking requests, allowing developers to plugin their own request routing mechanism.
Let's see how this works in practice:
import play.api._
//notice: 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)
}
}Of course it's also possible to intercept only a specific method. This can be achieved via Actions composition
Next: Testing your application
- HTTP programming
- Asynchronous HTTP programming
- The template engine
- HTTP form submission and validation
- Working with JSON
- Working with XML
- Handling file upload
- Accessing an SQL database
- Using the Cache
- Calling WebServices
- Integrating with Akka
- Internationalization
- The application Global object
- Testing your application