4 Replies Latest reply on Oct 22, 2013 10:52 AM by Mike schwery

    lookup remote ejb using java:global/as7project/SampleBeanRemoteImpl

    Mike schwery Novice

      I'm trying to get a client in one project to look up a ejb in another project that JBoss says is java:global/as7project/SampleBeanRemoteImpl when it srarts up.

      Both projects are running on the same server. I have used the folling code and the ejb has @Remote.


      Properties props = new Properties();
      props.put(Context.PROVIDER_URL, "remote://localhost:4447");
      props.put(Context.SECURITY_PRINCIPAL, "ejbuser");
      props.put(Context.SECURITY_CREDENTIALS, "$ejbuser123");
      props.put("jboss.naming.client.ejb.context", true);
      props.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
      InitialContext context = new InitialContext(props);
      System.out.println("\n\tGot initial Context: "+context);
      Object obj = context.lookup("java:global/as7project/SampleBeanRemoteImpl!com.sample.ejb.SampleBeanRemote");
      System.out.println("pr" + obj);
      SampleBeanRemote remote = (SampleBeanRemote)javax.rmi.PortableRemoteObject.narrow(obj, SampleBeanRemote.class);
      System.out.println("remote" + remote);


      I am getting an class cast exception when I invoke the narrow command.

        • 1. Re: lookup remote ejb using java:global/as7project/SampleBeanRemoteImpl
          Wolf-Dieter Fink Master

          What kind of client do you use?

          If you run a remote standalone application you should read Remote EJB invocations via JNDI - EJB client API or remote-naming project

          But this is not the recommended approach to invoke EJB's.


          Try this approach EJB invocations from a remote client using JNDI

          • 2. Re: lookup remote ejb using java:global/as7project/SampleBeanRemoteImpl
            Mike schwery Novice

            My lookup code in a war on server a is the following.


            try {
                          final  Hashtable jndiProps = new Hashtable();
                          jndiProps.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
                          Context ctx = new InitialContext(jndiProps);


                         Object obj = ctx.lookup("as7project/SampleBeanRemoteImpl!com.sample.ejb.SampleBeanRemote");
                         SampleBeanRemoteImpl service = (SampleBeanRemoteImpl)obj;
                         service.echo("This is a test");


                      } catch (Throwable t) {



            The EJB is the following.


            package com.sample.ejb;


            import javax.ejb.Remote;
            import javax.ejb.Stateless;

            public class  SampleBeanRemoteImpl implements SampleBeanRemote  {


                public String echo(String s) {


                    return "Hello "+s;


            The server says at startup.




            The lookup code is in a war on one server and the ejb is in a war on another server.

            I want the client war to go to the other server to get the ejb, there is no ejb on the server with the look code.

            We are not using security on the ejb.

            • 3. Re: lookup remote ejb using java:global/as7project/SampleBeanRemoteImpl
              Wolf-Dieter Fink Master

              As you use EJB3 there is no need to use narrow().

              Also you can not cast to the implementation, the client should not have the *Impl class in the classpath, you should use this instead:

                Object obj = ctx.lookup("as7project/SampleBeanRemoteImpl!com.sample.ejb.SampleBeanRemote");

                SampleBeanRemote service = (SampleBeanRemote)obj;

                service.echo("This is a test");

              • 4. Re: lookup remote ejb using java:global/as7project/SampleBeanRemoteImpl
                Mike schwery Novice

                It ended up being that when I started the client and remote server I didn't assign node names.

                It works now.