users@jersey.java.net

Re: One Resource class for two URLs

From: Martin Probst <mail_at_martin-probst.com>
Date: Tue, 22 Apr 2008 08:16:35 +0200

Hi,

> @Path("/")
> public class SomeResource {
> [...]

Thanks, this might work. Though I'll have to try and see how this
works with implicit views and the implicit trailing part of the
request, i.e. if /books/ maps to a class Books, /books/new will render
the new.jsp (for example).

> although I would not recommend that approach. Think a bit about how
> your resource are going to be used - i.e:
>
> 1) Get all books: /books/
> 2) From the list of books show detailed info about a particular
> one: /books/42

Is there a way do discriminate between the /books/42 usage and a /
books/new URL? Is there some kind of order in processing or a way to
further specify the URL patterns, e.g. by regexp?

Another way might be returning this on some matching part, e.g.:

@Path("/")
class Books {
   @Path("books") getBooks() { return this; }
   @Path("book/{id}") getBook(long id) { ... }
}

I'll have to try this out.

Regards,
Martin