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]]
Sent: Wednesday, March 23, 2011 2:18 PM
To: [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