3 Replies Latest reply on Jan 9, 2002 12:56 AM by Sergei Batiuk

    Accessing EJBs from applet

    Sergei Batiuk Newbie

      Hello,

      I am trying to connect to a session EJB that is deployed in JBoss. I can successfuly connect to my EJB and invoke remote methods from JBuilder's appletviewer.

      However, when I try to connect to the EJBs from the same applet from a real applet (on a web page, I am using SUN's java plugin), I can connect, but can invoke no methods. It doesn't throw any exceptions, it doesn't hang when i try to invoke remote methods. I simply receive no reaction, like nothing had happened.

      Could anyone connect to an EJB from applet? If yes, please share that experience.

      Sincerely,
      Sergei Batiuk.

        • 1. Re: Accessing EJBs from applet
          Sergei Batiuk Newbie

          I have finally received a reaction to my attempts to connect to an EJB. Here is the exception i received:

          javax.naming.CommunicationException [Root exception is java.io.InvalidClassException: org.jboss.ejb.plugins.jrmp.server.JRMPContainerInvoker_Stub; Local class not compatible: stream classdesc serialVersionUID=2 local class serialVersionUID=0]

          Here is the code I use to connect to the EJB:

          Hashtable properties = new Hashtable();

          String host = this.getCodeBase().getHost();
          //host = "thunder";
          properties.put( Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory" );
          properties.put( Context.PROVIDER_URL, "jnp://" + host + ":1099" );
          properties.put( Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces" );
          properties.put( Context.SECURITY_PRINCIPAL, "sbatiuk" );
          properties.put( Context.SECURITY_CREDENTIALS, "mf" );

          try {
          Context ctx = new InitialContext( properties );
          Object obj = ctx.lookup( "Employee" );
          EmployeeHome employeeHome = ( EmployeeHome )javax.rmi.PortableRemoteObject.narrow( obj, bsv.employees.EmployeeHome.class );
          //EmployeeHome employeeHome = ( EmployeeHome )obj;
          Employee employee = employeeHome.create();
          textArea.append( employee.getName() );
          }
          catch( ServiceUnavailableException ex ) {
          ....
          }
          catch( Exception ex ) {
          ....
          }

          Please HELP!!

          Sincerely,
          Sergei Batiuk.

          • 2. Re: Accessing EJBs from applet
            Larry Newbie

            Remember when you use appletviewer, your client is running in the same VM as the server. That means you have access to the lib/ext and anything else in your classpath. An applet running in the browser can only count on whatever is in the archive. You should have everything your applet needs in a jar file named in the archive tag. (That includes any interface classes for your RMI.)

            • 3. Re: Accessing EJBs from applet
              Sergei Batiuk Newbie

              Dear larry054,

              Thank you very much! I did think that I have included all the jars, but oops! I checked once again and it appeared that one was missing... It works now!!!

              Sincerely,
              Sergei Batiuk.