gpt4 book ai didi

java - JClouds 和 OpenStack : IllegalStateException: Expected BEGIN_ARRAY but was STRING

转载 作者:行者123 更新时间:2023-11-30 03:03:04 26 4
gpt4 key购买 nike

我正在尝试访问OpenStack Swift使用Apache JClouds 1.9.2 库。 Maven 依赖:

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

我从 getting started guide 开始及其代码示例。一般来说,我连接和保存 blob 没有问题。但是,当我尝试列出容器列表(或容器的内容)时,出现以下错误:

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将起作用。

我只能认为 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 库没有限制,所以我想知道是否最好使用另一个库而不是 JClouds,尽管这个看起来是最合适的。

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 的建议,我启用了线路日志(见下文)。我隐藏了一些细节(IP...)。希望我没有在那里妥协任何事情。

在我看来,首先,有一个对身份 v2 端点的调用,它会获取一个提供不同端点的有效 JSON 响应,就像 swift v1 的端点一样。请求和响应中的内容类型都是application/json。然后,调用这个 swift 端点,但它只会返回纯文本响应。也就是说,请求中的请求内容类型是 application/json ,而响应中的请求内容类型是 text/plain 。 “Dev”和“dev2”是对象存储中两个容器的名称。

我想知道我的Java代码是否有什么问题(我主要复制了示例,但我可能配置错误),或者我使用的库有什么问题,甚至我的Openstack安装中有什么问题(我无法控制它) ,但我可以询问具体细节)。

请参阅下面的日志。

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

关于java - JClouds 和 OpenStack : IllegalStateException: Expected BEGIN_ARRAY but was STRING,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35439056/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com