2 Replies Latest reply on Dec 2, 2004 1:56 PM by amayingenta

    JNDI serialization problem

    amayingenta

      Hi, I'm using JBoss 4.0.0 and I'm having some problems with JBoss apparently ignoring the CallByValue=false attribute of the NamingService in my custom JBoss configuration.

      I have a custom server configuration containing those services I need deployed. It is based upon the standard configuration so that it behaves more like 3.2.x and we were taking advantage (probably unwisely) of the fact that objects retrieved from JNDI do not have to be rebound when modified because the reference to the object in JNDI was being returned.

      I could swear that this was working as expected with my configuration until recently, and I have not made any changes recently, however now it is not working (altough I think it did work once, briefly until I restarted the server).

      To try and isolate the problem, I wrote a little MBean:

      public class JndiTest implements JndiTestMBean
      {
       public void start()
       {
       }
      
       public void stop()
       {
       }
      
       public void performJndiTest() throws Exception
       {
       Context ctx = new InitialContext();
       ctx.rebind("testvalue", new TestValue("TransientString"));
       TestValue v = (TestValue)ctx.lookup("testvalue");
       System.out.println("Retrieved value: "+v.getValue());
       }
      
       private static class TestValue implements Serializable
       {
       private transient String str;
      
       public TestValue(String str)
       {
       this.str = str;
       }
      
       public String getValue()
       {
       return str;
       }
      
       private void writeObject(ObjectOutputStream out) throws IOException
       {
       System.out.println("WriteObject. Value="+str);
       out.defaultWriteObject();
       }
      
       private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException
       {
       in.defaultReadObject();
       System.out.println("ReadObject. Value="+str);
       }
       }
      


      When I deploy this MBean in an otherwise unmodified copy of the standard server and call performJndiTest() from the jmx-console I see this:

      11:57:19,297 INFO [STDOUT] WriteObject. Value=TransientString
      11:57:19,298 INFO [STDOUT] Retrieved value: TransientString

      When I deploy this in my custom configuration (along with my application) I see this:

      12:20:53,458 INFO [STDOUT] WriteObject. Value=TransientString
      12:20:53,508 INFO [STDOUT] ReadObject. Value=null
      12:20:53,508 INFO [STDOUT] Retrieved value: null

      The conf/jboss-service.xml in my custom configuration only differs from standard/conf/jboss-service.xml due to modified port numbers and that I've commented out the PooledInvoker because I don't know what it does(!).

      ----

      I've just performed another test - this time using my custom configuration without the EAR that contains my application. Now the test performs as expected, with the transient value being retained. So it appears that deploying my EAR somehow affects the behaviour of JNDI.

      My ear-deployer.xml is the same as the standard ear-deployer.xml (I originally had CallByValue=true in there because we're almost entirely using Local interfaces and want any remote calls to serialize even if they are within the same VM).

      We did switch from deploying our EJB jars seperately (with all support classes included in the EJB jars) to using an EAR (with the minimum number of classes in the EJB jars and a separate jar referenced by Class-Path: in the EJB jar Manifest). It may be that this is the point where JNDI started serializing.

      I've looked at the change notes for the 4.0.1 release candidates and I can't see anything that would have fixed this.

      Can anyone shed any light on this?

      Thanks,
      Andrew

        • 1. Re: JNDI serialization problem
          starksm64

          Your application can change the jndi semantics by including a jndi.properties which does so. Run your app test in the unmodified standard configuration to validate whether its a change you made in the config or something the app is doing.

          • 2. Re: JNDI serialization problem
            amayingenta

            Thanks for your reply.
            I'd accidentally included the jndi.properties intended for test clients in the jar of classes inside my EAR.

            Everything now works as expected.

            Thanks again,
            Andrew