You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by pe...@apache.org on 2010/11/24 18:41:09 UTC
svn commit: r1038716 - in /wicket/branches/wicket-1.4.x/wicket/src:
main/java/org/apache/wicket/util/io/WicketObjectOutputStream.java
test/java/org/apache/wicket/resource/DummyPage.java
test/java/org/apache/wicket/util/io/WicketOutputStreamTest.java
Author: pedro
Date: Wed Nov 24 17:41:09 2010
New Revision: 1038716
URL: http://svn.apache.org/viewvc?rev=1038716&view=rev
Log:
Using an stack to make sure that the WicketObjectOutputStream has the correct ClassStreamHandler on each defaultWriteObject call at the methods invocations stack. This method is trigger an indirect recursion, so it is important don't share the ClassStreamHandler as an instance variable.
Issue: WICKET-3136
Modified:
wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/util/io/WicketObjectOutputStream.java
wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/resource/DummyPage.java
wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/util/io/WicketOutputStreamTest.java
Modified: wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/util/io/WicketObjectOutputStream.java
URL: http://svn.apache.org/viewvc/wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/util/io/WicketObjectOutputStream.java?rev=1038716&r1=1038715&r2=1038716&view=diff
==============================================================================
--- wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/util/io/WicketObjectOutputStream.java (original)
+++ wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/util/io/WicketObjectOutputStream.java Wed Nov 24 17:41:09 2010
@@ -28,11 +28,18 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
+import java.util.Stack;
+import org.apache.wicket.protocol.http.WebApplication;
import org.apache.wicket.util.lang.Generics;
/**
+ * The Wicket ObjectOutputStream to enable back-button support for the reloading mechanism, be sure
+ * to put <tt>Objects.setObjectStreamFactory(new WicketObjectStreamFactory());</tt> in your
+ * application's {@link WebApplication#init()} method.
+ *
+ * @see org.apache.wicket.protocol.http.ReloadingWicketFilter
* @author jcompagner
*/
public final class WicketObjectOutputStream extends ObjectOutputStream
@@ -445,7 +452,7 @@ public final class WicketObjectOutputStr
private final HandleArrayListStack<Object> defaultWrite = new HandleArrayListStack<Object>();
private final DataOutputStream out;
- private ClassStreamHandler classHandler;
+ private final Stack<ClassStreamHandler> classHandlerStack = new Stack<ClassStreamHandler>();
private PutField curPut;
@@ -470,7 +477,7 @@ public final class WicketObjectOutputStr
@Override
public void close() throws IOException
{
- classHandler = null;
+ classHandlerStack.clear();
curObject = null;
curPut = null;
handledObjects.clear();
@@ -487,7 +494,7 @@ public final class WicketObjectOutputStr
if (!defaultWrite.contains(curObject))
{
defaultWrite.add(curObject);
- classHandler.writeFields(this, curObject);
+ classHandlerStack.peek().writeFields(this, curObject);
}
}
@@ -790,7 +797,7 @@ public final class WicketObjectOutputStr
else
{
Class<?> realClz = cls;
- classHandler = ClassStreamHandler.lookup(realClz);
+ ClassStreamHandler classHandler = ClassStreamHandler.lookup(realClz);
Object object = classHandler.writeReplace(obj);
if (object != null)
@@ -815,6 +822,7 @@ public final class WicketObjectOutputStr
curObject = obj;
try
{
+ classHandlerStack.push(classHandler);
if (!classHandler.invokeWriteMethod(this, obj))
{
classHandler.writeFields(this, obj);
@@ -849,6 +857,7 @@ public final class WicketObjectOutputStr
}
finally
{
+ classHandlerStack.pop();
curObject = oldObject;
curPut = old;
}
Modified: wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/resource/DummyPage.java
URL: http://svn.apache.org/viewvc/wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/resource/DummyPage.java?rev=1038716&r1=1038715&r2=1038716&view=diff
==============================================================================
--- wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/resource/DummyPage.java (original)
+++ wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/resource/DummyPage.java Wed Nov 24 17:41:09 2010
@@ -16,6 +16,7 @@
*/
package org.apache.wicket.resource;
+import org.apache.wicket.IPageMap;
import org.apache.wicket.markup.html.WebPage;
/**
@@ -36,4 +37,10 @@ public class DummyPage extends WebPage
super();
}
+
+ public DummyPage(IPageMap pageMap)
+ {
+ super(pageMap);
+ }
+
}
Modified: wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/util/io/WicketOutputStreamTest.java
URL: http://svn.apache.org/viewvc/wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/util/io/WicketOutputStreamTest.java?rev=1038716&r1=1038715&r2=1038716&view=diff
==============================================================================
--- wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/util/io/WicketOutputStreamTest.java (original)
+++ wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/util/io/WicketOutputStreamTest.java Wed Nov 24 17:41:09 2010
@@ -17,6 +17,7 @@
package org.apache.wicket.util.io;
import java.io.ByteArrayInputStream;
+import java.io.IOException;
import java.math.BigInteger;
import java.util.GregorianCalendar;
import java.util.Locale;
@@ -24,10 +25,12 @@ import java.util.Locale;
import junit.framework.Assert;
import org.apache.wicket.Page;
+import org.apache.wicket.PageMap;
import org.apache.wicket.RequestCycle;
import org.apache.wicket.WicketTestCase;
import org.apache.wicket.protocol.http.HttpSessionStore;
import org.apache.wicket.protocol.http.WebApplication;
+import org.apache.wicket.resource.DummyPage;
import org.apache.wicket.session.ISessionStore;
/**
@@ -139,6 +142,17 @@ public class WicketOutputStreamTest exte
RequestCycle.get().detach();
}
+ public void testPageWithPageMapSerialization() throws IOException, ClassNotFoundException
+ {
+ DummyPage dummyPage = new DummyPage(PageMap.forName("test"));
+ woos.writeObject(dummyPage);
+ ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
+
+ WicketObjectInputStream wois = new WicketObjectInputStream(bais);
+ DummyPage dummyPage2 = (DummyPage)wois.readObject();
+
+ Assert.assertEquals(dummyPage.getClass(), dummyPage2.getClass());
+ }
// public void testStringsEqualsAfterSerialization() throws Exception
// {