JClouds和OpenStack:IllegalStateException:预期为BEGIN_ARRAY,但为STRING [英] JClouds and OpenStack : IllegalStateException: Expected BEGIN_ARRAY but was STRING

查看:104
本文介绍了JClouds和OpenStack:IllegalStateException:预期为BEGIN_ARRAY,但为STRING的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用

I'm trying to access OpenStack Swift using Apache JClouds 1.9.2 library. Maven dependency :

<dependency>
    <groupId>org.apache.jclouds</groupId>
    <artifactId>jclouds-all</artifactId>
    <version>1.9.2</version>
</dependency>

我从入门指南及其代码示例开始.总的来说,我没有问题可以连接并保持Blob.但是,当我尝试列出容器列表(或容器的内容)时,出现以下错误:

I began with the getting started guide and its code sample. In general, I have no problem to connect and persist a blob. But when I try to list the list of containers (or the contents of a container) I get the following error :

SEVERE: Error parsing input: java.lang.IllegalStateException: 
Expected BEGIN_ARRAY but was STRING at line 1 column 1 path $
com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was STRING at line 1 column 1 path $
    at com.google.gson.Gson.fromJson(Gson.java:817)
    at com.google.gson.Gson.fromJson(Gson.java:770)
    at com.google.gson.Gson.fromJson(Gson.java:719)
    at org.jclouds.json.internal.GsonWrapper.fromJson(GsonWrapper.java:42)
    at org.jclouds.http.functions.ParseJson.apply(ParseJson.java:83)
    at org.jclouds.http.functions.ParseJson.apply(ParseJson.java:77)
    at org.jclouds.http.functions.ParseJson.apply(ParseJson.java:62)
    at org.jclouds.http.functions.ParseJson.apply(ParseJson.java:42)
    at org.jclouds.rest.internal.InvokeHttpMethod.invoke(InvokeHttpMethod.java:90)
    at org.jclouds.rest.internal.InvokeHttpMethod.apply(InvokeHttpMethod.java:73)
    at org.jclouds.rest.internal.InvokeHttpMethod.apply(InvokeHttpMethod.java:44)
    at org.jclouds.reflect.FunctionalReflection$FunctionalInvocationHandler.handleInvocation(FunctionalReflection.java:117)
    at com.google.common.reflect.AbstractInvocationHandler.invoke(AbstractInvocationHandler.java:87)
    at com.sun.proxy.$Proxy57.list(Unknown Source)
Caused by: java.lang.IllegalStateException: 
Expected BEGIN_ARRAY but was STRING at line 1 column 1 path $
    at com.google.gson.stream.JsonReader.beginArray(JsonReader.java:351)
    at org.jclouds.json.internal.NullFilteringTypeAdapterFactories$IterableTypeAdapter.readAndBuild(NullFilteringTypeAdapterFactories.java:88)
    at org.jclouds.json.internal.NullFilteringTypeAdapterFactories$IterableTypeAdapter.read(NullFilteringTypeAdapterFactories.java:82)
    at org.jclouds.json.internal.NullFilteringTypeAdapterFactories$FluentIterableTypeAdapter.read(NullFilteringTypeAdapterFactories.java:239)
    at org.jclouds.json.internal.NullFilteringTypeAdapterFactories$FluentIterableTypeAdapter.read(NullFilteringTypeAdapterFactories.java:225)
    at com.google.gson.Gson.fromJson(Gson.java:805)

下面的代码摘自示例,当执行containerApi.list()时将失败.如前所述,方法createContaineruploadObjectFromString将起作用.

The code below taken from the sample that will fail when executing containerApi.list() . As commented, methods createContainer and uploadObjectFromString will work.

我只能认为Swift以JSON格式返回的响应与JClouds期望的稍有不同,但是我不知道这是否正确或如何解决. 另外,我在OpenStack仪表板中看到 对象存储为 http://xx.xx.xx.107:80/swift/v1 身份为 http://xx.xx.xx.101:5000/v2.0 不知道为什么其中一个是v1,另一个是v2.0,以及使用Java库时是否应该考虑这一点. 我认为我对使用哪种Java库没有限制,所以我想知道是否最好使用另一个Java库而不是JClouds,尽管这个库看起来是最合适的.

I can only think that Swift is returning a response in a JSON format slightly different from what JClouds is expecting but I don't know whether this is true or how to solve it. Also, I see in my OpenStack Dashboard that although Object Store is http://xx.xx.xx.107:80/swift/v1 Identity is http://xx.xx.xx.101:5000/v2.0 Not sure why one of them would be v1 and the other v2.0 and whether I should take this into account when using the Java libraries. I don't think I have a restriction about what Java libraries to use, so I wonder whether I'd better use another one instead of JClouds, although this one looked like the most suitable one.

import java.io.Closeable;
import java.io.IOException;
import java.util.Set;
import org.jclouds.ContextBuilder;
import org.jclouds.openstack.swift.v1.SwiftApi;
import org.jclouds.openstack.swift.v1.domain.Container;
import org.jclouds.openstack.swift.v1.features.ContainerApi;
import com.google.common.io.Closeables;
public class JCloudsSwift implements Closeable {
    private SwiftApi swiftApi;
    public static void main(String[] args) {
        JCloudsSwift jcloudsSwift = new JCloudsSwift();

          try {
             jcloudsSwift.listContainers();
             jcloudsSwift.close();
          } catch (Exception e) {
             e.printStackTrace();
          } finally {
             try {
                jcloudsSwift.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
          }
    }
    public JCloudsSwift() {
          String provider = "openstack-swift";
          String identity = "tenantName:userName";
          String credential = "password";
          String endPoint = "http://xx.xx.xx.101:5000/v2.0/";
          swiftApi = ContextBuilder.newBuilder(provider)
                .endpoint(endPoint)
                .credentials(identity, credential)
                .buildApi(SwiftApi.class);
       }
       private void listContainers() {
          String region = "us-east-1a";
          ContainerApi containerApi = swiftApi.getContainerApi(region);
          Set<Container> containers = containerApi.list().toSet();
          for (Container container : containers) {
             System.out.println("  " + container);
          }
       }
       public void close() throws IOException {
          Closeables.close(swiftApi, true);
       }
}

按照zachsh的建议,我启用了 wire log (请参见下文).我隐藏了一些细节(IPs ...).希望我在那里没有妥协.

Following zachsh's suggestion, I enabled the wire log (see below). I hid some details (IPs...). Hopefully I didn't compromise anything there.

在我看来,一开始,有一个对Identity v2终结点的调用,该调用会获得一个提供不同终结点的有效JSON响应,例如带有swift v1的终结点.请求和响应中的内容类型均为application/json.然后,将调用此快速端点,但它只会返回纯文本响应.也就是说,请求中的请求内容类型为application/json,而在响应中为text/plain. "Dev"和"dev2"是我在对象存储中的两个容器的名称.

It looks to me that at first, there is a call to the identity v2 endpoint which gets a valid JSON response providing the different endpoints, like the one with swift v1. Both content-type in the request and the response are application/json. Then, this swift endpoint is called but it will only return the response in plain text. That is, the request content-type in the request is application/json and in the response it´s text/plain . "Dev" and "dev2" are the names of my two containers in the object store.

我想知道我的Java代码中是否存在任何错误(我大多复制了示例,但可能配置有误),或者关于我使用的库的某些信息,或者甚至在我的Openstack安装中没有任何控制(我无法控制它) ,但我可以要求提供具体信息.

I wonder whether there is anything wrong in my Java code (I mostly copied the example but I may have misconfigured something), or something about the libraries I use, or even something in my Openstack installation (I have no control over it, but I could ask for specifics).

请参阅下面的日志.

jclouds-wire.log

2016-02-17 09:31:04,562 DEBUG [jclouds.wire] [main] >> "Sensitive data in payload, use PROPERTY_LOGGER_WIRE_LOG_SENSITIVE_INFO override to enable logging this data."
2016-02-17 09:31:04,562 DEBUG [jclouds.headers] [main] >> POST http://xx.xx.xx.101:5000/v2.0/tokens HTTP/1.1
2016-02-17 09:31:04,562 DEBUG [jclouds.headers] [main] >> Accept: application/json
2016-02-17 09:31:04,562 DEBUG [jclouds.headers] [main] >> Content-Type: application/json
2016-02-17 09:31:04,562 DEBUG [jclouds.headers] [main] >> Content-Length: 103
2016-02-17 09:31:04,984 DEBUG [jclouds.headers] [main] << HTTP/1.1 200 OK
2016-02-17 09:31:04,984 DEBUG [jclouds.headers] [main] << X-Distribution: Ubuntu
2016-02-17 09:31:04,984 DEBUG [jclouds.headers] [main] << Connection: keep-alive
2016-02-17 09:31:04,984 DEBUG [jclouds.headers] [main] << Vary: X-Auth-Token
2016-02-17 09:31:04,984 DEBUG [jclouds.headers] [main] << Date: Wed, 17 Feb 2016 09:31:27 GMT
2016-02-17 09:31:04,984 DEBUG [jclouds.headers] [main] << Content-Type: application/json
2016-02-17 09:31:04,984 DEBUG [jclouds.headers] [main] << Content-Length: 4421
2016-02-17 09:31:04,999 DEBUG [jclouds.wire] [main] << "{"access": {"token": {"issued_at": "2016-02-17T09:31:27.785179", "expires": "2016-02-17T10:31:27Z", "id": "fb6b46bd674046ef87c3270f1fd9dafd", "tenant": {"description": "", "enabled": true, "id": "c2c919f7f89a4d8f913e4ce19a0e6ace", "name": "my_tenant_name"}, "audit_ids": ["nIjY-heVSV-cbTfVIpEY-Q"]}, "serviceCatalog": [{"endpoints": [{"adminURL": "http://xx.xx.xx.102:8774/v2/c2c919f7f89a4d8f913e4ce19a0e6ace", "region": "us-east-1a", "internalURL": "http://xx.xx.xx.102:8774/v2/c2c919f7f89a4d8f913e4ce19a0e6ace", "id": "70c3eef4d3e242348c0e580f94414823", "publicURL": "http://xx.xx.xx.102:8774/v2/c2c919f7f89a4d8f913e4ce19a0e6ace"}], "endpoints_links": [], "type": "compute", "name": "nova"}, {"endpoints": [{"adminURL": "http://xx.xx.xx.105:9696", "region": "us-east-1a", "internalURL": "http://xx.xx.xx.105:9696", "id": "2a9328b17cc54538a38fb6ae13e5b3ac", "publicURL": "http://xx.xx.xx.105:9696"}], "endpoints_links": [], "type": "network", "name": "quantum"}, {"endpoints": [{"adminURL": "http://xx.xx.xx.104:8776/v2/c2c919f7f89a4d8f913e4ce19a0e6ace", "region": "us-east-1a", "internalURL": "http://xx.xx.xx.104:8776/v2/c2c919f7f89a4d8f913e4ce19a0e6ace", "id": "2eda4420ba0a49f9891ed9bd803b569c", "publicURL": "http://xx.xx.xx.104:8776/v2/c2c919f7f89a4d8f913e4ce19a0e6ace"}], "endpoints_links": [], "type": "volumev2", "name": "cinderv2"}, {"endpoints": [{"adminURL": "http://xx.xx.xx.102:3333", "region": "us-east-1a", "internalURL": "http://xx.xx.xx.102:3333", "id": "538aab805479410da21399abd012ceff", "publicURL": "http://xx.xx.xx.102:3333"}], "endpoints_links": [], "type": "s3", "name": "s3"}, {"endpoints": [{"adminURL": "http://xx.xx.xx.103:9292", "region": "us-east-1a", "internalURL": "http://xx.xx.xx.103:9292", "id": "80559923bf354541bdd9f56a45bedd7a", "publicURL": "http://xx.xx.xx.103:9292"}], "endpoints_links": [], "type": "image", "name": "glance"}, {"endpoints": [{"adminURL": "http://xx.xx.xx.108:8777", "region": "us-east-1a", "internalURL": "http://xx.xx.xx.108:8777", "id": "a777efdc724643ecb6e705ff2eb47004", "publicURL": "http://xx.xx.xx.108:8777"}], "endpoints_links": [], "type": "metering", "name": "ceilometer"}, {"endpoints": [{"adminURL": "http://xx.xx.xx.220:8000/v1", "region": "us-east-1a", "internalURL": "http://xx.xx.xx.220:8000/v1", "id": "253135e684c24e00bb7bea6feb7cf595", "publicURL": "http://xx.xx.xx.220:8000/v1"}], "endpoints_links": [], "type": "cloudformation", "name": "heat-cfn"}, {"endpoints": [{"adminURL": "http://xx.xx.xx.104:8776/v1/c2c919f7f89a4d8f913e4ce19a0e6ace", "region": "us-east-1a", "internalURL": "http://xx.xx.xx.104:8776/v1/c2c919f7f89a4d8f913e4ce19a0e6ace", "id": "38264ccfbb574fcd81ba345c9eb7d37b", "publicURL": "http://xx.xx.xx.104:8776/v1/c2c919f7f89a4d8f913e4ce19a0e6ace"}], "endpoints_links": [], "type": "volume", "name": "cinder"}, {"endpoints": [{"adminURL": "http://xx.xx.xx.102:8773/services/Cloud", "region": "us-east-1a", "internalURL": "http://xx.xx.xx.102:8773/services/Cloud", "id": "4da43f1139c94d8aaf82564e16156ca5", "publicURL": "http://xx.xx.xx.102:8773/services/Cloud"}], "endpoints_links": [], "type": "ec2", "name": "ec2"}, {"endpoints": [{"adminURL": "http://xx.xx.xx.220:8004/v1/c2c919f7f89a4d8f913e4ce19a0e6ace", "region": "us-east-1a", "internalURL": "http://xx.xx.xx.220:8004/v1/c2c919f7f89a4d8f913e4ce19a0e6ace", "id": "1180dc51deea4523a088871a352d9f72", "publicURL": "http://xx.xx.xx.220:8004/v1/c2c919f7f89a4d8f913e4ce19a0e6ace"}], "endpoints_links": [], "type": "orchestration", "name": "heat"}, {"endpoints": [{"adminURL": "http://xx.xx.xx.107:80/swift", "region": "us-east-1a", "internalURL": "http://xx.xx.xx.107:80/swift/v1", "id": "0457cd31064243c9b548dfe2eb0c1bc8", "publicURL": "http://xx.xx.xx.107:80/swift/v1"}], "endpoints_links": [], "type": "object-store", "name": "swift"}, {"endpoints": [{"adminURL": "http://xx.xx.xx.101:35357/v2.0", "region": "us-east-1a", "internalURL": "http://xx.xx.xx.101:5000/v2.0", "id": "40d04c8899cc4ea083dc5ecac808a825", "publicURL": "http://xx.xx.xx.101:5000/v2.0"}], "endpoints_links": [], "type": "identity", "name": "keystone"}], "user": {"username": "my_user_name", "roles_links": [], "id": "e9312e8a3579404d91ba53894dcf72ea", "roles": [{"name": "Member"}, {"name": "_member_"}], "name": "my_user_name"}, "metadata": {"is_admin": 0, "roles": ["647df06e706f4d1f8a8810246e19bd26", "9fe2ff9ee4384b1894a90878d3e92bab"]}}}"
2016-02-17 09:31:05,062 DEBUG [jclouds.headers] [main] >> GET http://xx.xx.xx.107:80/swift/v1 HTTP/1.1
2016-02-17 09:31:05,062 DEBUG [jclouds.headers] [main] >> Accept: application/json
2016-02-17 09:31:05,062 DEBUG [jclouds.headers] [main] >> X-Auth-Token: fb6b46bd674046ef87c3270f1fd9dafd
2016-02-17 09:31:05,405 DEBUG [jclouds.headers] [main] << HTTP/1.1 200 OK
2016-02-17 09:31:05,405 DEBUG [jclouds.headers] [main] << Content-type: text/plain; charset=utf-8
2016-02-17 09:31:05,405 DEBUG [jclouds.headers] [main] << Connection: Keep-Alive
2016-02-17 09:31:05,405 DEBUG [jclouds.headers] [main] << Date: Wed, 17 Feb 2016 09:31:28 GMT
2016-02-17 09:31:05,405 DEBUG [jclouds.headers] [main] << Content-Type: text/plain; charset=utf-8
2016-02-17 09:31:05,405 DEBUG [jclouds.headers] [main] << Content-Length: 9
2016-02-17 09:31:05,405 DEBUG [jclouds.wire] [main] << "dev[\n]"
2016-02-17 09:31:05,405 DEBUG [jclouds.wire] [main] << "dev2[\n]"

jclouds.log

2016-02-17 09:31:04,562 DEBUG [org.jclouds.rest.internal.InvokeHttpMethod] [main] >> invoking AuthenticationApi.authenticateWithTenantNameAndCredentials
2016-02-17 09:31:04,562 DEBUG [org.jclouds.http.internal.JavaUrlHttpCommandExecutorService] [main] Sending request -1271935931: POST http://xx.xx.xx.101:5000/v2.0/tokens HTTP/1.1
2016-02-17 09:31:04,984 DEBUG [org.jclouds.http.internal.JavaUrlHttpCommandExecutorService] [main] Receiving response -1271935931: HTTP/1.1 200 OK
2016-02-17 09:31:05,046 DEBUG [org.jclouds.openstack.keystone.v2_0.suppliers.RegionIdToURIFromAccessForTypeAndVersion] [main] endpoints for apiType object-store and version 1: {us-east-1a=[Endpoint{id=0457cd31064243c9b548dfe2eb0c1bc8, region=us-east-1a, publicURL=http://xx.xx.xx.107:80/swift/v1, internalURL=http://xx.xx.xx.107:80/swift/v1, adminURL=http://xx.xx.xx.107:80/swift}]}
2016-02-17 09:31:05,062 DEBUG [org.jclouds.rest.internal.InvokeHttpMethod] [main] >> invoking container:list
2016-02-17 09:31:05,062 DEBUG [org.jclouds.http.internal.JavaUrlHttpCommandExecutorService] [main] Sending request -629919459: GET http://xx.xx.xx.107:80/swift/v1 HTTP/1.1
2016-02-17 09:31:05,405 DEBUG [org.jclouds.http.internal.JavaUrlHttpCommandExecutorService] [main] Receiving response -629919459: HTTP/1.1 200 OK
2016-02-17 09:31:05,420 ERROR [org.jclouds.http.functions.ParseJson] [main] Error parsing input: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was STRING at line 1 column 1 path $
com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was STRING at line 1 column 1 path $
    at com.google.gson.Gson.fromJson(Gson.java:817)
    at com.google.gson.Gson.fromJson(Gson.java:770)
    at com.google.gson.Gson.fromJson(Gson.java:719)
    at org.jclouds.json.internal.GsonWrapper.fromJson(GsonWrapper.java:42)
    at org.jclouds.http.functions.ParseJson.apply(ParseJson.java:83)
    at org.jclouds.http.functions.ParseJson.apply(ParseJson.java:77)
    at org.jclouds.http.functions.ParseJson.apply(ParseJson.java:62)
    at org.jclouds.http.functions.ParseJson.apply(ParseJson.java:42)
    at org.jclouds.rest.internal.InvokeHttpMethod.invoke(InvokeHttpMethod.java:90)
    at org.jclouds.rest.internal.InvokeHttpMethod.apply(InvokeHttpMethod.java:73)
    at org.jclouds.rest.internal.InvokeHttpMethod.apply(InvokeHttpMethod.java:44)
    at org.jclouds.reflect.FunctionalReflection$FunctionalInvocationHandler.handleInvocation(FunctionalReflection.java:117)
    at com.google.common.reflect.AbstractInvocationHandler.invoke(AbstractInvocationHandler.java:87)
    at com.sun.proxy.$Proxy57.list(Unknown Source)
    at com.ceph.JCloudsSwift.listContainers(JCloudsSwift.java:58)
    at com.ceph.JCloudsSwift.main(JCloudsSwift.java:22)
Caused by: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was STRING at line 1 column 1 path $
    at com.google.gson.stream.JsonReader.beginArray(JsonReader.java:351)
    at org.jclouds.json.internal.NullFilteringTypeAdapterFactories$IterableTypeAdapter.readAndBuild(NullFilteringTypeAdapterFactories.java:88)
    at org.jclouds.json.internal.NullFilteringTypeAdapterFactories$IterableTypeAdapter.read(NullFilteringTypeAdapterFactories.java:82)
    at org.jclouds.json.internal.NullFilteringTypeAdapterFactories$FluentIterableTypeAdapter.read(NullFilteringTypeAdapterFactories.java:239)
    at org.jclouds.json.internal.NullFilteringTypeAdapterFactories$FluentIterableTypeAdapter.read(NullFilteringTypeAdapterFactories.java:225)
    at com.google.gson.Gson.fromJson(Gson.java:805)
    ... 15 common frames omitted

推荐答案

看起来像个错误.谢谢!将在此处跟踪: https://issues.apache.org/jira/browse/JCLOUDS-1080

Looks like a bug. Thanks! Will track here: https://issues.apache.org/jira/browse/JCLOUDS-1080

这篇关于JClouds和OpenStack:IllegalStateException:预期为BEGIN_ARRAY,但为STRING的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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