views:

93

answers:

1

I'm writing a RESTful Web Service with RESTeasy. This is an implementation of JAX-RS. You annotate a class or method with a single @Path annotation. Regular expressions are used to get path parameters. For instance

@Path("/foo{varname:.*}/bar")

matches all patterns starting with "/foo", ending with "/bar" and having anything in between. Whatever is in between is assigned to a parameter named varname.

Some frameworks (like Django) have a list of regular expressions and methods that will be tried in order. For instance /john/q/smith, /john/{.*}/smith, /john/{.*}/{.*}. "/john/henry/smith" matches the second and third, but the second one will be dispatched because it is the first match found.

Is this possible in JAX-RS, or is there no inherent order to the classes and methods? For /john/{.*}/{.*} would you have to write a regex that means /john/anything/anythingbutsmith? You would have to change it every time you changed the other ones.

+1  A: 

There is a well defined algorithm, section 3.7.1 of the JAX-RS spec describes it. Frankly, I find the explanation pretty opaque - so reading it, I can't answer your question.

However, I've just found the CXF overview of the selection alogorithm, and that seems to indicate that the precedence rules do indeed let you do what you want.

djna