Discussion:
how to change to a specific java naming initial factory in servicemix?
geniusit
2016-11-10 23:40:01 UTC
Permalink
Hello all,

Today im using Apache Camel in Apache Karaf OSGI environment.

I can publish messages in my embeded ActiveMq container in a very easy way.

However, problems occur when i try to publish messages to a broker outside
my OSGI container. (webMethods broker in my case)

How to deal with when i have to get the objets through JNDI?

In a 'traditional' way I just have to make these few lines of code to work
with my connection factory :

Properties props = new Properties();
props.setProperty("java.naming.factory.initial",
"com.webmethods.jms.naming.WmJmsNamingCtxFactory");
props.setProperty("java.naming.provider.url",
"wmjmsnaming://***@dexcz1wbm23.preprod.org:6889");
InitialContext initialContext = new InitialContext(props);
ConnectionFactory cf = (ConnectionFactory)
initialContext.lookup("dev01_CFC_BDE");

I already added the webMethods clients jar file in my build path.

But how to do this in a OSGI context?

I dropped my jars in the deploy directory of my karaf instance and i can see
them in the list of active bundles (thanks to automatic wrap protocol).

Here you are my blueprint configuration :


<bean id="jmsJndiTemplate1" class="org.springframework.jndi.JndiTemplate">
<property name="environment">
<props>
<prop
key="java.naming.factory.initial">com.webmethods.jms.naming.WmJmsNamingCtxFactory</prop>
<prop
key="java.naming.provider.url">wmjmsnaming://***@dexcz1wbm23.preprod.org:6889</prop>
</props>
</property>
</bean>

<bean id="connectionFactory1"
class="org.springframework.jndi.JndiObjectFactoryBean"
init-method="afterPropertiesSet">
<property name="jndiName" value="dev01_CFC_BDE" />
<property name="jndiTemplate" ref="jmsJndiTemplate1" />
</bean>

<bean id="jndiDestinationResolver1"

class="org.springframework.jms.support.destination.JndiDestinationResolver">
<property name="jndiTemplate" ref="jmsJndiTemplate1" />
</bean>

<bean id="jmsInConnectionFactory1" factory-ref="connectionFactory1"
factory-method="getObject" />

<bean id="producerJmsConfig"
class="org.apache.camel.component.jms.JmsConfiguration">
<property name="connectionFactory" ref="jmsInConnectionFactory1" />
</bean>


<bean id="jmsProducer" class="org.apache.camel.component.jms.JmsComponent">
<property name="configuration" ref="producerJmsConfig" />
</bean>



When I try to install my features in Karaf, my bundle is in a failure state
with this stacktrace :

Status: Failure
Blueprint
08/11/16 16:37
Exception:
Unable to initialize bean connectionFactory1
org.osgi.service.blueprint.container.ComponentDefinitionException: Unable to
initialize bean connectionFactory1
at
org.apache.aries.blueprint.container.BeanRecipe.runBeanProcInit(BeanRecipe.java:738)
at
org.apache.aries.blueprint.container.BeanRecipe.internalCreate2(BeanRecipe.java:848)
at
org.apache.aries.blueprint.container.BeanRecipe.internalCreate(BeanRecipe.java:811)
at
org.apache.aries.blueprint.di.AbstractRecipe$1.call(AbstractRecipe.java:79)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at
org.apache.aries.blueprint.di.AbstractRecipe.create(AbstractRecipe.java:88)
at
org.apache.aries.blueprint.container.BlueprintRepository.createInstances(BlueprintRepository.java:255)
at
org.apache.aries.blueprint.container.BlueprintRepository.createAll(BlueprintRepository.java:186)
at
org.apache.aries.blueprint.container.BlueprintContainerImpl.instantiateEagerComponents(BlueprintContainerImpl.java:724)
at
org.apache.aries.blueprint.container.BlueprintContainerImpl.doRun(BlueprintContainerImpl.java:411)
at
org.apache.aries.blueprint.container.BlueprintContainerImpl.run(BlueprintContainerImpl.java:276)
at
org.apache.aries.blueprint.container.BlueprintExtender.createContainer(BlueprintExtender.java:300)
at
org.apache.aries.blueprint.container.BlueprintExtender.createContainer(BlueprintExtender.java:269)
at
org.apache.aries.blueprint.container.BlueprintExtender.createContainer(BlueprintExtender.java:265)
at
org.apache.aries.blueprint.container.BlueprintExtender.modifiedBundle(BlueprintExtender.java:255)
at
org.apache.aries.util.tracker.hook.BundleHookBundleTracker$Tracked.customizerModified(BundleHookBundleTracker.java:500)
at
org.apache.aries.util.tracker.hook.BundleHookBundleTracker$Tracked.customizerModified(BundleHookBundleTracker.java:433)
at
org.apache.aries.util.tracker.hook.BundleHookBundleTracker$AbstractTracked.track(BundleHookBundleTracker.java:725)
at
org.apache.aries.util.tracker.hook.BundleHookBundleTracker$Tracked.bundleChanged(BundleHookBundleTracker.java:463)
at
org.apache.aries.util.tracker.hook.BundleHookBundleTracker$BundleEventHook.event(BundleHookBundleTracker.java:422)
at
org.apache.felix.framework.util.SecureAction.invokeBundleEventHook(SecureAction.java:1179)
at
org.apache.felix.framework.util.EventDispatcher.createWhitelistFromHooks(EventDispatcher.java:731)
at
org.apache.felix.framework.util.EventDispatcher.fireBundleEvent(EventDispatcher.java:486)
at org.apache.felix.framework.Felix.fireBundleEvent(Felix.java:4541)
at org.apache.felix.framework.Felix.startBundle(Felix.java:2172)
at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:998)
at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:984)
at
org.apache.karaf.features.internal.service.FeaturesServiceImpl.startBundle(FeaturesServiceImpl.java:1262)
at
org.apache.karaf.features.internal.service.Deployer.deploy(Deployer.java:840)
at
org.apache.karaf.features.internal.service.FeaturesServiceImpl.doProvision(FeaturesServiceImpl.java:1152)
at
org.apache.karaf.features.internal.service.FeaturesServiceImpl$1.call(FeaturesServiceImpl.java:1048)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: javax.naming.NoInitialContextException: Unable to find the
InitialContextFactory com.webmethods.jms.naming.WmJmsNamingCtxFactory.
at
org.apache.aries.jndi.ContextHelper.getInitialContext(ContextHelper.java:150)
at
org.apache.aries.jndi.OSGiInitialContextFactoryBuilder.getInitialContext(OSGiInitialContextFactoryBuilder.java:51)
at
javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:684)
at
javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:313)
at javax.naming.InitialContext.init(InitialContext.java:244)
at javax.naming.InitialContext.<init>(InitialContext.java:216)
at
org.springframework.jndi.JndiTemplate.createInitialContext(JndiTemplate.java:136)
at
org.springframework.jndi.JndiTemplate.getContext(JndiTemplate.java:103)
at
org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:85)
at
org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:152)
at
org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:179)
at
org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport.java:95)
at
org.springframework.jndi.JndiObjectLocator.lookup(JndiObjectLocator.java:106)
at
org.springframework.jndi.JndiObjectFactoryBean.lookupWithFallback(JndiObjectFactoryBean.java:231)
at
org.springframework.jndi.JndiObjectFactoryBean.afterPropertiesSet(JndiObjectFactoryBean.java:217)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at
org.apache.aries.blueprint.utils.ReflectionUtils.invoke(ReflectionUtils.java:299)
at
org.apache.aries.blueprint.container.BeanRecipe.invoke(BeanRecipe.java:980)
at
org.apache.aries.blueprint.container.BeanRecipe.runBeanProcInit(BeanRecipe.java:736)
... 34 more


So my question is how to register the
com.webmethods.jms.naming.WmJmsNamingCtxFactory initial context factory in
servicemix / karaf?

Many thanks

Bertrand



--
View this message in context: http://servicemix.396122.n5.nabble.com/how-to-change-to-a-specific-java-naming-initial-factory-in-servicemix-tp5724071.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.
Loading...