summaryrefslogtreecommitdiffstats
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
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
-rw-r--r--sca-java-2.x/trunk/features/eclipse-pde/pom.xml8
-rw-r--r--sca-java-2.x/trunk/modules/binding-jms-runtime/META-INF/MANIFEST.MF2
-rw-r--r--sca-java-2.x/trunk/modules/binding-jms-runtime/pom.xml10
-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
5 files changed, 59 insertions, 4 deletions
diff --git a/sca-java-2.x/trunk/features/eclipse-pde/pom.xml b/sca-java-2.x/trunk/features/eclipse-pde/pom.xml
index 36c778d044..949bbe55b0 100644
--- a/sca-java-2.x/trunk/features/eclipse-pde/pom.xml
+++ b/sca-java-2.x/trunk/features/eclipse-pde/pom.xml
@@ -57,6 +57,14 @@
<version>1.0.1</version>
</dependency>
+ <!-- Add the dependency for ActiveMQ as the JMS runtime to use -->
+ <dependency>
+ <groupId>org.apache.activemq</groupId>
+ <artifactId>activemq-core</artifactId>
+ <version>5.3.0</version>
+ </dependency>
+ <!-- end of addition for ActiveMQ -->
+
</dependencies>
<build>
diff --git a/sca-java-2.x/trunk/modules/binding-jms-runtime/META-INF/MANIFEST.MF b/sca-java-2.x/trunk/modules/binding-jms-runtime/META-INF/MANIFEST.MF
index 4d7f88a476..beeb3a366e 100644
--- a/sca-java-2.x/trunk/modules/binding-jms-runtime/META-INF/MANIFEST.MF
+++ b/sca-java-2.x/trunk/modules/binding-jms-runtime/META-INF/MANIFEST.MF
@@ -12,6 +12,7 @@ Import-Package: javax.jms,
javax.security.auth,
javax.xml.namespace,
javax.xml.stream,
+ org.apache.activemq.jndi;resolution:=optional,
org.apache.axiom.om,
org.apache.axiom.om.impl.builder,
org.apache.tuscany.sca.assembly;version="2.0.0",
@@ -25,6 +26,7 @@ Import-Package: javax.jms,
org.apache.tuscany.sca.common.xml.dom;version="2.0.0",
org.apache.tuscany.sca.core;version="2.0.0",
org.apache.tuscany.sca.databinding.xml;version="2.0.0",
+ org.apache.tuscany.sca.extensibility;version="2.0.0",
org.apache.tuscany.sca.interfacedef;version="2.0.0",
org.apache.tuscany.sca.interfacedef.impl;version="2.0.0",
org.apache.tuscany.sca.interfacedef.util;version="2.0.0",
diff --git a/sca-java-2.x/trunk/modules/binding-jms-runtime/pom.xml b/sca-java-2.x/trunk/modules/binding-jms-runtime/pom.xml
index 01ab3dd8f9..cca26fec30 100644
--- a/sca-java-2.x/trunk/modules/binding-jms-runtime/pom.xml
+++ b/sca-java-2.x/trunk/modules/binding-jms-runtime/pom.xml
@@ -58,7 +58,15 @@
<version>2.0.0</version>
<scope>provided</scope>
</dependency>
-
+
+ <!-- Add the dependency for ActiveMQ as the JMS runtime to use -->
+ <dependency>
+ <groupId>org.apache.activemq</groupId>
+ <artifactId>activemq-core</artifactId>
+ <version>5.3.0</version>
+ </dependency>
+ <!-- end of addition for ActiveMQ -->
+
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
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;
}