users@jersey.java.net

Re: [Jersey] Sub Resource Locator and container/item modeling

From: Marc Hadley <marc.hadley_at_oracle.com>
Date: Thu, 8 Apr 2010 11:39:41 -0400

The JAX-RS matching algorithm doesn't support mixing of sub-resource methods and locators with the same @Path value, the sub-resource locator is always ignored if there's a sub-resource method with the same @Path. See step 2.f in:

https://jsr311.dev.java.net/nonav/releases/1.1/spec/spec3.html#x3-360003.7.2

I need to think about the implications some more but your use-case could be accommodated by making a change to step 2.c to only add sub-resource method templates when the request method matches.

Could you add an issue in the jsr311.dev.java.net project so we can keep track of this issue and consider it for a subsequent version of JAX-RS.

Marc.

On Apr 8, 2010, at 9:37 AM, Magnus Eklund wrote:

> Hi
>
> First of all, thanks for an amazing product. It has transformed the way I design and build web applications.
>
> I am having a little problems achieving something that would simplify things further. I am trying to combine sub resource locators with HTTP methods.
>
> I'm supplying an exemple where i try to get ContainerResource to manage the access, creation and deletion of items and leave everything else to the ItemResource. This would simplify the code of ItemResource considerably (moving PUT and DELETE into the ItemResource forces me to call DB.lookup in all other methods...)
>
> The following example gives 504 for a GET to /someItemId (at least my real code similar to the example does). I realize that this is probably by design, but is there a way to achieve what I'm trying to do or would it make sense to support it?
>
> I'm using version 1.1.5.
>
> @Path("/")
> public class ContainerResource {
>
> @GET
> public Response getAllItems() {
> reurn new GenericType......
> }
>
> @Path("{itemId})
> public ItemResource item(@PathParam("itemId) final String itemId) {
>
> if (!authorized()) {
> throw new WebApplicationException(....);
> }
>
> try {
> return new ItemResource(DB.lookupItem(itemId));
> } catch (ItemNotFound e) {
> throw new WebApplicationException(.....);
> }
> }
>
> @PUT
> @Path("{itemId})
> public Response addItem(@PathParam("itemId") final String itemId) {
> DB.addItem(new Item(itemId))
> return Response.ok().build();
> }
>
> @DELETE
> @Path("{itemId})
> public Response deleteItem(@PathParam("itemId") final String itemId) {
> DB.deleteItem(itemId);
> return Response.ok().build();
> }
> }
>
> public class ItemResource {
>
> public ItemResource(final Item item) {
> this.item = item;
> }
>
> @GET
> @Produces(....)
> public Item get() {
> return item;
> }
>
> @Path
> public SomeOtherResource otherResource() {...}
> ....
> ....
> }
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>