In my current architecture, I have a JAX-RS resource that is behind:
/categories /categories/{catId}
which is implemented as follows:
@Path("/categories") @Produces("application/json") public class CategoryResourcesApi { @GET public Response getCategories() {
and another that serves:
/products /products/{prodId}
and has a similar implementation:
@Path("/products") @Produces("application/json") public class ProductResourcesApi { @GET public Response getProducts() {
Besides these simple paths, I also need to serve them:
/categories/{catId}/products /categories/{catId}/products/{prodId}
which will be products belonging to a certain category.
The most natural thing to do is to make ProductResourcesApi serve them, but by the way, I understand the structure of JAX-RS annotations, it can only be served by CategoryResourcesApi (or, ultimately, a third class, I think).
I use @Context and other annotations in my resource implementations, so the direct new ProductResourcesAPI().getProducts() does not work, I think.
Is there a way to forward one resource path to another within the framework of JAX-RS (or Jersey)? What other options do I have? I would like to keep all this easy, if possible convenient, so I selected one resource for each root path with sub-resources inside.