-
1. Re: Call / Import bundle in java dsl
ffang Aug 18, 2010 9:58 PM (in response to bagavathysivaraman)Hi,
In OSGi world, call another bundle means call the services from another bundle. If the bundle you want to call already publish some services, you can easily get the servicereference from your java dsl.
Just let your java dsl code implement BundleContextAware inferface, and then you can get the serivcereference from the BundleContext.
Freeman
-
2. Re: Call / Import bundle in java dsl
bagavathysivaraman Aug 29, 2010 7:19 PM (in response to ffang)Hi Freeman,
Thanks for you reply.
As you said I have tried to get the ServiceReference of another bundle which already published / providing services. But am getting nullpointer exception.
Below are the steps that I have followed:
1. Implement BundleContextAware interface in camel java dsl.
2. Override the method setBundleContext method
3. I have tried to access the another bunlde service as below :
3.1. ServiceReference srRef = bndleCtx.getServiceReference("SMX :: ESB :: MY :: SAMLE :: MyProperties");
Where SMX :: ESB :: MY :: SAMLE :: MyProperties is another bundle name which already published (am getting it from another bundle's MANIFEST.MF)
3.2. InputStream propStream = srRef.getBundle().getClass().getResourceAsStream("my.properties");
3.3. Using java.util.Properties, am trying to get the properties defined in my.properties.
4. I can able to build and while deploy SMX4.2 am getting below said exception.
Please help me with sample code to to get the another bundle from camel java dsl.(As per my project requirement i cannt keep these property in SMXHOME/etc folder).
Believe there should be some way to access the another bundle property from camel java dsl.
Please help me in this regard.
karaf@root> Exception in thread "SpringOsgiExtenderThread-62" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'MyCamelJavaDsl': Invocation of init method failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ' crMessageSwithToGC' defined in URL bundleentry://211.fwk32755292/META-INF/spring/camel-context.xml
- at com.my.sample.teswt.MyCamelJavaDsl.setBundleContext(MyCamelJavaDsl.java:98)*
- at org.springframework.osgi.context.support.BundleContextAwareProcessor.postProcessBeforeInitialization(BundleContextAwareProcessor.java:48)*
- at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapable*
Edited by: bagavathysivaraman on Aug 29, 2010 11:17 PM
-
3. Re: Call / Import bundle in java dsl
njiang Aug 29, 2010 1:45 AM (in response to bagavathysivaraman)Hi,
The NPE is thrown from you route builder (MyCamelJavaDsl), can past the code for it.
BTW, if you want to use the properties in the camel route, you can take a look at camel-properties[1].
https://cwiki.apache.org/CAMEL/properties.html
Willem
-
4. Re: Call / Import bundle in java dsl
bagavathysivaraman Aug 29, 2010 8:37 PM (in response to njiang)Hi William,
Thanks for your reply.
Yeah, the NPE is thrown from MyCamelJavaDsl.java. Herewith I past the code.
-
public class MyCamelJavaDsl extends RouteBuilder implements BundleContextAware{
private static String XSL_URI;
/**
Configure the route.
*
@throws java.lang.Exception
*/
public void configure() throws Exception {
from("nmr:myMessageTransform").
to("xslt:" + XSL_URI + "message/transform/myrequest/FromSystem1-ToSystem2.xsl").
to("log:After Transaltion?showAll=true&level=DEBUG").
end();
}
@Override
public void setBundleContext(BundleContext bndleCtx) {
// TODO Auto-generated method stub
ServiceReference srf= bndleCtx.getServiceReference("SMX :: ESB :: MY :: SAMLE :: MyProperties");
InputStream propStream = srf.getBundle().getClass().getResourceAsStream("common.properties");
Properties props = new Properties();
try {
props.load(propStream);
propStream.close();
} catch (IOException e) {
e.printStackTrace();
}
XSL_URI = props.getProperty("xsl.uri");
}
}
----
I created myproperties bundle and deployed in SMX4.2. I can able to read the properties defined in my.properties using Spring DSL. I havnt faced any issue with spring DSL . When I try to get the propetry from Camel Java DSL, am facing above said issue.
Herewith I past the MyProperties bundle's MANIFEST.MF content to get an idea / clue.
-
Manifest-Version: 1.0
Export-Package: com.my.sample.common.resources
Built-By: ax45689
Build-Jdk: 1.6.0_21
Bundle-Version: 0.0.0.main-SNAPSHOT
Tool: Bnd-0.0.357
Bundle-Name: SMX :: ESB :: MY :: SAMLE :: MyProperties
Bnd-LastModified: 1280434965500
Created-By: Apache Maven Bundle Plugin
Bundle-ManifestVersion: 2
Bundle-SymbolicName: MyProperties
-
Could you help me to fix above said issue and how to read the properties from property file whic is an another bundle.
If explore the MyProperties-main-SNAPSHOT.jar, my.properties are available in package com.my.sample.common.resources. So I import / access that package from camel java DSL, I can get the properties defined in my.properties.
-
-
-
As you said, I have tried to use camel-properties.But it is available as of camel2.3.
But already my project is running on ServiceMix4.2. As by default it contains the features came-core-2.2.0-fuse-02-00,I cannt start bundle (which implements camel-properties using camel 2.3). Despite, I install the camel-core2.3.0(to support camel properties) features.
But while deploy the bundle into Servicemix4.2, am getting .... Package uses conflict: Import-Package: org.apache.servicemix.camel.nmr; version="0.0.0", Package uses conflict: Import-Package: org.apache.camel.osgi; version="0.0.0" ....etc.All are due to camel2.3.
Is there any way to upgrade ALL the Servicemix4.2 packages to camel2.3 compatible.
or
It is better to go for Servicemix4.3 in order to use camel2.3.
As of now we not in the position to upgarade from 4.2 to 4.3(since project deliverty date is very near :(.
So, please help me to get the properties which is in another bundle from camel javadsl in SMX4.2.
Regards,
Saji
Edited by: bagavathysivaraman on Aug 30, 2010 12:33 AM
-
5. Re: Call / Import bundle in java dsl
davsclaus Aug 30, 2010 12:04 AM (in response to bagavathysivaraman)FUSE ESB (ServiceMix) 4.3 has been release which contains Camel 2.4
-
6. Re: Call / Import bundle in java dsl
ffang Aug 30, 2010 1:09 AM (in response to bagavathysivaraman)Hi,
What you do isn't correct.
1. You should simply override the method setBundleContext method like
this.bundleContext = bundleContext;
This method generally get invoked by the OSGi container so that can inject bundleContext to your class.
You shouldn't put extra logic in setBundleContext generally.
2. As now you have bundleContext, you can get the ServiceReference already published by other bundles.
I don't think get services through bundle name like
ServiceReference srf= bndleCtx.getServiceReference("SMX :: ESB :: MY :: SAMLE :: MyProperties");
make any sense here, you should get ServiceReference from the interface that Service implemented.
For example, the way to get ConfigAdmin ServiceReference
ServiceReference ref = bndleCtx.getServiceReference(ConfigurationAdmin.class.getName());
You may need google to get some basic concept about how OSGi service works.
3. If you want to read properties from other bundles, you can use
a. ConfigAdmin service, this may need you put property files into SMX_HOME/etc folder
or
b. From the bundle which you have property file, create a method like
readProprties() , and publish it as a OSGi serivce, then in your camel java dsl bundle, you can retrieve this OSGi service and call readProperties method.
Freeman