Hi Tim,
On Nov 3, 2008, at 8:34 PM, Tim Pesce wrote:
> 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()):
>
Drat, that is a bug. The path needs to be obtained after filters have
been applied. Also the request filter can return a new request so that
needs to be catered for as well. Could you log an issue?
> ---
>
> 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?
>
You can do it explicitly with resource classes and reuse code:
@Path("content")
public class ResourceContext {
@Path("scope/{scopeid}/resource"
@GET
... getAsPath(@PathParam("scopeid") String scope) {
return getAsQuery(scope);
}
@Path("resource")
@GET
... getAsQuery(@QueryParam("scope") Scope scope) { ... }
}
I suspect that is not what you want.
Like Jeff i am curious as to why you want to do this to understand
your use-case better.
Paul.
> Tim
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>