Deploy lib as OSGI bundle

Issue #199 resolved
Дмитрий Дыдышко created an issue

Hi,

We faced with issue while using it as OSGI bundle in Apache Karaf.
We are getting the following error:

org.osgi.framework.BundleException: Unresolved constraint in bundle oauth2-oidc-sdk [242]: Unable to resolve 242.0: missing requirement [242.0] osgi.wiring.package; (&(osgi.wiring.package=com.nimbusds.jose)(version>=4.29.0)(!(version>=5.0.0))) [caused by: Unable to resolve 239.0: missing requirement [239.0] osgi.wiring.package; (osgi.wiring.package=net.jcip.annotations)]
    at org.apache.felix.framework.Felix.resolveBundleRevision(Felix.java:3826)[org.apache.felix.framework-4.0.3.jar:]
    at org.apache.felix.framework.Felix.startBundle(Felix.java:1868)[org.apache.felix.framework-4.0.3.jar:]
    at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:944)[org.apache.felix.framework-4.0.3.jar:]
    at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundle(DirectoryWatcher.java:1263)[6:org.apache.felix.fileinstall:3.2.8]
    at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundles(DirectoryWatcher.java:1235)[6:org.apache.felix.fileinstall:3.2.8]
    at org.apache.felix.fileinstall.internal.DirectoryWatcher.startAllBundles(DirectoryWatcher.java:1224)[6:org.apache.felix.fileinstall:3.2.8]
    at org.apache.felix.fileinstall.internal.DirectoryWatcher.process(DirectoryWatcher.java:519)[6:org.apache.felix.fileinstall:3.2.8]
    at org.apache.felix.fileinstall.internal.DirectoryWatcher.run(DirectoryWatcher.java:308)[6:org.apache.felix.fileinstall:3.2.8]

Technical details:
1. Apache Karaf 2.3.5
2. Java version "1.7.0_75"
3. We are trying to use library com.nimbusds/oauth2-oidc-sdk/5.18.1
4. Commands (from Karaf console) we're using to deploy bundle:
- osgi:install -s mvn:com.nimbusds/oauth2-oidc-sdk/5.18.1
- osgi:install -s wrap:mvn:com.nimbusds/oauth2-oidc-sdk/5.18.1

Comments (15)

  1. Dzmitry Hubin Account Deactivated

    Dear support,

    Adding some details there:

    I was able to install this as osgi bundle using: osgi:install mvn:com.nimbusds/oauth2-oidc-sdk/5.18.1

    and when I use osgi:list I see the following: [ 236] [Installed ] [ ] [ ] [ 80] OAuth 2.0 SDK with OpenID Connect extensions (5.18.1)

    But when I'm startting the bunde: osgi:start 236

    I see the following error:

    Error executing command: Error starting bundles: Unable to start bundle 236: Unresolved constraint in bundle oauth2-oidc-sdk [236]: Unable to resolve 236.0: missing requirement [236.0] osgi.wiring.package; (&(osgi.wiring.package=com.nimbusds.jose)(version>=4.29.0)(!(version>=5.0.0)))

    Any ideas why I have it and how to fix it ? We've tried a lot :) spent 5 days but no lack :)

  2. Connect2id OSS

    Figured out the problem: there has been a problem with deployments to Maven Central, so JOSE+JWT libs past 4.27.1 haven't made it to central. Stay tuned!

  3. Dzmitry Hubin Account Deactivated

    @c2id-support Thanks for letting me know about that. Could you please suggest me some another stable version to use it as osgi bundle together with jose+jwt in a meanwhile ?

    Thanks, Dima.

  4. Connect2id OSS

    Get the following SDK version: 5.17.6

    If necessary, lock down the JWT dep to:

    <dependency>
    <groupId>com.nimbusds</groupId>
    <artifactId>nimbus-jose-jwt</artifactId>
    <version>4.27.1</version>
    </dependency>
    

    Still unsure why Maven Central is failing to sync the most recent versions. Will post here once that's resolved.

  5. Dzmitry Hubin Account Deactivated

    @c2id-support Thanks for the suggestion. So looks like we are talking about different issues. Generally it's all ok with maven central and we are successfully fetched all necessary dependency which are required for compile stage. But when we start oidc-sdk bundle(because it's osgi friendly jar) we get the mentioned above issues when OSGI container can't resolve their imports/exports dependencies which are required to start bundle within osgi container successfully.

    So do we have some list of prerequisites bundles we need to define in order to run oidc-sdk + jose+jwt libs as bundles without dependencies conflicts within osgi container ? Or we can use some technics like <Embed-Dependency> in bundles as part of maven-bundle-plugin in pom.xml to solve it ?

  6. Connect2id OSS

    We managed to force Maven Central to refresh the index by uploading the most recent versions again:

    http://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.nimbusds%22%20AND%20a%3A%22oauth2-oidc-sdk%22

    http://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.nimbusds%22%20AND%20a%3A%22nimbus-jose-jwt%22

    If Maven Central isn't a problem here, I don't know what to suggest. We don't work with OSGI here. The OSGI patch was contributed by a user a while ago, and he claimed that it worked after that. If you think the OSGI bit in the pom.xml needs some fixing, we'll do it. It's just that we're not experts on OSGI.

  7. Dzmitry Hubin Account Deactivated

    @c2id-support thanks for the support. Yes the issue was with osgi setup we managed to inject this library by using wrapper bundle with following maven-bundle-plugin config:

                <configuration>
                    <instructions>
                        <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
                        <Bundle-Version>${project.version}</Bundle-Version>
                        <Embed-Dependency>
                            !bcprov-jdk15on,
                            !bcpkix-jdk15on,
                            !mail,
                            !commons-collections4,
                            *;scope=compile;inline=false
                        </Embed-Dependency>
                        <Embed-Transitive>true</Embed-Transitive>
                        <Embed-Directory>OSGI-INF/lib</Embed-Directory>
                        <Import-Package>
                            *;resolution:=optional
                        </Import-Package>
                        <Export-Package>
                            com.nimbusds.*
                        </Export-Package>
                    </instructions>
                </configuration>
    
  8. Connect2id OSS

    Hi! We're back on this issue. I'm not sure how to interpret your resolution. Is the original OSGi config of the library incorrect, and needs to be updated to match your snippet? Or, can we leave it as it is? Thanks!

  9. Dzmitry Hubin Account Deactivated

    @c2id-support I think we can close it for now perhaps it was caused by our apache karaf bundles specifics. But if anyone come back to this then we could apply my solution then.

    Thanks, Dima.

  10. Jan Brunia

    Hello,

    I'm have trouble getting the nimbusds bundles to work in Karaf and found this thread resembling the issues I am facing.

    I added many dependent bundles to the install causing the nimbusds jars to start but my blueprints to fail due to a class not found exception.

    2017-06-07 11:52:59,229 | ERROR | FelixStartLevel | BlueprintContainerImpl | 33 - org.apache.aries.blueprint.core - 1.6.2 | Unable to start blueprint container for bundle cedi-web-bt/9.0.0.0_MAIN-SNAPSHOT org.osgi.service.blueprint.container.ComponentDefinitionException: java.lang.NoClassDefFoundError: org/objectweb/asm/commons/AdviceAdapter at org.apache.aries.blueprint.container.ReferenceRecipe.internalCreate(ReferenceRecipe.java:123)[33:org.apache.aries.blueprint.core:1.6.2]

    It looks like something gets broken with the introduction of the asm jars. These are my dependencies I added:

    <!-- The nimbusds depedencies START -->
    <!-- Including below bundles causes some of our edi bundles to fail -->
    <bundle>mvn:com.nimbusds/oauth2-oidc-sdk/5.27</bundle>
    <bundle>mvn:com.nimbusds/nimbus-jose-jwt/4.39</bundle>
    <bundle>mvn:com.nimbusds/lang-tag/1.4.3</bundle>
    <bundle>wrap:mvn:com.github.stephenc.jcip/jcip-annotations/1.0-1</bundle>
    <bundle>mvn:net.minidev/json-smart/2.3</bundle>
    <bundle>mvn:net.minidev/accessors-smart/1.2</bundle>
    <bundle>mvn:org.ow2.asm/asm/5.0.4</bundle>
    <bundle>mvn:org.ow2.asm/asm-commons/5.0.4</bundle>
    <bundle>mvn:org.apache.commons/commons-collections4/4.1</bundle>
    <bundle>mvn:org.apache.commons/commons-lang3/3.5</bundle>
    <bundle>mvn:org.bouncycastle/bcpkix-jdk15on/1.55</bundle>
    <bundle>mvn:org.bouncycastle/bcpkix-jdk15on/1.52</bundle>
     <bundle>mvn:org.bouncycastle/bcprov-jdk15on/1.55</bundle>
    <!-- The nimbusds depedencies END -->
    

    I was reading about the embedding of jars and a wrapper bundle was also mentioned and was interested in that solution. Appreciate if that could be shared with me how to go about it.

    Thanks!

    Jan Brunia

  11. Dzmitry Hubin Account Deactivated

    Hi @JB777,

    Sorry for quite late reply. But the whole thing there is to include what you need and exclude what you don't need) Sounds very obvious I know) But we achieved this successful injection only by step by step inclusions/exclusions cause of the numbus bundles itself already osgi-ready and you have to make sure that it won't conflict with all others bundles you already have previously connected.

    Thanks anyway for sharing your experience and good luck!

  12. Jan Brunia

    Hi Dzmitry Hubin,

    No problem. I was wondering about this you said in one of the replies:

         Yes the issue was with osgi setup we managed to inject this library by
         using wrapper bundle with following maven-bundle-plugin config
    

    How do I accomplish this? How I make a wrapper bundle. Appreciate if you could give me some pointers on this how to accomplish it?

    Thanks!

    Jan

  13. Dzmitry Hubin Account Deactivated

    @JB777 yes that's right. So we created new empty maven module what I called wrapper bundle that is actually a new karaf bundle and then included nimbus libraries(bundles) into it using maven-bundle-plugin config:

    <configuration>
                    <instructions>
                        <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
                        <Bundle-Version>${project.version}</Bundle-Version>
                        <Embed-Dependency>
                            !bcprov-jdk15on,
                            !bcpkix-jdk15on,
                            !mail,
                            !commons-collections4,
                            *;scope=compile;inline=false
                        </Embed-Dependency>
                        <Embed-Transitive>true</Embed-Transitive>
                        <Embed-Directory>OSGI-INF/lib</Embed-Directory>
                        <Import-Package>
                            *;resolution:=optional
                        </Import-Package>
                        <Export-Package>
                            com.nimbusds.*
                        </Export-Package>
                    </instructions>
    </configuration>
    

    Plugin usage you can check out there http://felix.apache.org/documentation/subprojects/apache-felix-maven-bundle-plugin-bnd.html

    Unfortunately I haven't repo sources at a hand so can't provide you with code examples.

    Thanks, Dima.

  14. Log in to comment