2 Replies Latest reply on Oct 7, 2005 5:49 PM by L.A. D.Z.

    Problem with an easy example

    L.A. D.Z. Newbie

      I've a problem with a very simple "application" I'm writing to understand EJB3.
      I've a Session Stateless Bean (there'a a method called service that receive a String and returns a String) and a command-line java client that calls this method.

      Here is the code:

      mainpkg/SessionStateless.java

      package mainpkg;
      
      import javax.ejb.Remote;
      
      @Remote
      public interface SessionStateless {
       public String service(String s);
      }


      mainpkg/SessionStatelessBean.java
      package mainpkg;
      
      import javax.ejb.Stateless;
      import mainpkg.SessionStateless;
      
      public @Stateless class SessionStatelessBean implements SessionStateless {
      
       public String service(String s) {
       return s + "World";
       }
      
      }


      clientpkg.client.java
      package clientpkg;
      
      import javax.naming.Context;
      import javax.naming.InitialContext;
      import javax.naming.NamingException;
      import java.rmi.RMISecurityManager;
      import mainpkg.SessionStateless;
      
      public class Client {
      
       private SessionStateless SSbean;
       private String str;
      
       public Client(String cl) {str=cl;}
      
       public void init() {
       try {
       if (System.getSecurityManager() == null) {
       System.setSecurityManager(new RMISecurityManager());
       }
       Context context = new InitialContext();
       String sss = SessionStateless.class.getName();
       Object ssr = context.lookup(sss);
       SSbean = (SessionStateless) ssr;
       } catch (NamingException e) {
       e.printStackTrace();
       }
       }
      
       public String add() {
       return SSbean.service(str);
       }
      
       public static void main(String[] args) {
       Client client = new Client(args[0]);
       client.init();
       System.out.println(client.add());
       }
      }


      java.security.policy (otherwise I get SecurityException when I try to connect)
      grant {
       permission java.security.AllPermission;
      };



      When I package the ejb3 file I have the 2 SessionStateless(Bean).class files inside mainpkg folder, and the META-INF folder with MANIFEST.MF inside.

      When I deploy I've got this message from jboss-4.0.3:
      18:31:05,486 INFO [JaccHelper] Initialising JACC Context for deployment: test-ejb3.ejb3
      18:31:05,666 INFO [Ejb3AnnotationHandler] found EJB3: ejbName=mainpkg.SessionStatelessBean, class=mainpkg.SessionStatelessBean, type=STATELESS
      18:31:05,767 INFO [JaccHelper] mainpkg.SessionStatelessBean has no @SecurityDomain - skipping JACC configuration
      18:31:05,767 INFO [JaccHelper] JACC Policy Configuration for deployment has been put in service
      18:31:05,767 INFO [Ejb3Deployment] EJB3 deployment time took: 281
      18:31:05,897 INFO [ProxyDeployer] no declared remote bindings for : mainpkg.SessionStatelessBean
      18:31:05,897 INFO [ProxyDeployer] there is remote interfaces for mainpkg.SessionStatelessBean
      18:31:05,897 INFO [ProxyDeployer] default remote binding has jndiName of mainpkg.SessionStateless
      18:31:06,097 INFO [EJB3Deployer] Deployed: file:/C:/Programmi/jboss-4.0.3/server/all/deploy/test-ejb3.ejb3


      When I execute Client.java with a String and with -Djava.security.policy=path_to_my_java.security.policy option, I get this error:
      javax.naming.CommunicationException [Root exception is java.lang.ClassNotFoundException: org.jboss.proxy.ejb.EJBMetaDataImpl]
      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 clientpkg.Client.init(Client.java:23)
      at clientpkg.Client.main(Client.java:36)
      Caused by: java.lang.ClassNotFoundException: org.jboss.proxy.ejb.EJBMetaDataImpl
      at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
      at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
      at java.lang.Class.forName0(Native Method)
      at java.lang.Class.forName(Class.java:242)
      at sun.rmi.server.LoaderHandler.loadClass(LoaderHandler.java:430)
      at sun.rmi.server.LoaderHandler.loadClass(LoaderHandler.java:165)
      at java.rmi.server.RMIClassLoader$2.loadClass(RMIClassLoader.java:620)
      at java.rmi.server.RMIClassLoader.loadClass(RMIClassLoader.java:247)
      at sun.rmi.server.MarshalInputStream.resolveClass(MarshalInputStream.java:197)
      at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1538)
      at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1460)
      at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1693)
      at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1299)
      at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1912)
      at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1836)
      at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1713)
      at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1299)
      at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1912)
      at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1836)
      at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1713)
      at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1299)
      at java.io.ObjectInputStream.readObject(ObjectInputStream.java:339)
      at java.rmi.MarshalledObject.get(MarshalledObject.java:135)
      at org.jnp.interfaces.MarshalledValuePair.get(MarshalledValuePair.java:57)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:637)
      ... 4 more
      Exception in thread "main" java.lang.NullPointerException
      at clientpkg.Client.add(Client.java:31)
      at clientpkg.Client.main(Client.java:37)

      The exception in when executing this line in Client.java: "Object ssr = context.lookup(sss);"

      What can I do?
      Thanks a lot!