users@jersey.java.net

Transforming paths via filter

From: Tim Pesce <tpesce_at_foxfish.com>
Date: Mon, 3 Nov 2008 12:34:33 -0700

I have a scenario where I'd like to extract a path parameter into a
query parameter. So URIs of the form:

/context/scope/{scopeid}/resource

would become:

/context/resource?scope=scopeid

My initial approach was to create a ContainerRequestFilter and modify
the request's URIs via ContainerRequest.setUris(). However, this
approach does not seem viable because the path is calculated prior to
filter invocation (from WebApplicationImpl._handleRequest()):

---
StringBuilder path = new StringBuilder();
path.append("/").append(localContext.getPath(false));
[....]
for (ContainerRequestFilter f : requestFilters)
     request = f.filter(request);
if (!rootsRule.accept(path, null, localContext)) {
     throw new NotFoundException();
}
---
My new plan is to perform this transformation via Servlet filter,  but  
given the earlier discussion around per-resource filters and issue  
#134 I'm wondering if this use case may be something that Jersey can  
more directly support in the future. Also more generally, are there  
better approaches for handling this scenario within Jersey?
Tim