2 Replies Latest reply on Oct 25, 2012 5:59 AM by Smitha K

    Need to call deployed EJB on JBOSS from a standalone java class

    Smitha K Newbie

      Intention of my exercise is:-

       

      To call   EJB deployed as an ear on JBOSS from a remote client.

       

      1] EJB application on JBOSS has the following structures:-

       

      a)It has  Meta-INF folder containign application.xml

      <?xml version="1.0" encoding="UTF-8"?>

      <!DOCTYPE application PUBLIC '-//Sun Microsystems, Inc.//DTD J2EE Application 1.3//EN' 'http://java.sun.com/dtd/application_1_3.dtd'>

      <application>
        <display-name>MyFirstBean</display-name>
        <description>Application description</description>
        <module>
          <ejb>ejb.jar</ejb>
        </module>
      </application>

      b) it has ejb.jar

      which has following files and meta-inf which has ejb.jar.xml

      <?xml version="1.0" encoding="UTF-8"?>
      <ejb-jar>
        <description>A simple session bean</description>
        <display-name>Simple Message EJB</display-name>
        <enterprise-beans>
          <session>
            <ejb-name>SimpleMessenger</ejb-name>
            <home>FirstEJBHome</home>
            <remote>FirstEJBObject</remote>
            <ejb-class>FirstEJBBean</ejb-class>
            <session-type>Stateless</session-type>
            <transaction-type>Container</transaction-type>
          </session>
        </enterprise-beans>
      </ejb-jar>

      And it has FirstEJBBean.class

      FirstEJBHome.class

      FirstEJBObject.class

       

      It has successfully deployed my ejb on jboss.

       

      2] To call this EJB from remote client.

      I created a class FirstEJBClient with the following code:-

      import java.rmi.RemoteException;
      import java.util.Hashtable;

      import javax.ejb.CreateException;
      import javax.ejb.EJBException;
      import javax.ejb.EJBHome;
      import javax.ejb.EJBObject;
      import javax.ejb.SessionBean;
      import javax.ejb.SessionContext;
      import javax.naming.Context;
      import javax.naming.InitialContext;
      import javax.naming.NamingException;
      import javax.rmi.PortableRemoteObject;

      public class FirstEJBClient  {

      public static void main(String args[])
      {
       
      try {
       
        Hashtable environment = new Hashtable();
              environment.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
              environment.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
              environment.put(Context.PROVIDER_URL, "jnp://172.16.84.66:1099"); // remote machine IP
              InitialContext context = new InitialContext(environment);
              Object obj = context.lookup("FirstEJBHome"); //ejb-name
              System.out.println("-->> lookup object successfully");


             
        FirstEJBHome ejbHome = (FirstEJBHome) PortableRemoteObject.narrow(obj,EJBHome.class);
        try {
         FirstEJBObject firstEJBObject =(FirstEJBObject) ejbHome.create();
         firstEJBObject.firstHello();
        
        } catch (RemoteException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
        } catch (CreateException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
        }

       

       

      } catch (NamingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }



      }
      }

       

       

      Getting this exception while running the class:-

       

      log4j:WARN Please initialize the log4j system properly.

      javax.naming.NameNotFoundException: FirstEJBHome not bound

      at org.jnp.server.NamingServer.getBinding(NamingServer.java:771)

      at org.jnp.server.NamingServer.getBinding(NamingServer.java:779)

      at org.jnp.server.NamingServer.getObject(NamingServer.java:785)

      at org.jnp.server.NamingServer.lookup(NamingServer.java:443)

      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

      at java.lang.reflect.Method.invoke(Method.java:597)

      at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:305)

      at sun.rmi.transport.Transport$1.run(Transport.java:159)

      at java.security.AccessController.doPrivileged(Native Method)

      at sun.rmi.transport.Transport.serviceCall(Transport.java:155)

      at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:535)

      at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:790)

      at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:649)

      at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)

      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)

      at java.lang.Thread.run(Thread.java:619)

      at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Unknown Source)

      at sun.rmi.transport.StreamRemoteCall.executeCall(Unknown Source)

      at sun.rmi.server.UnicastRef.invoke(Unknown Source)

      at org.jnp.server.NamingServer_Stub.lookup(Unknown Source)

      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:726)

      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:686)

      at javax.naming.InitialContext.lookup(Unknown Source)

      at FirstEJBClient.main(FirstEJBClient.java:28)

        • 1. Re: Need to call deployed EJB on JBOSS from a standalone java class
          Smitha K Newbie

          Getting this exception on the serverr while uploading.

           

          15:20:43,719 INFO  [SessionSpecContainer] Stopping jboss.j2ee:ear=FirstEJBBean.e
          ar,jar=FirstEJBBean.jar,name=FirstEJBBean,service=EJB3
          15:20:43,723 ERROR [AbstractKernelController] Error installing to Start: name=jb
          oss.j2ee:ear=FirstEJBBean.ear,jar=FirstEJBBean.jar,name=FirstEJBBean,service=EJB
          3 state=Create
          java.lang.NullPointerException
                  at javax.naming.NameImpl.<init>(NameImpl.java:264)
                  at javax.naming.CompoundName.<init>(CompoundName.java:187)
                  at org.jnp.interfaces.NamingParser.parse(NamingParser.java:62)
                  at org.jboss.util.naming.Util.bind(Util.java:90)
                  at org.jboss.ejb3.proxy.impl.jndiregistrar.JndiSessionRegistrarBase.bind
          (JndiSessionRegistrarBase.java:910)
                  at org.jboss.ejb3.proxy.impl.jndiregistrar.JndiSessionRegistrarBase.bind
          (JndiSessionRegistrarBase.java:895)
                  at org.jboss.ejb3.proxy.impl.jndiregistrar.JndiSessionRegistrarBase.bind
          (JndiSessionRegistrarBase.java:884)
                  at org.jboss.ejb3.proxy.impl.jndiregistrar.JndiSessionRegistrarBase.bind
          Ejb(JndiSessionRegistrarBase.java:151)
                  at org.jboss.ejb3.session.SessionContainer.lockedStart(SessionContainer.
          java:210)
                  at org.jboss.ejb3.session.SessionSpecContainer.lockedStart(SessionSpecCo
          ntainer.java:577)
                  at org.jboss.ejb3.stateless.StatelessContainer.lockedStart(StatelessCont
          ainer.java:192)
                  at org.jboss.ejb3.EJBContainer.start(EJBContainer.java:884)
                  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
          java:39)
                  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
          sorImpl.java:25)
                  at java.lang.reflect.Method.invoke(Method.java:597)
                  at org.jboss.reflect.plugins.introspection.ReflectionUtils.invoke(Reflec
          tionUtils.java:59)
                  at org.jboss.reflect.plugins.introspection.ReflectMethodInfoImpl.invoke(
          ReflectMethodInfoImpl.java:150)
                  at org.jboss.joinpoint.plugins.BasicMethodJoinPoint.dispatch(BasicMethod
          JoinPoint.java:66)
                  at org.jboss.kernel.plugins.dependency.KernelControllerContextAction$Joi
          npointDispatchWrapper.execute(KernelControllerContextAction.java:241)
                  at org.jboss.kernel.plugins.dependency.ExecutionWrapper.execute(Executio
          nWrapper.java:47)
                  at org.jboss.kernel.plugins.dependency.KernelControllerContextAction.dis
          patchExecutionWrapper(KernelControllerContextAction.java:109)
                  at org.jboss.kernel.plugins.dependency.KernelControllerContextAction.dis
          patchJoinPoint(KernelControllerContextAction.java:70)
                  at org.jboss.kernel.plugins.dependency.LifecycleAction.installActionInte
          rnal(LifecycleAction.java:221)
                  at org.jboss.kernel.plugins.dependency.InstallsAwareAction.installAction
          (InstallsAwareAction.java:54)
                  at org.jboss.kernel.plugins.dependency.InstallsAwareAction.installAction
          (InstallsAwareAction.java:42)
                  at org.jboss.dependency.plugins.action.SimpleControllerContextAction.sim
          pleInstallAction(SimpleControllerContextAction.java:62)
                  at org.jboss.dependency.plugins.action.AccessControllerContextAction.ins
          tall(AccessControllerContextAction.java:71)
                  at org.jboss.dependency.plugins.AbstractControllerContextActions.install
          (AbstractControllerContextActions.java:51)
                  at org.jboss.dependency.plugins.AbstractControllerContext.install(Abstra
          ctControllerContext.java:348)
                  at org.jboss.dependency.plugins.AbstractController.install(AbstractContr
          oller.java:1631)
                  at org.jboss.dependency.plugins.AbstractController.incrementState(Abstra
          ctController.java:934)
                  at org.jboss.dependency.plugins.AbstractController.resolveContexts(Abstr
          actController.java:1082)
                  at org.jboss.dependency.plugins.AbstractController.resolveContexts(Abstr
          actController.java:984)
                  at org.jboss.dependency.plugins.AbstractController.install(AbstractContr
          oller.java:774)
                  at org.jboss.dependency.plugins.AbstractController.install(AbstractContr
          oller.java:540)
                  at org.jboss.deployers.vfs.deployer.kernel.BeanMetaDataDeployer.deploy(B
          eanMetaDataDeployer.java:121)
                  at org.jboss.deployers.vfs.deployer.kernel.BeanMetaDataDeployer.deploy(B
          eanMetaDataDeployer.java:51)
                  at org.jboss.deployers.spi.deployer.helpers.AbstractSimpleRealDeployer.i
          nternalDeploy(AbstractSimpleRealDeployer.java:62)
                  at org.jboss.deployers.spi.deployer.helpers.AbstractRealDeployer.deploy(
          AbstractRealDeployer.java:50)
                  at org.jboss.deployers.plugins.deployers.DeployerWrapper.deploy(Deployer
          Wrapper.java:171)
                  at org.jboss.deployers.plugins.deployers.DeployersImpl.doDeploy(Deployer
          sImpl.java:1439)
                  at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFi
          rst(DeployersImpl.java:1157)
                  at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFi
          rst(DeployersImpl.java:1178)
                  at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFi
          rst(DeployersImpl.java:1210)
                  at org.jboss.deployers.plugins.deployers.DeployersImpl.install(Deployers
          Impl.java:1098)
                  at org.jboss.dependency.plugins.AbstractControllerContext.install(Abstra
          ctControllerContext.java:348)
                  at org.jboss.dependency.plugins.AbstractController.install(AbstractContr
          oller.java:1631)
                  at org.jboss.dependency.plugins.AbstractController.incrementState(Abstra
          ctController.java:934)
                  at org.jboss.dependency.plugins.AbstractController.resolveContexts(Abstr
          actController.java:1082)
                  at org.jboss.dependency.plugins.AbstractController.resolveContexts(Abstr
          actController.java:984)
                  at org.jboss.dependency.plugins.AbstractController.change(AbstractContro
          ller.java:822)
                  at org.jboss.dependency.plugins.AbstractController.change(AbstractContro
          ller.java:553)
                  at org.jboss.deployers.plugins.deployers.DeployersImpl.process(Deployers
          Impl.java:781)
                  at org.jboss.deployers.plugins.main.MainDeployerImpl.process(MainDeploye
          rImpl.java:702)
                  at org.jboss.system.server.profileservice.repository.MainDeployerAdapter
          .process(MainDeployerAdapter.java:117)
                  at org.jboss.system.server.profileservice.repository.ProfileDeployAction
          .install(ProfileDeployAction.java:70)
                  at org.jboss.system.server.profileservice.repository.AbstractProfileActi
          on.install(AbstractProfileAction.java:53)
                  at org.jboss.system.server.profileservice.repository.AbstractProfileServ
          ice.install(AbstractProfileService.java:361)
                  at org.jboss.dependency.plugins.AbstractControllerContext.install(Abstra
          ctControllerContext.java:348)
                  at org.jboss.dependency.plugins.AbstractController.install(AbstractContr
          oller.java:1631)
                  at org.jboss.dependency.plugins.AbstractController.incrementState(Abstra
          ctController.java:934)
                  at org.jboss.dependency.plugins.AbstractController.resolveContexts(Abstr
          actController.java:1082)
                  at org.jboss.dependency.plugins.AbstractController.resolveContexts(Abstr
          actController.java:984)
                  at org.jboss.dependency.plugins.AbstractController.change(AbstractContro
          ller.java:822)
                  at org.jboss.dependency.plugins.AbstractController.change(AbstractContro
          ller.java:553)
                  at org.jboss.system.server.profileservice.repository.AbstractProfileServ
          ice.activateProfile(AbstractProfileService.java:306)
                  at org.jboss.system.server.profileservice.ProfileServiceBootstrap.start(
          ProfileServiceBootstrap.java:271)
                  at org.jboss.bootstrap.AbstractServerImpl.start(AbstractServerImpl.java:
          461)
                  at org.jboss.Main.boot(Main.java:221)
                  at org.jboss.Main$1.run(Main.java:556)
                  at java.lang.Thread.run(Thread.java:619)
          15:20:43,821 ERROR [ProfileServiceBootstrap] Failed to load profile: Summary of
          incomplete deployments (SEE PREVIOUS ERRORS FOR DETAILS):

          • 2. Re: Need to call deployed EJB on JBOSS from a standalone java class
            Smitha K Newbie

            I have also added jboss.xml  as  attached in the  FirstEJBBean.jar

             

            <?xml version="1.0" encoding="UTF-8"?>
            <jboss>
              <enterprise-beans>
                <session>
                  <ejb-name>FirstEJBBean</ejb-name>
                  <jndi-name>FirstEJBTrySM</jndi-name>
                </session>
              </enterprise-beans>
            </jboss>

             

            Still  getting the exception