繁体   English   中英

在 Liferay 中使用 OkHttp 来使用外部 rest API。 OSGi 的问题

[英]Using OkHttp inside Liferay to consume external rest APIs. Problem with OSGi

Inside a gradle java Liferay REST API backend (created with blade create -t rest), we are trying to use an OkHttp client from within Liferay 7.2 to access another rest API which is external.

build.gradle 依赖项包括以下行:

implementation group: 'com.squareup.okhttp3', name: 'okhttp', version: '4.9.0'

构建顺利,但是当我们将 jar 部署到 Liferay 服务器时,我们收到一条错误消息:

org.osgi.framework.BundleException: Could not resolve module: backendapp [1177]_  Unresolved requirement: Import-Package: okhttp3_ [Sanitized]
at org.eclipse.osgi.container.Module.start(Module.java:444)

OkHttp OSGI 是否为 Liferay 做好了准备? 如果不是,从 LR 内部的 java 内部使用 rest API 的 LR 友好替代方案是什么?

感谢您的任何提示。

假设 OkHttp 是作为一个有效的 OSGi 包交付的:仅仅构建你的插件不会使其依赖项对运行时可用。 您必须将它(及其依赖项)单独部署到运行时以使其可用。

当然这只需要发生一次,而不是每次更新自己的插件时

如果不用于其他插件,您可以在 jar 中嵌入外部 jars。 请按照如何将非 osgi jar 包含到 Liferay 模块中

您可以在 build.gradle 中添加以下依赖项

compileInclude group: "com.squareup.retrofit2", name: "retrofit", version: "2.5.0"
compileInclude group: "com.squareup.retrofit2", name: "converter-jackson", version: "2.5.0"
compileInclude group: 'org.cache2k', name: 'cache2k-all', version: '1.0.2.Final'
compileInclude group: 'com.squareup.okhttp3', name: 'okhttp', version: '4.2.2'

您还需要在 bnd.bnd 文件中添加以下行

Import-Package: \
!android.*,\
!com.android.*,\
!dalvik.system,\
!javax.annotation.meta,\
!kotlin.internal.jdk7,\
!kotlin.internal.jdk8,\
!kotlin.reflect.jvm.internal,\
!org.conscrypt,\
!org.openjsse.javax.net.ssl,\
!org.openjsse.net.ssl,\
!org.xmlpull.v1,\
!sun.security.ssl,\
*

希望对你有效。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM