O'Reilly logo

Play Framework Cookbook - Second Edition by Giancarlo Inductivo, Alexander Reelsen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using filters

For this recipe, we will explore how Play Framework provide APIs for HTTP request and response filters. HTTP filters provide a way to transparently decorate a HTTP request or response and is useful for lower-level services (such as response compression), gathering metrics, and more in-depth logging.

Note

It is also worth noting that presently (as of Play 2.3.7), HTTP filters are best implemented using the Play Scala API with the play.api.mvc.EssentialFilter trait. So for this recipe, we will implement a Scala-based filter for our Java recipe.

How to do it…

For Java, we need to take the following steps:

  1. Run the foo_java application with Hot-Reloading enabled.
  2. Create a new filter object by creating the file foo_java/app/ResponseTimeLogFilter.scala ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required