3 Replies Latest reply on Oct 13, 2006 5:36 AM by lmierzej

    Remote access error (in the most simple situation, why?);

    lmierzej

      Hi,
      I have a problem, which I can't solve :( Help really appreciated.

      I'm using JBoss 4.0.4.GA-Patch1 (EJB 3.0)

      From JSF backing bean in bgsw.ear I'm trying to access session bean in bgsc.ear (remote access, the same JBoss server).

      Invoking from bgsw.ear, JSF backing bean - Test.java

      InitialContext ctx = new InitialContext();
      BoardGamesServiceFacade bgsf = (BoardGamesServiceFacade) ctx
       .lookup(BoardGamesServiceFacade.class.getName());
      bgsf.test();
      

      Trying to reach bgsc.ear, session's bean interface - BoardGamesServiceFacade.java (interface)
      @Remote
      public interface BoardGamesServiceFacade {
       public int test();
      }
      

      BoardGamesServiceFacadeBean.java (class implementing interface)
      @Stateless
      public class BoardGamesServiceFacadeBean implements BoardGamesServiceFacade {
      
       public int test() {
       System.out.println("Ok!");
       return 0;
       }
      }
      

      I really have no idea how to pass to JSF backing bean Test.java in bgsw.ear the definition of BoardGamesServiceFacade.java from bgsc.ear?

      From JSF backing bean Test.java in bgsw.ear I'm trying to access BoardGamesServiceFacade.java from bgsc.ear, so I need this definition.

      I have copied to bgsw.ear "incomplete" BoardGamesServiceFacade.java
      //!NO @Remote annotation!
      public interface BoardGamesServiceFacade {
       public int test();
      }
      

      I feel that it's terribly stupid thing to do :( Should I creat some stub from BoardGamesServiceFacade.java from bgsc.ear?

      Anyway I'm getting this error when trying to run:
      javax.naming.NameNotFoundException: lmierzej.bgsc.businessMethods.BoardGamesServiceFacade not bound
      


      jmx-console says:
      | +- BoardGamesServiceFacadeBean (class: org.jnp.interfaces.NamingContext)
      | | +- local (proxy: $Proxy363 implements interface lmierzej.bgsc.businessMethods.BoardGamesServiceFacade,interface org.jboss.ejb3.JBossProxy,interface javax.ejb.EJBLocalObject)
      | +- BoardGamesServiceBean (class: org.jnp.interfaces.NamingContext)
      

      Does this mean it's local not remote interface bound? Why?


      Could You please point me to proper solution?
      Is there any good tutorial/example showing remote access (EJB 3.0)?

      Thank you for Your help and time.
      lmierzej

      P.S. Sorry for my english...

        • 1. Re: Remote access error (in the most simple situation, why?)
          wolfgangknauf

          Hi !

          First of all you cannot cast a remote interface but must use "PortableRemoteObject.narrow":

          Object objRemote = initialContext.lookup("....");
          BoardGamesServiceFacade bgsf = (BoardGamesServiceFacade) PortableRemoteObject.narrow(objRemote, BoardGamesServiceFacade.class);

          The JNDI-name of your bean is by default
          "EarName/BoardGamesServiceFacadeBean/remote" (where EARName is probably "bgsw" in your sample, your JNDI snippet is missing the first line where the ear name is shown ;-) ).

          Hope this helps

          Wolfgang

          • 2. Re: Remote access error (in the most simple situation, why?)
            lmierzej

            Thank you very much for your replay :)

            I have just managed to solve this problem.

            There were 2 problems.
            First, jndi lookup in Test.java in bgsw.ear should be like this:

            BoardGamesServiceFacade bgsf = (BoardGamesServiceFacade) ctx.lookup("bgsc/BoardGamesServiceFacadeBean/remote");
            

            In bgsw.ear I know definition of BoardGamesServiceFacade interface, because I imported a jar file to bgsw.ear, which contains needed classes.
            I guess that this is not the only way to do this.

            Second, jndi bindings whare not refreshed properly? I'm not sure. Now in jmx-console I can see:
             +- bgsc (class: org.jnp.interfaces.NamingContext)
             | +- BoardGamesBean (class: org.jnp.interfaces.NamingContext)
             | | +- local (proxy: $Proxy67 implements interface lmierzej.bgsc.businessMethods.BoardGames,interface org.jboss.ejb3.JBossProxy,interface javax.ejb.EJBLocalObject)
             | +- BoardGamesServiceFacadeBean (class: org.jnp.interfaces.NamingContext)
             | | +- remote (proxy: $Proxy69 implements interface lmierzej.bgsc.businessMethods.BoardGamesServiceFacade,interface org.jboss.ejb3.JBossProxy,interface javax.ejb.EJBObject)
            


            But now I have new doubts...
            I have 2 different ear archives (the same JBoss server), in both I make jndi lookups... Why they are serching/using the same bindigs (the same context)? How they know that they should use the same?

            Finally, what if had every ear on different JBoss server? How form first ear (on first server) would I get access to second ear (on second server)? How would they both knew now to use the same jndi context? Is there any additional configuration needed to do this?

            P.S. Sorry for my english... really.

            • 3. Re: Remote access error (in the most simple situation, why?)
              lmierzej

               

              "lmierzej" wrote:

              I have 2 different ear archives (the same JBoss server), in both I make jndi lookups... Why they are serching/using the same bindigs (the same context)? How they know that they should use the same?


              Because I have the same jndi.properties in both ears?! :D So that's way both ears "share" bindings?

              If that's right, only one question remains - what if had every ear on different JBoss server? Is there any additional configuration needed to do this?