2

According to the documentation, the filter chain happens after the request has been routed. Is there any way to have the filter chain apply before the request has been routed?

In particular, we want to apply a number of filters prior to the URL mapping. If we do these as normal filters, either we can't use the request binding that happens when routing, or we have to do that ourselves in the actions.

cdeszaq
  • 30,869
  • 25
  • 117
  • 173

3 Answers3

0

yes,

onRouteRequest(Http.RequestHeader request)
Called when an HTTP request has been received.

For more details, look at this https://www.playframework.com/documentation/2.2.0/api/java/play/GlobalSettings.html#onRouteRequest(play.mvc.Http.RequestHeader)

You need a class to extends GlobalSettings, 
and then override the method onRouteRequest(Http.RequestHeader request)
runcode
  • 3,533
  • 9
  • 35
  • 52
0

From the documentation: "if you do need to modify the request before the router is invoked, a better way to do this would be to place your logic in Global.onRouteRequest instead."

Nonos
  • 2,450
  • 2
  • 23
  • 34
0

In newer versions of Play (e.g., 2.6.x), the preferred way to apply custom logic before routing is to implement a custom HttpRequestHandler (see this page for the documentation for the Java version of HttpRequestHandler).

In many cases, you can extend the default request handler and override the routeRequest method.

From the filters documentation:

If you do need to modify the request before the router is invoked, a better way to do this would be to place your logic in HttpRequestHandler instead.

Jim Hurne
  • 7,187
  • 4
  • 44
  • 44