使用openstack4j {Blue

时间:2016-02-11 18:19:16

标签: ibm-cloud openstack object-storage

我目前正在使用openstack4j库连接到Bluemix中的Object Storage。当我尝试在本地运行java代码作为java应用程序时,连接似乎有效,但是当我在Bluemix中部署与Java Web应用程序相同的代码时,我在下面收到以下错误。当我尝试执行authenticate方法时,会发生失败的代码:

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)

2 个答案:

答案 0 :(得分:1)

堆栈跟踪是由WebSphere Liberty Profile中包含的默认jar文件集与使用OpenStack4J引入的jar文件之间的jar文件冲突引起的。最有可能的是,罪魁祸首是jaxrs-2.0,它扼杀了泽西岛的依赖。

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文档建议使用“反向类加载”,但这听起来不是最好的方法。

答案 1 :(得分:0)

我认为这是由于您的开发机器与Bluemix之间的Java环境存在差异。它不是特定于openstack或keystone。

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

CXF: No message body writer found for class - automatically mapping non-simple resources

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