OSGI中的Google客户端API [英] Google Client API in OSGI

查看:198
本文介绍了OSGI中的Google客户端API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在OSGI应用程序框架(AEM)中提供OAuth Client Library for Java所需的依赖关系时遇到问题。

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



我不想手动将每个依赖项转换为OSGI包,BND。所以我使用maven-bundle-plugin将它们嵌入到我的包中。到目前为止,我的过程一直是观察error.log中有关'未解析的束中约束'的消息。然后追踪丢失的包,添加Maven依赖项,并将其添加到Embed-Dependency部分。这似乎适用于谷歌HTTP客户端和谷歌OAUTH客户端。 GSON(或Jackson2)无法以这种方式解决,我收到消息...



更新:



Neil指出我需要为GSON(google-http-client-gson)嵌入不同的依赖关系。谢谢!



然而,它仍然无法部署,并且目前正在报告此消息...


org.osgi.framework.BundleException:包com.mypackage.services中的未解析约束[394]:无法解析394.130:缺少需求[394.130] osgi.wiring.package; (osgi.wiring.package = sun.misc)

看起来其他人对此有困难,可能与番石榴OSGi 我已经尝试让sun.misc可选。

 < Import-Package> sun.misc。*;分辨率:=可选,* LT; /导入-包装及GT; 

但是该包无法启动,并提供错误消息捆绑中的未解析约束。点我的问题是...

是否有人在OSGI中部署用于Java的Google CLient API成功?如果是这样,如何?



或者。我会很感激关于这个 sun.misc 包的建议,它可能与在OSGI中使用Guava相关



< hr>

my pom.xml

 <依赖关系> 
< dependency>
< groupId> com.google.api-client< / groupId>
< artifactId> google-api-client< / artifactId>
< version> 1.20.0< / version>
< /依赖关系>

< dependency>
< groupId> com.google.http-client< / groupId>
< artifactId> google-http-client< / artifactId>
< version> 1.20.0< / version>
< /依赖关系>

< dependency>
< groupId> com.google.api-client< / groupId>
< artifactId> google-api-client-java6< / artifactId>
< version> 1.20.0< / version>
< /依赖关系>

< dependency>
< groupId> com.google.http-client< / groupId>
< artifactId> google-http-client-jackson2< / artifactId>
< version> 1.20.0< / version>
< /依赖关系>

< dependency>
< groupId> com.google.http-client< / groupId>
< artifactId> google-http-client-gson< / artifactId>
< version> 1.20.0< / version>
< /依赖关系>

< dependency>
< groupId> com.google.oauth-client< / groupId>
< artifactId> google-oauth-client< / artifactId>
< version> 1.20.0< / version>
< /依赖关系>

< dependency>
< groupId> com.google.oauth-client< / groupId>
< artifactId> google-oauth-client-java6< / artifactId>
< version> 1.20.0< / version>
< /依赖关系>

< dependency>
< groupId> com.google.guava< / groupId>
< artifactId>番石榴< / artifactId>
< version> 18.0< / version>
< /依赖关系>

< dependency>
< groupId> org.glassfish< / groupId>
< artifactId> javax.jms< / artifactId>
< version> 3.2-b06< / version>
< /依赖关系>

< dependency>
< groupId> commons-logging< / groupId>
< artifactId> commons-logging< / artifactId>
< version> 1.1.3< / version>
< /依赖关系>


< dependency>
< groupId> org.apache.httpcomponents< / groupId>
< artifactId> httpclient< / artifactId>
< version> 4.5< / version>
< /依赖关系>

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

< dependency>
< groupId> org.apache.servicemix.bundles< / groupId>
< artifactId> org.apache.servicemix.bundles.avalon-framework< / artifactId>
< version> 4.3.1_1< / version>
< /依赖关系>
< /依赖关系>
< build>
< plugins>
< plugin>
< groupId> org.apache.felix< / groupId>
< artifactId> maven-bundle-plugin< / artifactId>
< extensions> true< / extensions>
<配置>
<指令>
< 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>

来自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或
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

$ b $因此,我终于有了它的工作。我已经发布了代码,以帮助其他人,或者找到更好的方法来实现它。



依赖关系...

 <! - 嵌入式Google客户端API JAR's  - > 
< dependency>
< groupId> com.google.api-client< / groupId>
< artifactId> google-api-client< / artifactId>
< version> 1.20.0< / version>
< /依赖关系>
< dependency>
< groupId> com.google.http-client< / groupId>
< artifactId> google-http-client< / artifactId>
< version> 1.20.0< / version>
< /依赖关系>
< dependency>
< groupId> com.google.api-client< / groupId>
< artifactId> google-api-client-java6< / artifactId>
< version> 1.20.0< / version>
< /依赖关系>
< dependency>
< groupId> com.google.http-client< / groupId>
< artifactId> google-http-client-jackson2< / artifactId>
< version> 1.20.0< / version>
< /依赖关系>
< dependency>
< groupId> com.google.http-client< / groupId>
< artifactId> google-http-client-gson< / artifactId>
< version> 1.20.0< / version>
< /依赖关系>
< dependency>
< groupId> com.google.oauth-client< / groupId>
< artifactId> google-oauth-client< / artifactId>
< version> 1.20.0< / version>
< /依赖关系>
< dependency>
< groupId> com.google.oauth-client< / groupId>
< artifactId> google-oauth-client-java6< / artifactId>
< version> 1.20.0< / version>
< /依赖关系>
< dependency>
< groupId> org.apache.servicemix.bundles< / groupId>
< artifactId> org.apache.servicemix.bundles.avalon-framework< / artifactId>
< version> 4.3.1_1< / version>
< /依赖关系>
< dependency>
< groupId> commons-logging< / groupId>
< artifactId> commons-logging< / artifactId>
< version> 1.1< / version>
< /依赖关系>
< dependency>
< groupId> org.glassfish< / groupId>
< artifactId> javax.jms< / artifactId>
< version> 3.2-b06< / version>
< /依赖关系>

maven-bundle-plugin设置

 < plugin> 
< groupId> org.apache.felix< / groupId>
< artifactId> maven-bundle-plugin< / artifactId>
< extensions> true< / extensions>
<配置>
<指令>
< Bundle-Activator> com.r2i.michigan.lsa.services.osgi.Activator< / Bundle-Activator>
< Embed-Dependency>
*; scope = compile | runtime,
< / Embed-Dependency>
< Embed-Transitive> true< / Embed-Transitive>
<导入包>
sun.misc;分辨率:=可选,
com.sun.jdmk.comm;分辨率:=可选,*
< / Import-Package>
< Sling-Test-Regexp>。* Test< / Sling-Test-Regexp>
< / instructions>
< / configuration>
< / plugin>


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

解决方案

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>   

这篇关于OSGI中的Google客户端API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆