Skip to content

Commit f66c9b1

Browse files
authored
Merge pull request #5566 from eclipse-ee4j/issue__5552
Add clue to error log when flash is unavailable after server restart without session persistence
2 parents 106ae5f + 9053978 commit f66c9b1

File tree

3 files changed

+393
-13
lines changed

3 files changed

+393
-13
lines changed

impl/src/main/java/com/sun/faces/context/flash/ELFlash.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,6 @@
3737
import java.util.logging.Level;
3838
import java.util.logging.Logger;
3939

40-
import com.sun.faces.config.WebConfiguration;
41-
import com.sun.faces.config.WebConfiguration.WebContextInitParameter;
42-
import com.sun.faces.facelets.tag.ui.UIDebug;
43-
import com.sun.faces.util.ByteArrayGuardAESCTR;
44-
import com.sun.faces.util.FacesLogger;
45-
4640
import jakarta.faces.application.FacesMessage;
4741
import jakarta.faces.component.UIViewRoot;
4842
import jakarta.faces.context.ExternalContext;
@@ -56,6 +50,12 @@
5650
import jakarta.servlet.http.Cookie;
5751
import jakarta.servlet.http.HttpServletRequest;
5852

53+
import com.sun.faces.config.WebConfiguration;
54+
import com.sun.faces.config.WebConfiguration.WebContextInitParameter;
55+
import com.sun.faces.facelets.tag.ui.UIDebug;
56+
import com.sun.faces.util.ByteArrayGuardAESCTR;
57+
import com.sun.faces.util.FacesLogger;
58+
5959
/**
6060
* <p>
6161
* How this implementation works
@@ -156,7 +156,7 @@ public class ELFlash extends Flash {
156156
*/
157157
static final String FLASH_NOW_REQUEST_KEY = FLASH_ATTRIBUTE_NAME + "n";
158158

159-
private enum CONSTANTS {
159+
enum CONSTANTS {
160160

161161
/**
162162
* The key in the FacesContext attributes map (hereafter referred to as contextMap) for the request scoped
@@ -209,7 +209,7 @@ private enum CONSTANTS {
209209
// <editor-fold defaultstate="collapsed" desc="Constructors and instance accessors">
210210

211211
/** Creates a new instance of ELFlash */
212-
private ELFlash(ExternalContext extContext) {
212+
ELFlash(ExternalContext extContext) {
213213
flashInnerMap = new ConcurrentHashMap<>();
214214
WebConfiguration config = WebConfiguration.getInstance(extContext);
215215
String value;
@@ -721,7 +721,7 @@ boolean isKeepFlagSet(FacesContext context) {
721721
return Boolean.TRUE == context.getAttributes().get(CONSTANTS.KeepFlagAttributeName);
722722
}
723723

724-
private long getNewSequenceNumber() {
724+
long getNewSequenceNumber() {
725725
long result = sequenceNumber.incrementAndGet();
726726

727727
if (0 == result % numberOfFlashesBetweenFlashReapings) {
@@ -1174,7 +1174,7 @@ private PreviousNextFlashInfoManager getCurrentFlashManager(FacesContext context
11741174
* </p>
11751175
*/
11761176

1177-
private static final class PreviousNextFlashInfoManager {
1177+
static final class PreviousNextFlashInfoManager {
11781178

11791179
private FlashInfo previousRequestFlashInfo;
11801180

@@ -1190,7 +1190,7 @@ private PreviousNextFlashInfoManager(ByteArrayGuardAESCTR guard) {
11901190
this.guard = guard;
11911191
}
11921192

1193-
private PreviousNextFlashInfoManager(ByteArrayGuardAESCTR guard, Map<String, Map<String, Object>> innerMap) {
1193+
PreviousNextFlashInfoManager(ByteArrayGuardAESCTR guard, Map<String, Map<String, Object>> innerMap) {
11941194
this.guard = guard;
11951195
this.innerMap = innerMap;
11961196
}
@@ -1366,6 +1366,8 @@ void decode(FacesContext context, ELFlash flash, Cookie cookie) throws InvalidKe
13661366
nextRequestFlashInfo.setFlashMap(flashMap);
13671367
}
13681368
} catch (Throwable t) {
1369+
previousRequestFlashInfo = new FlashInfo();
1370+
previousRequestFlashInfo.setFlashMap(new HashMap<>(1));
13691371
context.getAttributes().put(CONSTANTS.ForceSetMaxAgeZero, Boolean.TRUE);
13701372
if (LOGGER.isLoggable(Level.SEVERE)) {
13711373
LOGGER.log(Level.SEVERE, "faces.externalcontext.flash.bad.cookie", new Object[] { value });
@@ -1441,7 +1443,7 @@ void setIncomingCookieCameFromRedirect(boolean incomingCookieCameFromRedirect) {
14411443
* Encapsulate one of the two maps that back the flash for the current request.
14421444
* </p>
14431445
*/
1444-
private static final class FlashInfo {
1446+
static final class FlashInfo {
14451447

14461448
/**
14471449
* <p>

impl/src/main/resources/com/sun/faces/LogStrings.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ faces.config.legacy.facelet.warning=JSF1029: Application is versioned at 2.0 (e
119119
faces.view.cannot.render.response.committed=JSF1030: Unable to render view ''{0}'' as the response has already been committed.
120120
faces.compcomp.unecessary.targets.attribute=JSF1092: {0} : Unnecessary specification of the ''targets'' attribute for composite attribute ''{1}''. The ''targets'' attribute is only necessary when the composite attribute is named ''action'', ''actionListener'', ''validator'', or ''valueChangeListener''.
121121
faces.compcomp.binding.eval.non.compcomp=JSF1093: {0} : UIComponent returned by expression evaluation is not a valid composite component. Value will be ignored.
122-
faces.externalcontext.flash.bad.cookie=JSF1094: Could not decode flash data from incoming cookie value {0}. Processing will continue, but the flash is unavailable for this request.
122+
faces.externalcontext.flash.bad.cookie=JSF1094: Could not decode flash data from incoming cookie value {0}. Processing will continue, but the flash is unavailable for this request. Most probably server was restarted without session persistence. One solution is to set java:comp/env/faces/FlashSecretKey with a fixed AES256 key.
123123
faces.externalcontext.flash.response.already.committed=JSF1095: The response was already committed by the time we tried to set the outgoing cookie for the flash. Any values stored to the flash will not be available on the next request.
124124
faces.metadata.uiviewroot.unavailable=JSF1096: UIViewRoot unavailable at the time view metadata was being processed. Metadata will be unavailable.
125125
faces.application.resource.invalid_if_modified_since_header=JSF1097: Unable to parse date sent by User Agent for If-Modified-Since header, {0}.

0 commit comments

Comments
 (0)