4 Replies Latest reply on Nov 19, 2009 5:13 AM by delbd

    jndi, rebind, java.io.NotSerializableException

    delbd

      Hello,

      trying to migrate an application from tomcat to JBoss, i am blocked with this error.

      jvm 1 | java.io.NotSerializableException: org.enhydra.shark.Shark
      jvm 1 | at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1156)
      jvm 1 | at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:326)
      jvm 1 | at java.rmi.MarshalledObject.<init>(MarshalledObject.java:101)
      jvm 1 | at org.jnp.interfaces.MarshalledValuePair.<init>(MarshalledValuePair.java:65)
      jvm 1 | at org.jnp.interfaces.NamingContext.createMarshalledValuePair(NamingContext.java:1425)
      jvm 1 | at org.jnp.interfaces.NamingContext.rebind(NamingContext.java:567)
      jvm 1 | at org.jnp.interfaces.NamingContext.rebind(NamingContext.java:540)
      jvm 1 | at javax.naming.InitialContext.rebind(InitialContext.java:408)
      jvm 1 | at be.rmi.intranet.chain.setup.SharkSetup.execute(SharkSetup.java:56)
      jvm 1 | at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:166)
      jvm 1 | at be.rmi.intranet.servlet.SetupServlet.init(SetupServlet.java:298)
      

      The application am trying to migrate uses jndi to store objets created at startup that the whole application needs. Unfortunately, none of those objet are serializable and there is no reason to make them serialisable, since they are meant to be local to the JVM. According to JBoss docs i found on subjet, local VM / environment ressources are to be stored in the java:comp/env .

      This is what we do
      Binding shark at java:comp/env/Shark

      However, despite locality of objet, jboss complains it's not serializable. We can easily move those object to somewhere else in jndi so JBoss does not try to serialize them. But since those are proprietary objects, it's impossible or very difficult to make them serializable. Where should we store non serializable items in jndi? Or how can i tell jndi not to try to serialize objet (we don't need them to be remotely accessible or available in a cluster)

      Side question, how to convert this context.xml entry to jboss?
      <Environment name="conf/shark/GraphPictures" value="/home/intrarmi/shark-runtime/repository/png" type="java.lang.String" override="false" />


        • 1. Re: jndi, rebind, java.io.NotSerializableException
          jaikiran
          • 2. Re: jndi, rebind, java.io.NotSerializableException
            delbd

            Not possible. I already found this class, but it has two main problem.

            First, it introduces a dependency to jboss in my code, while i would like to stick with pure J2EE available specs.

            Second, this mean changing eveywhere my code calls like context.lookup(name) to something like NonSerializableFactory.lookup(name). I'd like not to change the code just because jboss has decided tha purely local objects need to be serialized.


            This doc http://docs.jboss.org/jbossas/admindevel326/html/ch3.chapter.html states


            Subcontexts and object bindings directly under java: are only visible within the JBoss server virtual machine and not to remote clients. Any other context or object binding is available to remote clients, provided the context or object supports serialization. [....]

            An example of where the restricting a binding to the java: context is useful would be a javax.sql.DataSource connection factory that can only be used inside of the JBoss server where the associated database pool resides.


            I see nowhere that is mandates objets are serializable and even if so, the only mention of serialization is about other context, not java: ones. However, the jboss still complains about serialization and fail while i bind an object to the name "java:Shark". Note that i tried "java:Shark", "java:comp/env/Shark" and "Shark", all are failing with serialization errors.

            • 3. Re: jndi, rebind, java.io.NotSerializableException
              jaikiran

               

              "delbd" wrote:

              Second, this mean changing eveywhere my code calls like context.lookup(name) to something like NonSerializableFactory.lookup(name).


              No. You will still do InitialContext.lookup(name), internally it's handled by ObjectFactory. It's only during the binding that you will use the NonSerializableFactory. And yes, it does introduce a dependency on JBoss code.

              • 4. Re: jndi, rebind, java.io.NotSerializableException
                delbd

                Ok, i copy/pasted the class in my webapp. This works now without dependencies to JBoss, thanks.