Hi Vincent,

I've just checkins the proposed changes to StatusFilter. 

1) StatusFilter now catches Errors in addition to Exceptions.

2) Added create*() methods on ApplicationHelper and ContainerHelper to allow
you to provide a subclass of StatusFilter and LogFilter. 

Checked in SVN. New snapshot available too.

Best regards,
Jerome  

> -----Message d'origine-----
> De : Jerome Louvel [mailto:[EMAIL PROTECTED] 
> Envoyé : samedi 28 octobre 2006 12:14
> À : [email protected]
> Objet : RE: Filter questions
> 
> 
> Hi Vincent, 
> 
> You encountered the bug with filter that was just fixed in the latest 
> snapshot. Please try it. 
> Also, I'll modify the default StatusFilter to also catch 
> Throwable and think 
> about a way to let you plug a custom StatusFilter. 
> 
> Best regards, 
> Jerome  
> 
> > -----Message d'origine----- 
> > De : news [mailto:[EMAIL PROTECTED] De la part de Vincent 
> > Envoyé : vendredi 27 octobre 2006 20:03 
> > À : [email protected] 
> > Objet : Filter questions 
> > 
> > Hi everybody, 
> > 
> > The (rather long) discussion I had on htis forum with some of 
> > you convinced me 
> > to give restlet a try and see if it'd be a good fit for our 
> > next project. 
> > I've been playing with the framework for a few days now and I 
> > hit my first snag. 
> > 
> > Here it goes: 
> > 
> > My initial configuration is: 
> > 
> > (filter1) ------- <router> ----- [handler1] 
> >                      | 
> >                      |---------- [handler2] 
> > 
> > 
> > Now, when a handler throws an Error, it is not caught because 
> > StatusFilter.doHandle only catches Exceptions. 
> > The second problem is that the call to the error-throwing 
> > handler never returns. 
> > 
> > 
> > So I decided to add a second filter, that has pretty much the 
> > same behavior as 
> > Status Filter, except that it catches Throwable. 
> > Here is the new configuration (see below for the code): 
> > 
> > 
> > (filter1) ------- (filter2) ------- <router> ----- [handler1] 
> >                                        | 
> >                                        |---------- [handler2] 
> > 
> > But much to my surprise, filter2.doHandle is never executed 
> (although 
> > filter2.beforeHandle gets executed). 
> > 
> > 
> > So, here are my questions: 
> > 
> > 1- how come filter2.doHandle is not executed? 
> >    Does it have something to do with scorers and the fact 
> > that filter2 does not 
> > score high enough? 
> >    I must admit I don't get this scoring thing. If somebody 
> > could shed some 
> > light, that'd be great. 
> > 
> > 2- How do I subclass StatusFilter to change its behaviour? 
> > I.e how do I make 
> > ApplicationHelper.start instanciate my StatusHelper class? 
> > 
> > 
> > Thanks, 
> > 
> > -Vincent. 
> > 
> > PS: I'm testing with the Simple web server. 
> > 
> >  
> > -------------------------------------------------------------- 
> > -------------------------------- 
> > import org.restlet.*; 
> > import org.restlet.data.*; 
> > 
> > public class Test { 
> >   public static void main(String[] args) 
> >   { 
> >     Container container = new Container(); 
> >     container.getServers().add(Protocol.HTTP, 8182); 
> > 
> >     Application application = new Application(container) 
> >     { 
> >       public Restlet createRoot() 
> >       { 
> >         // first filter 
> >         Filter filter1 = new Filter(getContext()){ 
> >           public void beforeHandle(Request request, Response 
> > response){ 
> >             System.out.println("In filter1.beforeHandle"); 
> >           } 
> >         }; 
> > 
> >         // second filter - chain it to the first filter 
> >         Filter filter2  = new Filter(getContext()){ 
> >           public void beforeHandle(Request request, Response 
> > response){ 
> >             System.out.println("In filter2.beforeHandle");// 
> > This method gets 
> > executed 
> >           } 
> >           public void dohandle(Request request, Response response){ 
> >             try{ 
> >               System.out.println("in filter2.doHandle"); // 
> > How come we never 
> > execute this? 
> >               super.doHandle(request, response); 
> >             } catch(Throwable t){ 
> >               t.printStackTrace(); 
> >               response.setStatus(Status.SERVER_ERROR_INTERNAL); 
> >             } 
> >           } 
> >         }; 
> >         filter1.setNext(filter2); 
> > 
> >         // A router with 2 handlers - chain it to the second filter 
> >         Router router = new Router(getContext()); 
> > 
> >         router.attach("/foo$",new Handler(){ 
> >           public void handle(Request request, Response response){ 
> >             response.setEntity("handler foo", 
> MediaType.TEXT_PLAIN); 
> >           } 
> >         }); 
> > 
> >         router.attach("/bar$",new Handler(){ 
> >           public void handle(Request request, Response response){ 
> >             throw new Error("boo!"); 
> >             //throw new NullPointerException("boo!"); 
> >           } 
> >         }); 
> >         filter2.setNext(router); 
> > 
> >         return filter1; 
> >       } 
> >   }; 
> >     container.getDefaultHost().attach("", application); 
> >     try { 
> >       container.start(); 
> >     } 
> >     catch(Exception e){ 
> >       e.printStackTrace(); 
> >     } 
> >   } 
> > } 
> > 
> > 
> > 
> 
> 

Reply via email to