Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
243 views
in Technique[技术] by (71.8m points)

java - Google Client API in OSGI

I'm having trouble providing the dependencies needed for OAuth Client Library for Java within an OSGI application framework (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 bundle, BND. So I'm using maven-bundle-plugin to embed these into my bundle. My process so far has been to watch the error.log for messages about 'Unresolved constraint in bundle.' Then track down the missing package, add the maven dependency, and add it to the Embed-Dependency section. That seemed to work for google-http-client and google-oauth-client. GSON (or Jackson2 ) cannot be resolved this way, and I get the message...

Update:

As Neil pointed out I needed to embed a different dependency for GSON (google-http-client-gson). Thank you!

However it's still not able to deploy, and currently reporting this message...

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

It seems others have had trouble with this, and possible related to Guava in OSGi I have tried making sun.misc optional.

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

But the bundle fails to start, and provides the error message 'Unresolved constraint in bundle.' At this point my questions are...

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

Alternatively. I would appreciate suggestions about this sun.misc package, and it's 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>

Portions from the 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
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

The dependencies...

<!-- Embedded Google Client API JAR's -->
<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>

the 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>   

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...