camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Willem Jiang <>
Subject Re: Proper method of looking up osgi service from camel component
Date Mon, 28 Feb 2011 11:17:30 GMT
Hi Madhav,

If you don't want your client to know about how to inject the osgi 
services, it's a best way to wrap the component with Java code.


On 2/28/11 6:15 PM, unmarshall wrote:
> Hi Willem,
> Thanks for your response. I am aware of this approach as Cxf follows the
> same approach. The problem is that i have defined a custom XML extension
> representing the component the same way Cxf does (<cxf:cxfEndpoint>)
> Now I can have a XML which will have just this osgi:reference and ask the
> user to include this resource using<beans:import>
> The reason which stopped me from this approach:
> I do not quite like the idea of having the onus on the user of the component
> to set the property with an osgi reference. It should be automatically
> injected as it is an internal implementation aspect which should not be
> exposed to the user.
> In case of Cxf it is fine as the user only needs to include the required xml
> resource files from META-INF/* directories. The user does not have to inject
> anything into the cxf endpoint bean definition as a result of this resource
> inclusion.
> The upside of this approach is that the code is decoupled from the osgi API,
> but there is a down side as well and that is the reason i asked this
> question.
> Best Regards,
> Madhav
> Willem.Jiang wrote:
>> Hi,
>> Here is another way to help your custom camel component not be polluted
>> by OSGi APIs.
>> If you custom camel component has the dependency of the OSGi service,
>> you just need to create a get/set method of that services interface in
>> your custom component.
>> Then you can inject the services into the camel component by use the
>> spring DM like this. and your camel component doesn't need to get touch
>> with any of the OSGi API like this.
>> <beans xmlns=""
>>          xmlns:xsi=""
>>          xmlns:osgi=""
>>          xsi:schemaLocation="
>>       <bean id="custom"
>>             class="com.example.CustomerCamelComponent">
>>           <property name="Services" ref="myServices"/>
>>       </bean>
>>       <osgi:reference id="myServices"
>>                       interface="com.example.osgi.Services" />
>>       <!-- you can add your camel route here -->
>> </beans>
>> Willem

Blog: (English)
Twitter: willemjiang

View raw message