You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@karaf.apache.org by Jens Reimann <jr...@redhat.com> on 2016/09/13 15:27:26 UTC

Looking for help using service reference with "#" in OSGi

Hi,

I am currently trying to solve an issue of injecting a service with OSGi in
an URL based endpoint. Using Camel 2.17.2.

For example the URL is "kura-cloud:myapp/xmltopic?cloudService=#pid"

I am using the OsgiDefaultCamelContext. The Camel component does call
"setProperties(endpoint, properties)" with the provided properties map of
camel. And now I would expect camel to lookup the OSGi service with the
"service.pid=pid" and inject this, using the "setCloudService" setter on
the endpoint.

However I do get:

---
Caused by: java.lang.IllegalArgumentException: Could not find a suitable
setter for property: cloudService as there isn't a setter method with same
type: java.lang.String nor type conversion possible: No type converter
available to convert from type: java.lang.String to the required type:
org.eclipse.kura.cloud.CloudService with value #pid
    at
org.apache.camel.util.IntrospectionSupport.setProperty(IntrospectionSupport.java:588)
    at
org.apache.camel.util.IntrospectionSupport.setProperty(IntrospectionSupport.java:616)
    at
org.apache.camel.util.IntrospectionSupport.setProperties(IntrospectionSupport.java:473)
    at
org.apache.camel.util.IntrospectionSupport.setProperties(IntrospectionSupport.java:483)
    at
org.apache.camel.util.EndpointHelper.setProperties(EndpointHelper.java:255)
    at
org.apache.camel.impl.DefaultComponent.setProperties(DefaultComponent.java:257)
    at
org.eclipse.kura.camel.cloud.KuraCloudComponent.createEndpoint(KuraCloudComponent.java:74)
    at
org.apache.camel.impl.DefaultComponent.createEndpoint(DefaultComponent.java:114)
    at
org.apache.camel.impl.DefaultCamelContext.getEndpoint(DefaultCamelContext.java:568)
---

Any help debugging or understand this would be great.

Thanks

Jens

-- 
Jens Reimann
Senior Software Engineer / EMEA ENG Middleware
Werner-von-Siemens-Ring 14
85630 Grasbrunn
Germany
phone: +49 89 2050 71286
_____________________________________________________________________________

Red Hat GmbH, www.de.redhat.com,
Registered seat: Grasbrunn, Commercial register: Amtsgericht Muenchen, HRB
153243,
Managing Directors: Paul Argiry, Charles Cachera, Michael Cunningham,
Michael O'Neill

Re: Looking for help using service reference with "#" in OSGi

Posted by Jens Reimann <jr...@redhat.com>.
Thanks for that explanation.

Unfortunately the reason why I wanted to use that is that I have multiple
services with the name interface registered and wanted to use the reference
as a filter for choosing the right one. So the best thing would be if I
could specify a filter expression instead.

What will happen when the service gets unregistered? Is there any special
handling for that situation in Camel?

Thanks for your help!

Jens

On Wed, Sep 14, 2016 at 5:50 PM, John Poth <po...@gmail.com> wrote:

> Hi Jens,
>
> The '#' symbol in Camel denotes a reference [1] which Camel will then try
> to lookup in it's registries [2]. In an OSGI environment, Camel will lookup
> the reference in the OsgiServiceRegistry [3] which thanks to [4] will try
> to look up the OSGI service by class name AND service PID :). However, it
> doesn't look like this PR is in any release so you'll have to use the
> master branch for now.
>
> Note that the service PID can change so by default I would recommend
> looking up by class name which is supported in earlier versions of Camel.
> So using the URI:
>
> kura-cloud:myapp/xmltopic?cloudService=org.eclipse.kura.cloud.CloudService
>
> should work.
>
> Hope this helps,
>
> John.
>
>
> [1] https://github.com/apache/camel/blob/master/camel-core/
> src/main/java/org/apache/camel/util/EndpointHelper.java#L292
> [2] https://github.com/apache/camel/blob/337a6756480354afea7531a1a4216d
> e9d232f211/camel-core/src/main/java/org/apache/camel/
> impl/CompositeRegistry.java#L79
> [3] https://github.com/apache/camel/blob/master/components/
> camel-core-osgi/src/main/java/org/apache/camel/core/osgi/
> OsgiServiceRegistry.java
> [4] https://github.com/apache/camel/pull/1083
>
> On Tue, Sep 13, 2016 at 5:27 PM, Jens Reimann <jr...@redhat.com> wrote:
>
>> Hi,
>>
>> I am currently trying to solve an issue of injecting a service with OSGi
>> in an URL based endpoint. Using Camel 2.17.2.
>>
>> For example the URL is "kura-cloud:myapp/xmltopic?cloudService=#pid"
>>
>> I am using the OsgiDefaultCamelContext. The Camel component does call
>> "setProperties(endpoint, properties)" with the provided properties map of
>> camel. And now I would expect camel to lookup the OSGi service with the
>> "service.pid=pid" and inject this, using the "setCloudService" setter on
>> the endpoint.
>>
>> However I do get:
>>
>> ---
>> Caused by: java.lang.IllegalArgumentException: Could not find a suitable
>> setter for property: cloudService as there isn't a setter method with same
>> type: java.lang.String nor type conversion possible: No type converter
>> available to convert from type: java.lang.String to the required type:
>> org.eclipse.kura.cloud.CloudService with value #pid
>>     at org.apache.camel.util.IntrospectionSupport.setProperty(Intro
>> spectionSupport.java:588)
>>     at org.apache.camel.util.IntrospectionSupport.setProperty(Intro
>> spectionSupport.java:616)
>>     at org.apache.camel.util.IntrospectionSupport.setProperties(Int
>> rospectionSupport.java:473)
>>     at org.apache.camel.util.IntrospectionSupport.setProperties(Int
>> rospectionSupport.java:483)
>>     at org.apache.camel.util.EndpointHelper.setProperties(EndpointH
>> elper.java:255)
>>     at org.apache.camel.impl.DefaultComponent.setProperties(Default
>> Component.java:257)
>>     at org.eclipse.kura.camel.cloud.KuraCloudComponent.createEndpoi
>> nt(KuraCloudComponent.java:74)
>>     at org.apache.camel.impl.DefaultComponent.createEndpoint(Defaul
>> tComponent.java:114)
>>     at org.apache.camel.impl.DefaultCamelContext.getEndpoint(Defaul
>> tCamelContext.java:568)
>> ---
>>
>> Any help debugging or understand this would be great.
>>
>> Thanks
>>
>> Jens
>>
>> --
>> Jens Reimann
>> Senior Software Engineer / EMEA ENG Middleware
>> Werner-von-Siemens-Ring 14
>> 85630 Grasbrunn
>> Germany
>> phone: +49 89 2050 71286
>> ____________________________________________________________
>> _________________
>>
>> Red Hat GmbH, www.de.redhat.com,
>> Registered seat: Grasbrunn, Commercial register: Amtsgericht Muenchen,
>> HRB 153243,
>> Managing Directors: Paul Argiry, Charles Cachera, Michael Cunningham,
>> Michael O'Neill
>>
>
>


-- 
Jens Reimann
Senior Software Engineer / EMEA ENG Middleware
Werner-von-Siemens-Ring 14
85630 Grasbrunn
Germany
phone: +49 89 2050 71286
_____________________________________________________________________________

Red Hat GmbH, www.de.redhat.com,
Registered seat: Grasbrunn, Commercial register: Amtsgericht Muenchen, HRB
153243,
Managing Directors: Paul Argiry, Charles Cachera, Michael Cunningham,
Michael O'Neill

Re: Looking for help using service reference with "#" in OSGi

Posted by John Poth <po...@gmail.com>.
Hi Jens,

The '#' symbol in Camel denotes a reference [1] which Camel will then try
to lookup in it's registries [2]. In an OSGI environment, Camel will lookup
the reference in the OsgiServiceRegistry [3] which thanks to [4] will try
to look up the OSGI service by class name AND service PID :). However, it
doesn't look like this PR is in any release so you'll have to use the
master branch for now.

Note that the service PID can change so by default I would recommend
looking up by class name which is supported in earlier versions of Camel.
So using the URI:

kura-cloud:myapp/xmltopic?cloudService=org.eclipse.kura.cloud.CloudService

should work.

Hope this helps,

John.


[1]
https://github.com/apache/camel/blob/master/camel-core/src/main/java/org/apache/camel/util/EndpointHelper.java#L292
[2]
https://github.com/apache/camel/blob/337a6756480354afea7531a1a4216de9d232f211/camel-core/src/main/java/org/apache/camel/impl/CompositeRegistry.java#L79
[3]
https://github.com/apache/camel/blob/master/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiServiceRegistry.java
[4] https://github.com/apache/camel/pull/1083

On Tue, Sep 13, 2016 at 5:27 PM, Jens Reimann <jr...@redhat.com> wrote:

> Hi,
>
> I am currently trying to solve an issue of injecting a service with OSGi
> in an URL based endpoint. Using Camel 2.17.2.
>
> For example the URL is "kura-cloud:myapp/xmltopic?cloudService=#pid"
>
> I am using the OsgiDefaultCamelContext. The Camel component does call
> "setProperties(endpoint, properties)" with the provided properties map of
> camel. And now I would expect camel to lookup the OSGi service with the
> "service.pid=pid" and inject this, using the "setCloudService" setter on
> the endpoint.
>
> However I do get:
>
> ---
> Caused by: java.lang.IllegalArgumentException: Could not find a suitable
> setter for property: cloudService as there isn't a setter method with same
> type: java.lang.String nor type conversion possible: No type converter
> available to convert from type: java.lang.String to the required type:
> org.eclipse.kura.cloud.CloudService with value #pid
>     at org.apache.camel.util.IntrospectionSupport.setProperty(
> IntrospectionSupport.java:588)
>     at org.apache.camel.util.IntrospectionSupport.setProperty(
> IntrospectionSupport.java:616)
>     at org.apache.camel.util.IntrospectionSupport.setProperties(
> IntrospectionSupport.java:473)
>     at org.apache.camel.util.IntrospectionSupport.setProperties(
> IntrospectionSupport.java:483)
>     at org.apache.camel.util.EndpointHelper.setProperties(
> EndpointHelper.java:255)
>     at org.apache.camel.impl.DefaultComponent.setProperties(
> DefaultComponent.java:257)
>     at org.eclipse.kura.camel.cloud.KuraCloudComponent.createEndpoint(
> KuraCloudComponent.java:74)
>     at org.apache.camel.impl.DefaultComponent.createEndpoint(
> DefaultComponent.java:114)
>     at org.apache.camel.impl.DefaultCamelContext.getEndpoint(
> DefaultCamelContext.java:568)
> ---
>
> Any help debugging or understand this would be great.
>
> Thanks
>
> Jens
>
> --
> Jens Reimann
> Senior Software Engineer / EMEA ENG Middleware
> Werner-von-Siemens-Ring 14
> 85630 Grasbrunn
> Germany
> phone: +49 89 2050 71286
> ____________________________________________________________
> _________________
>
> Red Hat GmbH, www.de.redhat.com,
> Registered seat: Grasbrunn, Commercial register: Amtsgericht Muenchen, HRB
> 153243,
> Managing Directors: Paul Argiry, Charles Cachera, Michael Cunningham,
> Michael O'Neill
>