RESTLET - chaining a validator and filter, why does it surpasses the filter?

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

RESTLET - chaining a validator and filter, why does it surpasses the filter?

saurabh narayan singh
Hi everyone,

I have a restlet in which i want to chain a validator and filter one after the other in the code. The code goes something like this

@Override
public synchronized Restlet createInboundRoot()
{
    Router router = new Router();
    Validator val = new  ParameterValidator(getContext());

    Filter fil = new MYFilter(getContext());
    router.attach("/HelloWorld", HW.class);
    fil.setNext(val);
    val.setNext(router);
    val.validate("Name",true,"^[a-z0-9A-Z]+$");
    return val;
}
but this doesn't checks in the filter, just works on the validator and then comes out.

But if i write this same code as given below, it works fine,

@Override
public synchronized Restlet createInboundRoot()
{
    Router router = new Router();
    Validator val = new ParameterValidator(getContext());

    Filter fil = new MYFilter(getContext());
    router.attach("/HelloWorld", fil);
    fil.setNext(val);
    val.setNext(HW.class);
    val.validate("Name",true,"^[a-z0-9A-Z]+$");
    return router;
}
The above code works fine but now in case i have to create a chain i'll have to create new objects of Validator and Filter with every new mapping. Any solution will be appreciated

Thanks

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=3074329
Reply | Threaded
Open this post in threaded view
|

Re: RESTLET - chaining a validator and filter, why does it surpasses the filter?

Tim Peierls
On Tue, Mar 11, 2014 at 3:29 AM, saurabh narayan singh <[hidden email]> wrote:
I have a restlet in which i want to chain a validator and filter one after the other in the code. The code goes something like this

@Override
public synchronized Restlet createInboundRoot()
{
    Router router = new Router();
    Validator val = new  ParameterValidator(getContext());

    Filter fil = new MYFilter(getContext());
    router.attach("/HelloWorld", HW.class);
    fil.setNext(val);
    val.setNext(router);
    val.validate("Name",true,"^[a-z0-9A-Z]+$");
    return val;    
    // Why not the following line instead?
    // return fil;
}
but this doesn't checks in the filter, just works on the validator and then comes out.

What happens if you return fil instead of val in the code above? As it stands, you're leaving the filter out.

--tim
Reply | Threaded
Open this post in threaded view
|

RE: Re: RESTLET - chaining a validator and filter, why does it surpasses the filter?

saurabh narayan singh
Works like a charm !!
My bad for ignoring/neglecting the filter..
Thankyou

> > @Override
> > public synchronized Restlet createInboundRoot()
> > {
> >     Router router = new Router();
> >     Validator val = new  ParameterValidator(getContext());
> >
> >     Filter fil = new MYFilter(getContext());
> >     router.attach("/HelloWorld", HW.class);
> >     fil.setNext(val);
> >     val.setNext(router);
> >     val.validate("Name",true,"^[a-z0-9A-Z]+$");
> >     return val;
>
> *    // Why not the following line instead?*
>
> *    // return fil;*
> > }
> > but this doesn't checks in the filter, just works on the validator and
> > then comes out.
> >
>
> What happens if you return fil instead of val in the code above? As it
> stands, you're leaving the filter out.
>
> --tim

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=3074399