users@jersey.java.net

Re: [Jersey] Sub-Resource Locators

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Wed, 23 Sep 2009 20:55:43 +0200

On Sep 11, 2009, at 2:27 PM, mkuchtiak wrote:

> Hello,
>
> In the Jersey documentation:
> https://jersey.dev.java.net/nonav/documentation/1.1.2-ea/user-guide.html
>
> Example 1.22 Sub-resource locators, there is a skeleton example
>
> @Path("/item")
> public class ItemResource {
> @Context UriInfo uriInfo;
> @Path("content")
> public ItemContentResource getItemContentResource() {
> return new ItemContentResource();
> }
> @GET
> @Produces("application/xml")
> public Item get() { ... }
> }
>
> public class ItemContentResource {
> @GET
> public Response get() { ... }
> @PUT
> @Path("{version}")
> public void put(
> @PathParam("version") int version,
> @Context HttpHeaders headers,
> byte[] in) { ... }
> }
>
> I consider this a little confusing and not very realistic.

It is extracted from a sample from Jersey that shows how one can
support optimistic concurrency:

   http://download.java.net/maven/2/com/sun/jersey/samples/optimistic-concurrency/1.1.2-ea/optimistic-concurrency-1.1.2-ea-project.zip


> Moreover I don't think it's typical when new instance is created in
> getItemContentResource method.
>

Why? in my experience, especially when using the per-request life-
cycle (which is the default) it is very common to return a new instance.


> As I correctly understand Sub-resource locators are mainly useful
> for Container->Item relationship, e.g. :

They are useful for a wide range of hierarchical relationships,
container->item being a very common relationship but by no means the
only one.

I think we can address the issue you raise by providing a common case
of the container->item pattern. Could you log an issue?

Thanks,
Paul.

> @Path("/container")
> public class ContainerResource { @Path("{item}")
> public ItemResource findItemResource("@PathParam("item") Integer
> id) {
> return findItem(id);
> }
> @GET
> @Produces("application/xml")
> public List<Item> get() { ... }
>
> @POST
> @Consumes("application/xml")
> public void post(Item item) { ... }
>
> private ItemResource findItem(Integer id) { ... }
> }
> public class ItemResource {
> @GET
> @Produces("application/xml")
> public Item get() { ... }
>
> @PUT
> @Consumes("text/plain")
> public void put(String itemContent) { ... }
>
> @DELETE
> public void delete() { ... }
>
> }
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>