views:

114

answers:

1

I'm writing a RESTful Java server with CXF framework.

How do I can write a @Path Regular Expression in order to obtain any URI finished in "/action" value?

+1  A: 

Not sure if its /action/*, /*/action, or /*/action/* you want?. Anyway here goes:

1) /action/* can be matched by

@Path("/action/{search:.*}")<br>
doStuff(@PathParam("search") List<PathSegment> list)

In this example, a request like GET /action/order/2/price will be served by the doStuff() method where list can be used to get to all the path segments in order/2/price captured by the regular expression.

2) /*/action can be matched by (WARNING untested)

@Path("/{search:.*}/action")
findStuff(@PathParam("search") List<PathSegment> list)

In this example, a request like GET /item/2/action will be served by the findStuff() method where list can be used to get to all the path segments in item/2 captured by the regular expression.

3) /*/action/* Here I believe you are out of luck (feel free to correct me if I am wrong), for further info check this blog post.

Lars Tackmann
It was the second case, sorry if the question is a little bit confusing.. I'm going to try it!
jaume