Router: 'not matched' versus 'not found'

classic Classic list List threaded Threaded
14 messages Options
Reply | Threaded
Open this post in threaded view
|

Router: 'not matched' versus 'not found'

Bruno Dumon
Hi,

I have a situation where it would be very useful if a router (a normal
Restlet Router or the routing part of JAX-RS) could tell in its response
whether there was a matching route.

An example to clarify: I would like all requests to be handled by
JAX-RS, and if there's no resource class to handle the request, move on
to another router to handle the request. (it's not possible to decide on
beforehand to what router to go, nor is the caller aware of what
resources are available within each router)

This is currently not possible, since what JAX-RS (or the normal Restlet
router) does when there's no matching resource class or matching route
is setting the response to 404. This is ok, but it doesn't allow to make
the distinction between "no matching route" or "a route matched, but the
addressed resource was not found".

Any suggestions?

Would this be something that could be considered for inclusion in
Restlet? The solution I'm thinking of is that restlets which perform
routing (= Router, JaxRsRestlet, possibly others) could set a special
response attribute to indicate there was no matching route.

--
Bruno Dumon                             http://outerthought.org/
Outerthought                            http://www.daisycms.org/
[hidden email]              http://www.kauriproject.org/

Reply | Threaded
Open this post in threaded view
|

Re: Router: 'not matched' versus 'not found'

Thierry Boileau
Hello Bruno,

I wonder if the Router#attachDefault can serve your purpose. The attached Resource or Restlet is invoked when no route matches.

Best regards,
Thierry Boileau
--
Restlet ~ Core developer ~ http://www.restlet.org
Noelios Technologies ~ Co-founder ~ http://www.noelios.com


Hi,

I have a situation where it would be very useful if a router (a normal
Restlet Router or the routing part of JAX-RS) could tell in its response
whether there was a matching route.

An example to clarify: I would like all requests to be handled by
JAX-RS, and if there's no resource class to handle the request, move on
to another router to handle the request. (it's not possible to decide on
beforehand to what router to go, nor is the caller aware of what
resources are available within each router)

This is currently not possible, since what JAX-RS (or the normal Restlet
router) does when there's no matching resource class or matching route
is setting the response to 404. This is ok, but it doesn't allow to make
the distinction between "no matching route" or "a route matched, but the
addressed resource was not found".

Any suggestions?

Would this be something that could be considered for inclusion in
Restlet? The solution I'm thinking of is that restlets which perform
routing (= Router, JaxRsRestlet, possibly others) could set a special
response attribute to indicate there was no matching route.

  
Reply | Threaded
Open this post in threaded view
|

Re: Router: 'not matched' versus 'not found'

Bruno Dumon
Hi Thierry,

I had not thought of attachDefault, but I do not think it will be a
satisfying solution for my problem.

My earlier problem description was a bit dense, I have meanwhile created
an issue where a concrete example is given (as well as a
patch-suggestion):
http://restlet.tigris.org/issues/show_bug.cgi?id=644

If it needs more clarification, just let me know.

On Thu, 2008-11-06 at 16:20 +0100, Thierry Boileau wrote:

> Hello Bruno,
>
> I wonder if the Router#attachDefault can serve your purpose. The
> attached Resource or Restlet is invoked when no route matches.
>
> Best regards,
> Thierry Boileau
> --
> Restlet ~ Core developer ~ http://www.restlet.org
> Noelios Technologies ~ Co-founder ~ http://www.noelios.com
>
> > Hi,
> >
> > I have a situation where it would be very useful if a router (a normal
> > Restlet Router or the routing part of JAX-RS) could tell in its response
> > whether there was a matching route.
> >
> > An example to clarify: I would like all requests to be handled by
> > JAX-RS, and if there's no resource class to handle the request, move on
> > to another router to handle the request. (it's not possible to decide on
> > beforehand to what router to go, nor is the caller aware of what
> > resources are available within each router)
> >
> > This is currently not possible, since what JAX-RS (or the normal Restlet
> > router) does when there's no matching resource class or matching route
> > is setting the response to 404. This is ok, but it doesn't allow to make
> > the distinction between "no matching route" or "a route matched, but the
> > addressed resource was not found".
> >
> > Any suggestions?
> >
> > Would this be something that could be considered for inclusion in
> > Restlet? The solution I'm thinking of is that restlets which perform
> > routing (= Router, JaxRsRestlet, possibly others) could set a special
> > response attribute to indicate there was no matching route.
> >
> >  

Reply | Threaded
Open this post in threaded view
|

Re: Router: 'not matched' versus 'not found'

StephanKoo
In reply to this post by Bruno Dumon
Hi Bruno,

I planned a possibility of JAX-RS for this, but I had no time to
implement it.
I will put it higher in my priority list.

best regards
   Stephan

Bruno Dumon schrieb:

> Hi,
>
> I have a situation where it would be very useful if a router (a normal
> Restlet Router or the routing part of JAX-RS) could tell in its response
> whether there was a matching route.
>
> An example to clarify: I would like all requests to be handled by
> JAX-RS, and if there's no resource class to handle the request, move on
> to another router to handle the request. (it's not possible to decide on
> beforehand to what router to go, nor is the caller aware of what
> resources are available within each router)
>
> This is currently not possible, since what JAX-RS (or the normal Restlet
> router) does when there's no matching resource class or matching route
> is setting the response to 404. This is ok, but it doesn't allow to make
> the distinction between "no matching route" or "a route matched, but the
> addressed resource was not found".
>
> Any suggestions?
>
> Would this be something that could be considered for inclusion in
> Restlet? The solution I'm thinking of is that restlets which perform
> routing (= Router, JaxRsRestlet, possibly others) could set a special
> response attribute to indicate there was no matching route.
>
>  
Reply | Threaded
Open this post in threaded view
|

Re: Router: 'not matched' versus 'not found'

Bruno Dumon
On Fri, 2008-11-07 at 10:06 +0100, Stephan Koops wrote:
> Hi Bruno,
>
> I planned a possibility of JAX-RS for this, but I had no time to
> implement it.
> I will put it higher in my priority list.
>

Cool.

I have just tried if I can do everything I need by some customization
(via subclassing). It works and it is a clean solution.

The only change I need in JaxRsRestlet is the ability to provide a
custom ExceptionHandler. I can then override the methods like
rootResourceNotFound() and set a flag in a response attribute.

I've attached a patch for this small change. I've added a method which
can be overridden using subclassing, just to avoid adding a public
method, but I'm fine with either approach. Do you think this is an
acceptable change?

--
Bruno Dumon                             http://outerthought.org/
Outerthought                            http://www.daisycms.org/
[hidden email]              http://www.kauriproject.org/

jaxrs-custom-exceptionhandler.txt (1K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

RE: Router: 'not matched' versus 'not found'

jlouvel
Administrator

Hi Bruno,

Sounds good to me. I would just suggest naming the method
"createExceptionHandler()". Stephan, any opinion on this change?

Otherwise, this should only go into SVN trunk as we can't modify the Restlet
API in the 1.1 branch. I hope that this won't be too big a burden in your
case.

Best regards,
Jérôme Louvel
--
Restlet ~ Founder and Lead developer ~ http://www.restlet.org
Noelios Technologies ~ Co-founder ~ http://www.noelios.com


-----Message d'origine-----
De : Bruno Dumon [mailto:[hidden email]]
Envoyé : vendredi 7 novembre 2008 11:58
À : [hidden email]
Objet : Re: Router: 'not matched' versus 'not found'

On Fri, 2008-11-07 at 10:06 +0100, Stephan Koops wrote:
> Hi Bruno,
>
> I planned a possibility of JAX-RS for this, but I had no time to
> implement it.
> I will put it higher in my priority list.
>

Cool.

I have just tried if I can do everything I need by some customization
(via subclassing). It works and it is a clean solution.

The only change I need in JaxRsRestlet is the ability to provide a
custom ExceptionHandler. I can then override the methods like
rootResourceNotFound() and set a flag in a response attribute.

I've attached a patch for this small change. I've added a method which
can be overridden using subclassing, just to avoid adding a public
method, but I'm fine with either approach. Do you think this is an
acceptable change?

--
Bruno Dumon                             http://outerthought.org/
Outerthought                            http://www.daisycms.org/
[hidden email]              http://www.kauriproject.org/

Reply | Threaded
Open this post in threaded view
|

Re: Router: 'not matched' versus 'not found'

StephanKoo
Hi Bruno,

I looked into the org.restlet.Router. I think the method
attachDefault(Restlet) does exact what you want for the Router, right?
I could also implement this for the JaxRsRouter. This is very easy to
implement and analogue to Router.

best regards
   Stephan

Jerome Louvel schrieb:

> Hi Bruno,
>
> Sounds good to me. I would just suggest naming the method
> "createExceptionHandler()". Stephan, any opinion on this change?
>
> Otherwise, this should only go into SVN trunk as we can't modify the Restlet
> API in the 1.1 branch. I hope that this won't be too big a burden in your
> case.
>
> Best regards,
> Jérôme Louvel
>
> -----Message d'origine-----
> De : Bruno Dumon [mailto:[hidden email]]
> Envoyé : vendredi 7 novembre 2008 11:58
> À : [hidden email]
> Objet : Re: Router: 'not matched' versus 'not found'
>
> On Fri, 2008-11-07 at 10:06 +0100, Stephan Koops wrote:
>  
>> Hi Bruno,
>>
>> I planned a possibility of JAX-RS for this, but I had no time to
>> implement it.
>> I will put it higher in my priority list.
>>    
> Cool.
>
> I have just tried if I can do everything I need by some customization
> (via subclassing). It works and it is a clean solution.
>
> The only change I need in JaxRsRestlet is the ability to provide a
> custom ExceptionHandler. I can then override the methods like
> rootResourceNotFound() and set a flag in a response attribute.
>
> I've attached a patch for this small change. I've added a method which
> can be overridden using subclassing, just to avoid adding a public
> method, but I'm fine with either approach. Do you think this is an
> acceptable change?
Reply | Threaded
Open this post in threaded view
|

Re: Router: 'not matched' versus 'not found'

Bruno Dumon
Hi Stephan,

On Mon, 2008-11-10 at 20:29 +0100, Stephan Koops wrote:
> Hi Bruno,
>
> I looked into the org.restlet.Router. I think the method
> attachDefault(Restlet) does exact what you want for the Router, right?
> I could also implement this for the JaxRsRouter. This is very easy to
> implement and analogue to Router.
>

Thierry suggested this earlier. I then thought it wouldn't help, but
thinking about it again, I don't see why not. So yes, this would solve
my problem. It would be very helpful if you could implement it.

--
Bruno Dumon                             http://outerthought.org/
Outerthought                            http://www.daisycms.org/
[hidden email]              http://www.kauriproject.org/

Reply | Threaded
Open this post in threaded view
|

Re: Router: 'not matched' versus 'not found'

StephanKoo
In reply to this post by Bruno Dumon
Hi Bruno,

ok, I will do it. This should be very easy.

best regards
   Stephan

> -----Ursprüngliche Nachricht-----
> Von: "Bruno Dumon" <[hidden email]>
> Gesendet: 13.11.08 11:44:14
> An: [hidden email]
> Betreff: Re: Router: 'not matched' versus 'not found'
>
> Hi Stephan,
>
> On Mon, 2008-11-10 at 20:29 +0100, Stephan Koops wrote:
> > Hi Bruno,
> >
> > I looked into the org.restlet.Router. I think the method
> > attachDefault(Restlet) does exact what you want for the Router, right?
> > I could also implement this for the JaxRsRouter. This is very easy to
> > implement and analogue to Router.
> >
>
> Thierry suggested this earlier. I then thought it wouldn't help, but
> thinking about it again, I don't see why not. So yes, this would solve
> my problem. It would be very helpful if you could implement it.
>
> --
> Bruno Dumon                             http://outerthought.org/
> Outerthought                            http://www.daisycms.org/
> [hidden email]              http://www.kauriproject.org/
>
>


________________________________________________________________________
Sensationsangebot nur bis 30.11: WEB.DE FreeDSL - Telefonanschluss + DSL
für nur 16,37 ¿/mtl.!* http://dsl.web.de/?ac=OM.AD.AD008K13805B7069a

Reply | Threaded
Open this post in threaded view
|

Re: Router: 'not matched' versus 'not found'

StephanKoo
In reply to this post by Bruno Dumon
Hi Bruno,

I've just implemented a method JaxRsRetlet.attachDefault(Restlet). It is
available in the trunk now. Please test it and let me now, if it works.
The attached Restlet should get the same Reference value etc. as you
give in the JaxRsRestlet.
So your patch for the ExceptionHandler is outdated, right?

best regards
   Stephan

Bruno Dumon schrieb:

>> Hi Bruno,
>>
>> I looked into the org.restlet.Router. I think the method
>> attachDefault(Restlet) does exact what you want for the Router, right?
>> I could also implement this for the JaxRsRouter. This is very easy to
>> implement and analogue to Router.
>>    
> Thierry suggested this earlier. I then thought it wouldn't help, but
> thinking about it again, I don't see why not. So yes, this would solve
> my problem. It would be very helpful if you could implement it.
Reply | Threaded
Open this post in threaded view
|

Re: Router: 'not matched' versus 'not found'

Bruno Dumon
Hi Stephan,

Great work. I've tested it, it works fine and fits my needs.

One comment though: I see the default route is only used when a root
resource is not found, not when a sub resource is not found. But from my
point of view, I'm only interested in whether there is some resource
which can handle the requested URI, I don't care if it is the root or
sub resource which is missing. IIUC, everything which can be done with
sub resources can also be done with root resources, so it seems like an
implementation detail to me. So I would call the default route in both
cases. What do you think?

The ExceptionHandler patch is indeed outdated now.

On Fri, 2008-11-14 at 01:31 +0100, Stephan Koops wrote:

> Hi Bruno,
>
> I've just implemented a method JaxRsRetlet.attachDefault(Restlet). It is
> available in the trunk now. Please test it and let me now, if it works.
> The attached Restlet should get the same Reference value etc. as you
> give in the JaxRsRestlet.
> So your patch for the ExceptionHandler is outdated, right?
>
> best regards
>    Stephan
>
> Bruno Dumon schrieb:
> >> Hi Bruno,
> >>
> >> I looked into the org.restlet.Router. I think the method
> >> attachDefault(Restlet) does exact what you want for the Router, right?
> >> I could also implement this for the JaxRsRouter. This is very easy to
> >> implement and analogue to Router.
> >>    
> > Thierry suggested this earlier. I then thought it wouldn't help, but
> > thinking about it again, I don't see why not. So yes, this would solve
> > my problem. It would be very helpful if you could implement it.

--
Bruno Dumon                             http://outerthought.org/
Outerthought                            http://www.daisycms.org/
[hidden email]              http://www.kauriproject.org/

Reply | Threaded
Open this post in threaded view
|

Re: Router: 'not matched' versus 'not found'

StephanKoo
Hi Bruno,
> Great work. I've tested it, it works fine and fits my needs.
>  
Fine.
> One comment though: I see the default route is only used when a root
> resource is not found, not when a sub resource is not found. But from my
> point of view, I'm only interested in whether there is some resource
> which can handle the requested URI, I don't care if it is the root or
> sub resource which is missing. IIUC, everything which can be done with
> sub resources can also be done with root resources, so it seems like an
> implementation detail to me. So I would call the default route in both
> cases. What do you think?
>  
The JaxRsRouter has now the same behaviour as in the org.restlet.Router.
If this Router finds a Route ("root resource class") and gave it the
request, but the reached Restlet could not forward the request (no "sub
resource class"), than the defaultRestlet will not catch this error.
In older versions I gave the possibility for such cases. Should I
reimplement it?

best regards
   Stephan
>> I've just implemented a method JaxRsRetlet.attachDefault(Restlet). It is
>> available in the trunk now. Please test it and let me now, if it works.
>> The attached Restlet should get the same Reference value etc. as you
>> give in the JaxRsRestlet.
>>    
Reply | Threaded
Open this post in threaded view
|

Re: Router: 'not matched' versus 'not found'

Bruno Dumon
On Fri, 2008-11-14 at 21:06 +0100, Stephan Koops wrote:

> Hi Bruno,
> > Great work. I've tested it, it works fine and fits my needs.
> >  
> Fine.
> > One comment though: I see the default route is only used when a root
> > resource is not found, not when a sub resource is not found. But from my
> > point of view, I'm only interested in whether there is some resource
> > which can handle the requested URI, I don't care if it is the root or
> > sub resource which is missing. IIUC, everything which can be done with
> > sub resources can also be done with root resources, so it seems like an
> > implementation detail to me. So I would call the default route in both
> > cases. What do you think?
> >  
> The JaxRsRouter has now the same behaviour as in the org.restlet.Router.
> If this Router finds a Route ("root resource class") and gave it the
> request, but the reached Restlet could not forward the request (no "sub
> resource class"), than the defaultRestlet will not catch this error.
> In older versions I gave the possibility for such cases. Should I
> reimplement it?

Yes, I'd like that.

IMO the situation can't be easily compared with org.restlet.Router, as
that one has no knowledge of the internal behavior of the attached
Restlet's (nor does it say anything about what kinds of restlets can be
attached), while the JAX-RS system defines and controls the complete
routing up to potential sub-resources.

--
Bruno Dumon                             http://outerthought.org/
Outerthought                            http://www.daisycms.org/
[hidden email]              http://www.kauriproject.org/

Reply | Threaded
Open this post in threaded view
|

Re: Router: 'not matched' versus 'not found'

StephanKoo
Hi Bruno,

now a Restlet given with JaxRsRestlet.attachDefault(Restlet) handles all requests, where no root resource class, no resource class or no resource method is found.
To give different Restlet for this cases there are some methods JaxRsRestlet.setNo*handler(Restlet).

best regards
   Stephan
The JaxRsRouter has now the same behaviour as in the org.restlet.Router. 
If this Router finds a Route ("root resource class") and gave it the 
request, but the reached Restlet could not forward the request (no "sub 
resource class"), than the defaultRestlet will not catch this error.
In older versions I gave the possibility for such cases. Should I 
reimplement it?
    
Yes, I'd like that.

IMO the situation can't be easily compared with org.restlet.Router, as
that one has no knowledge of the internal behavior of the attached
Restlet's (nor does it say anything about what kinds of restlets can be
attached), while the JAX-RS system defines and controls the complete
routing up to potential sub-resources.