1

我目前正在使用 openstack4j 库连接到 Bluemix 中的对象存储。当我尝试将 java 代码作为 java 应用程序在本地运行时,连接似乎可以工作,但是当我在 Bluemix 中部署与我们的 Java Web 应用程序相同的代码时,出现以下错误。当我尝试执行身份验证方法时,会发生失败的代码:

OSClient os = OSFactory.builderV3()
                 .endpoint(auth_url)
                 .credentials(username, password)
                 .scopeToProject(projectIdent, domainIdent)
                 .authenticate();

 Exception thrown by application class 'org.openstack4j.connectors.jersey2.HttpExecutorServiceImpl.invoke:58'
org.openstack4j.api.exceptions.ConnectionException: org.apache.cxf.interceptor.Fault: No message body writer has been found for class org.openstack4j.openstack.identity.domain.v3.KeystoneAuth, ContentType: application/json
at org.openstack4j.connectors.jersey2.HttpExecutorServiceImpl.invoke(HttpExecutorServiceImpl.java:58)
at org.openstack4j.connectors.jersey2.HttpExecutorServiceImpl.execute(HttpExecutorServiceImpl.java:33)
at org.openstack4j.core.transport.internal.HttpExecutor.execute(HttpExecutor.java:51)
at org.openstack4j.openstack.internal.OSAuthenticator.authenticateV3(OSAuthenticator.java:156)
at org.openstack4j.openstack.internal.OSAuthenticator.invoke(OSAuthenticator.java:78)
at org.openstack4j.openstack.client.OSClientBuilder$ClientV3.authenticate(OSClientBuilder.java:163)
at org.openstack4j.openstack.client.OSClientBuilder$ClientV3.authenticate(OSClientBuilder.java:127)
at com.ibm.sample.ObjectStorageService.(ObjectStorageService.java:36)
at wasdev.sample.servlet.SimpleServlet.doGet(SimpleServlet.java:30)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:687)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1290)
at [internal classes]
Caused by: javax.ws.rs.ProcessingException: org.apache.cxf.interceptor.Fault: No message body writer has been found for class org.openstack4j.openstack.identity.domain.v3.KeystoneAuth, ContentType: application/json
at org.apache.cxf.jaxrs.client.WebClient.doResponse(WebClient.java:1206)
at [internal classes]
at org.openstack4j.connectors.jersey2.HttpCommand.execute(HttpCommand.java:79)
at org.openstack4j.connectors.jersey2.HttpExecutorServiceImpl.invokeRequest(HttpExecutorServiceImpl.java:65)
at org.openstack4j.connectors.jersey2.HttpExecutorServiceImpl.invoke(HttpExecutorServiceImpl.java:56)
... 12 more
Caused by: org.apache.cxf.interceptor.Fault: No message body writer has been found for class org.openstack4j.openstack.identity.domain.v3.KeystoneAuth, ContentType: application/json
at org.apache.cxf.jaxrs.client.WebClient$BodyWriter.doWriteBody(WebClient.java:1286)
... 16 more
Caused by: javax.ws.rs.ProcessingException: No message body writer has been found for class org.openstack4j.openstack.identity.domain.v3.KeystoneAuth, ContentType: application/json
at org.apache.cxf.jaxrs.client.AbstractClient.reportMessageHandlerProblem(AbstractClient.java:758)
... 16 more
Caused by: org.codehaus.jackson.map.JsonMappingException: (was java.lang.NullPointerException) (through reference chain: org.openstack4j.openstack.identity.domain.v3.KeystoneAuth["id"])
at org.codehaus.jackson.map.JsonMappingException.wrapWithPath(JsonMappingException.java:215)
... 16 more
Caused by: java.lang.NullPointerException:
at org.openstack4j.openstack.identity.domain.v3.KeystoneAuth.getId(KeystoneAuth.java:90)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.codehaus.jackson.map.ser.BeanPropertyWriter.get(BeanPropertyWriter.java:285)
4

2 回答 2

1

堆栈跟踪是由包含在 WebSphere Liberty Profile 中的默认 jar 文件集与使用 OpenStack4J 拉入的 jar 文件之间的 jar 文件冲突引起的。最有可能的罪魁祸首是 jaxrs-2.0,它会拉动 Jersey 依赖项。

Liberty 配置文件的 Bluemix 文档列出了此处自动包含的 jar 文件: https ://www.ng.bluemix.net/docs/#starters/liberty/index.html#liberty

(在那个页面搜索这个文本:整个默认的Liberty server.xml配置文件如下)

要解决此问题,请照常将您的应用程序部署到 Bluemix。它会按照上述方法失败。

然后发出 Cloud Foundry 命令 (cf) 以指示 WebSphere Liberty 不要加载其默认 jar 的整个列表。

下面是一个示例 cf 命令,它将 WebSphere Liberty 加载的默认 jar 列表修剪为仅 2 个 jar 文件并去掉 jaxrs:

cf set-env <your app name here> JBP_CONFIG_LIBERTY "app_archive: {features: [jsp-2.3, websocket-1.1]}"

发出上述命令后,您必须“重新暂存”您的 Liberty 应用程序才能使更改生效:

cf restage <your app name here>

此时,您的 openstack4j 调用应该可以工作了。您必须根据您的代码确定此列表应包括的内容:

{features: [jsp-2.3, websocket-1.1]}

还有其他选项可以避免类路径冲突。您可以下载 OpenStack4J 源代码,修改 pom 文件以隐藏依赖关系,并将这个定制版本的 openstack4j 与 Bluemix 一起使用。

WebSphere Liberty 文档建议使用“反向类加载”,但这听起来不是最好的方法。

于 2016-02-18T16:34:33.510 回答
0

我相信这是由于从您的开发机器到 Bluemix 的 Java 环境存在差异。它不是特定于 openstack 或 keystone 的。

我建议查看以下堆栈溢出问题——它建议进行一些配置更改:

CXF:找不到类的消息正文编写器 - 自动映射非简单资源

如果您无法控制提供者,我会打开 Bluemix 支持票并询问哪些版本/版本是环境的一部分。

于 2016-02-17T19:56:35.660 回答