1 Reply Latest reply on Nov 18, 2003 4:24 PM by charleschr

    StreamCorruptedException looking up EJB

    charleschr

      Hi all,

      Apologies if this has been answered a thousand times before. I checked these forums, newsgroups, etc. but didn't see an answer to my question.

      I am using JBoss 3.2.2 and Sun JDK 1.3.1_07 on Windows XP Pro. I am able to start JBoss and all of the EJBs seem to deploy fine. However, when I try to do a lookup in my code, I get the following exception:

      [NamingContext] Failed to connect to localhost:8080
      javax.naming.CommunicationException: Failed to retrieve stub from server localhost:8080. Root exception is
      java.io.StreamCorruptedException: Caught EOFException while reading the stream header
      at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:840)
      at java.io.ObjectInputStream.(ObjectInputStream.java:163)
      at org.jnp.interfaces.NamingContext.getServer(NamingContext.java:197)
      at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:1181)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:514)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:507)
      at javax.naming.InitialContext.lookup(InitialContext.java:345)
      . . .

      Here is the code I am using to do the lookup. The code is meant to be able to get a reference to an EJBObject of any type, whether Session or Entity. I should note that the code works fine on Weblogic 5.1:

      private static final EJBObject getBean(String name, String home, String method, Object[] params)
      {
      EJBObject bean = null;

      String addr = "";
      String port = "";
      String factory = "";
      String protocol = "";

      Context ctx = null;

      try {
      addr = MYServerProperties.getProp(MYServerProperties.KEY_APPSERVER_ADDRESS);
      port = MYServerProperties.getProp(MYServerProperties.KEY_APPSERVER_PORT);
      factory = MYServerProperties.getProp(MYServerProperties.KEY_CONTEXT_FACTORY);
      protocol = MYServerProperties.getProp(MYServerProperties.KEY_CONTEXT_PROTOCOL);

      if(addr == null || factory == null || protocol == null || port == null)
      ctx = null;
      else
      {
      Properties p = System.getProperties();
      p.put(Context.INITIAL_CONTEXT_FACTORY, factory);
      p.put(Context.PROVIDER_URL, protocol + "://" + addr + ":" + port);

      ctx = new javax.naming.InitialContext(p);
      }

      if(ctx != null)
      {
      Object homeobj = ctx.lookup(name);
      Class c = homeobj.getClass();

      // get all interfaces implemented by this class
      Class ifs[] = c.getInterfaces();
      Class homeif = null;

      // find the appropriate home interface
      for(int i = 0; i < Array.getLength(ifs); i++)
      {
      if(ifs.getName().equals(home))
      {
      homeif = ifs
      ;
      break;
      }
      }

      if(homeif != null)
      {
      // get the runtime class of all the parameters
      Class ps[] = new Class[Array.getLength(params)];
      for(int i = 0; i < Array.getLength(params); i++)
      ps = params.getClass();

      // get the method to call on the home interface
      Method m = homeif.getMethod(method,ps);
      if(m != null)
      bean = (EJBObject)m.invoke(homeobj,params); // execute the method
      }
      }
      }

      catch(Exception ex) {
      bean = null;
      ex.printStackTrace();
      }

      finally {
      return bean;
      }
      }

      I'm sure there must be something simple I am not getting. Any hints you could give me would be greatly appreciated!

      Chuck