users@jersey.java.net

Re: [Jersey] Parent path through UriBuilder with sub-locators

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Fri, 10 Jul 2009 11:17:49 +0200

On Jul 10, 2009, at 11:10 AM, Martin Probst wrote:

> Hi,
>
> assuming that I am somewhere deep in a web request defined by sub
> locators, and I want to construct a URI to some resource.
>
> What is the recommended way to do so?
>
> I'm currently using UriInfo.getAbsolutePathBuilder(), but the problem
> is I can't see a way to construct my path to a specific object if that
> is only reachable through sub locators, in particular if I need to
> construct a "parent" link - i.e. if I'm not descending further in the
> path hierarchy, but trying to go upwards. My current solution is to
> use the raw URI and resolve(...), but that seems like a hack.
>
> The general problem is of course hard because it's not possible to
> know the absolute, canonical path to some sub resource. But if we
> already have the list of steps how we got "here", there should be a
> way to move upwards again, right?
>
> I see there is UriInfo.getMatchedResources() and
> UriInfo.getMatchedURIs(), but how do I use those?
>


The latter presents the list of paths (in reverse order) to to how we
got to "here" i.e. what was matched.

If you want to build a URI using one of those paths you can use the
base URI builder and then call "path" on that.

For former allows you to get instances of the matching resource
classes, thus if you know what they are you can start calling methods
on those if you wish. For example it should be possible using the
above to provider some sort of "breadcrumbs" view in a template (e.g.
JSP).

Paul.