Author: clebert.suconic(a)jboss.com
Date: 2011-11-18 15:01:24 -0500 (Fri, 18 Nov 2011)
New Revision: 11715
Added:
branches/Branch_2_2_AS7/mac-build.sh
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/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/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/XMLUtil.java
Log:
Fixing classLoading
Added: branches/Branch_2_2_AS7/mac-build.sh
===================================================================
--- branches/Branch_2_2_AS7/mac-build.sh (rev 0)
+++ branches/Branch_2_2_AS7/mac-build.sh 2011-11-18 20:01:24 UTC (rev 11715)
@@ -0,0 +1,2 @@
+#you need to define this variable on mac
+./build.sh -Djdk5.home=/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/
"$@"
Property changes on: branches/Branch_2_2_AS7/mac-build.sh
___________________________________________________________________
Added: svn:executable
+ *
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-11-18
17:44:13 UTC (rev 11714)
+++
branches/Branch_2_2_AS7/src/main/org/hornetq/core/client/impl/ClientSessionFactoryImpl.java 2011-11-18
20:01:24 UTC (rev 11715)
@@ -59,6 +59,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;
@@ -1351,18 +1352,7 @@
{
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.newInstanceFromClassLoader(connectorFactoryClassName);
}
});
}
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-11-18
17:44:13 UTC (rev 11714)
+++ branches/Branch_2_2_AS7/src/main/org/hornetq/core/logging/Logger.java 2011-11-18
20:01:24 UTC (rev 11715)
@@ -21,6 +21,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;
/**
*
@@ -202,46 +203,16 @@
delegate.trace(message, t);
}
- /** This seems duplicate code all over the place, but for security reasons we
can't let something like this to be open in a
- * utility class, as it would be a door to load anything you like in a safe VM.
- * For that reason any class trying to do a privileged block should do with the
AccessController directly.
- * @param className
- * @return
- */
+
private static Object safeInitNewInstance(final String className)
{
return AccessController.doPrivileged(new PrivilegedAction<Object>()
{
public Object run()
{
- ClassLoader loader = this.getClass().getClassLoader();
- try
- {
- Class<?> clazz = loader.loadClass(className);
- return clazz.newInstance();
- }
- catch (Throwable t)
- {
- 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);
- }
+ return ClassloadingUtil.newInstanceFromClassLoader(className);
}
});
}
-
-
}
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-11-18
17:44:13 UTC (rev 11714)
+++
branches/Branch_2_2_AS7/src/main/org/hornetq/core/remoting/impl/ssl/SSLSupport.java 2011-11-18
20:01:24 UTC (rev 11715)
@@ -32,6 +32,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>
*
@@ -197,7 +199,7 @@
throw new Exception("Failed to find a store at " + storePath);
}
-
+
/** This seems duplicate code all over the place, but for security reasons we
can't let something like this to be open in a
* utility class, as it would be a door to load anything you like in a safe VM.
* For that reason any class trying to do a privileged block should do with the
AccessController directly.
@@ -208,26 +210,7 @@
{
public URL run()
{
- ClassLoader loader = getClass().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;
+ return ClassloadingUtil.findResource(resourceName);
}
});
}
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-11-18
17:44:13 UTC (rev 11714)
+++
branches/Branch_2_2_AS7/src/main/org/hornetq/core/remoting/server/impl/RemotingServiceImpl.java 2011-11-18
20:01:24 UTC (rev 11715)
@@ -52,6 +52,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;
@@ -640,44 +641,15 @@
}
}
-
- /** This seems duplicate code all over the place, but for security reasons we
can't let something like this to be open in a
- * utility class, as it would be a door to load anything you like in a safe VM.
- * For that reason any class trying to do a privileged block should do with the
AccessController directly.
- */
private static Object safeInitNewInstance(final String className)
{
return AccessController.doPrivileged(new PrivilegedAction<Object>()
{
public Object run()
{
- ClassLoader loader = getClass().getClassLoader();
- try
- {
- Class<?> clazz = loader.loadClass(className);
- return clazz.newInstance();
- }
- catch (Throwable t)
- {
- 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);
- }
+ return ClassloadingUtil.newInstanceFromClassLoader(className);
}
});
}
-
}
\ No newline at end of file
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-11-18
17:44:13 UTC (rev 11714)
+++
branches/Branch_2_2_AS7/src/main/org/hornetq/core/server/impl/HornetQServerImpl.java 2011-11-18
20:01:24 UTC (rev 11715)
@@ -121,6 +121,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;
@@ -2109,30 +2110,7 @@
{
public Object run()
{
- ClassLoader loader = getClass().getClassLoader();
- try
- {
- Class<?> clazz = loader.loadClass(className);
- return clazz.newInstance();
- }
- catch (Throwable t)
- {
- 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);
- }
+ return ClassloadingUtil.newInstanceFromClassLoader(className);
}
});
}
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-11-18
17:44:13 UTC (rev 11714)
+++
branches/Branch_2_2_AS7/src/main/org/hornetq/jms/bridge/impl/JMSBridgeImpl.java 2011-11-18
20:01:24 UTC (rev 11715)
@@ -56,6 +56,7 @@
import org.hornetq.jms.bridge.QualityOfServiceMode;
import org.hornetq.jms.client.HornetQMessage;
import org.hornetq.jms.client.HornetQSession;
+import org.hornetq.utils.ClassloadingUtil;
/**
*
@@ -2003,6 +2004,7 @@
}
}
}
+
/** This seems duplicate code all over the place, but for security reasons we
can't let something like this to be open in a
* utility class, as it would be a door to load anything you like in a safe VM.
@@ -2014,33 +2016,9 @@
{
public Object run()
{
- ClassLoader loader = getClass().getClassLoader();
- try
- {
- Class<?> clazz = loader.loadClass(className);
- return clazz.newInstance();
- }
- catch (Throwable t)
- {
- 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);
- }
+ return ClassloadingUtil.newInstanceFromClassLoader(className);
}
});
}
-
}
Copied: branches/Branch_2_2_AS7/src/main/org/hornetq/utils/ClassloadingUtil.java (from rev
11506, 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-11-18
20:01:24 UTC (rev 11715)
@@ -0,0 +1,68 @@
+package org.hornetq.utils;
+
+import java.net.URL;
+
+/**
+* This class will be used to perform generic class-loader operations,
+* such as load a class first using TCCL, and then the classLoader used by HornetQ
(ClassloadingUtil.getClass().getClassLoader()).
+*
+* Is't required to use a Security Block on any calls to this class.
+*
+* @author <a href="mailto:hgao@redhat.com">Howard Gao</a>
+*/
+
+public class ClassloadingUtil
+{
+ public static Object newInstanceFromClassLoader(final String className)
+ {
+ ClassLoader loader = ClassloadingUtil.class.getClassLoader();
+ try
+ {
+ Class<?> clazz = loader.loadClass(className);
+ return clazz.newInstance();
+ }
+ catch (Throwable t)
+ {
+ 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)
+ {
+ 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-11-18 17:44:13
UTC (rev 11714)
+++ branches/Branch_2_2_AS7/src/main/org/hornetq/utils/XMLUtil.java 2011-11-18 20:01:24
UTC (rev 11715)
@@ -18,8 +18,6 @@
import java.io.StringReader;
import java.lang.reflect.Method;
import java.net.URL;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.List;
@@ -483,7 +481,7 @@
{
SchemaFactory factory =
SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
- Schema schema = factory.newSchema(findResource(schemaFile));
+ Schema schema = factory.newSchema(ClassloadingUtil.findResource(schemaFile));
Validator validator = schema.newValidator();
// validate the DOM tree
@@ -531,40 +529,6 @@
return nodes;
}
- /** This seems duplicate code all over the place, but for security reasons we
can't let something like this to be open in a
- * utility class, as it would be a door to load anything you like in a safe VM.
- * For that reason any class trying to do a privileged block should do with the
AccessController directly.
- */
- private static URL findResource(final String resourceName)
- {
- return AccessController.doPrivileged(new PrivilegedAction<URL>()
- {
- public URL run()
- {
- ClassLoader loader = getClass().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;
- }
- });
- }
-
// Inner classes
--------------------------------------------------------------------------------
}