仅在特定的网络浏览器中,WildFly 服务的网络应用程序上的 ViewExpiredException
Posted
技术标签:
【中文标题】仅在特定的网络浏览器中,WildFly 服务的网络应用程序上的 ViewExpiredException【英文标题】:ViewExpiredException on a WildFly-served webapp only in a particular webbrowser 【发布时间】:2014-11-10 20:49:26 【问题描述】:我有一个在 Wildfly 8.1.0Final 上运行的 jsf 应用程序,并且仅在 Google Chrome 中,当我点击登录按钮时,我收到 ViewExpiredException,在其他浏览器中或在 Chrome 隐身模式下,完美运行!
有人知道可能是什么吗?
20:29:18,531 INFO [stdout] (default task-49) 2014-09-16 20:29:18 ERROR context:218 - javax.faces.application.ViewExpiredException: viewId:/login.jsf - A exibição de /login.jsf não pôde ser restaurada.
20:29:18,532 INFO [stdout] (default task-49) at com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:210)
20:29:18,532 INFO [stdout] (default task-49) at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
20:29:18,532 INFO [stdout] (default task-49) at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:121)
20:29:18,532 INFO [stdout] (default task-49) at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
20:29:18,532 INFO [stdout] (default task-49) at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646)
20:29:18,532 INFO [stdout] (default task-49) at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85)
20:29:18,533 INFO [stdout] (default task-49) at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:61)
20:29:18,533 INFO [stdout] (default task-49) at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
20:29:18,533 INFO [stdout] (default task-49) at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
20:29:18,533 INFO [stdout] (default task-49) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25)
20:29:18,533 INFO [stdout] (default task-49) at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:113)
20:29:18,533 INFO [stdout] (default task-49) at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:56)
20:29:18,533 INFO [stdout] (default task-49) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25)
20:29:18,534 INFO [stdout] (default task-49) at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:45)
20:29:18,534 INFO [stdout] (default task-49) at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:61)
20:29:18,534 INFO [stdout] (default task-49) at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:58)
20:29:18,534 INFO [stdout] (default task-49) at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:70)
20:29:18,534 INFO [stdout] (default task-49) at io.undertow.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:76)
20:29:18,534 INFO [stdout] (default task-49) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25)
20:29:18,534 INFO [stdout] (default task-49) at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
20:29:18,535 INFO [stdout] (default task-49) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25)
20:29:18,535 INFO [stdout] (default task-49) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25)
20:29:18,535 INFO [stdout] (default task-49) at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:240)
20:29:18,535 INFO [stdout] (default task-49) at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:227)
20:29:18,536 INFO [stdout] (default task-49) at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:73)
20:29:18,536 INFO [stdout] (default task-49) at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:146)
20:29:18,536 INFO [stdout] (default task-49) at io.undertow.server.Connectors.executeRootHandler(Connectors.java:177)
20:29:18,536 INFO [stdout] (default task-49) at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:727)
20:29:18,536 INFO [stdout] (default task-49) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
20:29:18,536 INFO [stdout] (default task-49) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
20:29:18,536 INFO [stdout] (default task-49) at java.lang.Thread.run(Unknown Source)
20:29:18,536 INFO [stdout] (default task-49)
我的 pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.inbit</groupId>
<artifactId>ProjetoBase</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>ProjetoBase</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jetty.version>6.1.4</jetty.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>jsr250-api</artifactId>
<version>1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.faces</groupId>
<artifactId>javax.faces-api</artifactId>
<version>2.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.spec</groupId>
<artifactId>jboss-javaee-6.0</artifactId>
<version>3.0.2.Final</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.0-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>jsr250-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.spec.javax.ejb</groupId>
<artifactId>jboss-ejb-api_3.1_spec</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.faces</groupId>
<artifactId>javax.faces-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.spec.javax.servlet</groupId>
<artifactId>jboss-servlet-api_3.0_spec</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>4.0.0.GA</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.3.6.Final</version>
</dependency>
<!-- JPA Persistence Dependencies -->
<dependency>
<groupId>hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>1.8.0.10</version>
</dependency>
<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.1-901-1.jdbc4</version>
</dependency>
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>5.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.6</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.9.5</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>org.glassfish.web</groupId>
<artifactId>el-impl</artifactId>
<version>2.2</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.5.6</version>
</dependency>
</dependencies>
<repositories>
<!-- JBoss Repository used for Java EE 6 pieces -->
<repository>
<id>repository.jboss.org</id>
<name>JBoss Repository</name>
<url>http://repository.jboss.org/nexus/content/groups/public-jboss/</url>
</repository>
<repository>
<id>prime-repo</id>
<name>PrimeFaces Maven Repository</name>
<url>http://repository.primefaces.org</url>
<layout>default</layout>
</repository>
</repositories>
<build>
<finalName>ProjetoBase</finalName>
<plugins>
<!-- Facilitates downloading source and javadoc in Eclipse -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.8</version>
<configuration>
<wtpversion>2.0</wtpversion>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
</configuration>
</plugin>
<!-- Plugin to run and test through maven -->
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.25</version>
<configuration>
<scanIntervalSeconds>3</scanIntervalSeconds>
</configuration>
</plugin>
<!-- Ensures we are compiling at 1.7 level -->
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
还有我的登录页面:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<ui:composition template="/resources/template/principalAcesso.xhtml">
<ui:define name="conteudo">
<div id="login">
<h2>
<span class="fontawesome-lock"></span>ProjetoBase
</h2>
<h:form id="formLogin">
<h:panelGroup id="painelLogin" styleClass="loading">
<div id="fieldset">
<p:focus context="formLogin" />
<p>
<label for="input_login">Login</label>
</p>
<p>
<p:inputText styleClass="input" id="input_login"
value="#loginBack.login" />
</p>
<p>
<label for="senha">Senha</label>
</p>
<p>
<p:password id="senha" required="true" styleClass="input"
requiredMessage="A senha não pode ser em branco."
value="#loginBack.senha" />
</p>
<p style="text-align: center;">
<p:commandButton process="@form" value="Entrar"
action="#loginBack.login()" styleClass="botaoLogin"
update=":growl, formLogin" id="btnEntrar" />
</p>
</div>
</h:panelGroup>
<p:blockUI block="painelLogin" trigger="btnEntrar">
Realizando login...<br />
<img src="resources/images/ajax.gif" />
</p:blockUI>
</h:form>
</div>
</ui:define>
有人可以帮助我吗?
感谢您的帮助!
【问题讨论】:
从打开登录页面到点击登录按钮之间需要多少时间?也许您在打开登录页面后清除了 cookie? 我在 1 秒后点击登录按钮并显示错误... 【参考方案1】:WildFly 在其当前版本 8.1 中存在(会话)cookie 问题,尤其是来自“未知”服务器的那些。您可能已经知道 cookie 是特定于域的,并且每次都由浏览器发送回服务器。如果您之前在由不同服务器(例如 Tomcat、JBoss、GlassFish 等)提供服务的完全相同的域上使用相同的浏览器,并且有问题的 cookie 恰好是 JSESSIONID
cookie,那么 WildFly 将是无法正确创建 HTTP 会话。
如果您在打开 web 应用程序之前丢弃所有特定于域的 (localhost
) cookie,它将起作用。或者,正如您正确观察到的,如果您打开一个隐身窗口(基本上以清晰干净的状态开始),或者当 cookie 已经过期很长时间(那些其他浏览器很少使用,对吗?)。作为一种不需要在浏览器的 cookie 存储中摆弄的临时解决方法,您还可以创建一个 servlet 过滤器来检查重复的请求 cookie 并将它们丢弃。
顺便说一下,WildFly 的会话 cookie 存在另一个问题。第一次创建会话 cookie 时,它不使用 /
路径,而是使用空字符串作为路径(基本上转换为当前文件夹而不是根文件夹)。这会导致当您第一次通过请求文件夹路径访问 web 应用程序时,父/根文件夹将不会共享相同的会话。这部分反过来可以通过web.xml
中的以下设置解决:
<session-config>
<cookie-config>
<path>/</path>
</cookie-config>
</session-config>
另见:
Experiences migrating JBoss AS 7 to WildFly 8【讨论】:
我尝试将此添加到我的 web.xml,但在 eclipse 中出现错误“描述资源路径位置类型 cvc-complex-type.2.4.a:发现无效内容以元素 'cookie 开头-config'。'"java.sun.com/xml/ns/javaee":session-timeout' 之一是预期的。web.xml /project/src/main/webapp/WEB-INF 第 60 行 XML 问题“我解决了清理浏览器cookie的问题,你的回答绝对正确,我遇到这个问题是因为我从Tomcat迁移到Wildfly,谢谢! 此设置是自 Servlet 3.0 以来的新设置。因此,要么您没有声明您的web.xml
至少符合 Servlet 3.0(这也会产生其他后果......例如 @WebListener
、@WebFilter
等不工作),或者您的 IDE 已经过时并且没有准备好用于 Servlet 3.0 (Java EE 6) 开发。
@BalusC 这些问题还在 8.2 中吗?
@DanielSzalay 用于根部署的 cookie 在 WildFly 8.2 中已修复【参考方案2】:
现在是 2022 年,我使用的是 wildfly-26.0.0.Final。我只在 Brave 而不是 Chrome 中遇到了这个确切的问题。尽管 Wildfly 的更高版本和 Wildfly 8.2 中的错误修复,我认为值得练习一下 BalusC 为 Wildfly 8.1 提供的明确建议,但问题仍然存在 :)。
最后是删除了为我修复它的 Chrome Xdebug 浏览器扩展。
【讨论】:
以上是关于仅在特定的网络浏览器中,WildFly 服务的网络应用程序上的 ViewExpiredException的主要内容,如果未能解决你的问题,请参考以下文章
Wildfly 允许 OPTIONS 方法但返回 405 Method not allowed
Java 的 CDI 事件是不是聚集在 WildFly 中?