1

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?

Kevin Montrose
  • 22,191
  • 9
  • 88
  • 137
  • Are you doing this in a large batch where performance is important, or one at a time, where you favor simplicity? – Nick Craver Apr 27 '10 at 03:01
  • @Nick - Large batches, but rarely. Simplicity and robustness are more important than performance. I am currently dynamically generating regex for each and every log entry, with acceptable performance. – Kevin Montrose Apr 27 '10 at 03:07
  • I'm not 100% sure, but I believe SO encodes the `/` in the question title, so is just simple chunking in an array an option, I'm sure I'm missing some other factor, but it seems like a `.split("/")` is the simplest solution here, do you have a factor prohibiting this? – Nick Craver Apr 27 '10 at 03:10
  • @Nick - I gave the `/questions/{id}` route as an example, there are more complicated routes in the actual site. – Kevin Montrose Apr 27 '10 at 03:17
  • Ah gotcha, there's that other shoe I was looking for :) – Nick Craver Apr 27 '10 at 11:32

3 Answers3

2

I know this is an old question, but on the off chance someone else gets here via Google, I asked and answered my own question on this same subject here.

Community
  • 1
  • 1
Scott
  • 13,735
  • 20
  • 94
  • 152
0

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

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

Raj Kaimal
  • 8,304
  • 27
  • 18
  • 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 Apr 27 '10 at 03:08
0

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
  • 4,437
  • 6
  • 32
  • 52