[英]Vaadin request filter with filter chain?
Is there a way in Vaadin to hook into a request chain and perform operations around the real request/response cycle with VaadinSession
provided? Vaadin中是否可以通过提供的
VaadinSession
挂接到请求链并在实际请求/响应周期附近执行操作? Currently I use javax.servlet.Filter
, but it seems that VaadinSession.getCurrent()
is set somewhere deeper, and in the filter itself it is unset both before and after chain.doFilter
(). 当前,我使用
javax.servlet.Filter
,但似乎VaadinSession.getCurrent()
设置得更深一些,并且在过滤器本身中, chain.doFilter
()之前和之后chain.doFilter
设置。
I have found a workaround. 我找到了一种解决方法。 First of all, I can't plug into a request handler chain, as there is no such structure.
首先,我无法插入请求处理程序链,因为没有这样的结构。 To simulate it, I have split my code into pre-request and post-request code (It's somewhat OK in my case).
为了模拟它,我将我的代码分为请求前代码和请求后代码(在我看来这是可以的)。 I'm doing my pre-request stuff in an ordinary
VaadinRequestHandler
and returning false (for a normal request to proceed). 我在普通的
VaadinRequestHandler
执行请求前的VaadinRequestHandler
并返回false(以便继续进行常规请求)。 Post-request stuff goes to a javax.serlvet.Filter
mapped in web.xml
. 请求后的内容转到映射在
web.xml
的javax.serlvet.Filter
。
Second, if anybody else is having the same problem, and the code is also splittable using the same pattern, here is the a pre-request (vaadin-side) listing: 其次,如果其他人遇到相同的问题,并且代码也可以使用相同的模式进行拆分,则以下是请求前列表(vaadin端):
public class MyVaadinServlet extends VaadinServlet{
@Override
protected VaadinServletService createServletService(DeploymentConfiguration deploymentConfiguration) throws ServiceException {
VaadinServletService service = new VaadinServletService(this,
deploymentConfiguration){
@Override
protected List<RequestHandler> createRequestHandlers() throws ServiceException {
List<RequestHandler> handlers = super.createRequestHandlers();
handlers.add((session, request, response) -> {
// HERE GOES THE CODE
return false;
});
return handlers;
}
};
service.init();
return service;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.