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. Moreover I don't think it's typical when new instance is created in getItemContentResource method.
As I correctly understand Sub-resource locators are mainly useful for Container->Item relationship, e.g. :
@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() { ... }
}