[jboss-cvs] JBossAS SVN: r65010 - branches/Branch_4_2/iiop/src/main/org/jboss/proxy/ejb.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Sep 3 10:03:19 EDT 2007


Author: adrian at jboss.org
Date: 2007-09-03 10:03:18 -0400 (Mon, 03 Sep 2007)
New Revision: 65010

Modified:
   branches/Branch_4_2/iiop/src/main/org/jboss/proxy/ejb/HandleImplIIOP.java
   branches/Branch_4_2/iiop/src/main/org/jboss/proxy/ejb/HomeHandleImplIIOP.java
Log:
[JBAS-4655] - Fix the IIOP Handle serialization

Modified: branches/Branch_4_2/iiop/src/main/org/jboss/proxy/ejb/HandleImplIIOP.java
===================================================================
--- branches/Branch_4_2/iiop/src/main/org/jboss/proxy/ejb/HandleImplIIOP.java	2007-09-03 13:13:55 UTC (rev 65009)
+++ branches/Branch_4_2/iiop/src/main/org/jboss/proxy/ejb/HandleImplIIOP.java	2007-09-03 14:03:18 UTC (rev 65010)
@@ -26,10 +26,12 @@
 import java.io.ObjectOutputStream;
 import java.io.Serializable;
 import java.rmi.RemoteException;
+
 import javax.ejb.EJBObject;
 import javax.ejb.Handle;
 import javax.ejb.spi.HandleDelegate;
 import javax.rmi.PortableRemoteObject;
+import javax.rmi.CORBA.Stub;
 
 import org.jboss.iiop.CorbaORB;
 import org.jboss.proxy.ejb.handle.HandleDelegateImpl;
@@ -52,6 +54,9 @@
     * <code>EJBObject</code>. 
     */
    private String ior;
+
+   /** The stub class */
+   private transient Class<?> stubClass = EJBObject.class;
    
    /**
     * Constructs an <code>HandleImplIIOP</code>.
@@ -81,6 +86,7 @@
    public HandleImplIIOP(org.omg.CORBA.Object obj) 
    {
       this.ior = CorbaORB.getInstance().object_to_string(obj);
+      this.stubClass = obj.getClass();
    }
    
    // Public --------------------------------------------------------
@@ -91,24 +97,52 @@
     * Obtains the <code>EJBObject</code> represented by this handle.
     *
     * @return  a reference to an <code>EJBObject</code>.
-    *
     * @throws RemoteException
     */
-   public EJBObject getEJBObject() 
-         throws RemoteException 
+   public EJBObject getEJBObject() throws RemoteException 
    {
       try 
       {
-         return (EJBObject)PortableRemoteObject.narrow(
-                                  CorbaORB.getInstance().string_to_object(ior),
-                                  EJBObject.class);
+         org.omg.CORBA.Object obj = CorbaORB.getInstance().string_to_object(ior);
+         return narrow(obj);
       }
+      catch (RemoteException e)
+      {
+         throw e;
+      }
       catch (Exception e) 
       {
-         throw new RemoteException("Could not get EJBObject from Handle");
+         throw new RemoteException("Could not get EJBObject from Handle", e);
       }
    }
 
+   private EJBObject narrow(org.omg.CORBA.Object obj) throws ClassCastException, RemoteException
+   {
+      // Null object - this should probably throw some kind of error?
+      if (obj == null)
+         return null;
+      
+      // Already the correct type
+      if (stubClass.isAssignableFrom(obj.getClass()))
+         return (EJBObject) obj;
+      
+      // Backwards compatibility - almost certainly wrong!
+      if (stubClass == EJBObject.class)
+         return (EJBObject) PortableRemoteObject.narrow(obj, EJBObject.class);
+
+      // Create the stub from the stub class
+      try
+      {
+         Stub stub = (Stub) stubClass.newInstance();
+         stub._set_delegate(((org.omg.CORBA.portable.ObjectImpl) obj)._get_delegate());
+         return (EJBObject) stub;
+      }
+      catch (Exception e)
+      {
+         throw new RemoteException("Error creating stub", e);
+      }
+   }
+   
    private void writeObject(ObjectOutputStream oostream) throws IOException
    {
       HandleDelegate delegate = HandleDelegateImpl.getDelegate();
@@ -120,5 +154,6 @@
       HandleDelegate delegate = HandleDelegateImpl.getDelegate();
       EJBObject obj = delegate.readEJBObject(oistream);
       this.ior = CorbaORB.getInstance().object_to_string((org.omg.CORBA.Object) obj);
+      this.stubClass = obj.getClass();
    }
 }

Modified: branches/Branch_4_2/iiop/src/main/org/jboss/proxy/ejb/HomeHandleImplIIOP.java
===================================================================
--- branches/Branch_4_2/iiop/src/main/org/jboss/proxy/ejb/HomeHandleImplIIOP.java	2007-09-03 13:13:55 UTC (rev 65009)
+++ branches/Branch_4_2/iiop/src/main/org/jboss/proxy/ejb/HomeHandleImplIIOP.java	2007-09-03 14:03:18 UTC (rev 65010)
@@ -30,6 +30,7 @@
 import javax.ejb.HomeHandle;
 import javax.ejb.spi.HandleDelegate;
 import javax.rmi.PortableRemoteObject;
+import javax.rmi.CORBA.Stub;
 
 import org.jboss.iiop.CorbaORB;
 import org.jboss.proxy.ejb.handle.HandleDelegateImpl;
@@ -53,6 +54,9 @@
     * <code>EJBHome</code>. 
     */
    private String ior;
+
+   /** The stub class */
+   private transient Class<?> stubClass = EJBHome.class;
    
    /**
     * Constructs a <code>HomeHandleImplIIOP</code>.
@@ -82,6 +86,7 @@
    public HomeHandleImplIIOP(org.omg.CORBA.Object home) 
    {
       this.ior = CorbaORB.getInstance().object_to_string(home);
+      this.stubClass = home.getClass();
    }
    
    // Public --------------------------------------------------------
@@ -92,25 +97,52 @@
     * Obtains the <code>EJBHome</code> represented by this home handle.
     *
     * @return  a reference to an <code>EJBHome</code>.
-    *
     * @throws RemoteException
     */
-   public EJBHome getEJBHome() 
-         throws RemoteException 
+   public EJBHome getEJBHome() throws RemoteException 
    {
       try 
       {
-         return (EJBHome)PortableRemoteObject.narrow(
-                                  CorbaORB.getInstance().string_to_object(ior),
-                                  EJBHome.class);
+         org.omg.CORBA.Object obj = CorbaORB.getInstance().string_to_object(ior);
+         return narrow(obj);
       }
+      catch (RemoteException e)
+      {
+         throw e;
+      }
       catch (Exception e) 
       {
-         throw new RemoteException("Could not get EJBHome from HomeHandle");
+         throw new RemoteException("Could not get EJBHome from HomeHandle", e);
       }
    }
-   
 
+   private EJBHome narrow(org.omg.CORBA.Object obj) throws ClassCastException, RemoteException
+   {
+      // Null object - this should probably throw some kind of error?
+      if (obj == null)
+         return null;
+      
+      // Already the correct type
+      if (stubClass.isAssignableFrom(obj.getClass()))
+         return (EJBHome) obj;
+      
+      // Backwards compatibility - almost certainly wrong!
+      if (stubClass == EJBHome.class)
+         return (EJBHome) PortableRemoteObject.narrow(obj, EJBHome.class);
+
+      // Create the stub from the stub class
+      try
+      {
+         Stub stub = (Stub) stubClass.newInstance();
+         stub._set_delegate(((org.omg.CORBA.portable.ObjectImpl) obj)._get_delegate());
+         return (EJBHome) stub;
+      }
+      catch (Exception e)
+      {
+         throw new RemoteException("Error creating stub", e);
+      }
+   }
+
    public void writeObject(ObjectOutputStream oostream) throws IOException
    {
       HandleDelegate delegate = HandleDelegateImpl.getDelegate();
@@ -122,5 +154,6 @@
       HandleDelegate delegate = HandleDelegateImpl.getDelegate();
       EJBHome obj = delegate.readEJBHome(oistream);
       this.ior = CorbaORB.getInstance().object_to_string((org.omg.CORBA.Object) obj);
+      this.stubClass = obj.getClass();
    }
 }




More information about the jboss-cvs-commits mailing list