1 Reply Latest reply: Jun 30, 2010 3:13 PM by Andrew Rubinger RSS

ShrinkWrapStandardContext and Serializable

Andrew Rubinger Master



Regarding the new Tomcat/ShrinkWrap deployment mechanism:


StandardContext, the parent class of our extension, implements Serializable.  Therefore, our ShrinkWrapStandardContext implicitly does, too.  A few issues:


  1. We've got no explicit serialVersionUID
  2. We've got no explicit serialization protocol (either implement Externalizable or put in private readObject/writeObject methods)
  3. The instance member "archive" is not itself Serializable


Recommend implementing 1) as "1L", and accomplishing 2) and 3) in one swipe by taking advantage of the archive.as(SerializableView.class) and writing that.  Then you can reconstitute it back into an Archive during deserialization.


Bonus points for determining if we need to put tests in place which guard wire compatibility across version changes, future-proofing us.  I'm not sure if it's a requirement that we serialize  ShrinkWrapStandardContext between different versions of ShrinkWrap in the future,  If so, we'll need those, too.





PS - Shame on Tomcat for making us 1) Subclass their thingy instead of implement some interface and 2) Implement Serializable in the first place

  • 1. Re: ShrinkWrapStandardContext and Serializable
    Andrew Rubinger Master

    Of course, we could be up a creek on this one.  A simple test:


        * Ensures we can serialize/deserialize roundtrip 
       public void serializeAndDeserialize() throws Exception
          // Make a context
          final ShrinkWrapStandardContext context = new ShrinkWrapStandardContext(ShrinkWrap.create(JavaArchive.class,
          // Serialize
          final ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
          final ObjectOutputStream out = new ObjectOutputStream(byteOut);
          final ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(byteOut.toByteArray()));
          final ShrinkWrapStandardContext roundtrip = (ShrinkWrapStandardContext) in.readObject();


    ...yields that we now have a problem we might not be able to control:


    java.io.NotSerializableException: org.apache.catalina.util.LifecycleSupport
    at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1156)
    at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1509)
    at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1474)
    at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1392)
    at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1150)
    at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:326)
    at org.jboss.shrinkwrap.tomcat.test.SerializationUnitTestCase.serializeAndDeserialize(SerializationUnitTestCase.java:66)