6 Replies Latest reply on Aug 1, 2008 7:18 AM by mail_ranjan

    Invalid invocation of local interface (null container)

    piscean

      I am a newbie to EJB3. I have some experience with EJB2, but having hardtime with EJB3. I am trying to write one very simple stateless session bean. The files are,
      1. ejb.hello.HelloBean.java
      2. ejb.hello.HelloLocal.java
      3. WEB-INF/jndi.properties

      The files contents are,

      ejb.hello.HelloBean.java
      ----------------------------
      /**
      *
      */
      package ejb.hello;

      import javax.ejb.Stateless;

      @Stateless
      public class HelloBean implements HelloRemote, HelloLocal {

      private String greeting = "Hello";
      /* (non-Javadoc)
      * @see ejb.hello.Hello#hello()
      */
      public String hello() {
      return "Hello";
      }
      /**
      * @return the greeting
      */
      public String getGreeting() {
      return greeting;
      }
      /**
      * @param greeting the greeting to set
      */
      public void setGreeting(String greeting) {
      this.greeting = greeting;
      }

      }


      ejb.hello.HelloLocal.java
      ----------------------------
      /**
      *
      */
      package ejb.hello;

      import javax.ejb.Local;

      @Local
      public interface HelloLocal {
      public String hello();
      }


      WEB-INF/jndi.properties
      ----------------------------
      java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
      java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
      java.naming.provider.url=localhost:1099


      My client is HelloTest.java
      ------------------------------
      package ejb.web;

      import java.util.Hashtable;

      import javax.naming.Context;
      import javax.naming.InitialContext;

      import ejb.hello.HelloLocal;
      import ejb.hello.HelloRemote;


      public class HelloTest {

      /**
      * @param args
      */
      public static void main(String[] args) {
      try {
      InitialContext ctx = new InitialContext();
      HelloLocal hellol = (HelloLocal) ctx.lookup("HelloBean/local");
      if (hellol == null) {
      System.out.println("Hello is null");
      }
      System.out.println("Output = " + hellol.hello());
      }
      catch (Exception ex) {
      System.out.println("Error in main");
      ex.printStackTrace();
      }
      }
      }


      I get errors
      --------------

      Error in main
      javax.ejb.EJBException: Invalid invocation of local interface (null container)
      at org.jboss.ejb3.stateless.StatelessLocalProxy.invoke(StatelessLocalProxy.java:77)
      at $Proxy0.hello(Unknown Source)
      at ejb.web.HelloTest.main(HelloTest.java:24)


      When I start jboss server, it did display following lines in logs so I assume, the bean got deployed allright..
      -----------------------------------------------------------------------
      18:01:02,203 INFO [JmxKernelAbstraction] installing MBean: jboss.j2ee:jar=EHello.jar,name=HelloBean,service=EJB3 with dependencies:
      18:01:02,484 INFO [EJBContainer] STARTED EJB: ejb.hello.HelloBean ejbName: HelloBean
      18:01:02,578 INFO [EJB3Deployer] Deployed: file:/C:/jboss-4.2.0.GA/server/default/deploy/EHello.jar

      I assume, ejb-jar.xml, jboss.xml files are not needed with EJB3, Am I right? What am I doing wrong?

      Please help....

      Thanks.

        • 1. Re: Invalid invocation of local interface (null container)
          jaikiran

          You are trying to lookup a local bean interface from the standalone client (remote client). Local interfaces are not meant for that. Local interfaces can be used when the client is part of the same JVM as the application server. Lookup the remote interface instead of the local interface from your main() method:

          HelloRemote helloR = (HelloRemote) ctx.lookup("HelloBean/remote");
          if (helloR == null) {
          System.out.println("Hello is null");
          }
          System.out.println("Output = " + helloR.hello());


          • 2. Re: Invalid invocation of local interface (null container)
            piscean

            Thanks Jaikiran, I added remote interface and a client

            HelloRemote.java
            --------------------
            package ejb.hello;

            import javax.ejb.Remote;

            @Remote
            public interface HelloRemote {
            public String hello();
            }

            -------------------------
            HelloTestRemote.java
            -------------------------

            package ejb.web;

            import javax.naming.InitialContext;

            import ejb.hello.HelloRemote;


            public class HelloTestRemote {

            /**
            * @param args
            */
            public static void main(String[] args) {
            try {
            InitialContext ctx = new InitialContext();
            HelloRemote hellor = (HelloRemote) ctx.lookup("HelloBean/remote");
            if (hellor == null) {
            System.out.println("Hello is null");
            }
            System.out.println("Output = " + hellor.hello());
            }
            catch (Exception ex) {
            System.out.println("Error in main");
            ex.printStackTrace();
            }
            }
            }


            I actually already had remote interface, So didn't deploy the jar again...just added new client.
            I still get errors,....
            ---------------------------------

            java.lang.reflect.UndeclaredThrowableException
            at $Proxy0.hello(Unknown Source)
            at ejb.web.HelloTestRemote.main(HelloTestRemote.java:20)
            Caused by: java.lang.Exception: Can not make remoting client invocation due to not being connected to server.
            at org.jboss.remoting.Client.invoke(Client.java:1555)
            at org.jboss.remoting.Client.invoke(Client.java:530)
            at org.jboss.aspects.remoting.InvokeRemoteInterceptor.invoke(InvokeRemoteInterceptor.java:41)
            at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:88)
            at org.jboss.aspects.tx.ClientTxPropagationInterceptor.invoke(ClientTxPropagationInterceptor.java:46)
            at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:88)
            at org.jboss.aspects.security.SecurityClientInterceptor.invoke(SecurityClientInterceptor.java:40)
            at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:88)
            at org.jboss.ejb3.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:72)
            at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:88)
            at org.jboss.ejb3.stateless.StatelessRemoteProxy.invoke(StatelessRemoteProxy.java:103)
            ... 2 more
            Error in main

            • 3. Re: Invalid invocation of local interface (null container)
              jaikiran

               

              Caused by: java.lang.Exception: Can not make remoting client invocation due to not being connected to server.


              I havent seen that error before. Do you have a jndi.properties in the classpath of your client application (the HelloTestRemote client). I believe, you do have one. What are its contents?



              • 4. Re: Invalid invocation of local interface (null container)
                piscean

                Jaikiran,
                Yes, as you suspected, jndi.properties was not in the jar. I added that. Now the jar contents are

                META-INF
                META-INF/MANIFEST.MF
                jndi.properties
                ejb
                ejb/hello
                ejb/hello/HelloBean.class
                ejb/hello/HelloLocal.class
                ejb/hello/HelloRemote.class


                jndi.properties has contents
                --------------------------------
                java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
                java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
                java.naming.provider.url=localhost:1099


                Am I right with jndi.properties location? Am I missing any other descriptors?


                When I deploy the jar file, I see logs as ( Is that first warning suspicious?? )

                -----------------------------------------------
                20:02:15,234 WARN [JmxKernelAbstraction] jboss.j2ee:jar=EHello.jar,name=HelloBean,service=EJB3 is not registered
                20:02:25,437 INFO [JmxKernelAbstraction] creating wrapper delegate for: org.jboss.ejb3.stateless.StatelessContainer
                20:02:25,437 INFO [JmxKernelAbstraction] installing MBean: jboss.j2ee:jar=EHello.jar,name=HelloBean,service=EJB3 with dependencies:
                20:02:25,453 INFO [EJBContainer] STARTED EJB: ejb.hello.HelloBean ejbName: HelloBean
                20:02:25,484 INFO [EJB3Deployer] Deployed: file:/C:/jboss-4.2.0.GA/server/default/deploy/EHello.jar
                -



                The errors now I am getting are still the same
                ------------------------------------------------------
                Error in main
                java.lang.reflect.UndeclaredThrowableException
                at $Proxy0.hello(Unknown Source)
                at ejb.web.HelloTestRemote.main(HelloTestRemote.java:20)
                Caused by: java.lang.Exception: Can not make remoting client invocation due to not being connected to server.
                at org.jboss.remoting.Client.invoke(Client.java:1555)
                at org.jboss.remoting.Client.invoke(Client.java:530)
                at org.jboss.aspects.remoting.InvokeRemoteInterceptor.invoke(InvokeRemoteInterceptor.java:41)
                at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:88)
                at org.jboss.aspects.tx.ClientTxPropagationInterceptor.invoke(ClientTxPropagationInterceptor.java:46)
                at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:88)
                at org.jboss.aspects.security.SecurityClientInterceptor.invoke(SecurityClientInterceptor.java:40)
                at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:88)
                at org.jboss.ejb3.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:72)
                at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:88)
                at org.jboss.ejb3.stateless.StatelessRemoteProxy.invoke(StatelessRemoteProxy.java:103)
                ... 2 more

                • 5. Re: Invalid invocation of local interface (null container)
                  piscean

                  I am using jboss-4.2.1.GA server, jre1.6.0_02. I am just stuck with this. If I try anything other than HelloBean/remote, it gives errors saying not bound. I checked the jndiview, the names HelloBean/remote and HelloBean/local are showing up there. So I assume, the deploy is deployed correctly. It is just some issue with client, I am missing something small.. Please help.

                  • 6. Re: Invalid invocation of local interface (null container)
                    mail_ranjan

                    Thanx Jaikiran
                    I was getting the following exception:
                    javax.ejb.EJBException: Invalid invocation of local interface (null container)

                    Your hints worked.
                    :)

                    My Blog