https://issues.apache.org/jira/browse/AMQ-4727 - use OsgiBundleXmlApplicationContext from service factory so that an embedded camel route can find a required bundlecontext

This commit is contained in:
gtully 2015-01-26 15:39:04 +00:00
parent a620b403f4
commit 3a6d67e8f9
5 changed files with 30 additions and 3 deletions

View File

@ -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());

View File

@ -50,6 +50,7 @@ public class ActiveMQBrokerNdExternalCamelFeatureTest extends AbstractJmsFeature
assertFeatureInstalled("activemq");
executeCommand("features:addurl " + getCamelFeatureUrl());
installAndAssertFeature("camel");
installAndAssertFeature("activemq-camel");
withinReason(new Callable<Boolean>() {

View File

@ -23,6 +23,7 @@
<!-- Bundles needed if only client will be deployed in the container -->
<feature name="activemq-client" description="ActiveMQ client libraries" version="${project.version}" resolver="(obr)" start-level="50">
<feature version="[3.2,4)">spring</feature>
<feature>spring-dm</feature>
<bundle dependency="true">mvn:org.apache.geronimo.specs/geronimo-annotation_1.0_spec/1.1.1</bundle>
<bundle dependency="true">mvn:org.apache.geronimo.specs/geronimo-jta_1.1_spec/1.1.1</bundle>
<bundle dependency="true">mvn:org.apache.geronimo.specs/geronimo-jms_1.1_spec/1.1.1</bundle>

View File

@ -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 @@
<artifactId>activemq-spring</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.osgi</groupId>
<artifactId>spring-osgi-core</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>org.springframework.aop</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>org.springframework.beans</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>org.springframework.context</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>org.springframework.core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>activemq-runtime-config</artifactId>

View File

@ -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();