Skip to content
This repository was archived by the owner on May 13, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions jsf-ri/src/main/java/com/sun/faces/context/flash/ELFlash.java
Original file line number Diff line number Diff line change
Expand Up @@ -405,11 +405,12 @@ public Object get(Object key) {
if (null == result) {
result = getPhaseMapForReading().get(key);
}
if (distributable) {
if (distributable && context.getExternalContext().getSession(false) != null) {
SessionHelper sessionHelper =
SessionHelper.getInstance(context.getExternalContext());
assert(null != sessionHelper);
sessionHelper.update(context.getExternalContext(), this);
if (sessionHelper != null) {
sessionHelper.update(context.getExternalContext(), this);
}
}

if (LOGGER.isLoggable(Level.FINEST)) {
Expand Down Expand Up @@ -443,11 +444,12 @@ public Object put(String key, Object value) {
}
context.getApplication().publishEvent(context, PostPutFlashValueEvent.class, key);
}
if (distributable) {
if (distributable && context.getExternalContext().getSession(false) != null) {
SessionHelper sessionHelper =
SessionHelper.getInstance(context.getExternalContext());
assert(null != sessionHelper);
sessionHelper.update(context.getExternalContext(), this);
if (sessionHelper != null) {
sessionHelper.update(context.getExternalContext(), this);
}
}

return result;
Expand Down Expand Up @@ -808,7 +810,7 @@ private void reapFlashes() {
flashInnerMap.remove(cur);
}
}
if (distributable) {
if (distributable && FacesContext.getCurrentInstance().getExternalContext().getSession(false) != null) {
ExternalContext extContext = FacesContext.getCurrentInstance().getExternalContext();
SessionHelper sessionHelper = SessionHelper.getInstance(extContext);
if (null != sessionHelper) {
Expand Down
62 changes: 62 additions & 0 deletions test/servlet30/flashNoSession/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?xml version="1.0" encoding="UTF-8"?>

<!--

DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.

Copyright (c) 1997-2014 Oracle and/or its affiliates. All rights reserved.

The contents of this file are subject to the terms of either the GNU
General Public License Version 2 only ("GPL") or the Common Development
and Distribution License("CDDL") (collectively, the "License"). You
may not use this file except in compliance with the License. You can
obtain a copy of the License at
https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
or packager/legal/LICENSE.txt. See the License for the specific
language governing permissions and limitations under the License.

When distributing the software, include this License Header Notice in each
file and include the License file at packager/legal/LICENSE.txt.

GPL Classpath Exception:
Oracle designates this particular file as subject to the "Classpath"
exception as provided by Oracle in the GPL Version 2 section of the License
file that accompanied this code.

Modifications:
If applicable, add the following below the License Header, with the fields
enclosed by brackets [] replaced by your own identifying information:
"Portions Copyright [year] [name of copyright owner]"

Contributor(s):
If you wish your version of this file to be governed by only the CDDL or
only the GPL Version 2, indicate your decision by adding "[Contributor]
elects to include this software in this distribution under the [CDDL or GPL
Version 2] license." If you don't indicate a single choice of license, a
recipient has the option to distribute your version of this file under
either the CDDL, the GPL Version 2 or to extend the choice of license to
its licensees as provided above. However, if you add GPL Version 2 code
and therefore, elected the GPL Version 2 license, then the option applies
only if the new code is made subject to such option by the copyright
holder.

-->

<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.sun.faces.test.servlet30</groupId>
<artifactId>pom</artifactId>
<version>2.3.0-m01-SNAPSHOT</version>
</parent>
<artifactId>flashNoSession</artifactId>
<packaging>war</packaging>
<name>Mojarra ${project.version} - Test - Servlet 3.0 - Flash and no Session</name>
<build>
<finalName>test-servlet30-flashNoSession</finalName>
</build>
<properties>
<netbeans.hint.deploy.server>gfv3ee6</netbeans.hint.deploy.server>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 1997-2014 Oracle and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
* or packager/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at packager/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* Oracle designates this particular file as subject to the "Classpath"
* exception as provided by Oracle in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package com.sun.faces.test.servlet30.flashnosession;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;

@ManagedBean(name = "flashBean")
@RequestScoped
public class FlashBean {

public void setVariable(String val) {
FacesContext.getCurrentInstance().getExternalContext().getFlash().put("var", val);
}

public String getVariable() {
return (String) FacesContext.getCurrentInstance().getExternalContext().getFlash().get("var");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE glassfish-web-app PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Servlet 3.0//EN" "http://glassfish.org/dtds/glassfish-web-app_3_0-1.dtd">
<glassfish-web-app error-url="">
<context-root>/test-servlet30-flashNoSession</context-root>
<class-loader delegate="true"/>
<jsp-config>
<property name="keepgenerated" value="true">
<description>Keep a copy of the generated servlet class' java code.</description>
</property>
</jsp-config>
</glassfish-web-app>
31 changes: 31 additions & 0 deletions test/servlet30/flashNoSession/src/main/webapp/WEB-INF/web.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<distributable/>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>${webapp.projectStage}</param-value>
</context-param>
<context-param>
<param-name>javax.faces.PARTIAL_STATE_SAVING</param-name>
<param-value>${webapp.partialStateSaving}</param-value>
</context-param>
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>${webapp.stateSavingMethod}</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>30</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>faces/index.xhtml</welcome-file>
</welcome-file-list>
</web-app>
17 changes: 17 additions & 0 deletions test/servlet30/flashNoSession/src/main/webapp/getvar.xhtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core">
<head>
<f:view transient="true"/>
<title>Start Page</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<f:metadata>
<f:viewAction action="#{session.invalidate()}"/>
</f:metadata>
</head>
<body>
<h1>NPE Bug Reproducer</h1>
Session: #{facesContext.externalContext.sessionMap} <br/>
Flash Variable: #{flashBean.variable}
</body>
</html>
16 changes: 16 additions & 0 deletions test/servlet30/flashNoSession/src/main/webapp/setvar.xhtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version='1.0' encoding='UTF-8' ?>

<!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:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<f:view transient="true"/>
<h:head>
<title>Set Flash Variable</title>
</h:head>
<h:body>
Flash Variable Set: #{flashBean.setVariable('hello')} <br/>
</h:body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 1997-2014 Oracle and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
* or packager/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at packager/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* Oracle designates this particular file as subject to the "Classpath"
* exception as provided by Oracle in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package com.sun.faces.test.servlet30.flashnosession;

import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import org.junit.After;
import static org.junit.Assert.assertTrue;
import org.junit.Before;
import org.junit.Test;

public class Issue3621IT {

private String webUrl;
private WebClient webClient;

@Before
public void setUp() {
webUrl = System.getProperty("integration.url");
webClient = new WebClient();
}

@After
public void tearDown() {
webClient.closeAllWindows();
}

@Test
public void testCdataEscape5() throws Exception {
HtmlPage page = webClient.getPage(webUrl + "faces/setvar.xhtml");
page = webClient.getPage(webUrl + "faces/getvar.xhtml");
assertTrue(page.asXml().contains("hello"));
}
}
1 change: 1 addition & 0 deletions test/servlet30/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
<module>jarWithExactlyTwoContracts</module>
<module>mapping</module>
<module>multi-tenant</module>
<module>flashNoSession</module>
<module>navigation</module>
<module>resourceExposure</module>
<module>systest</module>
Expand Down