users@jersey.java.net

Re: How to get the path to the parent resource from UriBuilder

From: Martin Grotzke <martin.grotzke_at_javakaffee.de>
Date: Sat, 23 Feb 2008 12:21:56 +0100

On Fri, 2008-02-22 at 19:01 +0100, Paul Sandoz wrote:
> Martin Grotzke wrote:
> > Is there any documentation where I can look up the syntax of the
> > argument of path() (besides the source code :))?
> >
>
> What version of Jersey are you using? are you working from the trunk?
I have jersey-06-ea from 2/18/08, but I could build again from the
trunk.

>
> > I had a look in the jsr311 spec but didn't find s.th. relevant.
> >
>
> Have you looked at the JavaDoc?
>
> https://jsr311.dev.java.net/nonav/releases/0.6/index.html
Yes I had, but couldn't find a complete reference. Basically what I was
missing was the features of URI (normalize) that one can use here...

>
> the above corresponds to the 311 version currently in the Jersey trunk.
>
> Otherwise the following corresoinds to that of the 0.5 stable release:
>
> https://jsr311.dev.java.net/nonav/releases/0.5/index.html
>
> If you think things need clarifying just shout!
As you're providing such great help on this list I wouldn't dare to
shout :)

Until now everything I wanted to do was fairly easy to accomplish - and
especially the examples are an important and helpful thing for that.

Thanx && cheers,
Martin


>
> Paul.
>
> > Thanx a lot,
> > cheers,
> > Martin
> >
> >
> > On Fri, 2008-02-22 at 18:30 +0100, Paul Sandoz wrote:
> >> Hi Martin,
> >>
> >> If you know there is a parent child relationship then i think you could
> >> do this in the child resource:
> >>
> >> _uriInfo.getAbsolutePathBuilder().
> >> path("..").
> >> build().normalize().toString();
> >>
> >> There has been a request to the EG to have parent() method on the
> >> builder which would make it easier than normalizing.
> >>
> >> Paul.
> >>
> >> Martin Grotzke wrote:
> >>> Hi,
> >>>
> >>> is it possible to "navigate" to get the path to the parent resource from
> >>> UriBuilder?
> >>>
> >>> E.g. I have a resource with path "/parent/pId/child/cId" where pId is
> >>> the identifier of a "parent" resource and cId the id of "child". Then I
> >>> want to get "/parent/pId/child/" from UriBuilder. Is there any
> >>> possibility to achieve this? (Ok, I could cut off everything that
> >>> follows the last slash, but that doesn't feel good :))
> >>>
> >>> Right now I do the following, but this requires a lot of "knowledge"
> >>> about the context of a resource:
> >>>
> >>> _uriInfo.getBaseUriBuilder()
> >>> .path( ParentResource.class )
> >>> .path( "{p1}" )
> >>> .path( "child/" )
> >>> .build( "pId" ).toString()
> >>>
> >>> Thanx for your help,
> >>> cheers,
> >>> Martin
> >>>
> >>>
>