users@jersey.java.net

Re: Resources and subresources

From: Marc Hadley <Marc.Hadley_at_Sun.COM>
Date: Fri, 30 Nov 2007 12:27:37 -0500

On Nov 30, 2007, at 12:19 PM, Richard Wallace wrote:
>>
>> You cannot have a template like the following:
>>
>> @Path("/bookmarks/{uri}/comments/{comment-id}"
>>
>> if {uri} should be the bookmark URI because you never know the
>> termination of that URI.
>>
>
> When I saw this I can't tell you how disappointed I was.
> Thankfully, it seems you were mistaken. I just tried it and it
> works perfectly. I created two more resources as follows
>
> @Path("/bookmarks/{uri}/comments")
> public class CommentsResource { ... }
>
> and
>
> @Path("/bookmarks/{uri}/comments/{comment-id}")
> public class CommentResource { ... }
>
> When I hit
>
> http://localhost:8080/jersey-spike-webapp/api/bookmarks/http%3A%2F%2Fwww.google.com/comments
>
> it goes to my CommentsResource as I expected. When I hit
>
> http://localhost:8080/jersey-spike-webapp/api/bookmarks/http%3A%2F%2Fwww.google.com/comments/0
>
> it goes to my CommentResource and passes http://google.com as the
> value for the @UriParam("uri") parameter and 0 as the value for the
> @UriParam("comment-id") parameter.
>
Right, it should work provided the value of the uri variable is
encoded in the URI as shown above.

> I think this is the last major hurdle I had to overcome. I think I
> am going to move forward with using Jersey on my new project.

Great :-).

Marc.

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