msfbrasil
msfbrasil

Reputation: 41

PAM EXAM configuration dependency demanding older JAR when newer is available

I'm struggling with a PAX EXAM configuration for integration tests of a project I've started working some weeks ago.

The major problem are regarding the dependencies of the bundles I'm intending to test, but I was always able to evolve for each problem, but now I'm really stuck.

Below I'm listing the current version of my @Configuration method:

@Configuration
public Option[] configure() {

// Runs outside the OSGi framework
return options(
    junitBundles(),
    wrappedBundle( mavenBundle( "antlr", "antlr" ).version( "2.7.7" ) ),
    wrappedBundle( mavenBundle( "com.fasterxml", "classmate" ).version( "1.3.0" ) ),
    wrappedBundle( mavenBundle( "org.javassist", "javassist" ).version( "3.18.1-GA" ) ),
    wrappedBundle( mavenBundle( "org.jboss.logging", "jboss-logging" ).version( "3.1.0.GA" ) ),
    wrappedBundle( mavenBundle( "dom4j", "dom4j" ).version( "1.6.1" ) ),
    //wrappedBundle( mavenBundle( "org.hibernate.javax.persistence", "hibernate-jpa-2.0-api" ).version( "1.0.1.Final" ) ),
    mavenBundle( "javax.persistence", "com.springsource.javax.persistence" ).version( "2.0.0" ),

    wrappedBundle( mavenBundle( "org.jboss.spec.javax.transaction", "jboss-transaction-api_1.1_spec" ).version( "1.0.1.Final" ) ),
    //wrappedBundle( mavenBundle( "javax.transaction", "javax.transaction-api" ).version( "1.2" ) ),
    //wrappedBundle( mavenBundle( "javax.enterprise", "cdi-api" ).version( "1.0-SP4" ) ),
    //wrappedBundle( mavenBundle( "org.jboss.spec.javax.interceptor", "jboss-interceptors-api_1.1_spec" ).version( "1.0.0.Beta1" ) ),

    wrappedBundle( mavenBundle( "org.jboss", "jandex" ).version( "1.0.3.Final" ) ),
    wrappedBundle( mavenBundle( "org.hibernate", "hibernate-core" ).version( "4.2.21.Final" ) ),

    wrappedBundle( mavenBundle( "org.springframework", "spring-beans" ).version( "3.2.5.RELEASE" ) ).bundleSymbolicName( "org.springframework.beans" ).bundleVersion( "3.2.5.RELEASE" ),
    wrappedBundle( mavenBundle( "org.springframework", "spring-context" ).version( "3.2.5.RELEASE" ) ).bundleSymbolicName( "org.springframework.context" ).bundleVersion( "3.2.5.RELEASE" ),
    wrappedBundle( mavenBundle( "org.springframework", "spring-core" ).version( "3.2.5.RELEASE" ) ).bundleSymbolicName( "org.springframework.core" ).bundleVersion( "3.2.5.RELEASE" ),
    wrappedBundle( mavenBundle( "org.springframework", "spring-aop" ).version( "3.2.5.RELEASE" ) ).bundleSymbolicName( "org.springframework.aop" ).bundleVersion( "3.2.5.RELEASE" ),
    wrappedBundle( mavenBundle( "org.springframework", "spring-jdbc" ).version( "3.2.5.RELEASE" ) ).bundleSymbolicName( "org.springframework.jdbc" ).bundleVersion( "3.2.5.RELEASE" ),
    wrappedBundle( mavenBundle( "org.springframework", "spring-tx" ).version( "3.2.5.RELEASE" ) ).bundleSymbolicName( "org.springframework.tx" ).bundleVersion( "3.2.5.RELEASE" ),
    wrappedBundle( mavenBundle( "aopalliance", "aopalliance" ).version( "1.0" ) ),
    wrappedBundle( mavenBundle( "org.springframework.osgi", "spring-osgi-core" ).version( "1.2.1" ) ),
    wrappedBundle( mavenBundle( "org.springframework.osgi", "spring-osgi-annotation" ).version( "1.2.1" ) ),
    wrappedBundle( mavenBundle( "org.springframework.osgi", "spring-osgi-extender" ).version( "1.2.1" ) ),

    wrappedBundle( mavenBundle( "commons-lang", "commons-lang" ).version( "2.6" ) ),
    wrappedBundle( mavenBundle( "org.hibernate.common", "hibernate-commons-annotations" ).version( "4.0.2.Final" ) );
}

I removed our business dependencies because they are not necessary for the explanation.

Spring OSGI dependencies ("spring-osgi-core", "spring-osgi-annotation", etc) are dependent of version "2.5.6" of Spring Framework, which I'm already fulfilling with versions "3.2.5.RELEASE" of those libs, but for some reason the old versions are still getting enforced as could be seen by erros below:

    org.osgi.framework.BundleException: Unable to resolve br.com.mycompany.myapplication.osgi.entity.interceptor.entity-interceptor [39](R 39.0): missing requirement [br.com.mycompany.myapplication.osgi.entity.interceptor.entity-interceptor [39](R 39.0)] osgi.wiring.package; (&(osgi.wiring.package=org.springframework.osgi.extensions.annotation)(version>=1.2.0)) [caused by: Unable to resolve org.springframework.osgi.extensions.annotations [33](R 33.0): missing requirement [org.springframework.osgi.extensions.annotations [33](R 33.0)] osgi.wiring.package; (&(osgi.wiring.package=org.springframework.beans)(version>=2.5.6)(!(version>=4.0.0)))] Unresolved requirements: [[br.com.mycompany.myapplication.osgi.entity.interceptor.entity-interceptor [39](R 39.0)] osgi.wiring.package; (&(osgi.wiring.package=org.springframework.osgi.extensions.annotation)(version>=1.2.0))]
    at org.apache.felix.framework.Felix.resolveBundleRevision(Felix.java:4111)
    at org.apache.felix.framework.Felix.startBundle(Felix.java:2117)
    at org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:1371)
    at org.apache.felix.framework.FrameworkStartLevelImpl.run(FrameworkStartLevelImpl.java:308)
    at java.lang.Thread.run(Thread.java:748)
org.osgi.framework.BundleException: Unable to resolve br.com.mycompany.myapplication.api.log.application-log-service [40](R 40.0): missing requirement [br.com.mycompany.myapplication.api.log.application-log-service [40](R 40.0)] osgi.wiring.package; (osgi.wiring.package=br.com.mycompany.myapplication.osgi.entity.interceptor.repository) [caused by: Unable to resolve br.com.mycompany.myapplication.osgi.entity.interceptor.entity-interceptor [39](R 39.0): missing requirement [br.com.mycompany.myapplication.osgi.entity.interceptor.entity-interceptor [39](R 39.0)] osgi.wiring.package; (&(osgi.wiring.package=org.springframework.osgi.extensions.annotation)(version>=1.2.0)) [caused by: Unable to resolve org.springframework.osgi.extensions.annotations [33](R 33.0): missing requirement [org.springframework.osgi.extensions.annotations [33](R 33.0)] osgi.wiring.package; (&(osgi.wiring.package=org.springframework.beans)(version>=2.5.6)(!(version>=4.0.0)))]] Unresolved requirements: [[br.com.mycompany.myapplication.api.log.application-log-service [40](R 40.0)] osgi.wiring.package; (osgi.wiring.package=br.com.mycompany.myapplication.osgi.entity.interceptor.repository)]
    at org.apache.felix.framework.Felix.resolveBundleRevision(Felix.java:4111)
    at org.apache.felix.framework.Felix.startBundle(Felix.java:2117)
    at org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:1371)
    at org.apache.felix.framework.FrameworkStartLevelImpl.run(FrameworkStartLevelImpl.java:308)
    at java.lang.Thread.run(Thread.java:748)
ERROR: Bundle br.com.mycompany.myapplication.api.log.application-log-service [40] Error starting file:/tmp/1533155354575-0/pax-exam-downloads/br.com.mycompany.myapplication.api.log.application-log-service_1.46.0.SNAPSHOT.jar (org.osgi.framework.BundleException: Unable to resolve br.com.mycompany.myapplication.api.log.application-log-service [40](R 40.0): missing requirement [br.com.mycompany.myapplication.api.log.application-log-service [40](R 40.0)] osgi.wiring.package; (osgi.wiring.package=br.com.mycompany.myapplication.osgi.entity.interceptor.repository) [caused by: Unable to resolve br.com.mycompany.myapplication.osgi.entity.interceptor.entity-interceptor [39](R 39.0): missing requirement [br.com.mycompany.myapplication.osgi.entity.interceptor.entity-interceptor [39](R 39.0)] osgi.wiring.package; (&(osgi.wiring.package=org.springframework.osgi.extensions.annotation)(version>=1.2.0)) [caused by: Unable to resolve org.springframework.osgi.extensions.annotations [33](R 33.0): missing requirement [org.springframework.osgi.extensions.annotations [33](R 33.0)] osgi.wiring.package; (&(osgi.wiring.package=org.springframework.beans)(version>=2.5.6)(!(version>=4.0.0)))]] Unresolved requirements: [[br.com.mycompany.myapplication.api.log.application-log-service [40](R 40.0)] osgi.wiring.package; (osgi.wiring.package=br.com.mycompany.myapplication.osgi.entity.interceptor.repository)])
org.osgi.framework.BundleException: Unable to resolve br.com.mycompany.myapplication.api.log.listener.application-log-listener [41](R 41.0): missing requirement [br.com.mycompany.myapplication.api.log.listener.application-log-listener [41](R 41.0)] osgi.wiring.package; (osgi.wiring.package=br.com.mycompany.idpclient.model) Unresolved requirements: [[br.com.mycompany.myapplication.api.log.listener.application-log-listener [41](R 41.0)] osgi.wiring.package; (osgi.wiring.package=br.com.mycompany.idpclient.model)]
    at org.apache.felix.framework.Felix.resolveBundleRevision(Felix.java:4111)
    at org.apache.felix.framework.Felix.startBundle(Felix.java:2117)
    at org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:1371)
    at org.apache.felix.framework.FrameworkStartLevelImpl.run(FrameworkStartLevelImpl.java:308)
    at java.lang.Thread.run(Thread.java:748)

Does anyone have any ideas why is this happening?

Thanks a lot and best regards!

Upvotes: 0

Views: 86

Answers (2)

msfbrasil
msfbrasil

Reputation: 41

I was able to workaround the problem by wrapping the "org.springframework" dependencies in order to change their manifest, like below:

wrappedBundle( mavenBundle( "org.springframework", "spring-beans" ).version( "3.2.5.RELEASE" ) ).bundleSymbolicName( "org.springframework.beans" ).bundleVersion( "3.2.5.RELEASE" )
    .exports( "*;version=3.2.5.RELEASE" ).overwriteManifest( WrappedUrlProvisionOption.OverwriteMode.MERGE ),
wrappedBundle( mavenBundle( "org.springframework", "spring-core" ).version( "3.2.5.RELEASE" ) ).bundleSymbolicName( "org.springframework.core" ).bundleVersion( "3.2.5.RELEASE" )
    .exports( "*;version=3.2.5.RELEASE" ).overwriteManifest( WrappedUrlProvisionOption.OverwriteMode.MERGE ),
wrappedBundle( mavenBundle( "org.springframework", "spring-context" ).version( "3.2.5.RELEASE" ) ).bundleSymbolicName( "org.springframework.context" ).bundleVersion( "3.2.5.RELEASE" )
    .exports( "*;version=3.2.5.RELEASE" ).overwriteManifest( WrappedUrlProvisionOption.OverwriteMode.MERGE ),
wrappedBundle( mavenBundle( "org.springframework", "spring-jdbc" ).version( "3.2.5.RELEASE" ) ).bundleSymbolicName( "org.springframework.jdbc" ).bundleVersion( "3.2.5.RELEASE" )
    .exports( "*;version=3.2.5.RELEASE" ).overwriteManifest( WrappedUrlProvisionOption.OverwriteMode.MERGE ),
wrappedBundle( mavenBundle( "org.springframework", "spring-aop" ).version( "3.2.5.RELEASE" ) ).bundleSymbolicName( "org.springframework.aop" ).bundleVersion( "3.2.5.RELEASE" )
    .exports( "*;version=3.2.5.RELEASE" ).overwriteManifest( WrappedUrlProvisionOption.OverwriteMode.MERGE ),
wrappedBundle( mavenBundle( "org.springframework", "spring-orm" ).version( "3.2.5.RELEASE" ) ).bundleSymbolicName( "org.springframework.orm" ).bundleVersion( "3.2.5.RELEASE" )
    .exports( "*;version=3.2.5.RELEASE" ).overwriteManifest( WrappedUrlProvisionOption.OverwriteMode.MERGE ),
wrappedBundle( mavenBundle( "org.springframework", "spring-tx" ).version( "3.2.5.RELEASE" ) ).bundleSymbolicName( "org.springframework.transaction" ).bundleVersion( "3.2.5.RELEASE" )
    .exports( "*;version=3.2.5.RELEASE" ).overwriteManifest( WrappedUrlProvisionOption.OverwriteMode.MERGE ),

With this change, the "org.springframework.osgi" dependencies stop asking for the older "2.5.6" version of "org.springframework" libs.

Now I'm facing a different problem to get everyghing running as exposed on another question: PAX EXAM Rest Endpoint not available for felix integration test.

Upvotes: 0

Christian Schneider
Christian Schneider

Reputation: 19626

You should not wrap all the bundles on your own. Sometimes making an OSGi bundle requires more than the auto wrapping can provide. A good approach is to check what Apache Karaf uses.

Spring and many other libs you need are provided by service mix bundles.

Try this:

Download and start Apache Karaf 4.1.5
feature:install spring hibernate transaction
la -s

So you see what bundles karaf installs for spring. These should work better for your case.

Apart from that I would really try to get away from spring if you want to use OSGi. Spring was known to cause lots of issues in OSGi and the newer versions are even less compatible.

Upvotes: 0

Related Questions