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.
For Java, we need to take the following steps:
Run the
foo_java
application with Hot-Reloading enabled.Create a new filter object by creating the file
foo_java/app/ResponseTimeLogFilter.scala
, and adding the following contents:import play.api.mvc._ object ResponseTimeLogFilter { def apply(): ResponseTimeLogFilter = { new ResponseTimeLogFilter() } } class ResponseTimeLogFilter extends Filter ...