users@jsr311.java.net

Re: leading / in Path URI template

From: Marc Hadley <Marc.Hadley_at_Sun.COM>
Date: Fri, 30 May 2008 16:56:25 -0400

On May 30, 2008, at 4:32 PM, Bertold Kolics wrote:

> [ Excuse me if this has been asked before ]
>
> The JSR311 draft does not show any examples with the leading / in
> the URI template of Path annotations. Most of the samples in the
> Jersey codebase, however, have a leading / in the URI template.
>
> Does the leading slash in the path have any effect? If so, does it
> change how the path is computed when using a leading slash in sub
> resources?
>
A leading '/' has no effect. I discourage its use since all @Path
values are relative to either the application context (@Path on a
class) or the containing object path (@Path on a method). A leading
'/' might be taken to mean that the URI path is absolute which isn't
ever the case.

> For example,
> - is the URI template at line 9 valid?
Yes.

>
> - what should that resolve to if the base context of my application
> is http://example.com:8080/myrestapp? Should it resolve to http://example.com:8080/myrestapp/
> {id} or http://example.com:8080/myrestapp/widgets/{id}?

The latter. I think that is clearer without the leading '/'.

> Thanks for the clarification.
>
Thanks for bringing this up. I'll update the javadoc of @Path to make
this clearer.

Regards,
Marc.

>
>
> 1 @Path("widgets")
> 2 @ProduceMime("application/xml")
> 3 public class WidgetsResource {
> 4
> 5 @GET
> 6 public String getAll() {...}
> 7 8 @GET
> 9 @Path("/{id}")
> 10 public Widget getWidget(@UriParam("id") String id) {...}
> 11
> 12 @GET
> 13 @Path("{id}/description")
> 14 @ProduceMime("text/html")
> 15 public String getDescription(@UriParam("id") String id) {...}
> 16 }
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jsr311.dev.java.net
> For additional commands, e-mail: users-help_at_jsr311.dev.java.net
>

---
Marc Hadley <marc.hadley at sun.com>
CTO Office, Sun Microsystems.