mirror of
https://github.com/apache/activemq.git
synced 2025-02-27 20:59:06 +00:00
Updating ActiveMQServiceFactory to avoid using Spring DM directly and instead use the Camel factory bean if it exists Reverting back to Camel 2.16.3 until Spring DM is removed and Spring 4 can be used
This commit is contained in:
parent
982f739e24
commit
9da728407b
@ -64,7 +64,9 @@
|
||||
org.apache.xbean.spring*;resolution:=optional;version="[3.13,5)",
|
||||
org.apache.xbean*;version="[3.13,5)",
|
||||
javax.annotation*,
|
||||
javax.jms*,
|
||||
!com.thoughtworks.qdox*,
|
||||
org.apache.commons.logging;version="[1.2,2)";resolution:=optional,
|
||||
javax.jms*;version="[1.1,3)",
|
||||
javax.management*,
|
||||
javax.transaction*,
|
||||
javax.naming*;resolution:=optional,
|
||||
|
@ -26,15 +26,19 @@ 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.camel.osgi.CamelContextFactoryBean;
|
||||
import org.osgi.framework.BundleContext;
|
||||
import org.osgi.service.cm.ConfigurationException;
|
||||
import org.osgi.service.cm.ManagedServiceFactory;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
|
||||
import org.springframework.beans.factory.config.BeanPostProcessor;
|
||||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
|
||||
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.osgi.context.support.OsgiBundleXmlApplicationContext;
|
||||
|
||||
public class ActiveMQServiceFactory implements ManagedServiceFactory {
|
||||
|
||||
@ -74,14 +78,34 @@ public class ActiveMQServiceFactory implements ManagedServiceFactory {
|
||||
Thread.currentThread().setContextClassLoader(BrokerService.class.getClassLoader());
|
||||
Resource resource = Utils.resourceFromString(config);
|
||||
|
||||
// when camel is embedded it needs a bundle context
|
||||
OsgiBundleXmlApplicationContext ctx = new OsgiBundleXmlApplicationContext(new String[]{resource.getURL().toExternalForm()}) {
|
||||
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(
|
||||
new String[]{resource.getURL().toExternalForm()}, false);
|
||||
|
||||
if (isCamelContextFactoryBeanExist()) {
|
||||
|
||||
ctx.addBeanFactoryPostProcessor(new BeanFactoryPostProcessor() {
|
||||
|
||||
@Override
|
||||
protected void initBeanDefinitionReader(XmlBeanDefinitionReader reader) {
|
||||
reader.setValidating(false);
|
||||
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
|
||||
|
||||
beanFactory.addBeanPostProcessor(new BeanPostProcessor() {
|
||||
|
||||
@Override
|
||||
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
|
||||
if (bean instanceof CamelContextFactoryBean) {
|
||||
((CamelContextFactoryBean) bean).setBundleContext(bundleContext);
|
||||
}
|
||||
return bean;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
|
||||
return bean;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
ctx.setBundleContext(bundleContext);
|
||||
|
||||
// Handle properties in configuration
|
||||
PropertyPlaceholderConfigurer configurator = new PropertyPlaceholderConfigurer();
|
||||
@ -121,6 +145,15 @@ public class ActiveMQServiceFactory implements ManagedServiceFactory {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isCamelContextFactoryBeanExist() {
|
||||
try {
|
||||
Class.forName("org.apache.camel.osgi.CamelContextFactoryBean");
|
||||
return true;
|
||||
} catch (ClassNotFoundException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
synchronized public void deleted(String pid) {
|
||||
BrokerService broker = brokers.get(pid);
|
||||
|
Loading…
x
Reference in New Issue
Block a user