[jboss-cvs] JBossAS SVN: r78461 - in projects/ejb3/trunk/proxy/src/main/java/org/jboss/ejb3/proxy: objectfactory/session and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Sep 11 18:09:11 EDT 2008
Author: ALRubinger
Date: 2008-09-11 18:09:10 -0400 (Thu, 11 Sep 2008)
New Revision: 78461
Modified:
projects/ejb3/trunk/proxy/src/main/java/org/jboss/ejb3/proxy/factory/session/SessionProxyFactoryBase.java
projects/ejb3/trunk/proxy/src/main/java/org/jboss/ejb3/proxy/objectfactory/session/SessionProxyObjectFactory.java
Log:
[EJBTHREE-1442] Always use the Container CL to make proxies, and allow the caller (ObjectFactory) to redefine the Proxy in its own CL if necessary
Modified: projects/ejb3/trunk/proxy/src/main/java/org/jboss/ejb3/proxy/factory/session/SessionProxyFactoryBase.java
===================================================================
--- projects/ejb3/trunk/proxy/src/main/java/org/jboss/ejb3/proxy/factory/session/SessionProxyFactoryBase.java 2008-09-11 21:25:23 UTC (rev 78460)
+++ projects/ejb3/trunk/proxy/src/main/java/org/jboss/ejb3/proxy/factory/session/SessionProxyFactoryBase.java 2008-09-11 22:09:10 UTC (rev 78461)
@@ -197,30 +197,6 @@
Constructor<?> constructor = this.getConstructorsProxySpecificBusinessInterface().get(
businessInterfaceName.trim());
- /*
- * In place for web injection (isolated CL)
- */
- ClassLoader tcl = Thread.currentThread().getContextClassLoader();
- try
- {
- // See if we can get at the bean class from the TCL
- Class<?> businessInterfaceClass = Class.forName(businessInterfaceName, false, tcl);
-
- // If so, use the TCL to generate the Proxy class, not the Container CL
- Set<Class<?>> businessInterfaces = new HashSet<Class<?>>();
- businessInterfaces.add(businessInterfaceClass);
- constructor = this.createProxyConstructor(businessInterfaces, tcl);
-
- }
- catch (LinkageError le)
- {
- // Ignore
- }
- catch (ClassNotFoundException cce)
- {
- // Ignore
- }
-
// Ensure the constructor was found
assert constructor != null : "No business proxy constructor for \"" + businessInterfaceName
+ "\" was found; not created at start() properly? Bad value bound as RefAddr in JNDI?";
@@ -229,8 +205,11 @@
SessionProxyInvocationHandler handler = this
.createBusinessInterfaceSpecificInvocationHandler(businessInterfaceName);
- // Create a new Proxy instance, and return
- return constructor.newInstance(handler);
+ // Create a new Proxy instance
+ Object proxy = constructor.newInstance(handler);
+
+ // Return
+ return proxy;
}
catch (Throwable t)
{
Modified: projects/ejb3/trunk/proxy/src/main/java/org/jboss/ejb3/proxy/objectfactory/session/SessionProxyObjectFactory.java
===================================================================
--- projects/ejb3/trunk/proxy/src/main/java/org/jboss/ejb3/proxy/objectfactory/session/SessionProxyObjectFactory.java 2008-09-11 21:25:23 UTC (rev 78460)
+++ projects/ejb3/trunk/proxy/src/main/java/org/jboss/ejb3/proxy/objectfactory/session/SessionProxyObjectFactory.java 2008-09-11 22:09:10 UTC (rev 78461)
@@ -21,8 +21,12 @@
*/
package org.jboss.ejb3.proxy.objectfactory.session;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Proxy;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import javax.naming.Name;
@@ -129,6 +133,65 @@
proxy = sFactory.createProxyBusiness(businessInterface);
log.debug("Created Proxy of type " + proxy.getClass().getSimpleName() + " for EJB3 Business Interface: "
+ businessInterface);
+
+ /*
+ * We've got to ensure that the Proxy will be assignable to the target
+ * within this CL
+ */
+
+ // Get the TCL
+ ClassLoader tcl = Thread.currentThread().getContextClassLoader();
+
+ // Get the Proxy's CL
+ ClassLoader proxyCl = proxy.getClass().getClassLoader();
+
+ // If the classloaders are not equal
+ if (tcl != proxyCl)
+ {
+ /*
+ * Reconstruct/redefine the Proxy in our CL
+ */
+
+ // Get the Proxy Class
+ Class<?> proxyClass = proxy.getClass();
+
+ // Ensure we've got a Proxy
+ assert Proxy.isProxyClass(proxyClass) : "Assumed Proxy is not an instance of " + Proxy.class.getName();
+
+ // Get the InvocationHandler
+ InvocationHandler handler = Proxy.getInvocationHandler(proxy);
+
+ // Get the Interfaces
+ Class<?>[] proxyInterfaces = proxyClass.getInterfaces();
+
+ // Make a Set to hold the redefined classes
+ Set<Class<?>> ourClInterfaces = new HashSet<Class<?>>();
+
+ // For each interface defined by the Proxy
+ for (Class<?> proxyInterface : proxyInterfaces)
+ {
+ // Get the FQN
+ String proxyInterfaceName = proxyInterface.getName();
+
+ // Redefine the class in our CL
+ Class<?> ourDefinedProxyInterface = null;
+ try
+ {
+ ourDefinedProxyInterface = Class.forName(proxyInterfaceName, false, tcl);
+ }
+ catch (ClassNotFoundException e)
+ {
+ throw new RuntimeException("Can not find interface declared by Proxy in our CL + " + tcl, e);
+ }
+
+ // Add the Class to the Set
+ ourClInterfaces.add(ourDefinedProxyInterface);
+ }
+
+ // Redefine the Proxy in our CL
+ proxy = Proxy.newProxyInstance(tcl, ourClInterfaces.toArray(new Class<?>[]
+ {}), handler);
+ }
}
else
{
More information about the jboss-cvs-commits
mailing list