You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lu...@apache.org on 2017/12/21 21:01:09 UTC

svn commit: r1818981 - in /myfaces/core/branches/2.3.x/impl/src: main/java/org/apache/myfaces/application/ main/java/org/apache/myfaces/application/viewstate/ main/java/org/apache/myfaces/renderkit/ main/java/org/apache/myfaces/renderkit/html/ test/jav...

Author: lu4242
Date: Thu Dec 21 21:01:09 2017
New Revision: 1818981

URL: http://svn.apache.org/viewvc?rev=1818981&view=rev
Log:
rollback commits 1817658, 1817690, 1817695 related to MYFACES-4133 because there is a conflict with MYFACES-4078. Refactor to solve MYFACES-4133 is still pending

Added:
    myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/application/viewstate/CounterKeyFactory.java
      - copied unchanged from r1817689, myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/application/viewstate/CounterKeyFactory.java
    myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/application/viewstate/CounterSessionViewStorageFactory.java
      - copied unchanged from r1817689, myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/application/viewstate/CounterSessionViewStorageFactory.java
    myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/application/viewstate/IntByteArraySerializedViewKey.java
      - copied unchanged from r1817694, myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/application/viewstate/IntByteArraySerializedViewKey.java
    myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/application/viewstate/IntIntSerializedViewKey.java
      - copied unchanged from r1817694, myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/application/viewstate/IntIntSerializedViewKey.java
    myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/renderkit/StateTokenProcessor.java
      - copied unchanged from r1817657, myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/renderkit/StateTokenProcessor.java
Modified:
    myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/application/StateCache.java
    myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/application/viewstate/ClientSideStateCacheImpl.java
    myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/application/viewstate/RandomSessionViewStorageFactory.java
    myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/application/viewstate/SerializedViewCollection.java
    myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/application/viewstate/SerializedViewKey.java
    myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/application/viewstate/ServerSideStateCacheImpl.java
    myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/renderkit/html/HtmlResponseStateManager.java
    myfaces/core/branches/2.3.x/impl/src/test/java/org/apache/myfaces/application/viewstate/SerializedViewCollectionTestCase.java

Modified: myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/application/StateCache.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/application/StateCache.java?rev=1818981&r1=1818980&r2=1818981&view=diff
==============================================================================
--- myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/application/StateCache.java (original)
+++ myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/application/StateCache.java Thu Dec 21 21:01:09 2017
@@ -75,8 +75,6 @@ public abstract class StateCache<K, V>
     public static final String RANDOM_KEY_IN_CSRF_SESSION_TOKEN_SECURE_RANDOM_ALGORITM_PARAM 
             = "org.apache.myfaces.RANDOM_KEY_IN_CSRF_SESSION_TOKEN_SECURE_RANDOM_ALGORITM";
 
-    public static final String STATELESS_TOKEN = "stateless";
-    
     /**
      * Put the state on the cache, to can be restored later.
      * 
@@ -126,16 +124,4 @@ public abstract class StateCache<K, V>
      * @return 
      */
     public abstract String createCryptographicallyStrongTokenFromSession(FacesContext context);
-    
-    
-    
-    
-    public abstract Object decodeStateToken(FacesContext facesContext, String token);
-    
-    public abstract String encodeStateToken(FacesContext facesContext, Object savedStateObject);
-    
-    public boolean isStatelessToken(FacesContext facesContext, String token)
-    {
-        return STATELESS_TOKEN.equals(token);
-    }
 }

Modified: myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/application/viewstate/ClientSideStateCacheImpl.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/application/viewstate/ClientSideStateCacheImpl.java?rev=1818981&r1=1818980&r2=1818981&view=diff
==============================================================================
--- myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/application/viewstate/ClientSideStateCacheImpl.java (original)
+++ myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/application/viewstate/ClientSideStateCacheImpl.java Thu Dec 21 21:01:09 2017
@@ -22,9 +22,7 @@ import javax.faces.context.ExternalConte
 import javax.faces.context.FacesContext;
 
 import org.apache.myfaces.application.StateCache;
-import static org.apache.myfaces.application.StateCache.STATELESS_TOKEN;
 import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFWebConfigParam;
-import org.apache.myfaces.shared.util.StateUtils;
 import org.apache.myfaces.shared.util.WebConfigParamUtils;
 
 class ClientSideStateCacheImpl extends StateCache<Object, Object>
@@ -198,28 +196,4 @@ class ClientSideStateCacheImpl extends S
     {
         return csrfSessionTokenFactory.createCryptographicallyStrongTokenFromSession(context);
     }
-    
-    @Override
-    public Object decodeStateToken(FacesContext facesContext, String token)
-    {
-        if (isStatelessToken(facesContext, token))
-        {
-            // Should not happen, because ResponseStateManager.isStateless(context,viewId) should
-            // catch it first
-            return null;
-        }
-        Object savedStateObject = StateUtils.reconstruct((String)token, facesContext.getExternalContext());
-        return savedStateObject;
-    }
-
-    @Override
-    public String encodeStateToken(FacesContext facesContext, Object savedStateObject)
-    {
-        if (facesContext.getViewRoot().isTransient())
-        {
-            return STATELESS_TOKEN;
-        }
-        String serializedState = StateUtils.construct(savedStateObject, facesContext.getExternalContext());
-        return serializedState;
-    }
 }

Modified: myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/application/viewstate/RandomSessionViewStorageFactory.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/application/viewstate/RandomSessionViewStorageFactory.java?rev=1818981&r1=1818980&r2=1818981&view=diff
==============================================================================
--- myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/application/viewstate/RandomSessionViewStorageFactory.java (original)
+++ myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/application/viewstate/RandomSessionViewStorageFactory.java Thu Dec 21 21:01:09 2017
@@ -40,7 +40,7 @@ class RandomSessionViewStorageFactory ex
     @Override
     public SerializedViewKey createSerializedViewKey(FacesContext context, String viewId, byte[] key)
     {
-        return new SerializedViewKey(viewId == null ? 0 : viewId.hashCode(), key);
+        return new IntByteArraySerializedViewKey(viewId == null ? 0 : viewId.hashCode(), key);
     }
     
 }

Modified: myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/application/viewstate/SerializedViewCollection.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/application/viewstate/SerializedViewCollection.java?rev=1818981&r1=1818980&r2=1818981&view=diff
==============================================================================
--- myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/application/viewstate/SerializedViewCollection.java (original)
+++ myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/application/viewstate/SerializedViewCollection.java Thu Dec 21 21:01:09 2017
@@ -39,10 +39,11 @@ class SerializedViewCollection implement
     private static final Object[] EMPTY_STATES = new Object[]{null, null};
 
     private static final long serialVersionUID = -3734849062185115847L;
-    private final List<SerializedViewKey> _keys = new ArrayList<>(
+    private final List<SerializedViewKey> _keys = 
+        new ArrayList<SerializedViewKey>(
             MyfacesConfig.INIT_PARAM_NUMBER_OF_VIEWS_IN_SESSION_DEFAULT);
-    private final Map<SerializedViewKey, Object> _serializedViews =  new HashMap<>();
-    
+    private final Map<SerializedViewKey, Object> _serializedViews = 
+        new HashMap<SerializedViewKey, Object>();
     /**
      * The viewScopeIds can be shared between multiple entries of the same
      * view. To store it into session, the best is use two maps, one to 
@@ -54,7 +55,8 @@ class SerializedViewCollection implement
     private HashMap<SerializedViewKey, String> _viewScopeIds = null;
     private HashMap<String, Integer> _viewScopeIdCounts = null;
 
-    private final Map<SerializedViewKey, SerializedViewKey> _precedence = new HashMap<>();
+    private final Map<SerializedViewKey, SerializedViewKey> _precedence =
+        new HashMap<SerializedViewKey, SerializedViewKey>();
     private Map<String, SerializedViewKey> _lastWindowKeys = null;
 
     public void put(FacesContext context, Object state, 

Modified: myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/application/viewstate/SerializedViewKey.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/application/viewstate/SerializedViewKey.java?rev=1818981&r1=1818980&r2=1818981&view=diff
==============================================================================
--- myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/application/viewstate/SerializedViewKey.java (original)
+++ myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/application/viewstate/SerializedViewKey.java Thu Dec 21 21:01:09 2017
@@ -19,52 +19,12 @@
 package org.apache.myfaces.application.viewstate;
 
 import java.io.Serializable;
-import java.util.Arrays;
 
 /**
  * Base implementation where all keys used to identify the state of a view should
  * extend.
  */
-class SerializedViewKey implements Serializable
+abstract class SerializedViewKey implements Serializable
 {
-    final int _viewId;
-    final byte[] _sequenceId;
-
-    public SerializedViewKey(int viewId, byte[] sequence)
-    {
-        _sequenceId = sequence;
-        _viewId = viewId;
-    }
-
-    @Override
-    public boolean equals(Object obj)
-    {
-        if (obj == null)
-        {
-            return false;
-        }
-        if (getClass() != obj.getClass())
-        {
-            return false;
-        }
-        final SerializedViewKey other = (SerializedViewKey) obj;
-        if (this._viewId != other._viewId)
-        {
-            return false;
-        }
-        if (!Arrays.equals(this._sequenceId, other._sequenceId))
-        {
-            return false;
-        }
-        return true;
-    }
-
-    @Override
-    public int hashCode()
-    {
-        int hash = 5;
-        hash = 37 * hash + this._viewId;
-        hash = 37 * hash + Arrays.hashCode(this._sequenceId);
-        return hash;
-    }
+    
 }

Modified: myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/application/viewstate/ServerSideStateCacheImpl.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/application/viewstate/ServerSideStateCacheImpl.java?rev=1818981&r1=1818980&r2=1818981&view=diff
==============================================================================
--- myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/application/viewstate/ServerSideStateCacheImpl.java (original)
+++ myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/application/viewstate/ServerSideStateCacheImpl.java Thu Dec 21 21:01:09 2017
@@ -25,7 +25,6 @@ import java.io.InputStream;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
 import java.io.OutputStream;
-import java.io.UnsupportedEncodingException;
 import java.security.AccessController;
 import java.security.PrivilegedActionException;
 import java.security.PrivilegedExceptionAction;
@@ -34,7 +33,6 @@ import java.util.logging.Level;
 import java.util.logging.Logger;
 import java.util.zip.GZIPInputStream;
 import java.util.zip.GZIPOutputStream;
-import javax.faces.FacesException;
 import javax.faces.FacesWrapper;
 import javax.faces.application.StateManager;
 
@@ -47,7 +45,6 @@ import org.apache.myfaces.buildtools.mav
 import org.apache.myfaces.shared.config.MyfacesConfig;
 import org.apache.myfaces.shared.renderkit.RendererUtils;
 import org.apache.myfaces.shared.util.MyFacesObjectInputStream;
-import org.apache.myfaces.shared.util.StateUtils;
 import org.apache.myfaces.shared.util.WebConfigParamUtils;
 import org.apache.myfaces.spi.ViewScopeProvider;
 import org.apache.myfaces.spi.ViewScopeProviderFactory;
@@ -127,18 +124,19 @@ class ServerSideStateCacheImpl extends S
     public static final String USE_FLASH_SCOPE_PURGE_VIEWS_IN_SESSION
             = "org.apache.myfaces.USE_FLASH_SCOPE_PURGE_VIEWS_IN_SESSION";
 
+    public static final String RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_NONE = "none";
     public static final String RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_SECURE_RANDOM = "secureRandom";
     public static final String RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_RANDOM = "random";
     
     /**
      * Adds a random key to the generated view state session token.
      */
-    @JSFWebConfigParam(since="2.1.9, 2.0.15", expectedValues="secureRandom, random", 
-            defaultValue="secureRandom", group="state")
+    @JSFWebConfigParam(since="2.1.9, 2.0.15", expectedValues="secureRandom, random, none", 
+            defaultValue="none", group="state")
     public static final String RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_PARAM
             = "org.apache.myfaces.RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN";
     public static final String RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_PARAM_DEFAULT = 
-            RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_SECURE_RANDOM;
+            RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_NONE;
 
     /**
      * Set the default length of the random key added to the view state session token.
@@ -203,11 +201,7 @@ class ServerSideStateCacheImpl extends S
         }
         else
         {
-            log.warning("org.apache.myfaces.RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN \""
-                    + randomMode + "\" is not supported (anymore)."
-                    + " Fallback to \"secureRandom\"");
-            sessionViewStorageFactory = new RandomSessionViewStorageFactory(
-                    new SecureRandomKeyFactory(facesContext));
+            sessionViewStorageFactory = new CounterSessionViewStorageFactory(new CounterKeyFactory());
         }
         
         String csrfRandomMode = WebConfigParamUtils.getStringInitParameter(facesContext.getExternalContext(),
@@ -504,7 +498,8 @@ class ServerSideStateCacheImpl extends S
         }
         
         // Fallback old parameter.
-        value = context.getExternalContext().getInitParameter(SERIALIZE_STATE_IN_SESSION_PARAM);
+        value = context.getExternalContext().getInitParameter(
+                SERIALIZE_STATE_IN_SESSION_PARAM);
         if (value != null)
         {
            serialize = Boolean.valueOf(value);
@@ -586,7 +581,17 @@ class ServerSideStateCacheImpl extends S
                     }
                 }
             }
-            catch (PrivilegedActionException | IOException | ClassNotFoundException e)
+            catch (PrivilegedActionException e) 
+            {
+                log.log(Level.SEVERE, "Exiting deserializeView - Could not deserialize state: " + e.getMessage(), e);
+                return null;
+            }
+            catch (IOException e)
+            {
+                log.log(Level.SEVERE, "Exiting deserializeView - Could not deserialize state: " + e.getMessage(), e);
+                return null;
+            }
+            catch (ClassNotFoundException e)
             {
                 log.log(Level.SEVERE, "Exiting deserializeView - Could not deserialize state: " + e.getMessage(), e);
                 return null;
@@ -601,7 +606,7 @@ class ServerSideStateCacheImpl extends S
 
             return state;
         }
-        else if (state == null)
+        else if(state == null)
         {
             log.severe("Exiting deserializeView - this method should not be called with a null-state.");
             return null;
@@ -700,53 +705,4 @@ class ServerSideStateCacheImpl extends S
     {
         return csrfSessionTokenFactory.createCryptographicallyStrongTokenFromSession(context);
     }
-
-    @Override
-    public Object decodeStateToken(FacesContext facesContext, String token)
-    {
-        if (isStatelessToken(facesContext, token))
-        {
-            // Should not happen, because ResponseStateManager.isStateless(context,viewId) should
-            // catch it first
-            return null;
-        }
-
-        try
-        {
-            byte[] tokenBytes = token.getBytes(StateUtils.ZIP_CHARSET);
-            byte[] tokenBytesDecoded = StateUtils.decode(tokenBytes);
-            String tokenDecoded = new String(tokenBytesDecoded, StateUtils.ZIP_CHARSET);
-
-            return tokenDecoded;
-        }
-        catch (UnsupportedEncodingException e)
-        {
-            throw new FacesException(e);
-        }
-
-    }
-
-    @Override
-    public String encodeStateToken(FacesContext facesContext, Object savedStateObject)
-    {
-        if (facesContext.getViewRoot().isTransient())
-        {
-            return STATELESS_TOKEN;
-        }
-
-        try
-        {
-            // string from #encodeSerializedState
-            String token = (String) savedStateObject;
-            byte[] tokenBytes = token.getBytes(StateUtils.ZIP_CHARSET);
-            byte[] tokenBytesEncoded = StateUtils.encode(tokenBytes);
-            String tokenEncoded = new String(tokenBytesEncoded, StateUtils.ZIP_CHARSET);
-
-            return tokenEncoded;
-        }
-        catch (UnsupportedEncodingException e)
-        {
-            throw new FacesException(e);
-        }
-    }
 }

Modified: myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/renderkit/html/HtmlResponseStateManager.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/renderkit/html/HtmlResponseStateManager.java?rev=1818981&r1=1818980&r2=1818981&view=diff
==============================================================================
--- myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/renderkit/html/HtmlResponseStateManager.java (original)
+++ myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/renderkit/html/HtmlResponseStateManager.java Thu Dec 21 21:01:09 2017
@@ -32,8 +32,10 @@ import javax.faces.render.ResponseStateM
 import org.apache.myfaces.application.StateCache;
 import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFWebConfigParam;
 import org.apache.myfaces.renderkit.MyfacesResponseStateManager;
+import org.apache.myfaces.renderkit.StateTokenProcessor;
 import org.apache.myfaces.shared.config.MyfacesConfig;
 import org.apache.myfaces.shared.renderkit.html.HTML;
+import org.apache.myfaces.shared.util.StateUtils;
 import org.apache.myfaces.shared.util.WebConfigParamUtils;
 import org.apache.myfaces.spi.StateCacheProvider;
 import org.apache.myfaces.spi.StateCacheProviderFactory;
@@ -62,11 +64,14 @@ public class HtmlResponseStateManager ex
             "org.apache.myfaces.AUTOCOMPLETE_OFF_VIEW_STATE";
             
     private StateCacheProvider _stateCacheFactory;
-        
+    
+    private StateTokenProcessor _stateTokenProcessor;
+    
     private Boolean _autoCompleteOffViewState;
     
     public HtmlResponseStateManager()
     {
+        _stateTokenProcessor = new DefaultStateTokenProcessor();
         _autoCompleteOffViewState = null;
     }
     
@@ -119,7 +124,7 @@ public class HtmlResponseStateManager ex
     private void writeViewStateField(FacesContext facesContext, ResponseWriter responseWriter, Object savedState)
         throws IOException
     {
-        String serializedState = getStateCache(facesContext).encodeStateToken(facesContext, savedState);
+        String serializedState = _stateTokenProcessor.encode(facesContext, savedState);
         ExternalContext extContext = facesContext.getExternalContext();
         MyfacesConfig myfacesConfig = MyfacesConfig.getCurrentInstance(extContext);
 
@@ -181,12 +186,12 @@ public class HtmlResponseStateManager ex
     {
         Object encodedState = 
             facesContext.getExternalContext().getRequestParameterMap().get(STANDARD_STATE_SAVING_PARAM);
-        if (encodedState == null || (((String) encodedState).length() == 0))
+        if(encodedState==null || (((String) encodedState).length() == 0))
         {
             return null;
         }
 
-        Object savedStateObject = getStateCache(facesContext).decodeStateToken(facesContext, (String)encodedState);
+        Object savedStateObject = _stateTokenProcessor.decode(facesContext, (String)encodedState);
         
         return savedStateObject;
     }
@@ -220,22 +225,22 @@ public class HtmlResponseStateManager ex
         
         Object state = getStateCache(facesContext).saveSerializedView(facesContext, baseState);
 
-        return getStateCache(facesContext).encodeStateToken(facesContext, state);
+        return _stateTokenProcessor.encode(facesContext, state);
     }
 
     @Override
-    public boolean isStateless(FacesContext facesContext, String viewId)
+    public boolean isStateless(FacesContext context, String viewId)
     {
-        if (facesContext.isPostback())
+        if (context.isPostback())
         {
             String encodedState = 
-                facesContext.getExternalContext().getRequestParameterMap().get(STANDARD_STATE_SAVING_PARAM);
+                context.getExternalContext().getRequestParameterMap().get(STANDARD_STATE_SAVING_PARAM);
             if(encodedState==null || (((String) encodedState).length() == 0))
             {
                 return false;
             }
 
-            return getStateCache(facesContext).isStatelessToken(facesContext, encodedState);
+            return _stateTokenProcessor.isStateless(context, encodedState);
         }
         else 
         {
@@ -334,6 +339,41 @@ public class HtmlResponseStateManager ex
         return id;
     }
 
+    private static class DefaultStateTokenProcessor extends StateTokenProcessor
+    {
+        private static final String STATELESS_TOKEN = "stateless";
+
+        @Override
+        public Object decode(FacesContext facesContext, String token)
+        {
+            if (STATELESS_TOKEN.equals(token))
+            {
+                // Should not happen, because ResponseStateManager.isStateless(context,viewId) should
+                // catch it first
+                return null;
+            }
+            Object savedStateObject = StateUtils.reconstruct((String)token, facesContext.getExternalContext());
+            return savedStateObject;
+        }
+
+        @Override
+        public String encode(FacesContext facesContext, Object savedStateObject)
+        {
+            if (facesContext.getViewRoot().isTransient())
+            {
+                return STATELESS_TOKEN;
+            }
+            String serializedState = StateUtils.construct(savedStateObject, facesContext.getExternalContext());
+            return serializedState;
+        }
+
+        @Override
+        public boolean isStateless(FacesContext facesContext, String token)
+        {
+            return STATELESS_TOKEN.equals(token);
+        }
+    }
+    
     private boolean isAutocompleteOffViewState(FacesContext facesContext)
     {
         if (_autoCompleteOffViewState == null)

Modified: myfaces/core/branches/2.3.x/impl/src/test/java/org/apache/myfaces/application/viewstate/SerializedViewCollectionTestCase.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.3.x/impl/src/test/java/org/apache/myfaces/application/viewstate/SerializedViewCollectionTestCase.java?rev=1818981&r1=1818980&r2=1818981&view=diff
==============================================================================
--- myfaces/core/branches/2.3.x/impl/src/test/java/org/apache/myfaces/application/viewstate/SerializedViewCollectionTestCase.java (original)
+++ myfaces/core/branches/2.3.x/impl/src/test/java/org/apache/myfaces/application/viewstate/SerializedViewCollectionTestCase.java Thu Dec 21 21:01:09 2017
@@ -36,8 +36,8 @@ public class SerializedViewCollectionTes
         
         SerializedViewCollection collection = new SerializedViewCollection();
         String viewId = "/test.xhtml";
-        SerializedViewKey key1 = new SerializedViewKey(viewId.hashCode(), new byte[] {(byte) 1});
-        SerializedViewKey key2 = new SerializedViewKey(viewId.hashCode(), new byte[] {(byte) 2});
+        SerializedViewKey key1 = new IntIntSerializedViewKey(viewId.hashCode(), 1);
+        SerializedViewKey key2 = new IntIntSerializedViewKey(viewId.hashCode(), 2);
         
         TestViewScopeProvider provider = new TestViewScopeProvider();
         
@@ -58,9 +58,9 @@ public class SerializedViewCollectionTes
         
         SerializedViewCollection collection = new SerializedViewCollection();
         String viewId = "/test.xhtml";
-        SerializedViewKey key1 = new SerializedViewKey(viewId.hashCode(), new byte[] {(byte) 1});
-        SerializedViewKey key2 = new SerializedViewKey(viewId.hashCode(), new byte[] {(byte) 2});
-        SerializedViewKey key3 = new SerializedViewKey(viewId.hashCode(), new byte[] {(byte) 3});
+        SerializedViewKey key1 = new IntIntSerializedViewKey(viewId.hashCode(), 1);
+        SerializedViewKey key2 = new IntIntSerializedViewKey(viewId.hashCode(), 2);
+        SerializedViewKey key3 = new IntIntSerializedViewKey(viewId.hashCode(), 3);
         
         TestViewScopeProvider provider = new TestViewScopeProvider();
         
@@ -84,9 +84,9 @@ public class SerializedViewCollectionTes
         
         SerializedViewCollection collection = new SerializedViewCollection();
         String viewId = "/test.xhtml";
-        SerializedViewKey key1 = new SerializedViewKey(viewId.hashCode(), new byte[] {(byte) 1});
-        SerializedViewKey key2 = new SerializedViewKey(viewId.hashCode(), new byte[] {(byte) 2});
-        SerializedViewKey key3 = new SerializedViewKey(viewId.hashCode(), new byte[] {(byte) 3});
+        SerializedViewKey key1 = new IntIntSerializedViewKey(viewId.hashCode(), 1);
+        SerializedViewKey key2 = new IntIntSerializedViewKey(viewId.hashCode(), 2);
+        SerializedViewKey key3 = new IntIntSerializedViewKey(viewId.hashCode(), 3);
         
         TestViewScopeProvider provider = new TestViewScopeProvider();
         
@@ -112,9 +112,9 @@ public class SerializedViewCollectionTes
         
         SerializedViewCollection collection = new SerializedViewCollection();
         String viewId = "/test.xhtml";
-        SerializedViewKey key1 = new SerializedViewKey(viewId.hashCode(), new byte[] {(byte) 1});
-        SerializedViewKey key2 = new SerializedViewKey(viewId.hashCode(), new byte[] {(byte) 2});
-        SerializedViewKey key3 = new SerializedViewKey(viewId.hashCode(), new byte[] {(byte) 3});
+        SerializedViewKey key1 = new IntIntSerializedViewKey(viewId.hashCode(), 1);
+        SerializedViewKey key2 = new IntIntSerializedViewKey(viewId.hashCode(), 2);
+        SerializedViewKey key3 = new IntIntSerializedViewKey(viewId.hashCode(), 3);
         
         TestViewScopeProvider provider = new TestViewScopeProvider();
         
@@ -139,10 +139,10 @@ public class SerializedViewCollectionTes
         
         SerializedViewCollection collection = new SerializedViewCollection();
         String viewId = "/test.xhtml";
-        SerializedViewKey key1 = new SerializedViewKey(viewId.hashCode(), new byte[] {(byte) 1});
-        SerializedViewKey key2 = new SerializedViewKey(viewId.hashCode(), new byte[] {(byte) 2});
-        SerializedViewKey key3 = new SerializedViewKey(viewId.hashCode(), new byte[] {(byte) 3});
-        SerializedViewKey key4 = new SerializedViewKey(viewId.hashCode(), new byte[] {(byte) 4});
+        SerializedViewKey key1 = new IntIntSerializedViewKey(viewId.hashCode(), 1);
+        SerializedViewKey key2 = new IntIntSerializedViewKey(viewId.hashCode(), 2);
+        SerializedViewKey key3 = new IntIntSerializedViewKey(viewId.hashCode(), 3);
+        SerializedViewKey key4 = new IntIntSerializedViewKey(viewId.hashCode(), 4);
         
         TestViewScopeProvider provider = new TestViewScopeProvider();
         
@@ -180,15 +180,15 @@ public class SerializedViewCollectionTes
         
         SerializedViewCollection collection = new SerializedViewCollection();
         String viewId = "/test.xhtml";
-        SerializedViewKey key1 = new SerializedViewKey(viewId.hashCode(), new byte[] {(byte) 1});
-        SerializedViewKey key2 = new SerializedViewKey(viewId.hashCode(), new byte[] {(byte) 2});
-        SerializedViewKey key3 = new SerializedViewKey(viewId.hashCode(), new byte[] {(byte) 3});
-        SerializedViewKey key4 = new SerializedViewKey(viewId.hashCode(), new byte[] {(byte) 4});
-        SerializedViewKey key5 = new SerializedViewKey(viewId.hashCode(), new byte[] {(byte) 5});
-        SerializedViewKey key6 = new SerializedViewKey(viewId.hashCode(), new byte[] {(byte) 6});
-        SerializedViewKey key7 = new SerializedViewKey(viewId.hashCode(), new byte[] {(byte) 7});
-        SerializedViewKey key8 = new SerializedViewKey(viewId.hashCode(), new byte[] {(byte) 8});
-        SerializedViewKey key9 = new SerializedViewKey(viewId.hashCode(), new byte[] {(byte) 9});
+        SerializedViewKey key1 = new IntIntSerializedViewKey(viewId.hashCode(), 1);
+        SerializedViewKey key2 = new IntIntSerializedViewKey(viewId.hashCode(), 2);
+        SerializedViewKey key3 = new IntIntSerializedViewKey(viewId.hashCode(), 3);
+        SerializedViewKey key4 = new IntIntSerializedViewKey(viewId.hashCode(), 4);
+        SerializedViewKey key5 = new IntIntSerializedViewKey(viewId.hashCode(), 5);
+        SerializedViewKey key6 = new IntIntSerializedViewKey(viewId.hashCode(), 6);
+        SerializedViewKey key7 = new IntIntSerializedViewKey(viewId.hashCode(), 7);
+        SerializedViewKey key8 = new IntIntSerializedViewKey(viewId.hashCode(), 8);
+        SerializedViewKey key9 = new IntIntSerializedViewKey(viewId.hashCode(), 9);
         
         TestViewScopeProvider provider = new TestViewScopeProvider();