Google client API in OSGI

I am having trouble providing the dependencies required for the Java OAuth Client Library within an OSGI Application (AEM).

https://developers.google.com/api-client-library/java/google-oauth-java-client/setup

I don't want to manually convert each dependency to an OSGI package, BND. So I am using the maven-bundle-plugin to embed them in my bundle. So far, my process has been to view the error.log for "Unresolved constraint in bundle" messages. Then track down the missing package, add the maven dependency and add it to the Embed-Dependency section. This is similar to google-http-client and google-oauth-client. GSON (or Jackson2) cannot be resolved this way and I get a message ...

Update:

As Neil pointed out, I needed to inject another dependency for GSON (google-http-client-gson). Thank!

However, it still cannot deploy and is currently reporting this message ...

org.osgi.framework.BundleException: Unresolved constraint in package com.mypackage.services [394]: Unable to resolve 394.130: Missing requirement [394.130] osgi.wiring.package; (Osgi.wiring.package = sun.misc)

It seems that others have had problems with this, and possibly related to Guava in OSGi I've tried making sun.misc optional.

<Import-Package>sun.misc.*;resolution:=optional,*</Import-Package>

      

But the bundle fails to start and gives an "Unresolved constraint in bundle" error. At this point, my questions ...

Has anyone had any success deploying the Google CLient API for Java in OSGI? If so, how?

As an alternative. I would appreciate some suggestions for this package sun.misc

and this is a possible relation to using Guava in OSGI


my pom.xml

<dependencies>
<dependency>
 <groupId>com.google.api-client</groupId>
 <artifactId>google-api-client</artifactId>
 <version>1.20.0</version>
</dependency>

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

<dependency>
  <groupId>com.google.api-client</groupId>
  <artifactId>google-api-client-java6</artifactId>
  <version>1.20.0</version>
</dependency>

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

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

<dependency>
  <groupId>com.google.oauth-client</groupId>
  <artifactId>google-oauth-client</artifactId>
  <version>1.20.0</version>
</dependency>

<dependency>
  <groupId>com.google.oauth-client</groupId>
  <artifactId>google-oauth-client-java6</artifactId>
  <version>1.20.0</version>
</dependency>

<dependency>
    <groupId>com.google.guava</groupId>
    <artifactId>guava</artifactId>
    <version>18.0</version>
</dependency>

<dependency>
    <groupId>org.glassfish</groupId>
    <artifactId>javax.jms</artifactId>
    <version>3.2-b06</version>
</dependency>

<dependency>
    <groupId>commons-logging</groupId>
    <artifactId>commons-logging</artifactId>
    <version>1.1.3</version>
</dependency>


<dependency>
    <groupId>org.apache.httpcomponents</groupId>
    <artifactId>httpclient</artifactId>
    <version>4.5</version>
</dependency>

<dependency>
    <groupId>org.apache.httpcomponents</groupId>
    <artifactId>httpcore</artifactId>
    <version>4.4.1</version>
</dependency>
<dependency>
    <groupId>org.apache.servicemix.bundles</groupId>
    <artifactId>org.apache.servicemix.bundles.ehcache</artifactId>
    <version>2.6.11_1</version>
</dependency>

<dependency>
    <groupId>org.apache.servicemix.bundles</groupId>
    <artifactId>org.apache.servicemix.bundles.avalon-framework</artifactId>
    <version>4.3.1_1</version>
</dependency>
</dependencies>
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.felix</groupId>
            <artifactId>maven-bundle-plugin</artifactId>
            <extensions>true</extensions>
            <configuration>
                <instructions>
                    <Bundle-Activator>com.mypackage.services.osgi.Activator</Bundle-Activator>
                    <Embed-Dependency>    
                        google-api-client;scope=compile,
                        google-oauth-client;scope=compile,
                        google-http-client;scope=compile,
                        google-api-client-gson;scope=compile,                 
                        gson;scope=compile,
                        httpclient;scope=compile, 
                    </Embed-Dependency>
                    <Sling-Test-Regexp>.*Test</Sling-Test-Regexp>
                </instructions>
            </configuration>
        </plugin>

      

Ports from MANIFEST.MF

Embed-Dependency: google-api-client;scope=compile,google-api-client-java
 6;scope=compile,google-oauth-client;scope=compile,google-oauth-client-j
 ava6;scope=compile,google-http-client;scope=compile,google-http-client-
 gson;scope=compile,google-http-client-jackson2;scope=compile,gson;scope
 =compile,guava;scope=compile,httpclient;scope=compile,httpcore;scope=co
 mpile,
Embedded-Artifacts: google-api-client-1.20.0.jar;g="com.google.api-clien
 t";a="google-api-client";v="1.20.0",google-api-client-java6-1.20.0.jar;
 g="com.google.api-client";a="google-api-client-java6";v="1.20.0",google
 -oauth-client-1.20.0.jar;g="com.google.oauth-client";a="google-oauth-cl
 ient";v="1.20.0",google-oauth-client-java6-1.20.0.jar;g="com.google.oau
 th-client";a="google-oauth-client-java6";v="1.20.0",google-http-client-
 1.20.0.jar;g="com.google.http-client";a="google-http-client";v="1.20.0"
 ,google-http-client-gson-1.20.0.jar;g="com.google.http-client";a="googl
 e-http-client-gson";v="1.20.0",google-http-client-jackson2-1.20.0.jar;g
 ="com.google.http-client";a="google-http-client-jackson2";v="1.20.0",gs
 on-2.3.jar;g="com.google.code.gson";a="gson";v="2.3",guava-18.0.jar;g="
 com.google.guava";a="guava";v="18.0",httpclient-4.5.jar;g="org.apache.h
 ttpcomponents";a="httpclient";v="4.5",httpcore-4.4.1.jar;g="org.apache.
 httpcomponents";a="httpcore";v="4.4.1"
Import-Package: com.adobe.cq.sightly;version="[2.2,3)",com.day.cq.common
 s;version="[5.7,6)",com.day.cq.commons.date;version="[5.7,6)",com.day.c
 q.dam.api;version="[1.2,2)",com.day.cq.search;version="[1.1,2)",com.day
 .cq.search.result;version="[1.1,2)",com.day.cq.tagging;version="[5.7,6)
 ",com.day.cq.wcm.api;version="[1.2,2)",com.day.cq.wcm.api.components;ve
 rsion="[5.7,6)",com.day.cq.wcm.commons;version="[5.7,6)",com.day.cq.wcm
 .foundation;version="[5.7,6)",com.fasterxml.jackson.core;version="[2.1,
 3)",javax.annotation,javax.crypto,javax.crypto.spec,javax.jcr;version="
 [2.0,3)",javax.naming,javax.naming.directory,javax.naming.ldap,javax.ne
 t,javax.net.ssl,javax.security.auth.x500,javax.servlet,javax.servlet.ht
 tp,javax.xml.parsers,org.apache.commons.codec.binary,org.apache.commons
 .httpclient;version="[3.1,4)",org.apache.commons.httpclient.methods;ver
 sion="[3.1,4)",org.apache.commons.httpclient.params;version="[3.1,4)",o
 rg.apache.commons.io;version="[1.4,2)",org.apache.commons.logging;versi
 on="[1.1,2)",org.apache.sling.api;version="[2.3,3)",org.apache.sling.ap
 i.request;version="[2.4,3)",org.apache.sling.api.resource;version="[2.5
 ,3)",org.apache.sling.api.servlets;version="[2.1,3)",org.apache.sling.a
 pi.wrappers;version="[2.5,3)",org.apache.sling.jcr.api;version="[2.2,3)
 ",org.apache.sling.junit.annotations;version="[1.0,2)",org.ietf.jgss,or
 g.junit;version="[4.8,5)",org.junit.runner;version="[4.8,5)",org.osgi.f
 ramework;version="[1.5,2)",org.osgi.service.component;version="[1.1,2)"
 ,org.slf4j;version="[1.6,2)",org.w3c.dom,org.xml.sax,sun.misc

      

+2


source to share


1 answer


So, I'm finally working. I've posted the code in case it helps others, or maybe find better ways to do this.

Dependencies ...

<!-- Embedded Google Client API JAR -->
<dependency>
 <groupId>com.google.api-client</groupId>
 <artifactId>google-api-client</artifactId>
 <version>1.20.0</version>
</dependency>
<dependency>
  <groupId>com.google.http-client</groupId>
  <artifactId>google-http-client</artifactId>
  <version>1.20.0</version>
</dependency>
<dependency>
  <groupId>com.google.api-client</groupId>
  <artifactId>google-api-client-java6</artifactId>
  <version>1.20.0</version>
</dependency>
<dependency>
    <groupId>com.google.http-client</groupId>
    <artifactId>google-http-client-jackson2</artifactId>
    <version>1.20.0</version>
</dependency>
<dependency>
    <groupId>com.google.http-client</groupId>
    <artifactId>google-http-client-gson</artifactId>
    <version>1.20.0</version>
</dependency>
<dependency>
  <groupId>com.google.oauth-client</groupId>
  <artifactId>google-oauth-client</artifactId>
  <version>1.20.0</version>
</dependency>
<dependency>
  <groupId>com.google.oauth-client</groupId>
  <artifactId>google-oauth-client-java6</artifactId>
  <version>1.20.0</version>
</dependency>
<dependency>
    <groupId>org.apache.servicemix.bundles</groupId>
    <artifactId>org.apache.servicemix.bundles.avalon-framework</artifactId>
    <version>4.3.1_1</version>
</dependency>
<dependency>
    <groupId>commons-logging</groupId>
    <artifactId>commons-logging</artifactId>
    <version>1.1</version>
</dependency>
<dependency>
    <groupId>org.glassfish</groupId>
    <artifactId>javax.jms</artifactId>
    <version>3.2-b06</version>
</dependency>

      



maven-bundle-plugin settings

    <plugin>
      <groupId>org.apache.felix</groupId>
      <artifactId>maven-bundle-plugin</artifactId>
      <extensions>true</extensions>
      <configuration>
          <instructions>
              <Bundle-Activator>com.r2i.michigan.lsa.services.osgi.Activator</Bundle-Activator>
              <Embed-Dependency>                             
                  *;scope=compile|runtime,
              </Embed-Dependency>
                <Embed-Transitive>true</Embed-Transitive> 
                <Import-Package>
                  sun.misc;resolution:=optional,
                  com.sun.jdmk.comm;resolution:=optional,*
                </Import-Package>                       
              <Sling-Test-Regexp>.*Test</Sling-Test-Regexp>
          </instructions>
      </configuration>
    </plugin>   

      

+4


source







All Articles