users@jsr311.java.net

Re: sub resource locators & generating urls

From: Stephan Koops <Stephan.Koops_at_web.de>
Date: Tue, 08 Jul 2008 09:55:19 +0200

Hi Jo,
> The best way to clear things up is probably to give a simple example.
> So i have a resource domain, and part of it is something like:
>
> /keywords/{keyword}/researchers
> /researchers/{id}/keywords
>
> with resources on all segments. Basically /keywords would list the
> keywords, /keywords/{keyword}/researchers would list the researchers
> tagged with the keyword (with urls to /researchers/1 etc.), and so on.
right.
> 1) If I wanted to have a Keywords and a Keyword class I can
> - use a sub resource locator, but then I have to give up all
> support for DI or 'pollute' the parent with the child's dependencies?
> - duplicate the path in the two classes?
>
> How should I model this effectively?
Yes, that is right. Dependencies are only injeced in classes
instantieated by the runtime. Marc answered a reason I think, but I
didn't know the reason yet. I also think it is useful to allow this
injection.
> 2) When I want to supply a representation of a researcher's keywords,
> I want to give out url's to them (after all, it's the web :)
>
> If I use sub resource locators, there is no way of doing this except
> hard coding the concatenated path elements (or something equivalent)
> in the representation rendering logic? Does this mean i'm stuck with
> not using sub resource locators?
>
> I am thinking that effective means of using the same mechanism for
> request mapping and url generation must be important for a rest api?
> But maybe it's to difficult or to early days?
You could get a UriInfo from the runtime in a resource method, if you
annotate it with @Context. Does this solve your issue?

BTW: you could join this mailing list to get all replies.

best regards
   Stephan