In my application I have a WebFilter. This Webfilter should check a coockie. But the use of FacesContext.getCurrentInstance() gives a Nullpointer exception. How can I solve this?
The WebFilter:
@Inject
private CookieManager cm;
[...]
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
if(cm.isDoCheck()){
cm.doCheck();
}
chain.doFilter(request, response);
}
[...]
The CookieManager which does the FacesContext.getCurrentInstance():
[...]
private void doCheck(){
FacesContext context = FacesContext.getCurrentInstance();
Map<String, Object> cookies = context.getExternalContext().getRequestCookieMap();
Cookie cookie = (Cookie) cookies.get("frontend");
if(cookie != null){
setSessionHash(cookie.getValue());
}
}
[...]
context.getExternalContext().getRequestCookieMap();
gives the
StandardWrapperValve[Faces Servlet]: Servlet.service() for servlet Faces Servlet threw exception
java.lang.NullPointerException