Mojarra JSF 中的闪存异常

Posted

技术标签:

【中文标题】Mojarra JSF 中的闪存异常【英文标题】:Exception about flash in Mojarra JSF 【发布时间】:2013-07-14 04:30:36 【问题描述】:

我升级到 Mojarra JSF 2.2.1(从 2.1.22 开始),从那时起,对于我的每个请求,我在控制台中都遇到了异常:

GRAVE: JSF1094: Could not decode flash data from incoming cookie value /?.  
Processing will continue, but the flash is unavailable for this request.
com.sun.faces.lifecycle.InvokeApplicationPhase execute

当我没有在其上使用 Flash 范围时,请求成功完成。但是,由于我将此范围用于FacesMessages,因此如果我在此处输入一条消息,我就会有一个NullPointerException 并且导航流程被中断:

GRAVE: El Servlet.service() para servlet Faces Servlet lanzó una excepción
java.lang.NullPointerException
    at com.sun.faces.context.flash.ELFlash.loggingGetPhaseMapForWriting(ELFlash.java:803)
    at com.sun.faces.context.flash.ELFlash.setKeepMessages(ELFlash.java:323)
    at org.omnifaces.util.Messages.addFlash(Messages.java:460)
    at org.omnifaces.util.Messages.addFlashInfo(Messages.java:488)
    at com.company.view.utils.FacesUtils.addInfoMessage(FacesUtils.java:91)
    at com.company.view.utils.FacesUtils.addInfoMessage(FacesUtils.java:79)
    at com.company.view.beans.navegable.detectables.generic.NavegableDetectableAddGeneric.save(NavegableDetectableAddGeneric.java:92)
    at com.company.view.beans.navegable.detectables.generic.NavegableDetectableAddGeneric.actionSave(NavegableDetectableAddGeneric.java:55)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.sun.el.parser.AstValue.invoke(AstValue.java:234)
    at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:297)
    at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
    at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:87)
    at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
    at javax.faces.component.UICommand.broadcast(UICommand.java:315)
    at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
    at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
    at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:79)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at com.ocpsoft.pretty.PrettyFilter.doFilter(PrettyFilter.java:145)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:646)
    at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:436)
    at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:374)
    at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:302)
    at com.ocpsoft.pretty.PrettyFilter.doFilter(PrettyFilter.java:137)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at com.tesicnor.system.view.filters.SetHttpHeadersFilter.doFilter(SetHttpHeadersFilter.java:143)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118)
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:183)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192)
    at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)
    at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
    at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at com.tesicnor.system.view.filters.SimpleSecurityFilter.doFilter(SimpleSecurityFilter.java:59)
    at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
    at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:615)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
    at java.lang.Thread.run(Thread.java:619)

我对 2.1.x 分支 (2.1.24) 的最新版本也有同样的问题。顺便说一句,这就是我的addInfoMessage 方法的作用:

/**
 * Add information message.
 * 
 * @param msg
 *            the information message
 */
public void addInfoMessage(String msg) 
    addInfoMessage(null, msg);


/**
 * Add information message to a specific client.
 * 
 * @param clientId
 *            the client id
 * @param msg
 *            the information message
 */
public void addInfoMessage(String clientId, String msg) 
    Messages.addFlashInfo(clientId, msg);

作为Messages 类的org.omnifaces.util.Messages 类型。


已编辑

当我清除浏览器的 cookie 时,该问题仅在 firefox 和涉及视图参数时发生,似乎消失了。它似乎也持续存在于整个 2.2.x 和 2.1.x 分支中(至少到 2.2.4-2.1.26),显示略有不同的痕迹:

com.sun.faces.context.flash.ELFlash getCurrentFlashManager 坟墓:JSF1094:无法从传入的 cookie 值解码闪存数据 解密值中的字符无效。处理将继续,但闪存不适用于此请求。

根据@BalusC here(2013 年 8 月):

我们在 Mojarra 2.1.24 中也遇到过这种情况。我们得出的结论是 ELFlash 课程 - 老实说 - 一个可怕的烂摊子,似乎最初是由一个没有扎实的 HTTP 问题背景知识的实习生编写的。

【问题讨论】:

我也有同样的问题。当存在活动闪存并且您重新启动服务器时,这似乎会发生。如果您清除浏览器 cookie(用于您的 url),那么它就会消失。 【参考方案1】:

我可以在任何浏览器上重现问题。我刚刚打开https://java.net/jira/browse/JAVASERVERFACES-2973 来解决这个问题。

【讨论】:

绝对是bug。 似乎他们在 2.1.25 中修复了它。但是,我仍然遇到问题,因为插入的闪存值在两个以上的请求中仍然存在。我使用 POST-REDIRECT-GET 模式。【参考方案2】:

我没有足够的代表发表评论,所以我写一个答案....

正如 Stan Silvert 所说,它发生在任何浏览器上。 2.1.25 正在修复它,但 https://java.net/jira/browse/JAVASERVERFACES-2862 已在 2.1.27 上修复 2.1.x 分支:https://java.net/jira/browse/JAVASERVERFACES-3089

2.1.27 的截止日期为 2014 年 1 月 2 日。

【讨论】:

【参考方案3】:

我认为 Mojarra 2.2.2 / 2.1.25 会解决这个问题,考虑到:https://java.net/jira/browse/JAVASERVERFACES-2955

【讨论】:

那个bug是关于IE的,我用的是火狐

以上是关于Mojarra JSF 中的闪存异常的主要内容,如果未能解决你的问题,请参考以下文章

Mojarra 版本是不是与 JSF 版本对应?

为 JSF 下载 Mojarra 库时,在 Eclipse 中显示错误“zip 文件为空”

JSF 2.2 内存消耗:为啥 Mojarra 将最后 25 个视图的 ViewScoped Beans 保留在内存中?

FacesContext 在带有 JSF 2.3 的 Wildfly 14 中不可注入(Mojarra,主模块)

嵌套 JSF 复合组件中的 AJAX

Bean 验证不适用于 mojarra 2.2.4