2014-11-25 4 views
0

openstacks의 객체 저장소에 업로드 된 파일이 있습니다. 이 스 니펫은 컨테이너 및 객체 목록을 가져 와서 인쇄합니다.Swift api에서 Json 응답을 구문 분석 할 때 예외가 발생했습니다

private void listContainers() { 
     ContainerApi containerApi = swiftApi.getContainerApiForRegion("region"); 
     Set<Container> containers = containerApi.list().toSet(); 

     for (Container container : containers) { 
      ObjectApi objectApi = swiftApi.getObjectApiForRegionAndContainer("region", container.getName()); 

      ObjectList objects = objectApi.list(); // crashes here 
      for (SwiftObject object: objects) { 
      System.out.println("\t\t"+ object); 
      } 

      System.out.println("\t" + container); 
     } 
    } 

콘솔 출력은 : 나는 파일 이름을 지정하고 '메타 데이터를 가져 오는 경우

DEBUG o.j.rest.internal.InvokeHttpMethod - >> invoking container:list 
DEBUG o.j.h.i.JavaUrlHttpCommandExecutorService - Sending request -363056976: GET http://127.0.0.1/swift/v1/?format=json HTTP/1.1 
DEBUG jclouds.headers - >> GET http://127.0.0.1/swift/v1/?format=json HTTP/1.1 
DEBUG jclouds.headers - >> Accept: application/json 
DEBUG jclouds.headers - >> X-Auth-Token: MIIQ... 
DEBUG o.j.h.i.JavaUrlHttpCommandExecutorService - Receiving response -363056976: HTTP/1.1 200 OK 
DEBUG jclouds.headers - << HTTP/1.1 200 OK 
DEBUG jclouds.headers - << Transfer-Encoding: chunked 
DEBUG jclouds.headers - << Date: Tue, 25 Nov 2014 07:39:44 GMT 
DEBUG jclouds.headers - << Keep-Alive: timeout=5, max=98 
DEBUG jclouds.headers - << Connection: Keep-Alive 
DEBUG jclouds.headers - << Server: Apache/2.2.22 (Ubuntu) 
DEBUG jclouds.headers - << Content-Type: application/json; charset=utf-8 
DEBUG jclouds.wire - << "[{"name":"jclouds-example","count":1,"bytes":12},{"name":"test_name","count":3,"bytes":22008217}]" 
DEBUG o.j.rest.internal.InvokeHttpMethod - >> invoking object:list 
DEBUG o.j.h.i.JavaUrlHttpCommandExecutorService - Sending request -1472717862: GET http://127.0.0.1/swift/v1/jclouds-example/?format=json HTTP/1.1 
DEBUG jclouds.headers - >> GET http://127.0.0.1/swift/v1/jclouds-example/?format=json HTTP/1.1 
DEBUG jclouds.headers - >> Accept: application/json 
DEBUG jclouds.headers - >> X-Auth-Token: MIIQ... 
DEBUG o.j.h.i.JavaUrlHttpCommandExecutorService - Receiving response -1472717862: HTTP/1.1 200 OK 
DEBUG jclouds.headers - << HTTP/1.1 200 OK 
DEBUG jclouds.headers - << Transfer-Encoding: chunked 
DEBUG jclouds.headers - << Date: Tue, 25 Nov 2014 07:39:44 GMT 
DEBUG jclouds.headers - << Keep-Alive: timeout=5, max=97 
DEBUG jclouds.headers - << Connection: Keep-Alive 
DEBUG jclouds.headers - << Server: Apache/2.2.22 (Ubuntu) 
DEBUG jclouds.headers - << Content-Type: application/json; charset=utf-8 
DEBUG jclouds.wire - << "[{"name":"jclouds-example.txt","hash":"ed076287532e86365e841e92bfc50d8c","bytes":12,"content_type":"application\/unknown","last_modified":"2014-11-25T07:39:44.000Z"}]" 
java.lang.NumberFormatException: null 
    at java.lang.Long.parseLong(Long.java:404) 
    at java.lang.Long.parseLong(Long.java:483) 
    at org.jclouds.openstack.swift.v1.functions.ParseContainerFromHeaders.apply(ParseContainerFromHeaders.java:39) 
    at org.jclouds.openstack.swift.v1.functions.ParseObjectListFromResponse.apply(ParseObjectListFromResponse.java:66) 
    at org.jclouds.openstack.swift.v1.functions.ParseObjectListFromResponse.apply(ParseObjectListFromResponse.java:41) 
    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.$Proxy66.list(Unknown Source) 
    at test.jcloud.JCloudsSwift.listContainers(JCloudsSwift.java:99) 
    at test.jcloud.JCloudsSwift.main(JCloudsSwift.java:39) 

, 모든 작동합니다 :

... 
for (Container container : containers) { 
    ObjectApi objectApi = swiftApi.getObjectApiForRegionAndContainer("region", container.getName()); 
    SwiftObject obj = objectApi.get("jclouds-example.txt"); 
    System.out.println("-- "+obj.getMetadata()); 
    ObjectList objects = objectApi.list(); 
... 

콘솔 출력 :

DEBUG o.j.rest.internal.InvokeHttpMethod - >> invoking object:get 
DEBUG o.j.h.i.JavaUrlHttpCommandExecutorService - Sending request -614124758: GET http://127.0.0.1/swift/v1/jclouds-example/jclouds-example.txt HTTP/1.1 
DEBUG jclouds.headers - >> GET http://127.0.0.1/swift/v1/jclouds-example/jclouds-example.txt HTTP/1.1 
DEBUG jclouds.headers - >> Accept: application/json 
DEBUG jclouds.headers - >> X-Auth-Token: MIIQ... 
DEBUG o.j.h.i.JavaUrlHttpCommandExecutorService - Receiving response -614124758: HTTP/1.1 200 OK 
DEBUG jclouds.headers - << HTTP/1.1 200 OK 
DEBUG jclouds.headers - << etag: ed076287532e86365e841e92bfc50d8c 
DEBUG jclouds.headers - << Date: Tue, 25 Nov 2014 07:48:49 GMT 
DEBUG jclouds.headers - << Last-Modified: Tue, 25 Nov 2014 07:48:49 GMT 
DEBUG jclouds.headers - << Keep-Alive: timeout=5, max=97 
DEBUG jclouds.headers - << X-Object-Meta-key4: blu 
DEBUG jclouds.headers - << X-Object-Meta-key3: value3 
DEBUG jclouds.headers - << Connection: Keep-Alive 
DEBUG jclouds.headers - << Accept-Ranges: bytes 
DEBUG jclouds.headers - << Server: Apache/2.2.22 (Ubuntu) 
DEBUG jclouds.headers - << Content-Type: application/unknown 
DEBUG jclouds.headers - << Content-Length: 12 
DEBUG jclouds.wire - << "Hello World!" 
-- {key4=blu, key3=value3} 

코드는를 기반으로합니다. jclouds 자바 객체에 객체 목록이 포함 된 JSON 데이터를 변환 할 때예와 this 예를

문제

개체 정보를 얻기 나는 NumberFormatException를 얻을.

질문

어떻게 각 컨테이너에 대한 파일 목록을 자신의 메타 데이터를 얻을 수 있나요?

답변

1

jclouds 1.8.1을 사용하여 OpenStack Juno에서이 기능을 시험해 보았습니다. OpenStack 및 jclouds의 어떤 버전을 사용하고 있습니까?

개체 목록 응답에 X-Container-Object-CountX-Container-Bytes-Used 헤더가 없습니다. 이상하게 들리면, 그들은이 api reference에 따라 거기에 있어야합니다. Apache 서버가 헤더를 조작하거나 필터링하고 있습니까?

jclouds 1.8.1을 사용하려면 먼저 release notes을 읽어야합니다.

+0

jclouds 1.8.1 및 openstack 2014.1을 사용하고 있습니다. – gkiko

+0

스위프트는 실제로 X-Container-Object-Count 및 X-Container-Bytes-Used 헤더를 다시 가져와야하며, 2014.1 이전부터 사용 해왔습니다. server.py] (https://github.com/openstack/swift/blob/fbc58b082cf93eb142c038f24e75ec01e6005894/swift/container/server.py#L62-70)). Apache 서버가 헤더를 조작하거나 필터링하고 있습니까? –

+0

또한 어떻게 끝낼 수 있습니까? format = json'GET http : //127.0.0.1/swift/v1/jclouds-example/? format = json'? 1.8.1에서 ObjectApi.list()를 호출 할 때 그렇게 할 방법이 없습니다 ([ObjectApi.java] (https://github.com/jclouds/jclouds/blob/master/apis/openstack-swift/src/main 참조). /java/org/jclouds/openstack/swift/v1/features/ObjectApi.java#L79-84)). –

관련 문제