Author: ataylor
Date: 2011-06-20 13:48:02 -0400 (Mon, 20 Jun 2011)
New Revision: 10860
Modified:
branches/Branch_2_2_AS7/src/main/org/hornetq/core/client/impl/ServerLocatorImpl.java
branches/Branch_2_2_AS7/src/main/org/hornetq/core/logging/Logger.java
branches/Branch_2_2_AS7/src/main/org/hornetq/core/remoting/impl/ssl/SSLSupport.java
branches/Branch_2_2_AS7/src/main/org/hornetq/core/remoting/server/impl/RemotingServiceImpl.java
branches/Branch_2_2_AS7/src/main/org/hornetq/core/server/cluster/impl/ClusterManagerImpl.java
branches/Branch_2_2_AS7/src/main/org/hornetq/core/server/impl/ConnectorsService.java
branches/Branch_2_2_AS7/src/main/org/hornetq/core/server/impl/HornetQServerImpl.java
branches/Branch_2_2_AS7/src/main/org/hornetq/jms/bridge/impl/JMSBridgeImpl.java
branches/Branch_2_2_AS7/src/main/org/hornetq/utils/ClassloadingUtil.java
branches/Branch_2_2_AS7/src/main/org/hornetq/utils/XMLUtil.java
Log:
https://issues.jboss.org/browse/HORNETQ-681
Modified:
branches/Branch_2_2_AS7/src/main/org/hornetq/core/client/impl/ServerLocatorImpl.java
===================================================================
---
branches/Branch_2_2_AS7/src/main/org/hornetq/core/client/impl/ServerLocatorImpl.java 2011-06-20
17:11:13 UTC (rev 10859)
+++
branches/Branch_2_2_AS7/src/main/org/hornetq/core/client/impl/ServerLocatorImpl.java 2011-06-20
17:48:02 UTC (rev 10860)
@@ -283,8 +283,24 @@
{
throw new IllegalStateException("Please specify a load balancing policy
class name on the session factory");
}
-
- loadBalancingPolicy =
(ConnectionLoadBalancingPolicy)ClassloadingUtil.safeInitNewInstance(connectionLoadBalancingPolicyClassName);
+
+ AccessController.doPrivileged(new PrivilegedAction<Object>()
+ {
+ public Object run()
+ {
+ try
+ {
+ loadBalancingPolicy = (ConnectionLoadBalancingPolicy)
ClassloadingUtil.safeInitNewInstance(connectionLoadBalancingPolicyClassName);
+ return null;
+ }
+ catch (Exception e)
+ {
+ throw new IllegalArgumentException("Unable to instantiate load
balancing policy \"" + connectionLoadBalancingPolicyClassName +
+ "\"",
+ e);
+ }
+ }
+ });
}
private synchronized void initialise() throws Exception
Modified: branches/Branch_2_2_AS7/src/main/org/hornetq/core/logging/Logger.java
===================================================================
--- branches/Branch_2_2_AS7/src/main/org/hornetq/core/logging/Logger.java 2011-06-20
17:11:13 UTC (rev 10859)
+++ branches/Branch_2_2_AS7/src/main/org/hornetq/core/logging/Logger.java 2011-06-20
17:48:02 UTC (rev 10860)
@@ -19,6 +19,7 @@
import org.hornetq.core.logging.impl.JULLogDelegateFactory;
import org.hornetq.spi.core.logging.LogDelegate;
import org.hornetq.spi.core.logging.LogDelegateFactory;
+import org.hornetq.utils.ClassloadingUtil;
/**
*
@@ -80,16 +81,7 @@
if (className != null)
{
- ClassLoader loader = Thread.currentThread().getContextClassLoader();
- try
- {
- Class<?> clz = loader.loadClass(className);
- delegateFactory = (LogDelegateFactory)clz.newInstance();
- }
- catch (Exception e)
- {
- throw new IllegalArgumentException("Error instantiating transformer
class \"" + className + "\"", e);
- }
+ delegateFactory = (LogDelegateFactory)
ClassloadingUtil.safeInitNewInstance(className);
}
else
{
Modified:
branches/Branch_2_2_AS7/src/main/org/hornetq/core/remoting/impl/ssl/SSLSupport.java
===================================================================
---
branches/Branch_2_2_AS7/src/main/org/hornetq/core/remoting/impl/ssl/SSLSupport.java 2011-06-20
17:11:13 UTC (rev 10859)
+++
branches/Branch_2_2_AS7/src/main/org/hornetq/core/remoting/impl/ssl/SSLSupport.java 2011-06-20
17:48:02 UTC (rev 10860)
@@ -30,6 +30,8 @@
import javax.net.ssl.TrustManagerFactory;
import javax.net.ssl.X509TrustManager;
+import org.hornetq.utils.ClassloadingUtil;
+
/**
* @author <a href="mailto:jmesnil@redhat.com">Jeff Mesnil</a>
*
@@ -185,7 +187,7 @@
}
else
{
- URL url =
Thread.currentThread().getContextClassLoader().getResource(storePath);
+ URL url = ClassloadingUtil.findResource(storePath);
if (url != null)
{
return url;
Modified:
branches/Branch_2_2_AS7/src/main/org/hornetq/core/remoting/server/impl/RemotingServiceImpl.java
===================================================================
---
branches/Branch_2_2_AS7/src/main/org/hornetq/core/remoting/server/impl/RemotingServiceImpl.java 2011-06-20
17:11:13 UTC (rev 10859)
+++
branches/Branch_2_2_AS7/src/main/org/hornetq/core/remoting/server/impl/RemotingServiceImpl.java 2011-06-20
17:48:02 UTC (rev 10860)
@@ -50,6 +50,7 @@
import org.hornetq.spi.core.remoting.BufferHandler;
import org.hornetq.spi.core.remoting.Connection;
import org.hornetq.spi.core.remoting.ConnectionLifeCycleListener;
+import org.hornetq.utils.ClassloadingUtil;
import org.hornetq.utils.ConfigurationHelper;
import org.hornetq.utils.HornetQThreadFactory;
@@ -108,13 +109,11 @@
this.server = server;
- ClassLoader loader = Thread.currentThread().getContextClassLoader();
for (String interceptorClass : config.getInterceptorClassNames())
{
try
{
- Class<?> clazz = loader.loadClass(interceptorClass);
- interceptors.add((Interceptor)clazz.newInstance());
+ interceptors.add((Interceptor)
ClassloadingUtil.safeInitNewInstance(interceptorClass));
}
catch (Exception e)
{
@@ -571,4 +570,4 @@
}
}
-}
\ No newline at end of file
+}
Modified:
branches/Branch_2_2_AS7/src/main/org/hornetq/core/server/cluster/impl/ClusterManagerImpl.java
===================================================================
---
branches/Branch_2_2_AS7/src/main/org/hornetq/core/server/cluster/impl/ClusterManagerImpl.java 2011-06-20
17:11:13 UTC (rev 10859)
+++
branches/Branch_2_2_AS7/src/main/org/hornetq/core/server/cluster/impl/ClusterManagerImpl.java 2011-06-20
17:48:02 UTC (rev 10860)
@@ -45,6 +45,7 @@
import org.hornetq.core.server.cluster.ClusterManager;
import org.hornetq.core.server.cluster.Transformer;
import org.hornetq.core.server.management.ManagementService;
+import org.hornetq.utils.ClassloadingUtil;
import org.hornetq.utils.ConcurrentHashSet;
import org.hornetq.utils.ExecutorFactory;
import org.hornetq.utils.UUID;
@@ -880,11 +881,9 @@
if (transformerClassName != null)
{
- ClassLoader loader = Thread.currentThread().getContextClassLoader();
try
{
- Class<?> clz = loader.loadClass(transformerClassName);
- transformer = (Transformer)clz.newInstance();
+ transformer = (Transformer)
ClassloadingUtil.safeInitNewInstance(transformerClassName);
}
catch (Exception e)
{
Modified:
branches/Branch_2_2_AS7/src/main/org/hornetq/core/server/impl/ConnectorsService.java
===================================================================
---
branches/Branch_2_2_AS7/src/main/org/hornetq/core/server/impl/ConnectorsService.java 2011-06-20
17:11:13 UTC (rev 10859)
+++
branches/Branch_2_2_AS7/src/main/org/hornetq/core/server/impl/ConnectorsService.java 2011-06-20
17:48:02 UTC (rev 10860)
@@ -20,6 +20,7 @@
import org.hornetq.core.server.ConnectorService;
import org.hornetq.core.server.ConnectorServiceFactory;
import org.hornetq.core.server.HornetQComponent;
+import org.hornetq.utils.ClassloadingUtil;
import org.hornetq.utils.ConfigurationHelper;
import java.util.HashSet;
@@ -60,16 +61,12 @@
public void start() throws Exception
{
- ClassLoader loader = Thread.currentThread().getContextClassLoader();
-
List<ConnectorServiceConfiguration> configurationList =
configuration.getConnectorServiceConfigurations();
for (ConnectorServiceConfiguration info : configurationList)
{
- Class<?> clazz = loader.loadClass(info.getFactoryClassName());
+ ConnectorServiceFactory factory = (ConnectorServiceFactory)
ClassloadingUtil.safeInitNewInstance(info.getFactoryClassName());
- ConnectorServiceFactory factory = (ConnectorServiceFactory)clazz.newInstance();
-
if (info.getParams() != null)
{
Set<String> invalid =
ConfigurationHelper.checkKeys(factory.getAllowableProperties(), info.getParams()
Modified:
branches/Branch_2_2_AS7/src/main/org/hornetq/core/server/impl/HornetQServerImpl.java
===================================================================
---
branches/Branch_2_2_AS7/src/main/org/hornetq/core/server/impl/HornetQServerImpl.java 2011-06-20
17:11:13 UTC (rev 10859)
+++
branches/Branch_2_2_AS7/src/main/org/hornetq/core/server/impl/HornetQServerImpl.java 2011-06-20
17:48:02 UTC (rev 10860)
@@ -116,6 +116,7 @@
import org.hornetq.spi.core.protocol.RemotingConnection;
import org.hornetq.spi.core.protocol.SessionCallback;
import org.hornetq.spi.core.security.HornetQSecurityManager;
+import org.hornetq.utils.ClassloadingUtil;
import org.hornetq.utils.ExecutorFactory;
import org.hornetq.utils.HornetQThreadFactory;
import org.hornetq.utils.OrderedExecutorFactory;
@@ -1860,18 +1861,7 @@
private Object instantiateInstance(final String className)
{
- ClassLoader loader = Thread.currentThread().getContextClassLoader();
- try
- {
- Class<?> clz = loader.loadClass(className);
- Object object = clz.newInstance();
-
- return object;
- }
- catch (Exception e)
- {
- throw new IllegalArgumentException("Error instantiating class \""
+ className + "\"", e);
- }
+ return ClassloadingUtil.safeInitNewInstance(className);
}
private static ClassLoader getThisClassLoader()
Modified: branches/Branch_2_2_AS7/src/main/org/hornetq/jms/bridge/impl/JMSBridgeImpl.java
===================================================================
---
branches/Branch_2_2_AS7/src/main/org/hornetq/jms/bridge/impl/JMSBridgeImpl.java 2011-06-20
17:11:13 UTC (rev 10859)
+++
branches/Branch_2_2_AS7/src/main/org/hornetq/jms/bridge/impl/JMSBridgeImpl.java 2011-06-20
17:48:02 UTC (rev 10860)
@@ -54,6 +54,7 @@
import org.hornetq.jms.bridge.QualityOfServiceMode;
import org.hornetq.jms.client.HornetQMessage;
import org.hornetq.jms.client.HornetQSession;
+import org.hornetq.utils.ClassloadingUtil;
/**
*
@@ -942,10 +943,8 @@
{
try
{
- ClassLoader loader = Thread.currentThread().getContextClassLoader();
- Class aClass = loader.loadClass(transactionManagerLocatorClass);
- Object o = aClass.newInstance();
- Method m = aClass.getMethod(transactionManagerLocatorMethod);
+ Object o =
ClassloadingUtil.safeInitNewInstance(transactionManagerLocatorClass);
+ Method m = o.getClass().getMethod(transactionManagerLocatorMethod);
tm = (TransactionManager)m.invoke(o);
}
catch (Exception e)
Modified: branches/Branch_2_2_AS7/src/main/org/hornetq/utils/ClassloadingUtil.java
===================================================================
--- branches/Branch_2_2_AS7/src/main/org/hornetq/utils/ClassloadingUtil.java 2011-06-20
17:11:13 UTC (rev 10859)
+++ branches/Branch_2_2_AS7/src/main/org/hornetq/utils/ClassloadingUtil.java 2011-06-20
17:48:02 UTC (rev 10860)
@@ -1,5 +1,6 @@
package org.hornetq.utils;
+import java.net.URL;
import java.security.AccessController;
import java.security.PrivilegedAction;
@@ -17,22 +18,62 @@
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)
+ catch (Throwable t)
{
- throw new IllegalArgumentException("Error instantiating connector
factory \"" + className + "\"", e);
+ try
+ {
+ loader = Thread.currentThread().getContextClassLoader();
+ if (loader != null)
+ return loader.loadClass(className).newInstance();
+ }
+ catch (RuntimeException e)
+ {
+ throw e;
+ }
+ catch (Exception e)
+ {
+ }
+
+ throw new IllegalArgumentException("Could not find class " +
className);
}
}
});
}
+ public static URL findResource(final String resourceName)
+ {
+ return AccessController.doPrivileged(new PrivilegedAction<URL>()
+ {
+ public URL run()
+ {
+ ClassLoader loader = ClassloadingUtil.class.getClassLoader();
+ try
+ {
+ URL resource = loader.getResource(resourceName);
+ if (resource != null)
+ return resource;
+ }
+ catch (Throwable t)
+ {
+ }
+
+ loader = Thread.currentThread().getContextClassLoader();
+ if (loader == null)
+ return null;
+
+ URL resource = loader.getResource(resourceName);
+ if (resource != null)
+ return resource;
+
+ return null;
+ }
+ });
+ }
+
}
Modified: branches/Branch_2_2_AS7/src/main/org/hornetq/utils/XMLUtil.java
===================================================================
--- branches/Branch_2_2_AS7/src/main/org/hornetq/utils/XMLUtil.java 2011-06-20 17:11:13
UTC (rev 10859)
+++ branches/Branch_2_2_AS7/src/main/org/hornetq/utils/XMLUtil.java 2011-06-20 17:48:02
UTC (rev 10860)
@@ -481,7 +481,7 @@
{
SchemaFactory factory =
SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
- Schema schema =
factory.newSchema(Thread.currentThread().getContextClassLoader().getResource(schemaFile));
+ Schema schema = factory.newSchema(ClassloadingUtil.findResource(schemaFile));
Validator validator = schema.newValidator();
// validate the DOM tree