[jboss-cvs] JBossAS SVN: r65011 - trunk/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:36 EDT 2007
Author: adrian at jboss.org
Date: 2007-09-03 10:03:36 -0400 (Mon, 03 Sep 2007)
New Revision: 65011
Modified:
trunk/iiop/src/main/org/jboss/proxy/ejb/HandleImplIIOP.java
trunk/iiop/src/main/org/jboss/proxy/ejb/HomeHandleImplIIOP.java
Log:
[JBAS-4655] - Fix the IIOP Handle serialization
Modified: trunk/iiop/src/main/org/jboss/proxy/ejb/HandleImplIIOP.java
===================================================================
--- trunk/iiop/src/main/org/jboss/proxy/ejb/HandleImplIIOP.java 2007-09-03 14:03:18 UTC (rev 65010)
+++ trunk/iiop/src/main/org/jboss/proxy/ejb/HandleImplIIOP.java 2007-09-03 14:03:36 UTC (rev 65011)
@@ -1,24 +1,24 @@
/*
-* JBoss, Home of Professional Open Source
-* Copyright 2005, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
package org.jboss.proxy.ejb;
import java.io.IOException;
@@ -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: trunk/iiop/src/main/org/jboss/proxy/ejb/HomeHandleImplIIOP.java
===================================================================
--- trunk/iiop/src/main/org/jboss/proxy/ejb/HomeHandleImplIIOP.java 2007-09-03 14:03:18 UTC (rev 65010)
+++ trunk/iiop/src/main/org/jboss/proxy/ejb/HomeHandleImplIIOP.java 2007-09-03 14:03:36 UTC (rev 65011)
@@ -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