1 Reply Latest reply on Mar 2, 2011 6:19 AM by stianst

    CommunicationException thrown when trying to lookup session bean

    stianst

      I'm trying to lookup a session bean from a servlet. There lookup code looks like this:

       

       

      {code}

      InitialContext ic = new InitialContext();

      ic.lookup("MyBean/remote");

      {code}

       

      I don't have a jndi.properties file

       

      However, the lookup throws javax.naming.CommunicationException: Receive timed out [Root exception is java.net.SocketTimeoutException: Receive timed out]

       

      I've had a look at NamingContext to figure out what is going on. To summarize NamingContext#checkRef does the following:

       

      1. Check if Context.PROVIDER_URL is specified in refEnv - It isn't
      2. Use the server in the same VM - localServer is null so this isn't available
      3. Discover server using broadcast - this is where the CommunicationException is thrown

       

      Does anyone have any idea what is going on? It seems to me that NamingContext#localServer shouldn't be null? Also why does it do a broadcast discovery by default (I assume HA isn't enabled by default)?

        • 1. CommunicationException thrown when trying to lookup session bean
          stianst

          Problem solved!

           

          NamingContext#localServer was null because jnp-client.jar was included in the WAR so the NamingContext class was loaded by the WAR class loader instead of retrieved from the system classloader. NamingContext#localServer is a static variable and is set by NamingBeanImpl on startup of the server and is obviously only set on the NamingContext class that is loaded by the system classloader.

           

          I still have some questions on this issue though:

           

          • Why is broadcast discovery enabled by default?
          • It seems the CommunicationException should be replaced with an exception that is more intuitive. The problem in this case is that InitialContext couldn't lookup an object as is couldn't get a hold of the naming server which is not at all made clear by the exception.