[英]RESTLET - chaining a validator and filter, why does it surpasses the filter?
I have a restlet in which i want to chain a validator and filter one after the other in the code. 我有一个restlet,我想在其中链接验证器并在代码中一个接一个地过滤。 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. 上面的代码可以正常工作,但是现在如果我必须创建一个链,则必须使用每个新映射来创建Validator和Filter的新对象。 Any solution will be appreciated 任何解决方案将不胜感激
I found the answer to above question in RESTLET mailing list. 我在RESTLET邮件列表中找到了上述问题的答案。 The reason the router is surpassing the filter is because it returns val 路由器超越过滤器的原因是因为它返回val
return val;
rather than that, if one uses 而不是那样,如果一个使用
return fil;
then the call will pass through the filter chain going through filter then validator.. 然后该调用将通过过滤器链,依次通过过滤器和验证器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.