You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@karaf.apache.org by Steinar Bang <sb...@dod.no> on 2020/02/03 22:27:21 UTC

Karaf 4.2.8: is there a way to find out if two bundles offer up the same versions of packages?

Is there a way to find out if two bundles offer up the same versions of
packages in karaf 4.2.8?

I have some applications that use jersey for the REST API.

I use the web whiteboard, so that the jersey servlet is started as a DS
component.

I use a setup where I add OSGi services injected into the jersey
servlet's HK2 dependency injection systems, so that the OSGi services
can be injected into the jersey resources as they are created to respond
to REST requests.

Earlier I've had some obscure problems in the code that inserts the OSGi
services into HK2.  I eventually tracked the problems town to
javax.inject being auto-wrapped, with a bundle version of 0.0.0.  When I
suppressed adding javax.inject to the feature file, jersey picked the
correct bundled version of javax.inject and all was well.

This worked fine for karaf 4.2.6 and 4.2.7, but with karaf 4.2.6 the
problem is back with the same symptoms and when I had the auto-wrapped
javax.inject.

But this time the autowrapped javax.inject isn't the cause, so it has to
be something else.

One thought that struck me was that several bundles could offer up the
javax.inject package inside the version rangers looked for and picking
the wrong bundle here could mess up things.

Is there a simple way to detect is two bundles offer up the same
package?

Thanks!

- Steinar


Re: Karaf 4.2.8: is there a way to find out if two bundles offer up the same versions of packages?

Posted by Steinar Bang <sb...@dod.no>.
>>>>> Steinar Bang <sb...@dod.no>:

> And the error message sounds similar to what one gets when using
> Class.forName() in OSGi when the class is outside of the current
> bundle. So maybe I'm running OSGi-incompatible reflection code?

> HK2 as a bundle named something like OSGi locator. And that one doesn't
> seem to be loaded. Instead, this one is loaded:
>  96 | Active   |  80 | 2.5.0          | ServiceLocator Default Implementation

Correction: both the default locator and the osgi locator are loaded:
 96 | Active   |  80 | 2.5.0          | ServiceLocator Default Implementation
 97 | Active   |  80 | 1.0.1          | OSGi resource locator bundle - used by various API providers that rely on META-INF/services mechanism to locate providers.

Note: Version of 1.0.1 of the OSGi resource locator is what the maven
dependencies of jersey 2.28 has as the version for the OSGi resource
locator.

The rest of the HK2 dependencies of the HK2 used in jersey 2.28 are
2.5.0


Re: Karaf 4.2.8: is there a way to find out if two bundles offer up the same versions of packages?

Posted by Erwin Hogeweg <er...@me.com>.
Good detective work Steiner, thanks for the update. 

Kind Regards,

Erwin

> El feb. 8, 2020, a la(s) 08:28, Steinar Bang <sb...@dod.no> escribió:
> 
> 
>> 
>>>>>> Steinar Bang <sb...@dod.no>:
> 
> [snip!]
>> Short story: it's a problem in jersey 2.28 on OSGi on JDK 8
> [snip!]
>> So I'll try upgrading to the most recent jersey resource first and see
>> how that works out (if it doesn't, I'll work my way backwards until I
>> (hopefully) find one that does).
> 
> Update: jersey 2.30, the current version of jersey, works fine on both
> JDK 8 and OpenJDK 11 (and works fine on both karaf 4.2.6 and 4.2.8).
> 
> I have updated my handwritten jersey karaf feature to jersey 2.30 (use
> version 1.5.0 of the jersey-karaf-feature, deployed to maven central):
> https://github.com/steinarb/jersey-karaf-feature
> 


Re: Karaf 4.2.8: is there a way to find out if two bundles offer up the same versions of packages?

Posted by Steinar Bang <sb...@dod.no>.
>>>>> Steinar Bang <sb...@dod.no>:

[snip!]
> Short story: it's a problem in jersey 2.28 on OSGi on JDK 8
[snip!]
> So I'll try upgrading to the most recent jersey resource first and see
> how that works out (if it doesn't, I'll work my way backwards until I
> (hopefully) find one that does).

Update: jersey 2.30, the current version of jersey, works fine on both
JDK 8 and OpenJDK 11 (and works fine on both karaf 4.2.6 and 4.2.8).

I have updated my handwritten jersey karaf feature to jersey 2.30 (use
version 1.5.0 of the jersey-karaf-feature, deployed to maven central):
 https://github.com/steinarb/jersey-karaf-feature


Re: Karaf 4.2.8: is there a way to find out if two bundles offer up the same versions of packages?

Posted by Steinar Bang <sb...@dod.no>.
>>>>> Jean-Baptiste Onofre <jb...@nanthrax.net>:

> Windows again ;)
> I’m more suspecting the platform rather than the JDK. Do you mind to create a Jira about that ? I will reproduce on Windows VM and investigate.

I've googled the error message a bit more and found some old issues from
the archived discontinued jersey project and one related from a
different project:
 https://github.com/jersey/jersey/issues/3712
 https://github.com/graphhopper/graphhopper/issues/1391

And then I found this issue in the current (eclipse hosted) jersey
project
 https://github.com/eclipse-ee4j/jersey/issues/4156

Short story: it's a problem in jersey 2.28 on OSGi on JDK 8

In jersey 2.28 the import-package for javax annotation lost its version
number, which means that on JDK 8, which has a built-in
javax.annotation, the built-in javax.annotation is picked, and that
javax.annotation is missing the Priority annotation.

(I guess a good thing with Jersey ending up under the eclipse umbrella,
is that eclipse cares about OSGi...)

Another good thing about Jersey finding a new home, is that there
actually *are* new versions and there have been three releases since
2.28.

So I'll try upgrading to the most recent jersey resource first and see
how that works out (if it doesn't, I'll work my way backwards until I
(hopefully) find one that does).


Re: Karaf 4.2.8: is there a way to find out if two bundles offer up the same versions of packages?

Posted by Jean-Baptiste Onofre <jb...@nanthrax.net>.
Windows again ;)

I’m more suspecting the platform rather than the JDK. Do you mind to create a Jira about that ? I will reproduce on Windows VM and investigate.

Thanks
Regards
JB

> Le 5 févr. 2020 à 23:05, Steinar Bang <sb...@dod.no> a écrit :
> 
>>>>>> Steinar Bang <sb...@dod.no>:
>>>>>> Steinar Bang <sb...@dod.no>:
> 
>>>> About your issue, are you using felix or equinox framework and what
>>>> JDK version ?
> 
>>> Framework: whatever comes with the binary karaf 4.2.8
>>> distro. Presumably felix?  JDK: openjdk 11.0.6 on debian and Oracle
>>> JDK 1.8.0_192 on windows 10
> 
> 
>> On the other hand the error message I'm getting, is:
>> 2020-02-03T22:17:15,772 | ERROR | features-2-thread-1 | Felix                            |  -  -  | Bundle org.ops4j.pax.web.pax-web-extender-whiteboard [112] EventDispatcher: Error during dispatch. (java.lang.NoClassDefFoundError: javax/annotation/Priority)
>> java.lang.NoClassDefFoundError: javax/annotation/Priority
> 
> Correction: this issue does not occur with 4.2.8 (or 4.2.6) on debian
> with openjdk-11.
> 
> It occurs on windows 10 with Oracle JDK 1.8.0_192 on both 4.2.6 and
> 4.2.8.
> 
> No idea if the platform or the JDK version that is the source of the
> problem, but I suspect the JDK version.
> 


Re: Karaf 4.2.8: is there a way to find out if two bundles offer up the same versions of packages?

Posted by Steinar Bang <sb...@dod.no>.
>>>>> Steinar Bang <sb...@dod.no>:
>>>>> Steinar Bang <sb...@dod.no>:

>>> About your issue, are you using felix or equinox framework and what
>>> JDK version ?

>> Framework: whatever comes with the binary karaf 4.2.8
>> distro. Presumably felix?  JDK: openjdk 11.0.6 on debian and Oracle
>> JDK 1.8.0_192 on windows 10


> On the other hand the error message I'm getting, is:
>  2020-02-03T22:17:15,772 | ERROR | features-2-thread-1 | Felix                            |  -  -  | Bundle org.ops4j.pax.web.pax-web-extender-whiteboard [112] EventDispatcher: Error during dispatch. (java.lang.NoClassDefFoundError: javax/annotation/Priority)
> java.lang.NoClassDefFoundError: javax/annotation/Priority

Correction: this issue does not occur with 4.2.8 (or 4.2.6) on debian
with openjdk-11.

It occurs on windows 10 with Oracle JDK 1.8.0_192 on both 4.2.6 and
4.2.8.

No idea if the platform or the JDK version that is the source of the
problem, but I suspect the JDK version.


Re: Karaf 4.2.8: is there a way to find out if two bundles offer up the same versions of packages?

Posted by Steinar Bang <sb...@dod.no>.
>>>>> Steinar Bang <sb...@dod.no>:

>>>>> Jean-Baptiste Onofré <jb...@nanthrax.net>:
>>> Hi,
>>> packages:exports|grep -i package

>>> You will have the package with version and the ID of bundles providing it.

>  karaf@root()> package:exports | grep inject
>  javax.inject                                    | 1.0.0       | 95  | org.glassfish.hk2.external.jakarta.inject
>  org.glassfish.jersey.inject.hk2                 | 2.28.0      | 105 | org.glassfish.jersey.inject.jersey-hk2
>  org.glassfish.jersey.internal.inject            | 2.28.0      | 102 | org.glassfish.jersey.core.jersey-common
>  org.glassfish.jersey.server.internal.inject     | 2.28.0      | 103 | org.glassfish.jersey.core.jersey-server
>  karaf@root()>

> ...so I guess scratch the theory of multiple bundles offering up
> javax.inject...? 

On the other hand the error message I'm getting, is:
 2020-02-03T22:17:15,772 | ERROR | features-2-thread-1 | Felix                            |  -  -  | Bundle org.ops4j.pax.web.pax-web-extender-whiteboard [112] EventDispatcher: Error during dispatch. (java.lang.NoClassDefFoundError: javax/annotation/Priority)
java.lang.NoClassDefFoundError: javax/annotation/Priority

and javax.annotation has two candidates, one from the felix framework
itself:
karaf@root()> package:exports | grep javax\.annotation
 javax.annotation.processing    | 1.0.0       | 0   | org.apache.felix.framework
 javax.annotation.security      | 1.3.0       | 51  | javax.annotation-api
 javax.annotation.sql           | 1.3.0       | 51  | javax.annotation-api
 javax.annotation               | 1.0.0       | 0   | org.apache.felix.framework
 javax.annotation               | 1.3.0       | 51  | javax.annotation-api
 karaf@root()>

However a pattern matching everything from 1.0 to (but not including)
2.0 should pick the 1.3.0 version, and indeed that's what seems to
happen:
 karaf@root()> bundle:capabilities 51
 javax.annotation-api [51] provides:
 -----------------------------------
 osgi.wiring.bundle; javax.annotation-api 1.3.0 [UNUSED]
 osgi.wiring.host; javax.annotation-api 1.3.0 [UNUSED]
 osgi.identity; javax.annotation-api 1.3.0 [UNUSED]
 osgi.wiring.package; javax.annotation 1.3.0 required by:
    org.ops4j.pax.web.pax-web-jetty [113]
    org.glassfish.hk2.utils [98]
 osgi.wiring.package; javax.annotation.security 1.3.0 required by:
    org.glassfish.jersey.core.jersey-server [103]
    org.glassfish.jersey.ext.jersey-entity-filtering [104]
 osgi.wiring.package; javax.annotation.sql 1.3.0 [UNUSED]
 karaf@root()>

And the error message sounds similar to what one gets when using
Class.forName() in OSGi when the class is outside of the current
bundle. So maybe I'm running OSGi-incompatible reflection code?

HK2 as a bundle named something like OSGi locator. And that one doesn't
seem to be loaded. Instead, this one is loaded:
 96 | Active   |  80 | 2.5.0          | ServiceLocator Default Implementation


Re: Karaf 4.2.8: is there a way to find out if two bundles offer up the same versions of packages?

Posted by Steinar Bang <sb...@dod.no>.
>>>>> Steinar Bang <sb...@dod.no>:

>>>>> Jean-Baptiste Onofré <jb...@nanthrax.net>:
>> Hi,
>> packages:exports|grep -i package

>> You will have the package with version and the ID of bundles providing it.

 karaf@root()> package:exports | grep inject
 javax.inject                                    | 1.0.0       | 95  | org.glassfish.hk2.external.jakarta.inject
 org.glassfish.jersey.inject.hk2                 | 2.28.0      | 105 | org.glassfish.jersey.inject.jersey-hk2
 org.glassfish.jersey.internal.inject            | 2.28.0      | 102 | org.glassfish.jersey.core.jersey-common
 org.glassfish.jersey.server.internal.inject     | 2.28.0      | 103 | org.glassfish.jersey.core.jersey-server
 karaf@root()>

...so I guess scratch the theory of multiple bundles offering up
javax.inject...? 


Re: Karaf 4.2.8: is there a way to find out if two bundles offer up the same versions of packages?

Posted by Steinar Bang <sb...@dod.no>.
>>>>> Jean-Baptiste Onofré <jb...@nanthrax.net>:

> Hi,
> packages:exports|grep -i package

> You will have the package with version and the ID of bundles providing it.

Thanks!

> About your issue, are you using felix or equinox framework and what JDK
> version ?

Framework: whatever comes with the binary karaf 4.2.8 distro. Presumably felix?
JDK: openjdk 11.0.6 on debian and Oracle JDK 1.8.0_192 on windows 10


Re: Karaf 4.2.8: is there a way to find out if two bundles offer up the same versions of packages?

Posted by Jean-Baptiste Onofré <jb...@nanthrax.net>.
Hi,

packages:exports|grep -i package

You will have the package with version and the ID of bundles providing it.

About your issue, are you using felix or equinox framework and what JDK
version ?

Regards
JB

On 03/02/2020 23:27, Steinar Bang wrote:
> Is there a way to find out if two bundles offer up the same versions of
> packages in karaf 4.2.8?
> 
> I have some applications that use jersey for the REST API.
> 
> I use the web whiteboard, so that the jersey servlet is started as a DS
> component.
> 
> I use a setup where I add OSGi services injected into the jersey
> servlet's HK2 dependency injection systems, so that the OSGi services
> can be injected into the jersey resources as they are created to respond
> to REST requests.
> 
> Earlier I've had some obscure problems in the code that inserts the OSGi
> services into HK2.  I eventually tracked the problems town to
> javax.inject being auto-wrapped, with a bundle version of 0.0.0.  When I
> suppressed adding javax.inject to the feature file, jersey picked the
> correct bundled version of javax.inject and all was well.
> 
> This worked fine for karaf 4.2.6 and 4.2.7, but with karaf 4.2.6 the
> problem is back with the same symptoms and when I had the auto-wrapped
> javax.inject.
> 
> But this time the autowrapped javax.inject isn't the cause, so it has to
> be something else.
> 
> One thought that struck me was that several bundles could offer up the
> javax.inject package inside the version rangers looked for and picking
> the wrong bundle here could mess up things.
> 
> Is there a simple way to detect is two bundles offer up the same
> package?
> 
> Thanks!
> 
> - Steinar
> 

-- 
Jean-Baptiste Onofré
jbonofre@apache.org
http://blog.nanthrax.net
Talend - http://www.talend.com