Issue 108

git-svn-id: http://jclouds.googlecode.com/svn/trunk@1943 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
adrian.f.cole 2009-10-04 00:25:12 +00:00
parent e95e8f3429
commit f78670f871
14 changed files with 185 additions and 116 deletions

View File

@ -23,7 +23,6 @@
*/
package org.jclouds.aws.s3.domain;
import java.util.List;
import java.util.SortedSet;
/**
@ -31,7 +30,7 @@ import java.util.SortedSet;
* @author Adrian Cole
*
*/
public class ArrayListBucketResponse extends org.jclouds.rest.BoundedTreeSet<ObjectMetadata>
public class TreeSetListBucketResponse extends org.jclouds.rest.BoundedTreeSet<ObjectMetadata>
implements ListBucketResponse {
/** The serialVersionUID */
private static final long serialVersionUID = -4475709781001190244L;
@ -40,8 +39,8 @@ public class ArrayListBucketResponse extends org.jclouds.rest.BoundedTreeSet<Obj
private final SortedSet<String> commonPrefixes;
private final boolean truncated;
public ArrayListBucketResponse(String bucketName, List<ObjectMetadata> contents, String prefix,
String marker, int maxResults, String delimiter, boolean isTruncated,
public TreeSetListBucketResponse(String bucketName, SortedSet<ObjectMetadata> contents,
String prefix, String marker, int maxResults, String delimiter, boolean isTruncated,
SortedSet<String> commonPrefixes) {
super(contents, prefix, marker, maxResults);
this.delimiter = delimiter;

View File

@ -23,29 +23,30 @@
*/
package org.jclouds.aws.s3.xml;
import java.util.ArrayList;
import java.util.List;
import java.util.SortedSet;
import javax.inject.Inject;
import org.jclouds.aws.s3.domain.CanonicalUser;
import org.jclouds.aws.s3.domain.BucketMetadata;
import org.jclouds.aws.s3.domain.CanonicalUser;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.util.DateService;
import javax.inject.Inject;
import com.google.common.collect.Sets;
/**
* Parses the following XML document:
* <p/>
* ListAllMyBucketsResult xmlns="http://doc.s3.amazonaws.com/2006-03-01"
* SortedSetAllMyBucketsResult xmlns="http://doc.s3.amazonaws.com/2006-03-01"
*
* @see <a
* href="http://docs.amazonwebservices.com/AmazonS3/2006-03-01/index.html?RESTServiceGET.html"
* />
* @author Adrian Cole
*/
public class ListAllMyBucketsHandler extends ParseSax.HandlerWithResult<List<BucketMetadata>> {
public class ListAllMyBucketsHandler extends ParseSax.HandlerWithResult<SortedSet<BucketMetadata>> {
private List<BucketMetadata> buckets = new ArrayList<BucketMetadata>();
private SortedSet<BucketMetadata> buckets = Sets.newTreeSet();
private BucketMetadata currentS3Bucket;
private CanonicalUser currentOwner;
private StringBuilder currentText = new StringBuilder();
@ -57,7 +58,7 @@ public class ListAllMyBucketsHandler extends ParseSax.HandlerWithResult<List<Buc
this.dateParser = dateParser;
}
public List<BucketMetadata> getResult() {
public SortedSet<BucketMetadata> getResult() {
return buckets;
}

View File

@ -23,21 +23,20 @@
*/
package org.jclouds.aws.s3.xml;
import java.util.List;
import java.util.SortedSet;
import java.util.TreeSet;
import org.jclouds.aws.s3.domain.ArrayListBucketResponse;
import javax.inject.Inject;
import org.jclouds.aws.s3.domain.CanonicalUser;
import org.jclouds.aws.s3.domain.ListBucketResponse;
import org.jclouds.aws.s3.domain.ObjectMetadata;
import org.jclouds.aws.s3.domain.TreeSetListBucketResponse;
import org.jclouds.http.HttpUtils;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.util.DateService;
import org.xml.sax.Attributes;
import com.google.common.collect.Lists;
import javax.inject.Inject;
import com.google.common.collect.Sets;
/**
* Parses the following XML document:
@ -50,7 +49,7 @@ import javax.inject.Inject;
* />
*/
public class ListBucketHandler extends ParseSax.HandlerWithResult<ListBucketResponse> {
private List<ObjectMetadata> contents;
private SortedSet<ObjectMetadata> contents;
private SortedSet<String> commonPrefixes;
private ObjectMetadata currentObjectMetadata;
private CanonicalUser currentOwner;
@ -67,12 +66,12 @@ public class ListBucketHandler extends ParseSax.HandlerWithResult<ListBucketResp
@Inject
public ListBucketHandler(DateService dateParser) {
this.dateParser = dateParser;
this.contents = Lists.newArrayList();
this.commonPrefixes = new TreeSet<String>();
this.contents = Sets.newTreeSet();
this.commonPrefixes = Sets.newTreeSet();
}
public ListBucketResponse getResult() {
return new ArrayListBucketResponse(bucketName, contents, prefix, marker, maxResults,
return new TreeSetListBucketResponse(bucketName, contents, prefix, marker, maxResults,
delimiter, isTruncated, commonPrefixes);
}

View File

@ -0,0 +1,88 @@
/**
*
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.com>
*
* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
* ====================================================================
*/
package org.jclouds.aws.s3.config;
import static org.testng.Assert.assertEquals;
import org.jclouds.aws.s3.handlers.AWSClientErrorRetryHandler;
import org.jclouds.aws.s3.handlers.AWSRedirectionRetryHandler;
import org.jclouds.aws.s3.handlers.ParseAWSErrorFromXmlContent;
import org.jclouds.aws.s3.reference.S3Constants;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.http.handlers.DelegatingErrorHandler;
import org.jclouds.http.handlers.DelegatingRetryHandler;
import org.jclouds.util.Jsr330;
import org.testng.annotations.Test;
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
/**
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "s3.RestS3ConnectionModuleTest")
public class RestS3ConnectionModuleTest {
Injector createInjector() {
return Guice.createInjector(new RestS3ConnectionModule(), new ParserModule(), new AbstractModule() {
@Override
protected void configure() {
bindConstant().annotatedWith(Jsr330.named(S3Constants.PROPERTY_AWS_ACCESSKEYID)).to(
"user");
bindConstant().annotatedWith(Jsr330.named(S3Constants.PROPERTY_AWS_SECRETACCESSKEY))
.to("key");
bindConstant().annotatedWith(Jsr330.named(S3Constants.PROPERTY_S3_ENDPOINT)).to(
"http://localhost");
}
});
}
@Test
void testServerErrorHandler() {
DelegatingErrorHandler handler = createInjector().getInstance(DelegatingErrorHandler.class);
assertEquals(handler.getServerErrorHandler().getClass(), ParseAWSErrorFromXmlContent.class);
}
@Test
void testClientErrorHandler() {
DelegatingErrorHandler handler = createInjector().getInstance(DelegatingErrorHandler.class);
assertEquals(handler.getClientErrorHandler().getClass(), ParseAWSErrorFromXmlContent.class);
}
@Test
void testClientRetryHandler() {
DelegatingRetryHandler handler = createInjector().getInstance(DelegatingRetryHandler.class);
assertEquals(handler.getClientErrorRetryHandler().getClass(),
AWSClientErrorRetryHandler.class);
}
@Test
void testRedirectionRetryHandler() {
DelegatingRetryHandler handler = createInjector().getInstance(DelegatingRetryHandler.class);
assertEquals(handler.getRedirectionRetryHandler().getClass(),
AWSRedirectionRetryHandler.class);
}
}

View File

@ -26,20 +26,13 @@ package org.jclouds.aws.s3.config;
import static org.testng.Assert.assertEquals;
import org.jclouds.aws.s3.S3BlobStore;
import org.jclouds.aws.s3.S3Context;
import org.jclouds.aws.s3.config.S3ContextModule.S3ContextImpl;
import org.jclouds.aws.s3.domain.BucketMetadata;
import org.jclouds.aws.s3.domain.ObjectMetadata;
import org.jclouds.aws.s3.domain.S3Object;
import org.jclouds.aws.s3.handlers.AWSClientErrorRetryHandler;
import org.jclouds.aws.s3.handlers.AWSRedirectionRetryHandler;
import org.jclouds.aws.s3.handlers.ParseAWSErrorFromXmlContent;
import org.jclouds.aws.s3.reference.S3Constants;
import org.jclouds.blobstore.BlobStoreMapsModule;
import org.jclouds.concurrent.WithinThreadExecutorService;
import org.jclouds.concurrent.config.ExecutorServiceModule;
import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.http.handlers.DelegatingErrorHandler;
import org.jclouds.http.handlers.DelegatingRetryHandler;
import org.jclouds.util.Jsr330;
import org.testng.annotations.Test;
@ -54,7 +47,7 @@ import com.google.inject.TypeLiteral;
public class S3ContextModuleTest {
Injector createInjector() {
return Guice.createInjector(new RestS3ConnectionModule(), BlobStoreMapsModule.Builder
return Guice.createInjector(new StubS3BlobStoreModule(), BlobStoreMapsModule.Builder
.newBuilder(new TypeLiteral<S3BlobStore>() {
}, new TypeLiteral<BucketMetadata>() {
}, new TypeLiteral<ObjectMetadata>() {
@ -70,34 +63,13 @@ public class S3ContextModuleTest {
"http://localhost");
super.configure();
}
}, new ParserModule(), new JavaUrlHttpCommandExecutorServiceModule(),
new ExecutorServiceModule(new WithinThreadExecutorService()));
});
}
@Test
void testServerErrorHandler() {
DelegatingErrorHandler handler = createInjector().getInstance(DelegatingErrorHandler.class);
assertEquals(handler.getServerErrorHandler().getClass(), ParseAWSErrorFromXmlContent.class);
}
@Test
void testClientErrorHandler() {
DelegatingErrorHandler handler = createInjector().getInstance(DelegatingErrorHandler.class);
assertEquals(handler.getClientErrorHandler().getClass(), ParseAWSErrorFromXmlContent.class);
}
@Test
void testClientRetryHandler() {
DelegatingRetryHandler handler = createInjector().getInstance(DelegatingRetryHandler.class);
assertEquals(handler.getClientErrorRetryHandler().getClass(),
AWSClientErrorRetryHandler.class);
}
@Test
void testRedirectionRetryHandler() {
DelegatingRetryHandler handler = createInjector().getInstance(DelegatingRetryHandler.class);
assertEquals(handler.getRedirectionRetryHandler().getClass(),
AWSRedirectionRetryHandler.class);
void testContextImpl() {
S3Context handler = createInjector().getInstance(S3Context.class);
assertEquals(handler.getClass(), S3ContextImpl.class);
}
}

View File

@ -36,12 +36,12 @@ import javax.inject.Provider;
import org.jclouds.aws.s3.S3BlobStore;
import org.jclouds.aws.s3.domain.AccessControlList;
import org.jclouds.aws.s3.domain.ArrayListBucketResponse;
import org.jclouds.aws.s3.domain.BucketMetadata;
import org.jclouds.aws.s3.domain.CannedAccessPolicy;
import org.jclouds.aws.s3.domain.ListBucketResponse;
import org.jclouds.aws.s3.domain.ObjectMetadata;
import org.jclouds.aws.s3.domain.S3Object;
import org.jclouds.aws.s3.domain.TreeSetListBucketResponse;
import org.jclouds.aws.s3.domain.AccessControlList.CanonicalUserGrantee;
import org.jclouds.aws.s3.domain.AccessControlList.EmailAddressGrantee;
import org.jclouds.aws.s3.domain.AccessControlList.Grant;
@ -61,7 +61,6 @@ import org.joda.time.DateTime;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.google.inject.internal.Nullable;
@ -167,8 +166,8 @@ public class StubS3BlobStore extends StubBlobStore<BucketMetadata, ObjectMetadat
}
contents = contentsSlice;
}
return new ArrayListBucketResponse(name, Lists.newArrayList(contents), prefix, marker,
maxResults, delimiter, truncated, commonPrefixes);
return new TreeSetListBucketResponse(name, contents, prefix, marker, maxResults,
delimiter, truncated, commonPrefixes);
}
};
}

View File

@ -27,7 +27,7 @@ import static org.testng.Assert.assertEquals;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.List;
import java.util.SortedSet;
import java.util.concurrent.Callable;
import java.util.concurrent.CompletionService;
import java.util.concurrent.ExecutionException;
@ -84,8 +84,8 @@ public class S3ParserTest extends PerformanceTest {
}
@SuppressWarnings("unchecked")
private List<BucketMetadata> runParseListAllMyBuckets() throws HttpException {
return (List<BucketMetadata>) factory.create(
private SortedSet<BucketMetadata> runParseListAllMyBuckets() throws HttpException {
return (SortedSet<BucketMetadata>) factory.create(
injector.getInstance(ListAllMyBucketsHandler.class)).parse(
IOUtils.toInputStream(listAllMyBucketsResultOn200));
}
@ -93,11 +93,11 @@ public class S3ParserTest extends PerformanceTest {
@Test
void testParseListAllMyBucketsParallelResponseTime() throws InterruptedException,
ExecutionException {
CompletionService<List<BucketMetadata>> completer = new ExecutorCompletionService<List<BucketMetadata>>(
CompletionService<SortedSet<BucketMetadata>> completer = new ExecutorCompletionService<SortedSet<BucketMetadata>>(
exec);
for (int i = 0; i < LOOP_COUNT; i++)
completer.submit(new Callable<List<BucketMetadata>>() {
public List<BucketMetadata> call() throws IOException, SAXException, HttpException {
completer.submit(new Callable<SortedSet<BucketMetadata>>() {
public SortedSet<BucketMetadata> call() throws IOException, SAXException, HttpException {
return runParseListAllMyBuckets();
}
});
@ -107,13 +107,13 @@ public class S3ParserTest extends PerformanceTest {
@Test
public void testCanParseListAllMyBuckets() throws HttpException {
List<BucketMetadata> s3Buckets = runParseListAllMyBuckets();
BucketMetadata container1 = s3Buckets.get(0);
SortedSet<BucketMetadata> s3Buckets = runParseListAllMyBuckets();
BucketMetadata container1 = s3Buckets.first();
assert container1.getName().equals("adrianjbosstest");
DateTime expectedDate1 = new DateTime("2009-03-12T02:00:07.000Z");
DateTime date1 = container1.getCreationDate();
assert date1.equals(expectedDate1);
BucketMetadata container2 = s3Buckets.get(1);
BucketMetadata container2 = (BucketMetadata) s3Buckets.toArray()[1];
assert container2.getName().equals("adrianjbosstest2");
DateTime expectedDate2 = new DateTime("2009-03-12T02:00:09.000Z");
DateTime date2 = container2.getCreationDate();

View File

@ -24,8 +24,7 @@
package org.jclouds.mezeo.pcs2.xml;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import java.util.SortedSet;
import javax.inject.Inject;
@ -36,13 +35,15 @@ import org.joda.time.DateTime;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import com.google.common.collect.Sets;
/**
* @author Adrian Cole
*/
public class FileListToContainerMetadataListHandler extends
ParseSax.HandlerWithResult<List<ContainerMetadata>> {
ParseSax.HandlerWithResult<SortedSet<ContainerMetadata>> {
private List<ContainerMetadata> containerMetadata = new ArrayList<ContainerMetadata>();
private SortedSet<ContainerMetadata> containerMetadata = Sets.newTreeSet();
private URI currentUrl;
private String currentName;
private DateTime currentCreated;
@ -63,7 +64,7 @@ public class FileListToContainerMetadataListHandler extends
this.dateParser = dateParser;
}
public List<ContainerMetadata> getResult() {
public SortedSet<ContainerMetadata> getResult() {
return containerMetadata;
}

View File

@ -24,8 +24,7 @@
package org.jclouds.mezeo.pcs2.xml;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import java.util.SortedSet;
import javax.inject.Inject;
@ -34,20 +33,22 @@ import org.jclouds.util.DateService;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import com.google.common.collect.Sets;
/**
* @author Adrian Cole
*/
public class FileListToFileMetadataListHandler extends
BaseFileMetadataHandler<List<FileMetadata>> {
BaseFileMetadataHandler<SortedSet<FileMetadata>> {
private List<FileMetadata> containerMetadata = new ArrayList<FileMetadata>();
private SortedSet<FileMetadata> containerMetadata = Sets.newTreeSet();
@Inject
public FileListToFileMetadataListHandler(DateService dateParser) {
super(dateParser);
}
public List<FileMetadata> getResult() {
public SortedSet<FileMetadata> getResult() {
return containerMetadata;
}

View File

@ -27,7 +27,7 @@ import static org.testng.Assert.assertEquals;
import java.io.InputStream;
import java.net.URI;
import java.util.List;
import java.util.SortedSet;
import org.jclouds.http.functions.BaseHandlerTest;
import org.jclouds.mezeo.pcs2.domain.ContainerMetadata;
@ -35,7 +35,7 @@ import org.jclouds.util.DateService;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSortedSet;
/**
* Tests behavior of {@code FileListToContainerMetadataListHandler}
@ -58,7 +58,7 @@ public class FileListToContainerMetadataListHandlerTest extends BaseHandlerTest
@SuppressWarnings("unchecked")
public void testApplyInputStream() {
InputStream is = getClass().getResourceAsStream("/test_file_list.xml");
List<ContainerMetadata> list = ImmutableList
SortedSet<ContainerMetadata> list = ImmutableSortedSet
.of(new ContainerMetadata(
"test1",
URI
@ -67,7 +67,7 @@ public class FileListToContainerMetadataListHandlerTest extends BaseHandlerTest
dateService.fromSeconds(1254008227), "adrian@jclouds.org", true, false, 1,
1024));
List<ContainerMetadata> result = (List<ContainerMetadata>) factory.create(
SortedSet<ContainerMetadata> result = (SortedSet<ContainerMetadata>) factory.create(
injector.getInstance(FileListToContainerMetadataListHandler.class)).parse(is);
assertEquals(result, list);

View File

@ -27,7 +27,7 @@ import static org.testng.Assert.assertEquals;
import java.io.InputStream;
import java.net.URI;
import java.util.List;
import java.util.SortedSet;
import javax.ws.rs.core.MediaType;
@ -37,10 +37,10 @@ import org.jclouds.util.DateService;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSortedSet;
/**
* Tests behavior of {@code FileListToFileMetadataListHandler}
* Tests behavior of {@code FileSortedSetToFileMetadataSortedSetHandler}
*
* @author Adrian Cole
*/
@ -60,7 +60,7 @@ public class FileListToFileMetadataListHandlerTest extends BaseHandlerTest {
@SuppressWarnings("unchecked")
public void testApplyInputStream() {
InputStream is = getClass().getResourceAsStream("/test_file_list.xml");
List<FileMetadata> list = ImmutableList.of(new FileMetadata("more", URI
SortedSet<FileMetadata> list = ImmutableSortedSet.of(new FileMetadata("more", URI
.create("https://pcsbeta.mezeo.net/v2/files/5C81DADC-AAEE-11DE-9D55-B39340AEFF3A"),
dateService.fromSeconds(1254005157), dateService.fromSeconds(1254005158),
dateService.fromSeconds(1254005159), "adrian@jclouds.org", false, false, 1, 254288,
@ -72,7 +72,7 @@ public class FileListToFileMetadataListHandlerTest extends BaseHandlerTest {
dateService.fromSeconds(1254000182), "adrian@jclouds.org", false, true, 3, 5,
MediaType.TEXT_PLAIN, false));
List<FileMetadata> result = (List<FileMetadata>) factory.create(
SortedSet<FileMetadata> result = (SortedSet<FileMetadata>) factory.create(
injector.getInstance(FileListToFileMetadataListHandler.class)).parse(is);
assertEquals(result, list);

View File

@ -27,7 +27,9 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Type;
import java.util.List;
import java.util.SortedSet;
import javax.inject.Inject;
import org.jclouds.blobstore.domain.BlobMetadata;
import org.jclouds.http.HttpUtils;
@ -35,24 +37,24 @@ import org.jclouds.http.functions.ParseJson;
import org.joda.time.DateTime;
import com.google.common.base.Function;
import com.google.common.collect.Lists;
import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import javax.inject.Inject;
/**
* This parses {@link BlobMetadata} from a gson string.
*
* @author Adrian Cole
*/
public class ParseBlobMetadataListFromJsonResponse extends ParseJson<List<BlobMetadata>> {
public class ParseBlobMetadataListFromJsonResponse extends ParseJson<SortedSet<BlobMetadata>> {
@Inject
public ParseBlobMetadataListFromJsonResponse(Gson gson) {
super(gson);
}
public static class CloudFilesMetadata {
public static class CloudFilesMetadata implements Comparable<CloudFilesMetadata> {
public CloudFilesMetadata() {
}
@ -61,25 +63,30 @@ public class ParseBlobMetadataListFromJsonResponse extends ParseJson<List<BlobMe
long bytes;
String content_type;
DateTime last_modified;
public int compareTo(CloudFilesMetadata o) {
return (this == o) ? 0 : name.compareTo(o.name);
}
}
public List<BlobMetadata> apply(InputStream stream) {
Type listType = new TypeToken<List<CloudFilesMetadata>>() {
public SortedSet<BlobMetadata> apply(InputStream stream) {
Type listType = new TypeToken<SortedSet<CloudFilesMetadata>>() {
}.getType();
try {
List<CloudFilesMetadata> list = gson.fromJson(new InputStreamReader(stream, "UTF-8"),
SortedSet<CloudFilesMetadata> list = gson.fromJson(new InputStreamReader(stream, "UTF-8"),
listType);
return Lists.transform(list, new Function<CloudFilesMetadata, BlobMetadata>() {
public BlobMetadata apply(CloudFilesMetadata from) {
BlobMetadata metadata = new BlobMetadata(from.name);
metadata.setSize(from.bytes);
metadata.setLastModified(from.last_modified);
metadata.setContentType(from.content_type);
metadata.setETag(HttpUtils.fromHexString(from.hash));
return metadata;
}
});
return Sets.newTreeSet(Iterables.transform(list,
new Function<CloudFilesMetadata, BlobMetadata>() {
public BlobMetadata apply(CloudFilesMetadata from) {
BlobMetadata metadata = new BlobMetadata(from.name);
metadata.setSize(from.bytes);
metadata.setLastModified(from.last_modified);
metadata.setContentType(from.content_type);
metadata.setETag(HttpUtils.fromHexString(from.hash));
return metadata;
}
}));
} catch (UnsupportedEncodingException e) {
throw new RuntimeException("jclouds requires UTF-8 encoding", e);

View File

@ -27,21 +27,22 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Type;
import java.util.List;
import java.util.SortedSet;
import javax.inject.Inject;
import org.jclouds.http.functions.ParseJson;
import org.jclouds.rackspace.cloudfiles.domain.ContainerCDNMetadata;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import javax.inject.Inject;
/**
* This parses {@link ContainerCDNMetadata} from a gson string.
*
* @author James Murty
*/
public class ParseContainerCDNMetadataListFromGsonResponse extends ParseJson<List<ContainerCDNMetadata>>
public class ParseContainerCDNMetadataListFromGsonResponse extends ParseJson<SortedSet<ContainerCDNMetadata>>
{
@Inject
@ -49,8 +50,8 @@ public class ParseContainerCDNMetadataListFromGsonResponse extends ParseJson<Lis
super(gson);
}
public List<ContainerCDNMetadata> apply(InputStream stream) {
Type listType = new TypeToken<List<ContainerCDNMetadata>>() {
public SortedSet<ContainerCDNMetadata> apply(InputStream stream) {
Type listType = new TypeToken<SortedSet<ContainerCDNMetadata>>() {
}.getType();
try {
return gson.fromJson(new InputStreamReader(stream, "UTF-8"), listType);

View File

@ -27,29 +27,30 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Type;
import java.util.List;
import java.util.SortedSet;
import javax.inject.Inject;
import org.jclouds.http.functions.ParseJson;
import org.jclouds.rackspace.cloudfiles.domain.ContainerMetadata;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import javax.inject.Inject;
/**
* This parses {@link ContainerMetadata} from a gson string.
*
* @author Adrian Cole
*/
public class ParseContainerListFromJsonResponse extends ParseJson<List<ContainerMetadata>> {
public class ParseContainerListFromJsonResponse extends ParseJson<SortedSet<ContainerMetadata>> {
@Inject
public ParseContainerListFromJsonResponse(Gson gson) {
super(gson);
}
public List<ContainerMetadata> apply(InputStream stream) {
Type listType = new TypeToken<List<ContainerMetadata>>() {
public SortedSet<ContainerMetadata> apply(InputStream stream) {
Type listType = new TypeToken<SortedSet<ContainerMetadata>>() {
}.getType();
try {
return gson.fromJson(new InputStreamReader(stream, "UTF-8"), listType);