Author: ataylor
Date: 2011-06-08 10:46:55 -0400 (Wed, 08 Jun 2011)
New Revision: 10787
Added:
branches/Branch_2_2_AS7/src/main/org/hornetq/utils/ClassloadingUtil.java
Modified:
branches/Branch_2_2_AS7/src/main/org/hornetq/core/client/impl/ClientSessionFactoryImpl.java
branches/Branch_2_2_AS7/src/main/org/hornetq/ra/Util.java
Log:
https://issues.jboss.org/browse/HORNETQ-681
Modified:
branches/Branch_2_2_AS7/src/main/org/hornetq/core/client/impl/ClientSessionFactoryImpl.java
===================================================================
---
branches/Branch_2_2_AS7/src/main/org/hornetq/core/client/impl/ClientSessionFactoryImpl.java 2011-06-08
14:33:58 UTC (rev 10786)
+++
branches/Branch_2_2_AS7/src/main/org/hornetq/core/client/impl/ClientSessionFactoryImpl.java 2011-06-08
14:46:55 UTC (rev 10787)
@@ -58,6 +58,7 @@
import org.hornetq.spi.core.remoting.ConnectionLifeCycleListener;
import org.hornetq.spi.core.remoting.Connector;
import org.hornetq.spi.core.remoting.ConnectorFactory;
+import org.hornetq.utils.ClassloadingUtil;
import org.hornetq.utils.ConcurrentHashSet;
import org.hornetq.utils.ConfigurationHelper;
import org.hornetq.utils.ExecutorFactory;
@@ -1188,24 +1189,7 @@
private ConnectorFactory instantiateConnectorFactory(final String
connectorFactoryClassName)
{
- return AccessController.doPrivileged(new
PrivilegedAction<ConnectorFactory>()
- {
- public ConnectorFactory run()
- {
- ClassLoader loader = Thread.currentThread().getContextClassLoader();
- try
- {
- Class<?> clazz = loader.loadClass(connectorFactoryClassName);
- return (ConnectorFactory)clazz.newInstance();
- }
- catch (Exception e)
- {
- throw new IllegalArgumentException("Error instantiating connector
factory \"" + connectorFactoryClassName +
- "\"",
- e);
- }
- }
- });
+ return (ConnectorFactory)
ClassloadingUtil.safeInitNewInstance(connectorFactoryClassName);
}
private void lockChannel1()
Modified: branches/Branch_2_2_AS7/src/main/org/hornetq/ra/Util.java
===================================================================
--- branches/Branch_2_2_AS7/src/main/org/hornetq/ra/Util.java 2011-06-08 14:33:58 UTC (rev
10786)
+++ branches/Branch_2_2_AS7/src/main/org/hornetq/ra/Util.java 2011-06-08 14:46:55 UTC (rev
10787)
@@ -19,6 +19,7 @@
import javax.transaction.TransactionManager;
import org.hornetq.core.logging.Logger;
+import org.hornetq.utils.ClassloadingUtil;
/**
* Various utility functions
@@ -256,6 +257,18 @@
{
try
{
+ ClassLoader loader = HornetQResourceAdapter.class.getClassLoader();
+ Class<?> aClass = loader.loadClass(locatorClass);
+ Object o = aClass.newInstance();
+ Method m = aClass.getMethod(locatorMethod);
+ return (TransactionManager)m.invoke(o);
+ }
+ catch (Throwable e)
+ {
+ log.debug(e.getMessage(), e);
+ }
+ try
+ {
ClassLoader loader = Thread.currentThread().getContextClassLoader();
Class<?> aClass = loader.loadClass(locatorClass);
Object o = aClass.newInstance();
Added: branches/Branch_2_2_AS7/src/main/org/hornetq/utils/ClassloadingUtil.java
===================================================================
--- branches/Branch_2_2_AS7/src/main/org/hornetq/utils/ClassloadingUtil.java
(rev 0)
+++ branches/Branch_2_2_AS7/src/main/org/hornetq/utils/ClassloadingUtil.java 2011-06-08
14:46:55 UTC (rev 10787)
@@ -0,0 +1,38 @@
+package org.hornetq.utils;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+/**
+* A ClassloadingUtil *
+* @author <a href="mailto:hgao@redhat.com">Howard Gao</a>
+*/
+
+public class ClassloadingUtil
+{
+ public static Object safeInitNewInstance(final String className)
+ {
+ return AccessController.doPrivileged(new PrivilegedAction<Object>()
+ {
+ public Object run()
+ {
+ ClassLoader loader = ClassloadingUtil.class.getClassLoader();
+ if (loader == null)
+ {
+ loader = Thread.currentThread().getContextClassLoader();
+ }
+ try
+ {
+ Class<?> clazz = loader.loadClass(className);
+ return clazz.newInstance();
+ }
+ catch (Exception e)
+ {
+ throw new IllegalArgumentException("Error instantiating connector
factory \"" + className + "\"", e);
+ }
+ }
+ });
+ }
+
+}
+