users@jersey.java.net

Re: [Jersey] Access to a classes _at_Path

From: Chris Carrier <ctcarrier_at_gmail.com>
Date: Fri, 5 Mar 2010 13:11:16 -0800

OK this method that you suggested did exactly what I wanted:

URI personResource = uriInfo.getBaseUriBuilder()
  .path(PersonEndpoint.class)
  .path(PersonEndpoint.class, "retrieve")
  .build(personAddressMapping.getPersonId());

I would have thought that would be equivalent to:

URI personResource = uriInfo.getBaseUriBuilder()
  .path(PersonEndpoint.class, "retrieve")
  .build(personAddressMapping.getPersonId());

But the second one misses the URL extension. I'm happy with using
this for what I want but I'm curious why the first '.path' is
necessary.

Anyway thanks a lot that was a big help!

Chris


On Fri, Mar 5, 2010 at 12:47 PM, Marc Hadley <Marc.Hadley_at_sun.com> wrote:
> On Mar 5, 2010, at 3:12 PM, Moises Lejter wrote:
>
>> Hmm - I thought that
>>
>>> URI personResource = uriInfo.getBaseUriBuilder()
>>>  .path(PersonEndpoint.class, "retrieve")
>>
>> would end put building the combined path from PersonEndpoint
>> and the retrieve method within it...
> I can see why you might think the above would extract both the class level @Path and the method level @Path, and maybe that would be a good option, but currently they are separate as shown below.
>
>>   Are they separate (and your
>> example the right way to go) because PersonEndpoint could be
>> a (non-root) subresource?
>>
> The reason is that a root-resource can also be re-used as a subresource and in that case the URI built would be incorrect.
>
> Marc.
>
>>
>> On Mar 5, 2010, at 2:05 PM, Marc Hadley wrote:
>>
>>> If you want to build an absolute URI the best way is to start from UriInfo like this:
>>>
>>> @Context UriInfo uriInfo;
>>>
>>> URI personResource = uriInfo.getBaseUriBuilder()
>>>  .path(PersonEndpoint.class)
>>>  .path(PersonEndpoint.class, "retrieve")
>>>  .build(personAddressMapping.getPersonId());
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>
>