Search code examples
javaosgiapache-karafapache-felixxero-api

Integration xero (invoicing gateway) in apache felix (osgi)


I have a project with multi modules in karaf (version 3.0.3), and i needed to add one dependency to Xero API (invoicing gateway) - https://github.com/XeroAPI/Xero-Java

I use OSGI implementation through the felix apache. In module, I added all dependencies to Xero, these are in pom bellow.

Pom.xml

  <dependency>
    <groupId>com.github.xeroapi</groupId>
    <artifactId>xero-java</artifactId>
    <version>${xero-java.version}</version>
  </dependency>
  <dependency>
    <groupId>com.github.xeroapi</groupId>
    <artifactId>xeroapi-schemas</artifactId>
    <version>${xero-schemas.version}</version>
  </dependency>
  <dependency>
    <groupId>javax.xml.bind</groupId>
    <artifactId>jaxb-api</artifactId>
    <version>${jaxb-api.version}</version>
  </dependency>
  <dependency>
    <groupId>com.sun.xml.bind</groupId>
    <artifactId>jaxb-core</artifactId>
    <version>${jaxb-core.version}</version>
  </dependency>
  <dependency>
    <groupId>com.sun.xml.bind</groupId>
    <artifactId>jaxb-impl</artifactId>
    <version>${jaxb-impl.version}</version>
  </dependency>
  <dependency>
    <groupId>javax.activation</groupId>
    <artifactId>activation</artifactId>
    <version>${javax-activation.version}</version>
  </dependency>
  <dependency>
    <groupId>org.threeten</groupId>
    <artifactId>threetenbp</artifactId>
    <version>${threetenbp.version}</version>
  </dependency>

      <plugin>
        <groupId>org.apache.felix</groupId>
        <artifactId>maven-bundle-plugin</artifactId>
        <extensions>true</extensions>
        <configuration>
          <instructions>
            <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
            <Import-Package>!com.google.api.client.http,*</Import-Package>
            <Embed-Dependency>com.google.api.client.http</Embed-Dependency>
          </instructions>
        </configuration>
      </plugin>

All implementation was deployed and compiled, but in running karaf i got the next error.

Log karaf

2019-07-19 15:44:19,812 | ERROR | lixDispatchQueue | FeatureDeploymentListener | 22 - org.apache.karaf.deployer.features - 3.0.3 | Unable to install features java.lang.Exception: Could not start bundle mvn:com.xtpo.im/im-bll-impl/0.2-SNAPSHOT in feature(s) be-invoice-mgmt-0.2-SNAPSHOT: Unresolved constraint in bundle com.xtpo.im.im-bll-impl [368]: Unable to resolve 368.0: missing requirement [368.0] osgi.wiring.package; (osgi.wiring.package=com.google.api.client.http) at org.apache.karaf.features.internal.FeaturesServiceImpl.startBundle(FeaturesServiceImpl.java:504)[21:org.apache.karaf.features.core:3.0.3] at org.apache.karaf.features.internal.FeaturesServiceImpl.installFeatures(FeaturesServiceImpl.java:459)[21:org.apache.karaf.features.core:3.0.3] at Proxya6f8789a_dbdc_4181_b0eb_837248e8cb78.installFeatures(Unknown Source)[:] at Proxycbafeabb_12c9_47e3_94d6_f999d20117fa.installFeatures(Unknown Source)[:] at org.apache.karaf.deployer.features.FeatureDeploymentListener.bundleChanged(FeatureDeploymentListener.java:213)[22:org.apache.karaf.deployer.features:3.0.3] at org.apache.felix.framework.util.EventDispatcher.invokeBundleListenerCallback(EventDispatcher.java:868)[org.apache.felix.framework-4.2.1.jar:] at org.apache.felix.framework.util.EventDispatcher.fireEventImmediately(EventDispatcher.java:789)[org.apache.felix.framework-4.2.1.jar:] at org.apache.felix.framework.util.EventDispatcher.run(EventDispatcher.java:1088)[org.apache.felix.framework-4.2.1.jar:] at org.apache.felix.framework.util.EventDispatcher.access$000(EventDispatcher.java:54)[org.apache.felix.framework-4.2.1.jar:] at org.apache.felix.framework.util.EventDispatcher$1.run(EventDispatcher.java:101)[org.apache.felix.framework-4.2.1.jar:] at java.lang.Thread.run(Thread.java:748)[:1.8.0_211] Caused by: org.osgi.framework.BundleException: Unresolved constraint in bundle com.xtpo.im.im-bll-impl [368]: Unable to resolve 368.0: missing requirement [368.0] osgi.wiring.package; (osgi.wiring.package=com.google.api.client.http) at org.apache.felix.framework.Felix.resolveBundleRevision(Felix.java:3974)[org.apache.felix.framework-4.2.1.jar:] at org.apache.felix.framework.Felix.startBundle(Felix.java:2037)[org.apache.felix.framework-4.2.1.jar:] at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:955)[org.apache.felix.framework-4.2.1.jar:] at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:942)[org.apache.felix.framework-4.2.1.jar:] at org.apache.karaf.features.internal.FeaturesServiceImpl.startBundle(FeaturesServiceImpl.java:501)[21:org.apache.karaf.features.core:3.0.3] ... 10 more

The problem is the com.google.api.client.http. Can someone help me solve this problem?

In file features i have the next dependencies:

features.xml

    <!--Xero dependencies-->
    <bundle>wrap:mvn:com.github.xeroapi/xero-java/${xero-java.version}</bundle>
    <bundle>wrap:mvn:com.github.xeroapi/xeroapi-schemas/${xero-schemas.version}</bundle>
    <bundle>wrap:mvn:javax.xml.bind/jaxb-api/${jaxb-api.version}</bundle>
    <bundle>wrap:mvn:com.sun.xml.bind/jaxb-impl/${jaxb-impl.version}</bundle>
    <bundle>wrap:mvn:javax.activation/activation/${javax-activation.version}</bundle>
    <bundle>wrap:mvn:org.threeten/threetenbp/${threetenbp.version}</bundle>

Thanks all


Solution

  • Felix is unable to resolve the package com.google.api.client.http. You must either deploy a bundle that contains the package or embed it into your own bundle. The package is available from the maven artifact com.google.http-client:google-http-client.

    You can configure the maven-bundle-plugin to embed compile scoped dependencies and add a dependency to the google http-client artifact linked to above:

    <dependency>
      <groupId>com.google.http-client</groupId>
      <artifactId>google-http-client</artifactId>
      <version>1.30.2</version>
    </dependency>
    

    Some tweaking with the version may be required. Please note that the artifact is packaged as an OSGi bundle, so you can also try to download it and deploy it to karaf along with your own bundle (instead of embedding it).