5 Replies Latest reply on Oct 23, 2008 6:52 AM by jaikiran

    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


        • 1. Re: Sending an Object from client (Swing) to Sever Remote (E
          jaikiran

           

          ClassLoader cl = Thread.currentThread().getContextClassLoader();
          Class k = cl.loadClass("client.H");

          H h = (H) k.newInstance();


          Instead of this, how about just instantiating a new object:

          H h = new client.H();


          • 2. Re: Sending an Object from client (Swing) to Sever Remote (E
            babak_azarmi

            no i've tried it but i encountered to no classloaders exception

            • 3. Re: Sending an Object from client (Swing) to Sever Remote (E
              jaikiran

               

              "babak_azarmi" wrote:
              no i've tried it but i encountered to no classloaders exception


              Please post the entire exception stacktrace that you see when you tried that. Also, are you having this client.H in the classpath? Is this class part of some jar file?

              • 4. Re: Sending an Object from client (Swing) to Sever Remote (E
                babak_azarmi

                my object is in my client side package jar file.
                for example i want to send a list of objects to severs.
                all my objectes are Entities and i've wrote a business in my server till this business persists all my objects that have been sent from client.

                in my sever side



                @Stateless
                public class MyClass implements MyClassRemote {
                 public void saveList(List<Object> list) {
                 do something with list
                 }
                }
                

                but i encountered to this exception
                javax.ejb.EJBException: nested exception is: java.rmi.MarshalException: CORBA MARSHAL 1398079745 Maybe; nested exception is:
                 org.omg.CORBA.MARSHAL: ----------BEGIN server-side stack trace----------
                org.omg.CORBA.MARSHAL: vmcid: SUN minor code: 257 completed: Maybe
                 at com.sun.corba.ee.impl.logging.ORBUtilSystemException.couldNotFindClass(ORBUtilSystemException.java:9684)
                 at com.sun.corba.ee.impl.logging.ORBUtilSystemException.couldNotFindClass(ORBUtilSystemException.java:9699)
                 at com.sun.corba.ee.impl.encoding.CDRInputStream_1_0.read_value(CDRInputStream_1_0.java:1042)
                 at com.sun.corba.ee.impl.encoding.CDRInputStream_1_0.read_value(CDRInputStream_1_0.java:896)
                 at com.sun.corba.ee.impl.encoding.CDRInputStream_1_0.read_abstract_interface(CDRInputStream_1_0.java:890)
                 at com.sun.corba.ee.impl.encoding.CDRInputStream_1_0.read_abstract_interface(CDRInputStream_1_0.java:880)
                 at com.sun.corba.ee.impl.encoding.CDRInputStream.read_abstract_interface(CDRInputStream.java:511)
                 at com.sun.corba.ee.impl.io.IIOPInputStream.readObjectDelegate(IIOPInputStream.java:386)
                 at com.sun.corba.ee.impl.io.IIOPInputStream.readObjectOverride(IIOPInputStream.java:547)
                 at java.io.ObjectInputStream.readObject(ObjectInputStream.java:345)
                 at java.util.ArrayList.readObject(ArrayList.java:593)
                 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                 at java.lang.reflect.Method.invoke(Method.java:597)
                 at com.sun.corba.ee.impl.io.IIOPInputStream.invokeObjectReader(IIOPInputStream.java:1679)
                 at com.sun.corba.ee.impl.io.IIOPInputStream.inputObject(IIOPInputStream.java:1202)
                 at com.sun.corba.ee.impl.io.IIOPInputStream.simpleReadObject(IIOPInputStream.java:422)
                 at com.sun.corba.ee.impl.io.ValueHandlerImpl.readValueInternal(ValueHandlerImpl.java:362)
                 at com.sun.corba.ee.impl.io.ValueHandlerImpl.readValue(ValueHandlerImpl.java:328)
                 at com.sun.corba.ee.impl.encoding.CDRInputStream_1_0.readRMIIIOPValueType(CDRInputStream_1_0.java:966)
                 at com.sun.corba.ee.impl.encoding.CDRInputStream_1_0.read_value(CDRInputStream_1_0.java:1052)
                 at com.sun.corba.ee.impl.encoding.CDRInputStream.read_value(CDRInputStream.java:475)
                 at com.sun.corba.ee.impl.presentation.rmi.DynamicMethodMarshallerImpl$14.read(DynamicMethodMarshallerImpl.java:368)
                 at com.sun.corba.ee.impl.presentation.rmi.DynamicMethodMarshallerImpl.readArguments(DynamicMethodMarshallerImpl.java:435)
                 at com.sun.corba.ee.impl.presentation.rmi.ReflectiveTie._invoke(ReflectiveTie.java:152)
                 at com.sun.corba.ee.impl.protocol.CorbaServerRequestDispatcherImpl.dispatchToServant(CorbaServerRequestDispatcherImpl.java:687)
                 at com.sun.corba.ee.impl.protocol.CorbaServerRequestDispatcherImpl.dispatch(CorbaServerRequestDispatcherImpl.java:227)
                 at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequestRequest(CorbaMessageMediatorImpl.java:1846)
                 at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequest(CorbaMessageMediatorImpl.java:1706)
                 at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleInput(CorbaMessageMediatorImpl.java:1088)
                 at com.sun.corba.ee.impl.protocol.giopmsgheaders.RequestMessage_1_2.callback(RequestMessage_1_2.java:223)
                 at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequest(CorbaMessageMediatorImpl.java:806)
                 at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.dispatch(CorbaMessageMediatorImpl.java:563)
                 at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.doWork(CorbaMessageMediatorImpl.java:2567)
                 at com.sun.corba.ee.impl.orbutil.threadpool.ThreadPoolImpl$WorkerThread.run(ThreadPoolImpl.java:555)
                
                ----------END server-side stack trace---------- vmcid: SUN minor code: 257 completed: Maybe
                
                

                is shows that in sever side the program can not deseriallize the List object
                why? i'm just sending a list from client and sever must be recognized the List Object and deserialize it?


                • 5. Re: Sending an Object from client (Swing) to Sever Remote (E
                  jaikiran

                  In most of the posts that i have seen till date, I haven't seen corba related stacktrace in JBoss server related stacktraces. Which application server are you using?