5 Replies Latest reply on Oct 12, 2004 5:04 PM by Mark LaPolla

    Session Bean Client hangs at Context Lookup

    tmccrary Newbie

      Hi, I am new to JBoss and I am having a problem.

      I created a test session bean and deployed it:



      15:44:58,306 INFO [EjbModule] Deploying TestEJB
      15:44:58,376 INFO [StatelessSessionInstancePool] Started jboss.j2ee:jndiName=TestEJB,plugin=pool,service=EJB
      15:44:58,377 INFO [StatelessSessionContainer] Started jboss.j2ee:jndiName=TestEJB,service=EJB
      15:44:58,377 INFO [EjbModule] Started jboss.j2ee:module=TestEJB.jar,service=EjbModule
      15:44:58,377 INFO [EJBDeployer] Deployed: file:/opt/jboss/server/default/deploy/TestEJB.jar
      15:44:58,391 INFO [MainDeployer] Deployed package: file:/opt/jboss/server/default/deploy/TestEJB.jar



      But whenever I run the client, it hangs at the context lookup forever. There are no exceptions thrown, it just sits there.

      Here is the code I am using:

      Remote Interface

      
      package com.test.ejbtest;
      
      import java.rmi.RemoteException;
      
      import javax.ejb.EJBObject;
      
      /**
       *
       *
       * TODO To change the template for this generated type comment go to
       * Window - Preferences - Java - Code Style - Code Templates
       */
      public interface TestEJB extends EJBObject {
      
       public String test() throws RemoteException;
      
      }
      
      
      


      Home Interface

      
      package com.test.ejbtest;
      
      import java.rmi.RemoteException;
      
      import javax.ejb.CreateException;
      import javax.ejb.EJBHome;
      
      /**
       *
       *
       * TODO To change the template for this generated type comment go to
       * Window - Preferences - Java - Code Style - Code Templates
       */
      public interface TestEJBHome extends EJBHome {
      
       TestEJB create() throws RemoteException, CreateException;
      
      }
      
      


      EJB

      
      package com.test.ejbtest;
      
      import java.rmi.RemoteException;
      
      import javax.ejb.EJBException;
      import javax.ejb.SessionBean;
      import javax.ejb.SessionContext;
      
      /**
       *
       *
       * TODO To change the template for this generated type comment go to
       * Window - Preferences - Java - Code Style - Code Templates
       */
      public class TestEJBBean implements SessionBean {
      
       /* (non-Javadoc)
       * @see javax.ejb.SessionBean#ejbActivate()
       */
       public void ejbActivate() throws EJBException, RemoteException {
       // TODO Auto-generated method stub
      
       }
      
       /* (non-Javadoc)
       * @see javax.ejb.SessionBean#ejbPassivate()
       */
       public void ejbPassivate() throws EJBException, RemoteException {
       // TODO Auto-generated method stub
      
       }
      
       /* (non-Javadoc)
       * @see javax.ejb.SessionBean#ejbRemove()
       */
       public void ejbRemove() throws EJBException, RemoteException {
       // TODO Auto-generated method stub
      
       }
      
       /* (non-Javadoc)
       * @see javax.ejb.SessionBean#setSessionContext(javax.ejb.SessionContext)
       */
       public void setSessionContext(SessionContext arg0) throws EJBException,
       RemoteException {
       // TODO Auto-generated method stub
      
       }
      
       public String test() {
      
      
       System.out.println("Testing the EJB on JBoss");
      
       return "Testing EJB ";
      
       }
      
       public void ejbCreate() {
      
       System.out.println("ejbCreate");
      
       }
      
      }
      
      


      EJB Descriptor

      
      
      <?xml version="1.0" encoding="UTF-8"?>
      
      <ejb-jar>
      
       <description>JBoss Test EJB</description>
       <display-name>Test EJB</display-name>
       <enterprise-beans>
      
       <session>
      
       <ejb-name>TestEJB</ejb-name>
       <home>com.nd.ejbtest.TestEJBHome</home>
       <remote>com.nd.ejbtest.TestEJB</remote>
       <ejb-class>com.nd.ejbtest.TestEJBBean</ejb-class>
       <session-type>Stateless</session-type>
       <transaction-type>Bean</transaction-type>
      
       </session>
      
       </enterprise-beans>
      
      </ejb-jar>
      
      
      



      Any help would be much appreciated :)

        • 1. Re: Session Bean Client hangs at Context Lookup
          tmccrary Newbie

          Also, my client app:

          
          package com.test.ejbtest;
          
          import java.util.Hashtable;
          
          import javax.naming.Context;
          import javax.naming.InitialContext;
          
          /**
           *
           *
           * TODO To change the template for this generated type comment go to
           * Window - Preferences - Java - Code Style - Code Templates
           */
          public class TestClient {
          
           public static void main(String[] args) {
          
          
           Hashtable env = new Hashtable();
           env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
           env.put(Context.PROVIDER_URL, "marge.ndindustries.com:1099");
           env.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
          
           System.out.println("Attempting connection to server...");
          
           try
           {
          
           System.out.println("A");
          
           Context ctx = new InitialContext(env);
          
           System.out.println("B");
          
           Object obj = ctx.lookup("TestEJB");
          
           System.out.println("C");
          
           TestEJBHome home = (TestEJBHome)javax.rmi.PortableRemoteObject.narrow(obj, TestEJBHome.class);
          
           TestEJB testejb = home.create();
          
           System.out.println("The server said" + testejb.test());
          
           testejb.remove();
          
           }
          
           catch (Exception e) {
          
           e.printStackTrace();
           System.out.println( "Exception: " + e.getMessage() );
          
           }
          
           }
          }
          
          


          • 2. Re: Session Bean Client hangs at Context Lookup
            gaurav Singh Newbie

            I had the same issue trying to connect remotely to the JBoss Server.


            You might want to check a few things

            1) Check if you can resolve marge.ndindustries.com by pinging the domain host


            telnet marge.ndindustries.com for the default common ports that are used by JBoss like 1099, 1098,4444,4445 . One of them might have another process listening on it and as aresult your client is timing out

            Hope that helps..

            Regards
            G

            • 3. Re: Session Bean Client hangs at Context Lookup
              Mark LaPolla Newbie

              I have a question about this:

              I modified the Duke's Bank to include a very simple object called SimpleEJB, with JNDI name MySimpleEJB and with a ref that was
              ejb/Simple.

              When I got the default initial context, it worked just great using

              initial.lookup("java:comp/env/ejb/Simple");

              However, when I tried this:

              Hashtable env = new Hashtable();
              env.putContext.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
              env.put(Context.PROVIDER_URL, "jnp://localhost:1099");
              env.put"java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
              InitialContext initial2 = new InitialContext(env);
              Object objref2 = initial2.lookup("ejb/Simple");
              


              It didn't work. It said it couldn't deference it and that was part of a NameNotFoundException because ejb was not bound.

              However, if I change that last line to read:

              Object objref2 = initial2.lookup("MySimpleEJB");
              


              It worked just great. Do I always have to use the JNDI name when not using the java:comp/env? That is, accessing a remote bean. I thought that JBoss would do that making using the refs.

              What I am trying to do is modify another war file I have to use an session bean but I am having trouble getting the bean even by the JNDI name. The war file I am using does include the bank-ejb.jar, I put it in there to try it out, and there is no way I can look up that bean.

              Some hints would help. Do I need the clientall-jboss.jar for the JNDI look up? I've been reading up on the Jboss JNDI but so far the book I am using, SAMS JBoss, says that I am settng up everything correctly.

              Thanks.


              • 4. Re: Session Bean Client hangs at Context Lookup
                pgajria Newbie

                similar issue with the jboss fibo example

                in your code you have

                initial.lookup("java:comp/env/ejb/Simple");

                on the jboss examples they use
                context.lookup("java:/comp/env/ejb/Fibo");

                is that leading / needed or not ?

                regardless i was never able to get their example
                to work

                also i get a lot of lookup of java:/comp/env failed
                tomcat errors when trying to run my own examples
                sometimes it will run & when i rerun the xdoclet & packing
                & redeploy it fails

                im not sure if this is a jboss issue or a tomcat issue

                btw the ejbs do display correctly in the jmx-console
                its the servlets that cant call them

                • 5. Re: Session Bean Client hangs at Context Lookup
                  Mark LaPolla Newbie

                  If I used java:comp/env it worked just fine when the bank-ejb.jar was part of the .ear.

                  I am having trouble using the URL to look up other ejbs that are not part of a war or ear. (See my last posting.) Those ejbs that are, in the same JVM but not in the same project.

                  The error I keep on getting is:

                  javax.naming.NamingExc
                  eption: Could not dereference object [Root exception is javax.naming.Communicati
                  onException [Root exception is java.lang.ClassNotFoundException: com.sun.ebank.e
                  jb.account.SimpleHome (no security manager: RMI class loader disabled)]]
                  


                  Thanks.