users@jersey.java.net

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

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Fri, 22 Feb 2008 19:01:01 +0100

Martin Grotzke wrote:
> Really great, thanx!
>
> 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 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

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!

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
>>>
>>>

-- 
| ? + ? = To question
----------------\
    Paul Sandoz
         x38109
+33-4-76188109