twitter/finatra — pull request #131 by grandbora (2014-04-14 01:15:52+00:00)
Title: path definitions on routes

* Adds path definitions to routes
* Refactors `findRouteAndMatch` method

Use case is; on controller error handler ([definition](https://github.com/twitter/finatra/blob/master/src/main/scala/com/twitter/finatra/Controller.scala#L29), [usage](https://github.com/capotej/finatra-example/blob/master/src/main/scala/com/twitter/finatra_example/App.scala#L127)) we want to log which endpoint is failed. One easy way to do that is to log the request path, but most of the paths we use have dynamic values (id, tag etc.). Therefore when we log the request path, we are having trouble when aggregating the log output for monitoring purposes. So instead of request path what we need is the route that is matched.
The closest I could get was getting the PathPattern from router as shown below;
```scala
val pathPattern = finatraController.route.findRouteAndMatch(request, request.getMethod).get._2.toString
```
Unfortunately PathPattern is not user friendly and doesn’t look good on graphs(eg `PathPattern(^/users/([^/?#]+)/xx/yy$,List(user))`). Therefore I added the the string path definition([eg](https://github.com/capotej/finatra-example/blob/master/src/main/scala/com/twitter/finatra_example/App.scala#L16)) to the `routes` of the controller. So with the same code above we can get the human readable definition of the route that is matched.

PS. this is a pain point for me, would be happy if you can either merge/release or suggest an alternative.
PS. also slightly refactored the method that does the matching.
PS. router does not have a spec.