summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms
diff options
context:
space:
mode:
authoredwardsmj <edwardsmj@13f79535-47bb-0310-9956-ffa450edef68>2010-12-10 12:34:10 +0000
committeredwardsmj <edwardsmj@13f79535-47bb-0310-9956-ffa450edef68>2010-12-10 12:34:10 +0000
commit1c430adf36cc8f0b93e13bbd353c5abc632ad25e (patch)
tree6914bcbf1824d1fb8ceca3d6683404068447b8e3 /sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms
parentbb116281aedb24dd26ff1f1295cc48fd8a420085 (diff)
Initial fixes to enable JMS runtime to work under OSGi as described in TUSCANY-3808
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1044330 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms')
-rw-r--r--sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSMessageProcessorUtil.java6
-rw-r--r--sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSResourceFactoryImpl.java37
2 files changed, 40 insertions, 3 deletions
diff --git a/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSMessageProcessorUtil.java b/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSMessageProcessorUtil.java
index b7622c942e..4b96f23d65 100644
--- a/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSMessageProcessorUtil.java
+++ b/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSMessageProcessorUtil.java
@@ -85,7 +85,11 @@ public class JMSMessageProcessorUtil {
try {
clazz = cl.loadClass(className);
} catch (ClassNotFoundException e) {
- clazz = binding.getClass().getClassLoader().loadClass(className);
+ // MJE 07/12/2010 - for OSGi the default message processor belongs to the same bundle as
+ // this JMSMessageProcessorUtil itself and so the "correct" classloader to use is the classloader
+ // for THIS class, and not the binding class (which is a different bundle)
+ // clazz = binding.getClass().getClassLoader().loadClass(className);
+ clazz = JMSMessageProcessorUtil.class.getClassLoader().loadClass(className);
}
Constructor<?> constructor = clazz.getDeclaredConstructor(new Class[] {JMSBinding.class, ExtensionPointRegistry.class});
diff --git a/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSResourceFactoryImpl.java b/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSResourceFactoryImpl.java
index 9c1a384c7a..4ab2f5ab2c 100644
--- a/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSResourceFactoryImpl.java
+++ b/sca-java-2.x/trunk/modules/binding-jms-runtime/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSResourceFactoryImpl.java
@@ -31,6 +31,8 @@ import javax.naming.NamingException;
import javax.resource.spi.ActivationSpec;
import org.apache.tuscany.sca.binding.jms.JMSBindingException;
+import org.apache.tuscany.sca.extensibility.ClassLoaderContext;
+import org.apache.activemq.jndi.ActiveMQInitialContextFactory;
/**
* Abstracts away any JMS provide specific feature from the JMS binding
@@ -139,7 +141,8 @@ public class JMSResourceFactoryImpl implements JMSResourceFactory {
ConnectionFactory connectionFactory = (ConnectionFactory)o;
connection = connectionFactory.createConnection();
}
-
+
+ static final String ACTIVEMQ_FACTORY = "org.apache.activemq.jndi.ActiveMQInitialContextFactory";
protected synchronized Context getInitialContext() throws NamingException {
if (context == null) {
Properties props = new Properties();
@@ -152,8 +155,38 @@ public class JMSResourceFactoryImpl implements JMSResourceFactory {
}
initJREEnvironment(props);
+
+ /**
+ * For OSGi, need to provide access to the InitialContextFactory for the JMS provider that is going to be used.
+ *
+ * The situation is that the InitialContext constructor instantiates an instance of the InitialContextFactory by
+ * calling "new" using the TCCL - thus there is a need to prepare the TCCL.
+ * 03/12/2010 MJE - for the present, only worry about ActiveMQ - other providers can be added later
+ * 10/12/2010 MJE - the following code attempts to get the classloader for the ActiveMQ initial context factory
+ * it will fail if the ActiveMQ classes are not available in the runtime, but the code will still
+ * execute (although under OSGi the new InitialContext() operation will fail to find a suitable
+ * InitialContextFactory object...)
+ */
+ ClassLoader ActiveMQCl = null;
+ try {
+ if( initialContextFactoryName == null || ACTIVEMQ_FACTORY.equals(initialContextFactoryName) ) {
+ ActiveMQCl = ActiveMQInitialContextFactory.class.getClassLoader();
+ props.setProperty(Context.INITIAL_CONTEXT_FACTORY, ACTIVEMQ_FACTORY);
+ } // end if
+ } catch (Exception e) {
+ // Nothing to do in this case - the ActiveMQCl classloader will simply be null
+ } // end try
- context = new InitialContext(props);
+ ClassLoader tccl = ClassLoaderContext.setContextClassLoader(JMSResourceFactoryImpl.class.getClassLoader(),
+ ActiveMQCl,
+ Thread.currentThread().getContextClassLoader() );
+ try {
+ // Load the JNDI InitialContext (will load the InitialContextFactory, if present)
+ context = new InitialContext(props);
+ } finally {
+ // Restore the TCCL if we changed it
+ if( tccl != null ) Thread.currentThread().setContextClassLoader(tccl);
+ } // end try
}
return context;
}