仅在特定的Web浏览器中,由WildFly提供服务的Web应用上的ViewExpiredException [英] ViewExpiredException on a WildFly-served webapp only in a particular webbrowser

查看:121
本文介绍了仅在特定的Web浏览器中,由WildFly提供服务的Web应用上的ViewExpiredException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在Wildfly 8.1.0Final上运行的jsf应用程序,并且只有在Google Chrome浏览器中,当我单击登录"按钮时,在其他浏览器或Chrome隐身模式下,我都能收到ViewExpiredException!

I have a jsf application running on Wildfly 8.1.0Final and, ONLY in Google Chrome, when I click on the Login button, i receive ViewExpiredException, in others browsers, or in Chrome Incognito Mode, works perfectly!

有人知道会是什么吗?

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>

有人可以帮助我吗?

感谢您的帮助!

推荐答案

WildFly在其当前版本8.1中遇到了(会话)cookie的问题,特别是那些源自未知"服务器的cookie.您可能已经知道cookie是特定于域的,并且每次都会由浏览器发送回给服务器.如果您以前在完全相同的域中使用了相同的浏览器,而该域由另一台服务器(例如Tomcat,JBoss,GlassFish等)提供服务,并且所涉及的Cookie恰巧是JSESSIONID cookie,那么WildFly将是无法正确创建HTTP会话.

WildFly in its current version 8.1 has trouble with (session) cookies, particularly those originating from "unknown" servers. You probably already know that cookies are domain specific and are everytime sent back to the server by the browser. If you've previously used the same browser on exactly the same domain which is served by a different server (e.g. Tomcat, JBoss, GlassFish, etc), and the cookie in question happens to be the JSESSIONID cookie, then WildFly will be unable to properly create the HTTP session.

如果在打开Web应用程序之前将所有特定于域的(localhost)cookie丢弃,它将起作用.或者,如您所正确观察到的那样,如果您打开一个隐身窗口(基本上以清晰,干净的状态开始),或者Cookies已经过期很长时间(其他浏览器很少使用,是吗?).作为一种临时的解决方法,而无需在浏览器的cookie存储中摆弄,您还可以创建一个servlet过滤器,以检查重复的请求cookie并将其丢弃.

It'll work if you trash all domain-specific (localhost) cookies before opening the webapp. Or, as you correctly observed, if you open an Incognito window (which basically starts with a crisp and clean state), or when the cookies are already expired for long (those other browsers are very rarely used, right?). As a temporary workaround without needing to fiddle around in browser's cookie store, you could also create a servlet filter which checks for duplicate request cookies and trash them.

WildFly会话cookie还有另一个问题.当它第一次创建会话cookie时,它不使用/路径,而是使用一个空字符串作为路径(它基本上转换为当前文件夹而不是根文件夹).结果是,当您第一次通过请求文件夹路径访问Web应用程序时,父/根文件夹将不会共享同一会话.反过来,可以使用web.xml中的以下设置来解决此问题:

WildFly has another problem with session cookies, by the way. When it creates the session cookie for the first time, it doesn't use the / path, but an empty string as path (which basically translates to the current folder instead of the root folder). This has the consequence that when you visit the webapp for the first time by requesting a folder path, then the parent/root folder(s) wouldn't share the same session. This part is in turn workaroundable with the following setting in web.xml:

<session-config>
    <cookie-config>
        <path>/</path>
    </cookie-config>
</session-config>

另请参见:

  • 将JBoss AS 7迁移到WildFly 8的经验
  • See also:

    • Experiences migrating JBoss AS 7 to WildFly 8
    • 这篇关于仅在特定的Web浏览器中,由WildFly提供服务的Web应用上的ViewExpiredException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆