views:

61

answers:

2

I've got a big old log file I'm trying to break down in terms of routes.

Essentially, I'm getting input of a path (/questions/31415 for example) and a list of all the registered Routes. What I want out is a Route and the parameters specified in the route (so in, /questions/{id}/{answer} I'd get id and answers out).

I've got a working solution that basically generates a nasty bit of regex on the fly with named groups to do matching and parsing all-in-one. My gut tells me this is a brittle way to do it, and frankly there has to be a better way, right?

A: 

Would the Routing Debugger help? Comes with sample code too.

http://haacked.com/archive/2008/03/13/url-routing-debugger.aspx

Raj Kaimal
To adapt this I'd have to fake a HttpContext, which is much more trouble than its worth; and arguably uglier than my current solution.
Kevin Montrose
A: 

This is very similar to the PathParameterFilter often used with spring/REST. I don't have a link to the source any more, but it has the regular expressions you need to pull things out. http://www.carbonfive.com/community/archives/2007/06/parameterized_rest_urls_with_spring_mvc.html

Justin