You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by mb...@apache.org on 2005/11/03 23:29:04 UTC
svn commit: r330658 - in /myfaces: examples/trunk/conf/basic-web.xml
examples/trunk/conf/web-develop.xml examples/trunk/conf/web.xml
impl/trunk/src/java/org/apache/myfaces/application/jsp/JspStateManagerImpl.java
Author: mbr
Date: Thu Nov 3 14:28:56 2005
New Revision: 330658
URL: http://svn.apache.org/viewcvs?rev=330658&view=rev
Log:
introduced a new webapp parameter (org.apache.myfaces.COMPRESS_STATE_IN_SESSION) to compress the serialized state if server side state is used
Modified:
myfaces/examples/trunk/conf/basic-web.xml
myfaces/examples/trunk/conf/web-develop.xml
myfaces/examples/trunk/conf/web.xml
myfaces/impl/trunk/src/java/org/apache/myfaces/application/jsp/JspStateManagerImpl.java
Modified: myfaces/examples/trunk/conf/basic-web.xml
URL: http://svn.apache.org/viewcvs/myfaces/examples/trunk/conf/basic-web.xml?rev=330658&r1=330657&r2=330658&view=diff
==============================================================================
--- myfaces/examples/trunk/conf/basic-web.xml (original)
+++ myfaces/examples/trunk/conf/basic-web.xml Thu Nov 3 14:28:56 2005
@@ -74,6 +74,17 @@
</context-param>
<context-param>
+ <param-name>org.apache.myfaces.COMPRESS_STATE_IN_SESSION</param-name>
+ <param-value>true</param-value>
+ <description>
+ Only applicable if state saving method is "server" (= default) and if
+ org.apache.myfaces.SERIALIZE_STATE_IN_SESSION is true (= default)
+ If true (default) the serialized state will be compressed before it
+ is written to the session. If false the state will not be compressed.
+ </description>
+ </context-param>
+
+ <context-param>
<param-name>org.apache.myfaces.ALLOW_JAVASCRIPT</param-name>
<param-value>true</param-value>
<description>
Modified: myfaces/examples/trunk/conf/web-develop.xml
URL: http://svn.apache.org/viewcvs/myfaces/examples/trunk/conf/web-develop.xml?rev=330658&r1=330657&r2=330658&view=diff
==============================================================================
--- myfaces/examples/trunk/conf/web-develop.xml (original)
+++ myfaces/examples/trunk/conf/web-develop.xml Thu Nov 3 14:28:56 2005
@@ -74,6 +74,17 @@
</context-param>
<context-param>
+ <param-name>org.apache.myfaces.COMPRESS_STATE_IN_SESSION</param-name>
+ <param-value>true</param-value>
+ <description>
+ Only applicable if state saving method is "server" (= default) and if
+ org.apache.myfaces.SERIALIZE_STATE_IN_SESSION is true (= default)
+ If true (default) the serialized state will be compressed before it
+ is written to the session. If false the state will not be compressed.
+ </description>
+ </context-param>
+
+ <context-param>
<param-name>org.apache.myfaces.ALLOW_JAVASCRIPT</param-name>
<param-value>true</param-value>
<description>
Modified: myfaces/examples/trunk/conf/web.xml
URL: http://svn.apache.org/viewcvs/myfaces/examples/trunk/conf/web.xml?rev=330658&r1=330657&r2=330658&view=diff
==============================================================================
--- myfaces/examples/trunk/conf/web.xml (original)
+++ myfaces/examples/trunk/conf/web.xml Thu Nov 3 14:28:56 2005
@@ -72,6 +72,17 @@
If false the state will not be serialized to a byte stream.
</description>
</context-param>
+
+ <context-param>
+ <param-name>org.apache.myfaces.COMPRESS_STATE_IN_SESSION</param-name>
+ <param-value>true</param-value>
+ <description>
+ Only applicable if state saving method is "server" (= default) and if
+ org.apache.myfaces.SERIALIZE_STATE_IN_SESSION is true (= default)
+ If true (default) the serialized state will be compressed before it
+ is written to the session. If false the state will not be compressed.
+ </description>
+ </context-param>
<context-param>
<param-name>org.apache.myfaces.ALLOW_JAVASCRIPT</param-name>
Modified: myfaces/impl/trunk/src/java/org/apache/myfaces/application/jsp/JspStateManagerImpl.java
URL: http://svn.apache.org/viewcvs/myfaces/impl/trunk/src/java/org/apache/myfaces/application/jsp/JspStateManagerImpl.java?rev=330658&r1=330657&r2=330658&view=diff
==============================================================================
--- myfaces/impl/trunk/src/java/org/apache/myfaces/application/jsp/JspStateManagerImpl.java (original)
+++ myfaces/impl/trunk/src/java/org/apache/myfaces/application/jsp/JspStateManagerImpl.java Thu Nov 3 14:28:56 2005
@@ -18,8 +18,10 @@
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
+import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
+import java.io.OutputStream;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
@@ -28,6 +30,8 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.zip.GZIPInputStream;
+import java.util.zip.GZIPOutputStream;
import javax.faces.FactoryFinder;
import javax.faces.application.StateManager;
@@ -73,7 +77,14 @@
private static final String SERIALIZE_STATE_IN_SESSION_PARAM = "org.apache.myfaces.SERIALIZE_STATE_IN_SESSION";
+ private static final String COMPRESS_SERVER_STATE_PARAM = "org.apache.myfaces.COMPRESS_STATE_IN_SESSION";
+
+ private static final boolean DEFAULT_COMPRESS_SERVER_STATE_PARAM = true;
+
private static final boolean DEFAULT_SERIALIZE_STATE_IN_SESSION = true;
+
+ private static final int UNCOMPRESSED_FLAG = 0;
+ private static final int COMPRESSED_FLAG = 1;
private RenderKitFactory _renderKitFactory = null;
@@ -446,7 +457,17 @@
ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
try
{
- ObjectOutputStream out = new ObjectOutputStream(baos);
+ OutputStream os = baos;
+ if(isCompressStateInSession(context))
+ {
+ os.write(COMPRESSED_FLAG);
+ os = new GZIPOutputStream(os, 1024);
+ }
+ else
+ {
+ os.write(UNCOMPRESSED_FLAG);
+ }
+ ObjectOutputStream out = new ObjectOutputStream(os);
out.writeObject(serializedView.getStructure());
out.writeObject(serializedView.getState());
out.close();
@@ -467,7 +488,7 @@
/**
* @param context
- * @return boolean true, if the state should be serialized in the session
+ * @return boolean true, if the server state should be serialized in the session
*/
protected boolean isSerializeStateInSession(FacesContext context)
{
@@ -481,14 +502,36 @@
return serialize;
}
+ /**
+ * @param context
+ * @return boolean true, if the server state steam should be compressed
+ */
+ protected boolean isCompressStateInSession(FacesContext context)
+ {
+ String value = context.getExternalContext().getInitParameter(
+ COMPRESS_SERVER_STATE_PARAM);
+ boolean compress = DEFAULT_COMPRESS_SERVER_STATE_PARAM;
+ if (value != null)
+ {
+ compress = new Boolean(value).booleanValue();
+ }
+ return compress;
+ }
+
protected SerializedView deserializeView(Object state)
{
if(state instanceof byte[])
{
try
{
+ ByteArrayInputStream bais = new ByteArrayInputStream((byte[]) state);
+ InputStream is = bais;
+ if(is.read() == COMPRESSED_FLAG)
+ {
+ is = new GZIPInputStream(is);
+ }
ObjectInputStream in = new ObjectInputStream(
- new ByteArrayInputStream((byte[]) state));
+ is);
return new SerializedView(in.readObject(), in.readObject());
}
catch (IOException e)