Hi Simon

thanks for the confirmation.

@Path("/users/{name}/")
 User getUser(@PathParam("name") String name) {
  return this.userList.get(name);
 }

with User having two methods

@XmlRootElement
public class User {
   @GET
   public User get() {return this;}

   @GET
   @Path("/comment/{id}")
   public Comment getComment(@PathParam("id") int id) {return
comments.get(id)};

}

should also work, and this approach can be applied recursively

Cheers, Sergey

On Fri, Apr 15, 2011 at 5:14 PM, Simon Chen <[email protected]> wrote:

> Hi all,
>
> I got some off-line help from Sergey. The trick is to have two methods:
>
>  @GET
>  @Path("/users/{name}/")
>  User getUser(@PathParam("name") String name) {
>   return this.userList.get(name);
>  }
>
>  @Path("/users/{name}/")
>  User getUserAsSub(@PathParam("name") String name) {
>    return this.userList.get(name);
>  }
>
> Basically the first one would allow GET User objects, and the second
> method would allow delegation into whatever methods "User" class would
> provide.
>
> Thanks, Sergey!
>
> -Simon
>
> On Fri, Apr 15, 2011 at 4:56 AM, Sergey Beryozkin <[email protected]>
> wrote:
> > Hi Simon
> >
> > On Thu, Apr 14, 2011 at 11:02 PM, Simon Chen <[email protected]>
> wrote:
> >>
> >> Hi all,
> >>
> >> I have some trouble putting a somewhat nested set of paths working in
> >> jax-rs...
> >>
> >> The idea is that we have:
> >>
> >> @Path("/webstore/")
> >> class WebStore {
> >>
> >>  @Path("/users/{name}/")
> >>  User getUser(@PathParam("name") String name) {
> >>    return this.userList.get(name);
> >>  }
> >> }
> >>
> >> With this, I can get "/webstore/users/some_one" to retrieve a
> >> particular user called "some_one".
> >>
> >> But let's say I also have:
> >>
> >> class User {
> >>  @Path("/comments/{id}")
> >>  Comment getComment(@PathParam("id") String id) {
> >>    return this.commentList.get(id);
> >>  }
> >> }
> >>
> >> What I want is to be able to get
> >> "/webstore/users/some_one/comments/c_100/", where "some_one" is the
> >> user ID and "c_100" is the comment ID.
> >>
> >
> > OK
> >
> >>
> >> I don't think this is working however I change the way I annotate
> >> "User" class. Is it possible?
> >>
> > That really has to work. What exactly is not working ?
> > 'User' acts as a subresource, the question is, but 'Comment' also acts as
> a
> > subresource, because
> > getComment() has no @GET.
> >
> > If Comment is the final bean that has to be returned then add @GET to
> > getComment(). Or, alternatively, have a Comment method which returns the
> > actual content annotated with @GET
> >
> > Hope it helps
> > Sergey
> >
> >
> >>
> >> Thanks!
> >> -Simon
> >
> >
> >
> > --
> > Sergey Beryozkin
> >
> > Application Integration Division of Talend
> > http://sberyozkin.blogspot.com
> >
>



-- 
Sergey Beryozkin

Application Integration Division of Talend <http://www.talend.com>
http://sberyozkin.blogspot.com

Reply via email to