Hmm.  I'm going to have to do some more testing.  I believe I saw one test 
fail, but that was casually done.  I'll set up a semi-automated test.

From: Sergey Beryozkin [mailto:[email protected]]
Sent: Thursday, March 24, 2011 4:17 AM
To: KARR, DAVID (ATTSI)
Cc: [email protected]
Subject: Re: Possible to have controller handler method that matches if nothing 
else matches?

I've done a quick test, it works for me. Example, given

@Path("/bookstore")
public class BookStore {

    @Path{"{catch:.*}"}
    @GET
    public Book getDefaultBook() {}

    @Path{"/books/{id}"}
    @GET
    public Book getBook(@PathParam("id") Long id) {}

}

a query like '/bookstore/books//' gets handled by getDefaultBook().

What CXF version do you use ? It has to work, may be you have a stricter reg 
expression than is used in my test. ?

Cheers, Sergey
On Wed, Mar 23, 2011 at 9:53 PM, KARR, DAVID (ATTSI) 
<[email protected]<mailto:[email protected]>> wrote:
Hmm, on second thought this didn't work as perfectly as I thought.

It catches URLs that are really completely off, but if I specify a URL that 
simply omits path variables, it still gets a 404.

For instance, I specified "/junk" as my path info, and that matches this.  
However, if I specified a path info with something like "something//" instead 
of "something/param/", where I have a '@Path("something/{param}")', then it 
gets a 404.

From: Sergey Beryozkin 
[mailto:[email protected]<mailto:[email protected]>]
Sent: Wednesday, March 23, 2011 2:18 PM
To: [email protected]<mailto:[email protected]>
Cc: KARR, DAVID (ATTSI)
Subject: Re: Possible to have controller handler method that matches if nothing 
else matches?

Hi
On Wed, Mar 23, 2011 at 9:00 PM, KARR, DAVID (ATTSI) 
<[email protected]<mailto:[email protected]>> wrote:
I have a controller with a root "@Path()" annotation.  I have controller 
handler methods in that class with "@Path()" annotations.  If I supply a valid 
URL that matches the controller and one of the handler methods, it works fine.

If I supply a URL that matches at least the root Path for the controller, but 
not any of the handler methods, it understandably gets a 404 back.

Is there any way I can write a handler method, along with the all-important 
"@Path" annotation, which will match any request that isn't matched by any of 
the other handler methods?

CXF allows customizing the selection algorithm [1] but it might useful when 
several matching root resources or methods are available.

You might want to introduce a resource method with a Path value containing a 
regular expression, say:

@Path("{id:.*}")

This Path will capture everything but the method will be selected only if no 
other, more specific matches have been found. Give it a try please.

Cheers, Sergey




[1] 
http://cxf.apache.org/docs/jax-rs-basics.html#JAX-RSBasics-Customselectionbetweenmultipleresources



--
Sergey Beryozkin

Application Integration Division of Talend<http://www.talend.com>
http://sberyozkin.blogspot.com

Reply via email to