You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by "KARR, DAVID (ATTSI)" <dk...@att.com> on 2011/03/23 22:00:34 UTC

Possible to have controller handler method that matches if nothing else matches?

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?

RE: Possible to have controller handler method that matches if nothing else matches?

Posted by "KARR, DAVID (ATTSI)" <dk...@att.com>.
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:sberyozkin@gmail.com]
Sent: Thursday, March 24, 2011 4:17 AM
To: KARR, DAVID (ATTSI)
Cc: users@cxf.apache.org
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) <dk...@att.com>> 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:sberyozkin@gmail.com<ma...@gmail.com>]
Sent: Wednesday, March 23, 2011 2:18 PM
To: users@cxf.apache.org<ma...@cxf.apache.org>
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) <dk...@att.com>> 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

Re: Possible to have controller handler method that matches if nothing else matches?

Posted by Sergey Beryozkin <sb...@gmail.com>.
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) <dk...@att.com> 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:sberyozkin@gmail.com]
> *Sent:* Wednesday, March 23, 2011 2:18 PM
> *To:* users@cxf.apache.org
> *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) <dk...@att.com>
> 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

RE: Possible to have controller handler method that matches if nothing else matches?

Posted by "KARR, DAVID (ATTSI)" <dk...@att.com>.
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:sberyozkin@gmail.com]
Sent: Wednesday, March 23, 2011 2:18 PM
To: users@cxf.apache.org
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) <dk...@att.com>> 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

Re: Possible to have controller handler method that matches if nothing else matches?

Posted by Sergey Beryozkin <sb...@gmail.com>.
Some information is here, but I'll add another example and some
clarifications

http://cxf.apache.org/docs/jax-rs-basics.html#JAX-RSBasics-Overviewoftheselectionalgorithm
.

Cheers, Sergey

On Wed, Mar 23, 2011 at 9:29 PM, KARR, DAVID (ATTSI) <dk...@att.com> wrote:

>  Bingo, works perfectly.  Is that mechanism described in the wiki?  I
> don’t see it. I think I remember seeing this in the JAX-RS spec, but I
> noticed at one time that I couldn’t find some of the features described in
> the spec in the CXF wiki.
>
>
>
> *From:* Sergey Beryozkin [mailto:sberyozkin@gmail.com]
> *Sent:* Wednesday, March 23, 2011 2:18 PM
> *To:* users@cxf.apache.org
> *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) <dk...@att.com>
> 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
>

RE: Possible to have controller handler method that matches if nothing else matches?

Posted by "KARR, DAVID (ATTSI)" <dk...@att.com>.
Bingo, works perfectly.  Is that mechanism described in the wiki?  I don't see it. I think I remember seeing this in the JAX-RS spec, but I noticed at one time that I couldn't find some of the features described in the spec in the CXF wiki.

From: Sergey Beryozkin [mailto:sberyozkin@gmail.com]
Sent: Wednesday, March 23, 2011 2:18 PM
To: users@cxf.apache.org
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) <dk...@att.com>> 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

Re: Possible to have controller handler method that matches if nothing else matches?

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi
On Wed, Mar 23, 2011 at 9:00 PM, KARR, DAVID (ATTSI) <dk...@att.com> 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