3 Replies Latest reply on Apr 8, 2009 2:21 PM by marcelr

    Sending an Object from client (Swing) to Sever Remote (EJB3)

    babak_azarmi

      Hello guys i've got a problem in sending an Object to sever by remote (EJB3) technology framework

      take look at my code

      in server side

      @Remote
      public interface TestRemote {
       public void sendObject(Object obj);
      }
      
      @Stateless
      public class TestBean implements TestRemote {
       public void sendObject(Object obj) {
       System.out.println("Object is Coming");
       }
      }


      in client side (swing)

      public class H implements Serializable {
       private static final long serialVersionUID = 1L;
       private int id;
      
       public void setId(int id) {
       this.id = id;
       }
      
       public int getId() {
       return id;
       }
      }
      
      public class RunMe {
       public RunMe() {
       try {
       Properties prop = new Properties();
      
       prop.setProperty("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
       prop.setProperty("java.naming.factory.url.pkgs","org.jboss.naming:org.jnp.interfaces");
       prop.setProperty("java.naming.provider.url","localhost:1099");
      
       Context ctx = new InitialContext(prop);
       System.out.println("Step 1");
      
       ClassLoader cl = Thread.currentThread().getContextClassLoader();
       Class k = cl.loadClass("client.H");
      
       H h = (H) k.newInstance();
       h.setId(44);
      
      
       System.out.println("Step 2");
       //Thread.currentThread().getContextClassLoader().
       RunMeRemote r = (RunMeRemote)
       ctx.lookup("RunMe/remote");
       r.setObject(h);
      
       } catch (Exception e) {
       System.out.println(e);
       }
       }
       public static void main(String[] st) {
       new RunMe();
       }
      }
      


      when I run this program i encountered to this exception

      Step 1
      Step 2
      log4j:WARN No appenders could be found for logger (org.jboss.security.SecurityAssociation).
      log4j:WARN Please initialize the log4j system properly.
      java.lang.RuntimeException: java.lang.ClassNotFoundException: No ClassLoaders found for: client.H (no security manager: RMI class loader disabled)

      when i add this code
      public class Client {
      
      
      
       @SuppressWarnings("unchecked")
       public Client() {
       try {
       Properties prop = new Properties();
      
       prop.setProperty("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
       prop.setProperty("java.naming.factory.url.pkgs","org.jboss.naming:org.jnp.interfaces");
       prop.setProperty("java.naming.provider.url","localhost:1099");
      
       Context ctx = new InitialContext(prop);
       if (System.getSecurityManager() == null) {
       System.setSecurityManager(new RMISecurityManager());
       }
       System.out.println("Step 1");
      
       ClassLoader cl = Thread.currentThread().getContextClassLoader();
       Class k = cl.loadClass("client.H");
      
       H h = (H) k.newInstance();
       h.setId(44);
      
      
       System.out.println("Step 2");
       //Thread.currentThread().getContextClassLoader().
       RunMeRemote r = (RunMeRemote) ctx.lookup("RunMe/remote");
       r.setObject(h);
      
       } catch (Exception e) {
       System.out.println(e);
       }
      
       }
      
       public static void main(String[] s) {
      
       new Client();
       }
      
      }
      


      another exception is appeared

      Step 1
      Step 2
      log4j:WARN No appenders could be found for logger (org.jnp.interfaces.NamingContext).
      log4j:WARN Please initialize the log4j system properly.
      javax.naming.CommunicationException: Could not obtain connection to any of these urls: localhost:1099 and discovery failed with error: java.security.AccessControlException: access denied (java.net.SocketPermission 230.0.0.4 connect,accept,resolve) [Root exception is javax.naming.CommunicationException: Failed to connect to server localhost:1099 [Root exception is java.security.AccessControlException: access denied (java.net.SocketPermission 127.0.0.1:1099 connect,resolve)]]

      Mention. when i want to send a String or int or any prmetive java Object my program works good and send the date for sever
      but when i want to send an object (Entity Object) the exception is appeared.

      tell what should i do to send an Object to sever by remote (EJB3) Technology? thanks so much