From 3a6d67e8f95320bea91b7c7106173c9b34773bc5 Mon Sep 17 00:00:00 2001 From: gtully Date: Mon, 26 Jan 2015 15:39:04 +0000 Subject: [PATCH] https://issues.apache.org/jira/browse/AMQ-4727 - use OsgiBundleXmlApplicationContext from service factory so that an embedded camel route can find a required bundlecontext --- .../ActiveMQBrokerNdCamelFeatureTest.java | 1 - ...iveMQBrokerNdExternalCamelFeatureTest.java | 1 + .../src/main/resources/features-core.xml | 1 + activemq-osgi/pom.xml | 24 +++++++++++++++++++ .../activemq/osgi/ActiveMQServiceFactory.java | 6 +++-- 5 files changed, 30 insertions(+), 3 deletions(-) diff --git a/activemq-karaf-itest/src/test/java/org/apache/activemq/karaf/itest/ActiveMQBrokerNdCamelFeatureTest.java b/activemq-karaf-itest/src/test/java/org/apache/activemq/karaf/itest/ActiveMQBrokerNdCamelFeatureTest.java index a9a0d6628e..45993b5723 100644 --- a/activemq-karaf-itest/src/test/java/org/apache/activemq/karaf/itest/ActiveMQBrokerNdCamelFeatureTest.java +++ b/activemq-karaf-itest/src/test/java/org/apache/activemq/karaf/itest/ActiveMQBrokerNdCamelFeatureTest.java @@ -44,7 +44,6 @@ public class ActiveMQBrokerNdCamelFeatureTest extends AbstractJmsFeatureTest { configure("activemq")); } - @Ignore("java.lang.IllegalArgumentException: BundleContext must be specified - needs investigation") @Test(timeout = 2 * 60 * 1000) public void test() throws Throwable { System.err.println(executeCommand("osgi:list").trim()); diff --git a/activemq-karaf-itest/src/test/java/org/apache/activemq/karaf/itest/ActiveMQBrokerNdExternalCamelFeatureTest.java b/activemq-karaf-itest/src/test/java/org/apache/activemq/karaf/itest/ActiveMQBrokerNdExternalCamelFeatureTest.java index 615da95be4..4cbe10ceb8 100644 --- a/activemq-karaf-itest/src/test/java/org/apache/activemq/karaf/itest/ActiveMQBrokerNdExternalCamelFeatureTest.java +++ b/activemq-karaf-itest/src/test/java/org/apache/activemq/karaf/itest/ActiveMQBrokerNdExternalCamelFeatureTest.java @@ -50,6 +50,7 @@ public class ActiveMQBrokerNdExternalCamelFeatureTest extends AbstractJmsFeature assertFeatureInstalled("activemq"); executeCommand("features:addurl " + getCamelFeatureUrl()); + installAndAssertFeature("camel"); installAndAssertFeature("activemq-camel"); withinReason(new Callable() { diff --git a/activemq-karaf/src/main/resources/features-core.xml b/activemq-karaf/src/main/resources/features-core.xml index 16dc95dc2d..6a688b69c0 100644 --- a/activemq-karaf/src/main/resources/features-core.xml +++ b/activemq-karaf/src/main/resources/features-core.xml @@ -23,6 +23,7 @@ spring + spring-dm mvn:org.apache.geronimo.specs/geronimo-annotation_1.0_spec/1.1.1 mvn:org.apache.geronimo.specs/geronimo-jta_1.1_spec/1.1.1 mvn:org.apache.geronimo.specs/geronimo-jms_1.1_spec/1.1.1 diff --git a/activemq-osgi/pom.xml b/activemq-osgi/pom.xml index 74be454f3e..705b93f0bb 100644 --- a/activemq-osgi/pom.xml +++ b/activemq-osgi/pom.xml @@ -62,6 +62,7 @@ org.xmlpull*;resolution:=optional, scala*;resolution:=optional, org.springframework*;version="[3,4]";resolution:=optional, + org.springframework.osgi*;version="[1,4]";resolution:=optional, org.apache.xbean.spring*;resolution:=optional, javax.annotation*, javax.jms*, @@ -167,6 +168,29 @@ activemq-spring + + org.springframework.osgi + spring-osgi-core + + + org.springframework + org.springframework.aop + + + org.springframework + org.springframework.beans + + + org.springframework + org.springframework.context + + + org.springframework + org.springframework.core + + + + ${project.groupId} activemq-runtime-config diff --git a/activemq-osgi/src/main/java/org/apache/activemq/osgi/ActiveMQServiceFactory.java b/activemq-osgi/src/main/java/org/apache/activemq/osgi/ActiveMQServiceFactory.java index 430a300bbb..5e49dfa3f4 100644 --- a/activemq-osgi/src/main/java/org/apache/activemq/osgi/ActiveMQServiceFactory.java +++ b/activemq-osgi/src/main/java/org/apache/activemq/osgi/ActiveMQServiceFactory.java @@ -26,7 +26,6 @@ import java.util.Properties; import org.apache.activemq.broker.BrokerService; import org.apache.activemq.spring.SpringBrokerContext; import org.apache.activemq.spring.Utils; -import org.apache.xbean.spring.context.ResourceXmlApplicationContext; import org.osgi.framework.BundleContext; import org.osgi.service.cm.ConfigurationException; import org.osgi.service.cm.ManagedServiceFactory; @@ -35,6 +34,7 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer; import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; import org.springframework.core.io.Resource; +import org.springframework.osgi.context.support.OsgiBundleXmlApplicationContext; public class ActiveMQServiceFactory implements ManagedServiceFactory { @@ -74,12 +74,14 @@ public class ActiveMQServiceFactory implements ManagedServiceFactory { Thread.currentThread().setContextClassLoader(BrokerService.class.getClassLoader()); Resource resource = Utils.resourceFromString(config); - ResourceXmlApplicationContext ctx = new ResourceXmlApplicationContext(resource, Collections.EMPTY_LIST, null, Collections.EMPTY_LIST, false) { + // when camel is embedded it needs a bundle context + OsgiBundleXmlApplicationContext ctx = new OsgiBundleXmlApplicationContext(new String[]{resource.getURL().toExternalForm()}) { @Override protected void initBeanDefinitionReader(XmlBeanDefinitionReader reader) { reader.setValidating(false); } }; + ctx.setBundleContext(bundleContext); // Handle properties in configuration PropertyPlaceholderConfigurer configurator = new PropertyPlaceholderConfigurer();