You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by gc...@apache.org on 2011/08/30 02:26:00 UTC
svn commit: r1163061 - in
/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal:
application/StateManagerImpl.java util/TokenCache.java
util/TokenCacheDebugUtils.java
Author: gcrawford
Date: Tue Aug 30 00:26:00 2011
New Revision: 1163061
URL: http://svn.apache.org/viewvc?rev=1163061&view=rev
Log:
TRINIDAD-2131 Make it easier to debug viewExpiredExceptions
Modified:
myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/application/StateManagerImpl.java
myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/util/TokenCache.java
myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/util/TokenCacheDebugUtils.java
Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/application/StateManagerImpl.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/application/StateManagerImpl.java?rev=1163061&r1=1163060&r2=1163061&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/application/StateManagerImpl.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/application/StateManagerImpl.java Tue Aug 30 00:26:00 2011
@@ -629,11 +629,7 @@ public class StateManagerImpl extends St
if(TokenCacheDebugUtils.debugTokenCache())
{
- TokenCacheDebugUtils.clearRequestStringBuffer();
- TokenCacheDebugUtils.addToRequestStringBuffer("-------------- Restore View ----------\n");
- TokenCacheDebugUtils.logIdString();
-
- // get view cache key with "." separator suffix to separate the SubKeyMap keys
+ // get the state map
String subkey = _getViewCacheKey(extContext,
RequestContext.getCurrentInstance(),
_SUBKEY_SEPARATOR);
@@ -641,8 +637,11 @@ public class StateManagerImpl extends St
Map<String, PageState> stateMap = new SubKeyMap<PageState>(
extContext.getSessionMap(),
subkey);
+
+ // log what's currently in the state map
+ TokenCacheDebugUtils.startLog("Restore View");
TokenCacheDebugUtils.logCacheInfo(stateMap, null, "token '" + token + "' not found");
- _LOG.severe(TokenCacheDebugUtils.getRequestString());
+ _LOG.severe(TokenCacheDebugUtils.getLogString());
}
return null;
Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/util/TokenCache.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/util/TokenCache.java?rev=1163061&r1=1163060&r2=1163061&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/util/TokenCache.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/util/TokenCache.java Tue Aug 30 00:26:00 2011
@@ -233,17 +233,15 @@ public class TokenCache implements Seria
if(TokenCacheDebugUtils.debugTokenCache())
{
- TokenCacheDebugUtils.clearRequestStringBuffer();
- TokenCacheDebugUtils.addToRequestStringBuffer("-------------- Add New Entry ----------\n");
- TokenCacheDebugUtils.logIdString();
+ TokenCacheDebugUtils.startLog("Add New Entry");
TokenCacheDebugUtils.addTokenToViewIdMap(token);
if (pinnedToken != null)
{
- TokenCacheDebugUtils.addToRequestStringBuffer("\nPINNING " +
- TokenCacheDebugUtils.getTokenToViewIdString(TokenCacheDebugUtils.getTokenToViewIdMap(), token) +
+ TokenCacheDebugUtils.addToLog("\nPINNING " +
+ TokenCacheDebugUtils.getTokenToViewIdString(token) +
" to " +
- TokenCacheDebugUtils.getTokenToViewIdString(TokenCacheDebugUtils.getTokenToViewIdMap(), pinnedToken));
+ TokenCacheDebugUtils.getTokenToViewIdString(pinnedToken));
}
}
@@ -266,7 +264,7 @@ public class TokenCache implements Seria
if(TokenCacheDebugUtils.debugTokenCache())
{
TokenCacheDebugUtils.logCacheInfo(targetStore, _pinned, "After Additions");
- _LOG.severe(TokenCacheDebugUtils.getRequestString());
+ _LOG.severe(TokenCacheDebugUtils.getLogString());
}
@@ -323,8 +321,8 @@ public class TokenCache implements Seria
if (TokenCacheDebugUtils.debugTokenCache())
{
- TokenCacheDebugUtils.addToRequestStringBuffer("\nREMOVING pinning of token " + token + " to " +
- TokenCacheDebugUtils.getTokenToViewIdString(TokenCacheDebugUtils.getTokenToViewIdMap(), wasPinned));
+ TokenCacheDebugUtils.addToLog("\nREMOVING pinning of token " + token + " to " +
+ TokenCacheDebugUtils.getTokenToViewIdString(wasPinned));
}
// Yup, so see if we can remove that token
@@ -335,8 +333,8 @@ public class TokenCache implements Seria
{
if (TokenCacheDebugUtils.debugTokenCache())
{
- TokenCacheDebugUtils.addToRequestStringBuffer("\nNOT removing pinned token from target store " +
- TokenCacheDebugUtils.getTokenToViewIdString(TokenCacheDebugUtils.getTokenToViewIdMap(), token) );
+ TokenCacheDebugUtils.addToLog("\nNOT removing pinned token from target store " +
+ TokenCacheDebugUtils.getTokenToViewIdString(token) );
}
_LOG.finest("Not removing pinned token ''{0}''", token);
@@ -363,9 +361,7 @@ public class TokenCache implements Seria
{
if(TokenCacheDebugUtils.debugTokenCache())
{
- TokenCacheDebugUtils.clearRequestStringBuffer();
- TokenCacheDebugUtils.addToRequestStringBuffer("-------------- Remove Old Entry ----------\n");
- TokenCacheDebugUtils.logIdString();
+ TokenCacheDebugUtils.startLog("Remove Old Entry");
}
_LOG.finest("Removing token {0} from cache", token);
@@ -378,7 +374,7 @@ public class TokenCache implements Seria
if (TokenCacheDebugUtils.debugTokenCache())
{
TokenCacheDebugUtils.logCacheInfo(targetStore, _pinned, "After removing old entry:");
- _LOG.severe(TokenCacheDebugUtils.getRequestString());
+ _LOG.severe(TokenCacheDebugUtils.getLogString());
}
}
Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/util/TokenCacheDebugUtils.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/util/TokenCacheDebugUtils.java?rev=1163061&r1=1163060&r2=1163061&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/util/TokenCacheDebugUtils.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/util/TokenCacheDebugUtils.java Tue Aug 30 00:26:00 2011
@@ -30,8 +30,33 @@ import javax.servlet.http.HttpSession;
import org.apache.myfaces.trinidad.context.RequestContext;
import org.apache.myfaces.trinidad.context.Window;
import org.apache.myfaces.trinidad.context.WindowManager;
-
-
+
+ /**
+ * ViewExpiredExceptions are fairly common, and the token cache is used for
+ * page state tokens, but the tokens aren't really human readable.
+ * In order to make it easier to understand what is in the cache
+ * we've added a system property for debugging purposes. When enabled
+ * we store a map of token -> viewId on the session which we use
+ * to log something more human readable.
+ *
+ * in order to use this the tester would set the system property to:
+ * -Dorg.apache.myfaces.trinidadinternal.DEBUG_TOKEN_CACHE=true
+ *
+ * TokenCacheDebugUtils provides methods to log human readable debugging info.
+ *
+ *
+ * The goal is to provide as much logging information in a single log message as possible.
+ * In order to do this we are pushing log info into a buffer and when we're ready to log
+ * we can get the string. To start the log call like so:
+ * TokenCacheDebugUtils.startLog("My Custom String");
+ *
+ * Then you can call methods like:
+ * TokenCacheDebugUtils.logCacheInfo(stateMap, null, "hello world");
+ * TokenCacheDebugUtils.addToLog("foo bar");
+ *
+ * Then when you're ready to actually put it in the log you would do this:
+ * _LOG.severe(TokenCacheDebugUtils.getLogString());
+ */
public final class TokenCacheDebugUtils
{
@@ -42,14 +67,18 @@ public final class TokenCacheDebugUtils
* Checks whether we are debugging the token cache.
* No other method in TokenCacheDebugUtils should be called unless this method returns true.
*/
- public static Boolean debugTokenCache()
+ public static boolean debugTokenCache()
{
return _DEBUG_TOKEN_CACHE;
}
/**
- * Method to help with debugging, should only be called when
- * debugTokenCache() is true
+ * In order to provide human readable information there is a map which
+ * has token to viewId information.
+ *
+ * Add the token passed in and associate it in the map with the current view id.
+ *
+ * This method should only be called when debugTokenCache() is true
*/
public static void addTokenToViewIdMap(String token)
{
@@ -57,59 +86,72 @@ public final class TokenCacheDebugUtils
throw new UnsupportedOperationException(_UNSUPPORTED_OPERATION_MESSAGE);
FacesContext context = FacesContext.getCurrentInstance();
- Map<String,String> tokenToViewIdMap = getTokenToViewIdMap();
+ Map<String,String> tokenToViewIdMap = _getTokenToViewIdMap(context);
UIViewRoot root = context.getViewRoot();
String viewId = root.getViewId();
tokenToViewIdMap.put(token, viewId);
-
- addToRequestStringBuffer("\nADDING " + getTokenToViewIdString(tokenToViewIdMap, token));
+
+ StringBuffer logBuffer = _getLogBuffer(context);
+ logBuffer.append("\nADDING ").append(_getTokenToViewIdString(tokenToViewIdMap, token));
}
/**
- * Method to help with debugging, should only be called when
- * debugTokenCache() is true
+ * In order to provide human readable information there is a map which
+ * has token to viewId information.
+ *
+ * Remove the view id info from the map for the given token.
+ *
+ * This method should only be called when debugTokenCache() is true
*/
public static void removeTokenFromViewIdMap(String token)
{
if (!_DEBUG_TOKEN_CACHE)
throw new UnsupportedOperationException(_UNSUPPORTED_OPERATION_MESSAGE);
-
- Map<String,String> tokenToViewIdMap = getTokenToViewIdMap();
-
- addToRequestStringBuffer("\nREMOVING " + getTokenToViewIdString(tokenToViewIdMap, token));
+
+ FacesContext context = FacesContext.getCurrentInstance();
+ Map<String,String> tokenToViewIdMap = _getTokenToViewIdMap(context);
+
+ StringBuffer logBuffer = _getLogBuffer(context);
+ logBuffer.append( "\nREMOVING ").append( _getTokenToViewIdString(tokenToViewIdMap, token));
tokenToViewIdMap.remove(token);
}
-
/**
- * Method to help with debugging, should only be called when
- * debugTokenCache() is true
+ * Generate a string showing the token and the view id we have saved for that token
+ *
+ * This method should only be called when debugTokenCache() is true
*/
- public static String getTokenToViewIdString(Map<String,String> tokenToViewId, String token)
- {
+ public static String getTokenToViewIdString(String token)
+ {
if (!_DEBUG_TOKEN_CACHE)
throw new UnsupportedOperationException(_UNSUPPORTED_OPERATION_MESSAGE);
-
- StringBuffer tokenBuffer = new StringBuffer();
- tokenBuffer.append(token);
- tokenBuffer.append(" (");
- tokenBuffer.append(tokenToViewId.get(token));
- tokenBuffer.append(")");
-
- return tokenBuffer.toString();
+ FacesContext context = FacesContext.getCurrentInstance();
+ return _getTokenToViewIdString( _getTokenToViewIdMap(context), token);
}
+
/**
- * Method to help with debugging, should only be called when
- * debugTokenCache() is true
+ *
+ * Add info about the cache to the log buffer.
+ *
+ * For the target store map, the keys are tokens. For each token we will call
+ * getTokenToViewIdString to show what's in the map.
+ *
+ * For the pinned map the keys and values are tokens, for each key/value pair call
+ * getTokenToViewIdString to show what is pinned.
+ *
+ * This method should only be called when debugTokenCache() is true
*/
public static <V> void logCacheInfo(Map<String, V> targetStore, Map<String, String> pinned, String logAddition)
{
if (!_DEBUG_TOKEN_CACHE)
throw new UnsupportedOperationException(_UNSUPPORTED_OPERATION_MESSAGE);
-
- Map<String,String> tokenToViewId = getTokenToViewIdMap();
- StringBuffer logString = new StringBuffer();
+
+ FacesContext context = FacesContext.getCurrentInstance();
+ Map<String,String> tokenToViewId = _getTokenToViewIdMap(context);
+ // TODO - add this directly to the log buffer
+ StringBuffer logString = _getLogBuffer(context);
+ logString.append("\n");
if (logAddition != null)
{
@@ -121,7 +163,7 @@ public final class TokenCacheDebugUtils
for (String targetStoreToken: targetStore.keySet())
{
logString.append("\n ");
- logString.append(getTokenToViewIdString(tokenToViewId, targetStoreToken));
+ logString.append(_getTokenToViewIdString(tokenToViewId, targetStoreToken));
}
if (pinned != null)
@@ -131,49 +173,92 @@ public final class TokenCacheDebugUtils
for (String pinnedKeyToken: pinned.keySet())
{
logString.append("\n ");
- logString.append(getTokenToViewIdString(tokenToViewId, pinnedKeyToken));
+ logString.append(_getTokenToViewIdString(tokenToViewId, pinnedKeyToken));
logString.append(" pinned to ");
String pinnedValueToken = pinned.get(pinnedKeyToken);
- logString.append(getTokenToViewIdString(tokenToViewId, pinnedValueToken));
+ logString.append(_getTokenToViewIdString(tokenToViewId, pinnedValueToken));
}
- }
-
- addToRequestStringBuffer("\n" + logString.toString());
+ }
}
+
/**
- * Method to help with debugging, should only be called when
- * debugTokenCache() is true
+ * Add a string to the current log buffer
+ *
+ * This method should only be called when debugTokenCache() is true
*/
- public static Map<String,String> getTokenToViewIdMap()
- {
+ public static void addToLog(String addString)
+ {
if (!_DEBUG_TOKEN_CACHE)
throw new UnsupportedOperationException(_UNSUPPORTED_OPERATION_MESSAGE);
FacesContext context = FacesContext.getCurrentInstance();
- Map<String,String> tokenToViewId = (Map<String, String>)context.getExternalContext().getSessionMap().get("org.apache.myfaces.trinidadinternal.util.TOKEN_FOR_VIEW_ID");
+ _getLogBuffer(context).append(addString);
+ }
+
+ /**
+ * Start a log buffer.
+ * The startString passed in will be printed, along with session id and window id information
+ *
+ * This method should only be called when debugTokenCache() is true
+ */
+ public static void startLog(String startString)
+ {
+ if (!_DEBUG_TOKEN_CACHE)
+ throw new UnsupportedOperationException(_UNSUPPORTED_OPERATION_MESSAGE);
- if (tokenToViewId == null)
- {
- tokenToViewId = new ConcurrentHashMap<String, String>();
- context.getExternalContext().getSessionMap().put("org.apache.myfaces.trinidadinternal.util.TOKEN_FOR_VIEW_ID", tokenToViewId);
-
- }
- return tokenToViewId;
+ FacesContext context = FacesContext.getCurrentInstance();
+ StringBuffer logBuffer = _getLogBuffer(context, true);
+ logBuffer.append("-------------- ").append(startString).append(" ----------\n");
+ _logIdString(context);
}
+
/**
- * Method to help with debugging, should only be called when
- * debugTokenCache() is true
+ * get the string from the log buffer.
+ *
+ * This method should only be called when debugTokenCache() is true
*/
- public static void logIdString()
+ public static String getLogString()
{
if (!_DEBUG_TOKEN_CACHE)
throw new UnsupportedOperationException(_UNSUPPORTED_OPERATION_MESSAGE);
+ FacesContext context = FacesContext.getCurrentInstance();
+ return _getLogBuffer(context).toString();
+ }
+
+ private static StringBuffer _getLogBuffer(FacesContext context)
+ {
+ return _getLogBuffer(context, false);
+ }
+
+ private static StringBuffer _getLogBuffer(FacesContext context, boolean startNewBuffer)
+ {
+ Map<String, Object> requestMap = context.getExternalContext().getRequestMap();
+
+ StringBuffer buff = null;
+
+ if (!startNewBuffer)
+ {
+ buff = (StringBuffer)requestMap.get(_STRINGBUFFER_KEY);
+ }
+
+ if ( buff == null)
+ {
+ buff = new StringBuffer();
+ requestMap.put(_STRINGBUFFER_KEY, buff);
+ }
- ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
+ return buff;
+ }
+
+ /**
+ */
+ private static void _logIdString(FacesContext context)
+ {
+ ExternalContext externalContext = context.getExternalContext();
String sessionId = "";
Object session = externalContext.getSession(false);
@@ -182,7 +267,8 @@ public final class TokenCacheDebugUtils
sessionId = ((HttpSession)session).getId();
}
- addToRequestStringBuffer("Session Id = " + sessionId);
+ StringBuffer buff = _getLogBuffer(context);
+ buff.append("Session Id = ").append(sessionId);
WindowManager wm = RequestContext.getCurrentInstance().getWindowManager();
if (wm != null)
@@ -191,92 +277,61 @@ public final class TokenCacheDebugUtils
if (window != null)
{
- addToRequestStringBuffer("\nWindow Id = " + window.getId() );
+ buff.append("\nWindow Id = ").append(window.getId());
}
else
{
- addToRequestStringBuffer("\nWindow Id could not be determined, window is null" );
+ buff.append("\nWindow Id could not be determined, window is null" );
}
}
else
{
- addToRequestStringBuffer("\nWindow Id could not be determined, window manager null" );
+ buff.append("\nWindow Id could not be determined, window manager null" );
}
}
-
- /**
- * Method to help with debugging, should only be called when
- * debugTokenCache() is true
- */
- public static void addToRequestStringBuffer(String addString)
- {
- if (!_DEBUG_TOKEN_CACHE)
- throw new UnsupportedOperationException(_UNSUPPORTED_OPERATION_MESSAGE);
-
- _getRequestStringBuffer().append(addString);
- }
/**
- * Method to help with debugging, should only be called when
- * debugTokenCache() is true
- */
- public static void clearRequestStringBuffer()
- {
- if (!_DEBUG_TOKEN_CACHE)
- throw new UnsupportedOperationException(_UNSUPPORTED_OPERATION_MESSAGE);
-
- Map<String, Object> requestMap = FacesContext.getCurrentInstance().getExternalContext().getRequestMap();
- requestMap.put("org.apache.myfaces.trinidadinternal.DEBUG_TOKEN_CACHE.StringBuffer", null);
- }
-
- /**
- * Method to help with debugging, should only be called when
- * debugTokenCache() is true
*/
- public static String getRequestString()
- {
- if (!_DEBUG_TOKEN_CACHE)
- throw new UnsupportedOperationException(_UNSUPPORTED_OPERATION_MESSAGE);
-
- return _getRequestStringBuffer().toString();
- }
-
- private static StringBuffer _getRequestStringBuffer()
+ private static Map<String,String> _getTokenToViewIdMap(FacesContext context)
{
- if (!_DEBUG_TOKEN_CACHE)
- throw new UnsupportedOperationException(_UNSUPPORTED_OPERATION_MESSAGE);
-
- Map<String, Object> requestMap = FacesContext.getCurrentInstance().getExternalContext().getRequestMap();
- StringBuffer buff = (StringBuffer)requestMap.get("org.apache.myfaces.trinidadinternal.DEBUG_TOKEN_CACHE.StringBuffer");
+ Map<String,String> tokenToViewId = (Map<String, String>)context.getExternalContext().getSessionMap().get("org.apache.myfaces.trinidadinternal.util.TOKEN_FOR_VIEW_ID");
- if ( buff == null)
+ if (tokenToViewId == null)
{
- buff = new StringBuffer();
- requestMap.put("org.apache.myfaces.trinidadinternal.DEBUG_TOKEN_CACHE.StringBuffer", buff);
+ tokenToViewId = new ConcurrentHashMap<String, String>();
+ context.getExternalContext().getSessionMap().put("org.apache.myfaces.trinidadinternal.util.TOKEN_FOR_VIEW_ID", tokenToViewId);
+
}
-
- return buff;
+ return tokenToViewId;
}
+
+
+ /**
+ */
+ private static String _getTokenToViewIdString(Map<String,String> tokenToViewId, String token)
+ {
+ StringBuffer tokenBuffer = new StringBuffer();
+ tokenBuffer.append(token);
+ tokenBuffer.append(" (");
+ tokenBuffer.append(tokenToViewId.get(token));
+ tokenBuffer.append(")");
+
+ return tokenBuffer.toString();
+ }
private static final String _UNSUPPORTED_OPERATION_MESSAGE =
"Methods in TokenCacheDebugUtils can only be called when " +
"TokenCacheDebugUtils.debugTokenCache() returns true. " +
"TokenCacheDebugUtils.debugTokenCache() returns true when the system property " +
"'org.apache.myfaces.trinidadinternal.DEBUG_TOKEN_CACHE' is true";
+
+
+ private static final String _STRINGBUFFER_KEY = TokenCacheDebugUtils.class.getName() + "#StringBuffer";
- // ViewExpiredExceptions are fairly common, and the token cache is used for
- // page state tokens, but the tokens aren't really human readable.
- // In order to make it easier to understand what is in the cache
- // we've added a system property for debugging purposes. When enabled
- // we store a map of token -> viewId on the session which we use
- // to log something more human readable.
- //
- // in order to use this the tester would set the system property to:
- // -Dorg.apache.myfaces.trinidadinternal.DEBUG_TOKEN_CACHE=true
- static private final Boolean _DEBUG_TOKEN_CACHE;
+ static private final boolean _DEBUG_TOKEN_CACHE;
static
{
String dtcProp = System.getProperty("org.apache.myfaces.trinidadinternal.DEBUG_TOKEN_CACHE");