users@jersey.java.net

Re: Resources and subresources

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Fri, 30 Nov 2007 18:32:56 +0100

Richard Wallace wrote:
> Paul Sandoz wrote:
>> Hi Richard,
>>
>> Richard Wallace wrote:
>>> Ok, so I jumped the gun a little again. I was using 0.5-ea but I
>>> just updated to the latest trunk build and things are better. My
>>> getBookmark(@UriParam("uri") uri) is no longer getting the full path,
>>> it's getting just the parameter part.
>>>
>>
>> If you want to match the whole URI then you need to set the limited
>> parameter on the @Path to false.
>>
>> 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.

Eeek sorry to be the bringer of emotional turmoil...


> Thankfully, it
> seems you were mistaken.

Phew, my bad. I was stupidly assuming that the URI was not percent encoded.

Tip: if so desired (and if not already doing so but it still may be
useful for others to know about) you can use java.net.URI for the
@UriParam("uri"). If the URI constructor throws an exception a 400
response will be returned. You can use the primitive type int for the
@UriParam("comment-id").


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

Paul.

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