12 Replies Latest reply on Apr 26, 2006 4:19 AM by khairul anwar

    How to access beans with a remote client?

    Tom Sedge Newbie

      Hi,

      I'm trying to access a session bean with a remote client. I can't see any examples in the tutorial for this and nor can I see any jndi.properties file.

      My code looks like this:


      Properties properties = new Properties();
      properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
      properties.put(Context.PROVIDER_URL, "jnp://localhost:1117");
      properties.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
      RemoteAccessor accessor = (RemoteAccessor)context.lookup(RemoteAccessor.class.getName());


      I have an AccessorBean session bean with Accessor local interface and RemoteAccessor remote interface. All I ever get is "name not found". Everything works locally just fine

      With EJB2.1 I used to have to have an application-client.xml and jboss-client.xml files. Do I see need these? If so, what are my beans now named as and what do their JNDI entries become?

      Am I just missing some required JNDI properties for JBoss 4.0.3?

      Help!

      Thanks,


      Tom.

        • 1. Re: How to access beans with a remote client?
          Bill Burke Master

          what are you talking about? Every example in the tutorial uses a remote client.

          • 2. Re: How to access beans with a remote client?
            Ronald Mathies Newbie

            First of all, you're code example looks a bit crappy on IE6 (it's not readable).

            But here is an example of a jndi.properties file.

            java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
            java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
            java.naming.provider.url=localhost
            


            To create an instance of for example a session bean:

            public class MyClass {
             private MySessionRemote mySessionRemote = null;
            
             public void method() {
             InitialContext ctx = new InitialContext();
             MySessionRemote mySessionRemoteInstance = (MySessionRemote) ctx.lookup(MySessionRemote.class.getName());
            
             }
            }
            


            • 3. Re: How to access beans with a remote client?
              Tom Sedge Newbie

              Thanks for the help Ronald. I am now getting:

              java.lang.NoClassDefFoundError: Lorg/jboss/remoting/InvokerLocator

              When I try this. I have put all the JBoss client libraries in the classpath AFAICS, do I need something extra?

              Bill: All the client examples I can see are JSP pages running in the same container with the JNDI context already set (and they appear to me to use the local interface, at least in the version of the trailblazing tutorial I downloaded a week or so ago). I am trying to write rich client applications accessing beans from a separate JVM; hence my questions.

              Thanks,


              Tom.

              • 4. Re: How to access beans with a remote client?
                Tom Sedge Newbie

                Hi,

                I found that it needed jboss-remoting.jar and have added this in. However, I now get:

                javax.naming.CommunicationException [Root exception is java.io.InvalidClassException: org.jboss.aspects.remoting.InvokeRemoteInterceptor; local class incompatible: stream classdesc serialVersionUID = -145166951731929406, local class serialVersionUID = 2143346381001045515]

                Any idea what the problem might be?

                Many thanks,


                Tom.

                • 5. Re: How to access beans with a remote client?
                  Tom Sedge Newbie

                  Ah - I've got it working.

                  Turns out that I had an old download and had missed the latest stuff & set it up wrongly.

                  Thanks anyway,


                  Tom.

                  • 6. Re: How to access beans with a remote client?
                    Bieth Bruno Newbie

                    Hi,

                    I have a similar problem with creating a remote client :

                    I put in my build path the following library :
                    - jbossall-client.jar
                    - myejb.jar (which is my ejb interface)

                    When I launch my client (JBoss 4.0.2 with EJB 3.0 RC1 is running and my ejb are well deployed) I get this :

                    javax.naming.CommunicationException [Root exception is java.lang.ClassNotFoundException: org.jboss.ejb3.JBossProxy (no security manager: RMI class loader disabled)]
                    at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:713)
                    at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:572)
                    at javax.naming.InitialContext.lookup(InitialContext.java:351)
                    at Client.main(Client.java:17)


                    My ejb are pretty simple :

                    package org.wiskee.bd;

                    import javax.persistence.Column;
                    import javax.persistence.Entity;
                    import javax.persistence.GeneratorType;
                    import javax.persistence.Id;

                    @Entity
                    public class Massif {
                    private int massifId;
                    private String nom;

                    @Id(generate = GeneratorType.AUTO)
                    @Column(name = "MASSIF_ID")
                    public int getMassifId() {
                    return massifId;
                    }
                    public void setMassifId(int id) {
                    this.massifId = id;
                    }

                    public String getNom() {
                    return nom;
                    }
                    public void setNom(String nom) {
                    this.nom = nom;
                    }

                    }


                    And the stateless session bean which manage this entity bean is :


                    package org.wiskee.bd;

                    import java.util.ArrayList;
                    import java.util.List;

                    import javax.ejb.Stateless;
                    import javax.persistence.EntityManager;
                    import javax.persistence.PersistenceContext;
                    import javax.persistence.Query;

                    public @Stateless class MassifsBean implements Massifs {
                    @PersistenceContext
                    private EntityManager manager;

                    public List<Massif> getAllMassif() {
                    ArrayList< Massif > massifs = new ArrayList< Massif>();

                    Query q = manager.createQuery( "from Massif");

                    for( Object o : q.getResultList()) {
                    massifs.add( (Massif)o);
                    }

                    return massifs;
                    }

                    public Massif addMassif(String nom) {
                    Massif massif = new Massif();
                    massif.setNom( nom );
                    manager.persist( massif );
                    return massif;
                    }
                    }


                    My client look like this :


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

                    import org.wiskee.bd.Massifs;
                    import org.wiskee.bd.Massif;

                    public class Client {

                    /**
                    * @param args
                    */
                    public static void main(String[] args) {
                    try {
                    System.out.println( "CLIENT" );
                    Context context = new InitialContext();
                    Massifs massifs = (Massifs) context.lookup(Massifs.class.getName());
                    massifs.addMassif( "Pyrenees" );
                    for( Massif m : massifs.getAllMassif() ) {
                    System.out.println( m.getMassifId() + " : " + m.getNom() );
                    }
                    } catch (NamingException e) {
                    e.printStackTrace();
                    }
                    }
                    }


                    I would like to know which library I have to put on my client build path ?
                    Is there something wrong with my EJB or my client ?

                    Thank you

                    • 7. Re: How to access beans with a remote client?
                      Bieth Bruno Newbie

                      I tried to put the jboss-ejb3.jar and I get another error : it need aop library ...
                      Is there a tutorial on this topic, I mean on standalone client using EJB 3 ?

                      • 8. Re: How to access beans with a remote client?
                        Joachim Van der Auwera Expert

                        From my experience, when using the ejb3 stuff, jbossall-client is no longer sufficient. You also need to include in your classpath (trying to remember by heart)

                        jnp-server.jar (from your configuration lib directory)
                        all jars from ejb3.deployer (in deploy)
                        all jars from aop (in deploy)

                        Joachim

                        • 9. Re: How to access beans with a remote client?
                          Gourish Bhat Newbie

                          Hi,

                          I am also getting the same error. What i did is integrated JBoss RMI with the JBoss, and tried to invoke the Remote Method from a bean.

                          The code worked with RMI program. Its giving following error when i Invoke this from a Message driven bean.

                          12:43:26,922 INFO [STDOUT] java.lang.NoClassDefFoundError: org/jboss/remoting/InvokerLocator
                          12:43:26,922 INFO [STDOUT] at SimpleMessageBean.makeInvocation(SimpleMessageBean.java:186)
                          12:43:26,922 INFO [STDOUT] at SimpleMessageBean.onMessage(SimpleMessageBean.java:63)

                          Also added line in jndi.properties file java.naming.provider.url=localhost, still getting the same error.

                          I am using JBoss 4.0.2.

                          Thanks,
                          gourish

                          • 10. Re: How to access beans with a remote client?
                            Jens Elkner Apprentice

                            For my rich clients I need at the moment:

                            client/hibernate-client.jar
                            client/jboss-aop-jdk50-client.jar
                            client/jboss-aspect-jdk50-client.jar
                            client/jboss-client.jar
                            client/jboss-common-client.jar
                            client/jboss-ejb3-client.jar
                            client/jboss-transaction-client.jar
                            client/jbossmq-client.jar
                            client/jbosssx-client.jar
                            client/jmx-invoker-adaptor-client.jar
                            client/jnp-client.jar
                            lib/concurrent.jar
                            server/all/deploy/ejb3.deployer/jboss-annotations-ejb3.jar
                            server/all/deploy/ejb3.deployer/jboss-ejb3x.jar
                            server/all/lib/asm-attrs.jar
                            server/all/lib/asm.jar
                            server/all/lib/cglib-2.1_2jboss.jar
                            server/all/lib/ejb3-persistence.jar
                            server/all/lib/javax.servlet.jar
                            server/all/lib/jboss-j2ee.jar
                            server/all/lib/jboss-remoting.jar


                            Perhaps this may help ;-)

                            • 11. Re: How to access beans with a remote client?
                              khairul anwar Newbie

                               

                              "mustaghattack" wrote:
                              Hi,

                              I have a similar problem with creating a remote client :

                              I put in my build path the following library :
                              - jbossall-client.jar
                              - myejb.jar (which is my ejb interface)

                              When I launch my client (JBoss 4.0.2 with EJB 3.0 RC1 is running and my ejb are well deployed) I get this :

                              javax.naming.CommunicationException [Root exception is java.lang.ClassNotFoundException: org.jboss.ejb3.JBossProxy (no security manager: RMI class loader disabled)]
                              at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:713)
                              at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:572)
                              at javax.naming.InitialContext.lookup(InitialContext.java:351)
                              at Client.main(Client.java:17)


                              My ejb are pretty simple :

                              package org.wiskee.bd;

                              import javax.persistence.Column;
                              import javax.persistence.Entity;
                              import javax.persistence.GeneratorType;
                              import javax.persistence.Id;

                              @Entity
                              public class Massif {
                              private int massifId;
                              private String nom;

                              @Id(generate = GeneratorType.AUTO)
                              @Column(name = "MASSIF_ID")
                              public int getMassifId() {
                              return massifId;
                              }
                              public void setMassifId(int id) {
                              this.massifId = id;
                              }

                              public String getNom() {
                              return nom;
                              }
                              public void setNom(String nom) {
                              this.nom = nom;
                              }

                              }


                              And the stateless session bean which manage this entity bean is :


                              package org.wiskee.bd;

                              import java.util.ArrayList;
                              import java.util.List;

                              import javax.ejb.Stateless;
                              import javax.persistence.EntityManager;
                              import javax.persistence.PersistenceContext;
                              import javax.persistence.Query;

                              public @Stateless class MassifsBean implements Massifs {
                              @PersistenceContext
                              private EntityManager manager;

                              public List<Massif> getAllMassif() {
                              ArrayList< Massif > massifs = new ArrayList< Massif>();

                              Query q = manager.createQuery( "from Massif");

                              for( Object o : q.getResultList()) {
                              massifs.add( (Massif)o);
                              }

                              return massifs;
                              }

                              public Massif addMassif(String nom) {
                              Massif massif = new Massif();
                              massif.setNom( nom );
                              manager.persist( massif );
                              return massif;
                              }
                              }


                              My client look like this :


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

                              import org.wiskee.bd.Massifs;
                              import org.wiskee.bd.Massif;

                              public class Client {

                              /**
                              * @param args
                              */
                              public static void main(String[] args) {
                              try {
                              System.out.println( "CLIENT" );
                              Context context = new InitialContext();
                              Massifs massifs = (Massifs) context.lookup(Massifs.class.getName());
                              massifs.addMassif( "Pyrenees" );
                              for( Massif m : massifs.getAllMassif() ) {
                              System.out.println( m.getMassifId() + " : " + m.getNom() );
                              }
                              } catch (NamingException e) {
                              e.printStackTrace();
                              }
                              }
                              }


                              I would like to know which library I have to put on my client build path ?
                              Is there something wrong with my EJB or my client ?

                              Thank you


                              • 12. Re: How to access beans with a remote client?
                                khairul anwar Newbie

                                uh, sorry about above's post. Found it through this link from google

                                http://www.jbossgroup.com/index.html?module=bb&op=posting&mode=quote&p=3890360

                                and somehow I press submit.

                                However, I'm currently working on JDeveloper10.1.3 + JBoss4.0.4RC2 , and got a same problem and try to solve it for days. But the good things I got it worked now, thanks to elkner.