mirror of https://github.com/apache/jclouds.git
Removed dependency of apache commons-io as it overlaps with guava. note guava will include google collections soon
git-svn-id: http://jclouds.googlecode.com/svn/trunk@2457 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
parent
f2e7e259d3
commit
8116d47b67
|
@ -35,7 +35,6 @@ import javax.inject.Provider;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
import javax.ws.rs.core.HttpHeaders;
|
import javax.ws.rs.core.HttpHeaders;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.jclouds.atmosonline.saas.reference.AtmosStorageConstants;
|
import org.jclouds.atmosonline.saas.reference.AtmosStorageConstants;
|
||||||
import org.jclouds.atmosonline.saas.reference.AtmosStorageHeaders;
|
import org.jclouds.atmosonline.saas.reference.AtmosStorageHeaders;
|
||||||
import org.jclouds.date.TimeStamp;
|
import org.jclouds.date.TimeStamp;
|
||||||
|
@ -47,6 +46,7 @@ import org.jclouds.http.HttpRequestFilter;
|
||||||
import org.jclouds.http.HttpUtils;
|
import org.jclouds.http.HttpUtils;
|
||||||
import org.jclouds.http.internal.SignatureWire;
|
import org.jclouds.http.internal.SignatureWire;
|
||||||
import org.jclouds.logging.Logger;
|
import org.jclouds.logging.Logger;
|
||||||
|
import org.jclouds.util.Utils;
|
||||||
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
|
|
||||||
|
@ -65,6 +65,8 @@ public class SignRequest implements HttpRequestFilter {
|
||||||
private final byte[] key;
|
private final byte[] key;
|
||||||
private final Provider<String> timeStampProvider;
|
private final Provider<String> timeStampProvider;
|
||||||
private final EncryptionService encryptionService;
|
private final EncryptionService encryptionService;
|
||||||
|
@Resource
|
||||||
|
Logger logger = Logger.NULL;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
@Named(HttpConstants.SIGNATURE_LOGGER)
|
@Named(HttpConstants.SIGNATURE_LOGGER)
|
||||||
|
@ -106,7 +108,7 @@ public class SignRequest implements HttpRequestFilter {
|
||||||
throws HttpException {
|
throws HttpException {
|
||||||
String signature = signString(toSign);
|
String signature = signString(toSign);
|
||||||
if (signatureWire.enabled())
|
if (signatureWire.enabled())
|
||||||
signatureWire.input(IOUtils.toInputStream(signature));
|
signatureWire.input(Utils.toInputStream(signature));
|
||||||
request.getHeaders().replaceValues(AtmosStorageHeaders.SIGNATURE,
|
request.getHeaders().replaceValues(AtmosStorageHeaders.SIGNATURE,
|
||||||
Collections.singletonList(signature));
|
Collections.singletonList(signature));
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,6 @@ import java.security.SecureRandom;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.jclouds.atmosonline.saas.blobstore.strategy.RecursiveRemove;
|
import org.jclouds.atmosonline.saas.blobstore.strategy.RecursiveRemove;
|
||||||
import org.jclouds.atmosonline.saas.domain.AtmosObject;
|
import org.jclouds.atmosonline.saas.domain.AtmosObject;
|
||||||
import org.jclouds.atmosonline.saas.domain.BoundedSortedSet;
|
import org.jclouds.atmosonline.saas.domain.BoundedSortedSet;
|
||||||
|
@ -218,7 +217,7 @@ public class AtmosStorageClientLiveTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
Object makeData(String in, boolean stream) {
|
Object makeData(String in, boolean stream) {
|
||||||
return stream ? IOUtils.toInputStream(in) : in;
|
return stream ? Utils.toInputStream(in) : in;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createOrReplaceObject(String name, Object data, String metadataValue)
|
private void createOrReplaceObject(String name, Object data, String metadataValue)
|
||||||
|
@ -274,7 +273,7 @@ public class AtmosStorageClientLiveTest {
|
||||||
String metadataValue) throws InterruptedException, ExecutionException,
|
String metadataValue) throws InterruptedException, ExecutionException,
|
||||||
TimeoutException, IOException {
|
TimeoutException, IOException {
|
||||||
AtmosObject getBlob = connection.headFile(path);
|
AtmosObject getBlob = connection.headFile(path);
|
||||||
assertEquals(IOUtils.toString(getBlob.getContent()), "");
|
assertEquals(Utils.toStringAndClose(getBlob.getContent()), "");
|
||||||
verifyMetadata(metadataValue, getBlob);
|
verifyMetadata(metadataValue, getBlob);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -282,7 +281,7 @@ public class AtmosStorageClientLiveTest {
|
||||||
String metadataValue) throws InterruptedException, ExecutionException,
|
String metadataValue) throws InterruptedException, ExecutionException,
|
||||||
TimeoutException, IOException {
|
TimeoutException, IOException {
|
||||||
AtmosObject getBlob = connection.readFile(path);
|
AtmosObject getBlob = connection.readFile(path);
|
||||||
assertEquals(IOUtils.toString(getBlob.getContent()), compare);
|
assertEquals(Utils.toStringAndClose(getBlob.getContent()), compare);
|
||||||
verifyMetadata(metadataValue, getBlob);
|
verifyMetadata(metadataValue, getBlob);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,6 @@ import javax.inject.Provider;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
import javax.ws.rs.core.HttpHeaders;
|
import javax.ws.rs.core.HttpHeaders;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.jclouds.aws.reference.AWSConstants;
|
import org.jclouds.aws.reference.AWSConstants;
|
||||||
import org.jclouds.aws.util.RequestSigner;
|
import org.jclouds.aws.util.RequestSigner;
|
||||||
import org.jclouds.date.TimeStamp;
|
import org.jclouds.date.TimeStamp;
|
||||||
|
@ -59,6 +58,7 @@ import org.jclouds.http.internal.SignatureWire;
|
||||||
import org.jclouds.logging.Logger;
|
import org.jclouds.logging.Logger;
|
||||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||||
|
import org.jclouds.util.Utils;
|
||||||
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
|
@ -162,7 +162,7 @@ public class FormSigner implements HttpRequestFilter, RequestSigner {
|
||||||
try {
|
try {
|
||||||
signature = encryptionService.hmacSha256Base64(stringToSign, secretKey.getBytes());
|
signature = encryptionService.hmacSha256Base64(stringToSign, secretKey.getBytes());
|
||||||
if (signatureWire.enabled())
|
if (signatureWire.enabled())
|
||||||
signatureWire.input(IOUtils.toInputStream(signature));
|
signatureWire.input(Utils.toInputStream(signature));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new HttpException("error signing request", e);
|
throw new HttpException("error signing request", e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,6 @@ import javax.inject.Provider;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
import javax.ws.rs.core.HttpHeaders;
|
import javax.ws.rs.core.HttpHeaders;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.jclouds.aws.s3.reference.S3Constants;
|
import org.jclouds.aws.s3.reference.S3Constants;
|
||||||
import org.jclouds.aws.util.RequestSigner;
|
import org.jclouds.aws.util.RequestSigner;
|
||||||
import org.jclouds.date.TimeStamp;
|
import org.jclouds.date.TimeStamp;
|
||||||
|
@ -49,6 +48,7 @@ import org.jclouds.http.HttpRequestFilter;
|
||||||
import org.jclouds.http.HttpUtils;
|
import org.jclouds.http.HttpUtils;
|
||||||
import org.jclouds.http.internal.SignatureWire;
|
import org.jclouds.http.internal.SignatureWire;
|
||||||
import org.jclouds.logging.Logger;
|
import org.jclouds.logging.Logger;
|
||||||
|
import org.jclouds.util.Utils;
|
||||||
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
|
|
||||||
|
@ -111,7 +111,7 @@ public class RequestAuthorizeSignature implements HttpRequestFilter, RequestSign
|
||||||
throws HttpException {
|
throws HttpException {
|
||||||
String signature = signString(toSign);
|
String signature = signString(toSign);
|
||||||
if (signatureWire.enabled())
|
if (signatureWire.enabled())
|
||||||
signatureWire.input(IOUtils.toInputStream(signature));
|
signatureWire.input(Utils.toInputStream(signature));
|
||||||
request.getHeaders().replaceValues(HttpHeaders.AUTHORIZATION,
|
request.getHeaders().replaceValues(HttpHeaders.AUTHORIZATION,
|
||||||
Collections.singletonList("AWS " + accessKey + ":" + signature));
|
Collections.singletonList("AWS " + accessKey + ":" + signature));
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,14 +26,13 @@ package org.jclouds.aws.s3.xml;
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
import static org.testng.Assert.assertTrue;
|
import static org.testng.Assert.assertTrue;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.jclouds.aws.s3.domain.AccessControlList;
|
import org.jclouds.aws.s3.domain.AccessControlList;
|
||||||
import org.jclouds.aws.s3.domain.AccessControlList.GroupGranteeURI;
|
import org.jclouds.aws.s3.domain.AccessControlList.GroupGranteeURI;
|
||||||
import org.jclouds.aws.s3.domain.AccessControlList.Permission;
|
import org.jclouds.aws.s3.domain.AccessControlList.Permission;
|
||||||
import org.jclouds.aws.s3.xml.AccessControlListHandler;
|
|
||||||
import org.jclouds.http.HttpException;
|
import org.jclouds.http.HttpException;
|
||||||
import org.jclouds.http.functions.BaseHandlerTest;
|
import org.jclouds.http.functions.BaseHandlerTest;
|
||||||
import org.jclouds.http.functions.ParseSax;
|
import org.jclouds.http.functions.ParseSax;
|
||||||
|
import org.jclouds.util.Utils;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
@Test(groups = "unit", testName = "s3.AccessControlListHandlerTest")
|
@Test(groups = "unit", testName = "s3.AccessControlListHandlerTest")
|
||||||
|
@ -50,7 +49,7 @@ public class AccessControlListHandlerTest extends BaseHandlerTest {
|
||||||
@Test
|
@Test
|
||||||
public void testAccessControlListOwnerOnly() throws HttpException {
|
public void testAccessControlListOwnerOnly() throws HttpException {
|
||||||
String ownerId = "1a405254c932b52e5b5caaa88186bc431a1bacb9ece631f835daddaf0c47677c";
|
String ownerId = "1a405254c932b52e5b5caaa88186bc431a1bacb9ece631f835daddaf0c47677c";
|
||||||
AccessControlList acl = createParser().parse(IOUtils.toInputStream(aclOwnerOnly));
|
AccessControlList acl = createParser().parse(Utils.toInputStream(aclOwnerOnly));
|
||||||
assertEquals(acl.getOwner().getId(), ownerId);
|
assertEquals(acl.getOwner().getId(), ownerId);
|
||||||
assertEquals(acl.getOwner().getDisplayName(), "jamesmurty");
|
assertEquals(acl.getOwner().getDisplayName(), "jamesmurty");
|
||||||
assertEquals(acl.getPermissions(ownerId).size(), 1);
|
assertEquals(acl.getPermissions(ownerId).size(), 1);
|
||||||
|
@ -64,7 +63,7 @@ public class AccessControlListHandlerTest extends BaseHandlerTest {
|
||||||
@Test
|
@Test
|
||||||
public void testAccessControlListExtreme() throws HttpException {
|
public void testAccessControlListExtreme() throws HttpException {
|
||||||
String ownerId = "1a405254c932b52e5b5caaa88186bc431a1bacb9ece631f835daddaf0c47677c";
|
String ownerId = "1a405254c932b52e5b5caaa88186bc431a1bacb9ece631f835daddaf0c47677c";
|
||||||
AccessControlList acl = createParser().parse(IOUtils.toInputStream(aclExtreme));
|
AccessControlList acl = createParser().parse(Utils.toInputStream(aclExtreme));
|
||||||
assertEquals(acl.getOwner().getId(), ownerId);
|
assertEquals(acl.getOwner().getId(), ownerId);
|
||||||
assertEquals(acl.getOwner().getDisplayName(), "jamesmurty");
|
assertEquals(acl.getOwner().getDisplayName(), "jamesmurty");
|
||||||
assertEquals(acl.getPermissions(ownerId).size(), 3);
|
assertEquals(acl.getPermissions(ownerId).size(), 3);
|
||||||
|
|
|
@ -28,7 +28,6 @@ import static org.testng.Assert.assertEquals;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.jclouds.aws.s3.domain.CanonicalUser;
|
import org.jclouds.aws.s3.domain.CanonicalUser;
|
||||||
import org.jclouds.aws.s3.domain.ListBucketResponse;
|
import org.jclouds.aws.s3.domain.ListBucketResponse;
|
||||||
import org.jclouds.aws.s3.domain.ObjectMetadata;
|
import org.jclouds.aws.s3.domain.ObjectMetadata;
|
||||||
|
@ -41,6 +40,7 @@ import org.jclouds.encryption.internal.JCEEncryptionService;
|
||||||
import org.jclouds.http.HttpException;
|
import org.jclouds.http.HttpException;
|
||||||
import org.jclouds.http.functions.BaseHandlerTest;
|
import org.jclouds.http.functions.BaseHandlerTest;
|
||||||
import org.jclouds.http.functions.ParseSax;
|
import org.jclouds.http.functions.ParseSax;
|
||||||
|
import org.jclouds.util.Utils;
|
||||||
import org.testng.annotations.BeforeTest;
|
import org.testng.annotations.BeforeTest;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
@ -135,7 +135,7 @@ public class ListBucketHandlerTest extends BaseHandlerTest {
|
||||||
public void testListMyBucketsWithDelimiterSlashAndCommonPrefixesAppsSlash() throws HttpException {
|
public void testListMyBucketsWithDelimiterSlashAndCommonPrefixesAppsSlash() throws HttpException {
|
||||||
|
|
||||||
ListBucketResponse bucket = createParser().parse(
|
ListBucketResponse bucket = createParser().parse(
|
||||||
IOUtils.toInputStream(listBucketWithSlashDelimiterAndCommonPrefixApps));
|
Utils.toInputStream(listBucketWithSlashDelimiterAndCommonPrefixApps));
|
||||||
assertEquals(bucket.getCommonPrefixes().iterator().next(), "apps/");
|
assertEquals(bucket.getCommonPrefixes().iterator().next(), "apps/");
|
||||||
assertEquals(bucket.getDelimiter(), "/");
|
assertEquals(bucket.getDelimiter(), "/");
|
||||||
assert bucket.getMarker() == null;
|
assert bucket.getMarker() == null;
|
||||||
|
@ -145,7 +145,7 @@ public class ListBucketHandlerTest extends BaseHandlerTest {
|
||||||
public void testListMyBucketsWithPrefixAppsSlash() throws HttpException {
|
public void testListMyBucketsWithPrefixAppsSlash() throws HttpException {
|
||||||
|
|
||||||
ListBucketResponse bucket = createParser().parse(
|
ListBucketResponse bucket = createParser().parse(
|
||||||
IOUtils.toInputStream(listBucketWithPrefixAppsSlash));
|
Utils.toInputStream(listBucketWithPrefixAppsSlash));
|
||||||
assertEquals(bucket.getPrefix(), "apps/");
|
assertEquals(bucket.getPrefix(), "apps/");
|
||||||
assertEquals(bucket.getMaxKeys(), 1000);
|
assertEquals(bucket.getMaxKeys(), 1000);
|
||||||
assert bucket.getMarker() == null;
|
assert bucket.getMarker() == null;
|
||||||
|
|
|
@ -34,7 +34,6 @@ import java.util.concurrent.CompletionService;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.ExecutorCompletionService;
|
import java.util.concurrent.ExecutorCompletionService;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.jclouds.PerformanceTest;
|
import org.jclouds.PerformanceTest;
|
||||||
import org.jclouds.aws.s3.domain.BucketMetadata;
|
import org.jclouds.aws.s3.domain.BucketMetadata;
|
||||||
import org.jclouds.aws.s3.domain.CanonicalUser;
|
import org.jclouds.aws.s3.domain.CanonicalUser;
|
||||||
|
@ -45,6 +44,7 @@ import org.jclouds.date.internal.SimpleDateFormatDateService;
|
||||||
import org.jclouds.http.HttpException;
|
import org.jclouds.http.HttpException;
|
||||||
import org.jclouds.http.functions.ParseSax;
|
import org.jclouds.http.functions.ParseSax;
|
||||||
import org.jclouds.http.functions.config.ParserModule;
|
import org.jclouds.http.functions.config.ParserModule;
|
||||||
|
import org.jclouds.util.Utils;
|
||||||
import org.testng.annotations.AfterTest;
|
import org.testng.annotations.AfterTest;
|
||||||
import org.testng.annotations.BeforeTest;
|
import org.testng.annotations.BeforeTest;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
@ -87,7 +87,7 @@ public class S3ParserTest extends PerformanceTest {
|
||||||
private SortedSet<BucketMetadata> runParseListAllMyBuckets() throws HttpException {
|
private SortedSet<BucketMetadata> runParseListAllMyBuckets() throws HttpException {
|
||||||
return (SortedSet<BucketMetadata>) factory.create(
|
return (SortedSet<BucketMetadata>) factory.create(
|
||||||
injector.getInstance(ListAllMyBucketsHandler.class)).parse(
|
injector.getInstance(ListAllMyBucketsHandler.class)).parse(
|
||||||
IOUtils.toInputStream(listAllMyBucketsResultOn200));
|
Utils.toInputStream(listAllMyBucketsResultOn200));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -148,14 +148,14 @@ public class S3ParserTest extends PerformanceTest {
|
||||||
|
|
||||||
private ListBucketResponse runParseListContainerResult() throws HttpException {
|
private ListBucketResponse runParseListContainerResult() throws HttpException {
|
||||||
return (ListBucketResponse) factory.create(injector.getInstance(ListBucketHandler.class))
|
return (ListBucketResponse) factory.create(injector.getInstance(ListBucketHandler.class))
|
||||||
.parse(IOUtils.toInputStream(listContainerResult));
|
.parse(Utils.toInputStream(listContainerResult));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final String successfulCopyObject200 = "<CopyObjectResult xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"><LastModified>2009-03-19T13:23:27.000Z</LastModified><ETag>\"92836a3ea45a6984d1b4d23a747d46bb\"</ETag></CopyObjectResult>";
|
public static final String successfulCopyObject200 = "<CopyObjectResult xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"><LastModified>2009-03-19T13:23:27.000Z</LastModified><ETag>\"92836a3ea45a6984d1b4d23a747d46bb\"</ETag></CopyObjectResult>";
|
||||||
|
|
||||||
private ObjectMetadata runParseCopyObjectResult() throws HttpException {
|
private ObjectMetadata runParseCopyObjectResult() throws HttpException {
|
||||||
return (ObjectMetadata) factory.create(injector.getInstance(CopyObjectHandler.class)).parse(
|
return (ObjectMetadata) factory.create(injector.getInstance(CopyObjectHandler.class)).parse(
|
||||||
IOUtils.toInputStream(successfulCopyObject200));
|
Utils.toInputStream(successfulCopyObject200));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCanParseCopyObjectResult() throws HttpException, UnsupportedEncodingException {
|
public void testCanParseCopyObjectResult() throws HttpException, UnsupportedEncodingException {
|
||||||
|
|
|
@ -25,11 +25,11 @@ package org.jclouds.aws.xml;
|
||||||
|
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.jclouds.aws.domain.AWSError;
|
import org.jclouds.aws.domain.AWSError;
|
||||||
import org.jclouds.http.HttpException;
|
import org.jclouds.http.HttpException;
|
||||||
import org.jclouds.http.functions.BaseHandlerTest;
|
import org.jclouds.http.functions.BaseHandlerTest;
|
||||||
import org.jclouds.http.functions.ParseSax;
|
import org.jclouds.http.functions.ParseSax;
|
||||||
|
import org.jclouds.util.Utils;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
@Test(groups = "unit", testName = "s3.ErrorHandlerTest")
|
@Test(groups = "unit", testName = "s3.ErrorHandlerTest")
|
||||||
|
@ -45,7 +45,7 @@ public class ErrorHandlerTest extends BaseHandlerTest {
|
||||||
@Test
|
@Test
|
||||||
public void testErrorFromAmazonIfYouDontRemoveTransferEncodingHeader() throws HttpException {
|
public void testErrorFromAmazonIfYouDontRemoveTransferEncodingHeader() throws HttpException {
|
||||||
ParseSax<AWSError> parser = createParser();
|
ParseSax<AWSError> parser = createParser();
|
||||||
AWSError error = parser.parse(IOUtils
|
AWSError error = parser.parse(Utils
|
||||||
.toInputStream(errorFromAmazonIfYouDontRemoveTransferEncodingHeader));
|
.toInputStream(errorFromAmazonIfYouDontRemoveTransferEncodingHeader));
|
||||||
assertEquals(error.getCode(), "NotImplemented");
|
assertEquals(error.getCode(), "NotImplemented");
|
||||||
assertEquals(error.getMessage(),
|
assertEquals(error.getMessage(),
|
||||||
|
|
|
@ -33,7 +33,6 @@ import java.util.Properties;
|
||||||
|
|
||||||
import javax.servlet.ServletContextEvent;
|
import javax.servlet.ServletContextEvent;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.jclouds.blobstore.BlobStoreContext;
|
import org.jclouds.blobstore.BlobStoreContext;
|
||||||
import org.jclouds.blobstore.BlobStoreContextBuilder;
|
import org.jclouds.blobstore.BlobStoreContextBuilder;
|
||||||
import org.jclouds.blobstore.reference.BlobStoreConstants;
|
import org.jclouds.blobstore.reference.BlobStoreConstants;
|
||||||
|
@ -42,6 +41,7 @@ import org.jclouds.samples.googleappengine.GetAllContainersController;
|
||||||
|
|
||||||
import com.google.appengine.repackaged.com.google.common.collect.ImmutableList;
|
import com.google.appengine.repackaged.com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
|
import com.google.common.io.Closeables;
|
||||||
import com.google.inject.Guice;
|
import com.google.inject.Guice;
|
||||||
import com.google.inject.Injector;
|
import com.google.inject.Injector;
|
||||||
import com.google.inject.TypeLiteral;
|
import com.google.inject.TypeLiteral;
|
||||||
|
@ -90,7 +90,7 @@ public class GuiceServletConfig extends GuiceServletContextListener {
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
} finally {
|
} finally {
|
||||||
IOUtils.closeQuietly(input);
|
Closeables.closeQuietly(input);
|
||||||
}
|
}
|
||||||
return props;
|
return props;
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,13 +37,13 @@ import java.io.InputStream;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.jclouds.aws.s3.S3PropertiesBuilder;
|
import org.jclouds.aws.s3.S3PropertiesBuilder;
|
||||||
import org.jclouds.aws.s3.blobstore.S3BlobStoreContextBuilder;
|
import org.jclouds.aws.s3.blobstore.S3BlobStoreContextBuilder;
|
||||||
import org.jclouds.azure.storage.blob.AzureBlobPropertiesBuilder;
|
import org.jclouds.azure.storage.blob.AzureBlobPropertiesBuilder;
|
||||||
import org.jclouds.azure.storage.blob.blobstore.AzureBlobStoreContextBuilder;
|
import org.jclouds.azure.storage.blob.blobstore.AzureBlobStoreContextBuilder;
|
||||||
import org.jclouds.rackspace.cloudfiles.CloudFilesPropertiesBuilder;
|
import org.jclouds.rackspace.cloudfiles.CloudFilesPropertiesBuilder;
|
||||||
import org.jclouds.rackspace.cloudfiles.blobstore.CloudFilesBlobStoreContextBuilder;
|
import org.jclouds.rackspace.cloudfiles.blobstore.CloudFilesBlobStoreContextBuilder;
|
||||||
|
import org.jclouds.util.Utils;
|
||||||
import org.testng.annotations.BeforeTest;
|
import org.testng.annotations.BeforeTest;
|
||||||
import org.testng.annotations.Parameters;
|
import org.testng.annotations.Parameters;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
@ -94,7 +94,7 @@ public class GoogleAppEngineLiveTest {
|
||||||
@Test
|
@Test
|
||||||
public void shouldPass() throws InterruptedException, IOException {
|
public void shouldPass() throws InterruptedException, IOException {
|
||||||
InputStream i = url.openStream();
|
InputStream i = url.openStream();
|
||||||
String string = IOUtils.toString(i);
|
String string = Utils.toStringAndClose(i);
|
||||||
assert string.indexOf("Welcome") >= 0 : string;
|
assert string.indexOf("Welcome") >= 0 : string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,7 +102,7 @@ public class GoogleAppEngineLiveTest {
|
||||||
public void testGuiceJCloudsSerial() throws InterruptedException, IOException {
|
public void testGuiceJCloudsSerial() throws InterruptedException, IOException {
|
||||||
URL gurl = new URL(url, "/guice/containers.blobstore");
|
URL gurl = new URL(url, "/guice/containers.blobstore");
|
||||||
InputStream i = gurl.openStream();
|
InputStream i = gurl.openStream();
|
||||||
String string = IOUtils.toString(i);
|
String string = Utils.toStringAndClose(i);
|
||||||
assert string.indexOf("List") >= 0 : string;
|
assert string.indexOf("List") >= 0 : string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,7 +110,7 @@ public class GoogleAppEngineLiveTest {
|
||||||
public void testGuiceJCloudsParallel() throws InterruptedException, IOException {
|
public void testGuiceJCloudsParallel() throws InterruptedException, IOException {
|
||||||
URL gurl = new URL(url, "/guice/containers.blobstore");
|
URL gurl = new URL(url, "/guice/containers.blobstore");
|
||||||
InputStream i = gurl.openStream();
|
InputStream i = gurl.openStream();
|
||||||
String string = IOUtils.toString(i);
|
String string = Utils.toStringAndClose(i);
|
||||||
assert string.indexOf("List") >= 0 : string;
|
assert string.indexOf("List") >= 0 : string;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,6 @@ import java.util.concurrent.TimeoutException;
|
||||||
|
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.jclouds.aws.s3.S3AsyncClient;
|
import org.jclouds.aws.s3.S3AsyncClient;
|
||||||
import org.jclouds.aws.s3.S3Client;
|
import org.jclouds.aws.s3.S3Client;
|
||||||
import org.jclouds.aws.s3.domain.ListBucketResponse;
|
import org.jclouds.aws.s3.domain.ListBucketResponse;
|
||||||
|
@ -50,6 +49,7 @@ import org.jclouds.aws.s3.domain.AccessControlList.GroupGranteeURI;
|
||||||
import org.jclouds.aws.s3.domain.AccessControlList.Permission;
|
import org.jclouds.aws.s3.domain.AccessControlList.Permission;
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
import org.jclouds.blobstore.domain.Blob;
|
||||||
import org.jclouds.blobstore.integration.internal.BaseBlobStoreIntegrationTest;
|
import org.jclouds.blobstore.integration.internal.BaseBlobStoreIntegrationTest;
|
||||||
|
import org.jclouds.util.Utils;
|
||||||
import org.jets3t.service.S3ObjectsChunk;
|
import org.jets3t.service.S3ObjectsChunk;
|
||||||
import org.jets3t.service.S3Service;
|
import org.jets3t.service.S3Service;
|
||||||
import org.jets3t.service.S3ServiceException;
|
import org.jets3t.service.S3ServiceException;
|
||||||
|
@ -190,7 +190,7 @@ public class JCloudsS3ServiceLiveTest extends BaseBlobStoreIntegrationTest<S3Asy
|
||||||
|
|
||||||
// TODO null keys from s3object! assertEquals(object.getKey(), objectKey);
|
// TODO null keys from s3object! assertEquals(object.getKey(), objectKey);
|
||||||
assertNotNull(object.getDataInputStream());
|
assertNotNull(object.getDataInputStream());
|
||||||
assertEquals(IOUtils.toString(object.getDataInputStream()), objectValue);
|
assertEquals(Utils.toStringAndClose(object.getDataInputStream()), objectValue);
|
||||||
assertEquals(object.getContentLength(), objectValue.length());
|
assertEquals(object.getContentLength(), objectValue.length());
|
||||||
assertEquals(object.getMetadata(metadataName), metadataValue);
|
assertEquals(object.getMetadata(metadataName), metadataValue);
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,6 @@ import java.util.concurrent.CompletionService;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.ExecutorCompletionService;
|
import java.util.concurrent.ExecutorCompletionService;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.jclouds.date.internal.SimpleDateFormatDateService;
|
import org.jclouds.date.internal.SimpleDateFormatDateService;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
@ -50,7 +49,7 @@ public class S3ParserTest extends org.jclouds.aws.s3.xml.S3ParserTest {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InputStream getInputStream() throws IOException {
|
public InputStream getInputStream() throws IOException {
|
||||||
return IOUtils.toInputStream(content);
|
return org.jclouds.util.Utils.toInputStream(content);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected MockHttpURLClient(String content) {
|
protected MockHttpURLClient(String content) {
|
||||||
|
|
|
@ -35,7 +35,6 @@ import javax.inject.Provider;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
import javax.ws.rs.core.HttpHeaders;
|
import javax.ws.rs.core.HttpHeaders;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.jclouds.azure.storage.reference.AzureStorageConstants;
|
import org.jclouds.azure.storage.reference.AzureStorageConstants;
|
||||||
import org.jclouds.date.TimeStamp;
|
import org.jclouds.date.TimeStamp;
|
||||||
import org.jclouds.encryption.EncryptionService;
|
import org.jclouds.encryption.EncryptionService;
|
||||||
|
@ -46,6 +45,7 @@ import org.jclouds.http.HttpRequestFilter;
|
||||||
import org.jclouds.http.HttpUtils;
|
import org.jclouds.http.HttpUtils;
|
||||||
import org.jclouds.http.internal.SignatureWire;
|
import org.jclouds.http.internal.SignatureWire;
|
||||||
import org.jclouds.logging.Logger;
|
import org.jclouds.logging.Logger;
|
||||||
|
import org.jclouds.util.Utils;
|
||||||
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
|
|
||||||
|
@ -106,7 +106,7 @@ public class SharedKeyAuthentication implements HttpRequestFilter {
|
||||||
throws HttpException {
|
throws HttpException {
|
||||||
String signature = signString(toSign);
|
String signature = signString(toSign);
|
||||||
if (signatureWire.enabled())
|
if (signatureWire.enabled())
|
||||||
signatureWire.input(IOUtils.toInputStream(signature));
|
signatureWire.input(Utils.toInputStream(signature));
|
||||||
request.getHeaders().replaceValues(HttpHeaders.AUTHORIZATION,
|
request.getHeaders().replaceValues(HttpHeaders.AUTHORIZATION,
|
||||||
Collections.singletonList("SharedKey " + account + ":" + signature));
|
Collections.singletonList("SharedKey " + account + ":" + signature));
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,6 @@ import java.net.URL;
|
||||||
import java.security.SecureRandom;
|
import java.security.SecureRandom;
|
||||||
import java.util.SortedSet;
|
import java.util.SortedSet;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.jclouds.azure.storage.AzureStorageResponseException;
|
import org.jclouds.azure.storage.AzureStorageResponseException;
|
||||||
import org.jclouds.azure.storage.blob.domain.AzureBlob;
|
import org.jclouds.azure.storage.blob.domain.AzureBlob;
|
||||||
import org.jclouds.azure.storage.blob.domain.BlobProperties;
|
import org.jclouds.azure.storage.blob.domain.BlobProperties;
|
||||||
|
@ -280,7 +279,7 @@ public class AzureBlobClientLiveTest {
|
||||||
}
|
}
|
||||||
// Test GET of object (including updated metadata)
|
// Test GET of object (including updated metadata)
|
||||||
AzureBlob getBlob = connection.getBlob(privateContainer, object.getProperties().getName());
|
AzureBlob getBlob = connection.getBlob(privateContainer, object.getProperties().getName());
|
||||||
assertEquals(IOUtils.toString(getBlob.getContent()), data);
|
assertEquals(Utils.toStringAndClose(getBlob.getContent()), data);
|
||||||
// TODO assertEquals(getBlob.getName(), object.getProperties().getName());
|
// TODO assertEquals(getBlob.getName(), object.getProperties().getName());
|
||||||
assertEquals(getBlob.getContentLength(), new Long(data.length()));
|
assertEquals(getBlob.getContentLength(), new Long(data.length()));
|
||||||
assertEquals(getBlob.getProperties().getContentType(), "text/plain");
|
assertEquals(getBlob.getProperties().getContentType(), "text/plain");
|
||||||
|
@ -340,7 +339,7 @@ public class AzureBlobClientLiveTest {
|
||||||
// .getBlob(privateContainer, object.getProperties().getName(),
|
// .getBlob(privateContainer, object.getProperties().getName(),
|
||||||
// GetOptions.Builder.startAt(8)).get(120,
|
// GetOptions.Builder.startAt(8)).get(120,
|
||||||
// TimeUnit.SECONDS);
|
// TimeUnit.SECONDS);
|
||||||
// assertEquals(IOUtils.toString((InputStream) getBlob.getData()), data.substring(8));
|
// assertEquals(Utils.toStringAndClose((InputStream) getBlob.getData()), data.substring(8));
|
||||||
|
|
||||||
connection.deleteBlob(privateContainer, "object");
|
connection.deleteBlob(privateContainer, "object");
|
||||||
connection.deleteBlob(privateContainer, "chunked-object");
|
connection.deleteBlob(privateContainer, "chunked-object");
|
||||||
|
|
|
@ -33,12 +33,12 @@ import java.util.Collections;
|
||||||
|
|
||||||
import javax.ws.rs.core.HttpHeaders;
|
import javax.ws.rs.core.HttpHeaders;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.jclouds.blobstore.config.BlobStoreObjectModule;
|
import org.jclouds.blobstore.config.BlobStoreObjectModule;
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
import org.jclouds.blobstore.domain.Blob;
|
||||||
import org.jclouds.blobstore.domain.MutableBlobMetadata;
|
import org.jclouds.blobstore.domain.MutableBlobMetadata;
|
||||||
import org.jclouds.http.HttpException;
|
import org.jclouds.http.HttpException;
|
||||||
import org.jclouds.http.HttpResponse;
|
import org.jclouds.http.HttpResponse;
|
||||||
|
import org.jclouds.util.Utils;
|
||||||
import org.testng.annotations.BeforeTest;
|
import org.testng.annotations.BeforeTest;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ public class ParseBlobFromHeadersAndHttpContentTest {
|
||||||
HttpResponse response = createMock(HttpResponse.class);
|
HttpResponse response = createMock(HttpResponse.class);
|
||||||
MutableBlobMetadata meta = createMock(MutableBlobMetadata.class);
|
MutableBlobMetadata meta = createMock(MutableBlobMetadata.class);
|
||||||
expect(metadataParser.apply(response)).andReturn(meta);
|
expect(metadataParser.apply(response)).andReturn(meta);
|
||||||
InputStream test = IOUtils.toInputStream("test");
|
InputStream test = Utils.toInputStream("test");
|
||||||
|
|
||||||
expect(meta.getSize()).andReturn(-1l);
|
expect(meta.getSize()).andReturn(-1l);
|
||||||
meta.setSize(-1l);
|
meta.setSize(-1l);
|
||||||
|
|
|
@ -39,7 +39,6 @@ import java.io.UnsupportedEncodingException;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.SortedSet;
|
import java.util.SortedSet;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.jclouds.blobstore.ContainerNotFoundException;
|
import org.jclouds.blobstore.ContainerNotFoundException;
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
import org.jclouds.blobstore.domain.Blob;
|
||||||
import org.jclouds.blobstore.domain.BlobMetadata;
|
import org.jclouds.blobstore.domain.BlobMetadata;
|
||||||
|
@ -48,6 +47,7 @@ import org.jclouds.blobstore.util.BlobStoreUtils;
|
||||||
import org.jclouds.encryption.internal.JCEEncryptionService;
|
import org.jclouds.encryption.internal.JCEEncryptionService;
|
||||||
import org.jclouds.http.HttpResponseException;
|
import org.jclouds.http.HttpResponseException;
|
||||||
import org.jclouds.http.Payloads;
|
import org.jclouds.http.Payloads;
|
||||||
|
import org.jclouds.util.Utils;
|
||||||
import org.testng.annotations.DataProvider;
|
import org.testng.annotations.DataProvider;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
@ -291,7 +291,7 @@ public class BaseBlobIntegrationTest<A, S> extends BaseBlobStoreIntegrationTest<
|
||||||
@DataProvider(name = "putTests")
|
@DataProvider(name = "putTests")
|
||||||
public Object[][] createData1() throws IOException {
|
public Object[][] createData1() throws IOException {
|
||||||
|
|
||||||
String realObject = IOUtils.toString(new FileInputStream("pom.xml"));
|
String realObject = Utils.toStringAndClose(new FileInputStream("pom.xml"));
|
||||||
|
|
||||||
return new Object[][] { { "file", "text/xml", new File("pom.xml"), realObject },
|
return new Object[][] { { "file", "text/xml", new File("pom.xml"), realObject },
|
||||||
{ "string", "text/xml", realObject, realObject },
|
{ "string", "text/xml", realObject, realObject },
|
||||||
|
|
|
@ -36,10 +36,10 @@ import java.util.Map.Entry;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.jclouds.blobstore.BlobStoreContext;
|
import org.jclouds.blobstore.BlobStoreContext;
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
import org.jclouds.blobstore.domain.Blob;
|
||||||
import org.jclouds.blobstore.util.BlobStoreUtils;
|
import org.jclouds.blobstore.util.BlobStoreUtils;
|
||||||
|
import org.jclouds.util.Utils;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -163,11 +163,11 @@ public class BaseBlobMapIntegrationTest<A, S> extends BaseMapIntegrationTest<A,
|
||||||
try {
|
try {
|
||||||
Map<String, Blob> map = createMap(context, bucketName);
|
Map<String, Blob> map = createMap(context, bucketName);
|
||||||
Blob object = newBlob("one");
|
Blob object = newBlob("one");
|
||||||
object.setPayload(IOUtils.toInputStream("apple"));
|
object.setPayload(Utils.toInputStream("apple"));
|
||||||
object.generateMD5();
|
object.generateMD5();
|
||||||
Blob old = map.put(object.getMetadata().getName(), object);
|
Blob old = map.put(object.getMetadata().getName(), object);
|
||||||
getOneReturnsAppleAndOldValueIsNull(map, old);
|
getOneReturnsAppleAndOldValueIsNull(map, old);
|
||||||
object.setPayload(IOUtils.toInputStream("bear"));
|
object.setPayload(Utils.toInputStream("bear"));
|
||||||
object.generateMD5();
|
object.generateMD5();
|
||||||
Blob apple = map.put(object.getMetadata().getName(), object);
|
Blob apple = map.put(object.getMetadata().getName(), object);
|
||||||
getOneReturnsBearAndOldValueIsApple(map, apple);
|
getOneReturnsBearAndOldValueIsApple(map, apple);
|
||||||
|
|
|
@ -36,7 +36,6 @@ import java.util.Map.Entry;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.jclouds.blobstore.BlobStoreContext;
|
import org.jclouds.blobstore.BlobStoreContext;
|
||||||
import org.jclouds.blobstore.InputStreamMap;
|
import org.jclouds.blobstore.InputStreamMap;
|
||||||
import org.jclouds.util.Utils;
|
import org.jclouds.util.Utils;
|
||||||
|
@ -102,12 +101,12 @@ public class BaseInputStreamMapIntegrationTest<A, S> extends
|
||||||
Set<Entry<String, InputStream>> entries = map.entrySet();
|
Set<Entry<String, InputStream>> entries = map.entrySet();
|
||||||
assertEquals(entries.size(), 5);
|
assertEquals(entries.size(), 5);
|
||||||
for (Entry<String, InputStream> entry : entries) {
|
for (Entry<String, InputStream> entry : entries) {
|
||||||
assertEquals(fiveStrings.get(entry.getKey()), IOUtils.toString(entry.getValue()));
|
assertEquals(fiveStrings.get(entry.getKey()), Utils.toStringAndClose(entry.getValue()));
|
||||||
entry.setValue(IOUtils.toInputStream(""));
|
entry.setValue(Utils.toInputStream(""));
|
||||||
}
|
}
|
||||||
assertConsistencyAwareMapSize(map, 5);
|
assertConsistencyAwareMapSize(map, 5);
|
||||||
for (InputStream value : map.values()) {
|
for (InputStream value : map.values()) {
|
||||||
assertEquals(IOUtils.toString(value), "");
|
assertEquals(Utils.toStringAndClose(value), "");
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
returnContainer(bucketName);
|
returnContainer(bucketName);
|
||||||
|
|
|
@ -28,7 +28,6 @@ import static org.testng.Assert.assertTrue;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -37,18 +36,20 @@ import java.util.Map.Entry;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.jclouds.blobstore.BlobStoreContext;
|
import org.jclouds.blobstore.BlobStoreContext;
|
||||||
import org.jclouds.blobstore.ListableMap;
|
import org.jclouds.blobstore.ListableMap;
|
||||||
|
import org.jclouds.util.Utils;
|
||||||
import org.testng.annotations.BeforeClass;
|
import org.testng.annotations.BeforeClass;
|
||||||
import org.testng.annotations.BeforeMethod;
|
import org.testng.annotations.BeforeMethod;
|
||||||
import org.testng.annotations.Optional;
|
import org.testng.annotations.Optional;
|
||||||
import org.testng.annotations.Parameters;
|
import org.testng.annotations.Parameters;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import com.google.common.base.Charsets;
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
|
import com.google.common.io.Files;
|
||||||
|
|
||||||
public abstract class BaseMapIntegrationTest<A, S, V> extends BaseBlobStoreIntegrationTest<A, S> {
|
public abstract class BaseMapIntegrationTest<A, S, V> extends BaseBlobStoreIntegrationTest<A, S> {
|
||||||
|
|
||||||
|
@ -75,7 +76,7 @@ public abstract class BaseMapIntegrationTest<A, S, V> extends BaseBlobStoreInteg
|
||||||
protected void setUpInputStreams() {
|
protected void setUpInputStreams() {
|
||||||
fiveInputs = Maps.transformValues(fiveStrings, new Function<String, InputStream>() {
|
fiveInputs = Maps.transformValues(fiveStrings, new Function<String, InputStream>() {
|
||||||
public InputStream apply(String from) {
|
public InputStream apply(String from) {
|
||||||
return IOUtils.toInputStream(from);
|
return Utils.toInputStream(from);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -93,7 +94,7 @@ public abstract class BaseMapIntegrationTest<A, S, V> extends BaseBlobStoreInteg
|
||||||
fiveFiles = Maps.newHashMap();
|
fiveFiles = Maps.newHashMap();
|
||||||
for (Entry<String, String> entry : fiveStrings.entrySet()) {
|
for (Entry<String, String> entry : fiveStrings.entrySet()) {
|
||||||
File file = new File(tmpDirectory, entry.getKey());
|
File file = new File(tmpDirectory, entry.getKey());
|
||||||
IOUtils.write(entry.getValue().getBytes(), new FileOutputStream(file));
|
Files.write(entry.getValue().getBytes(Charsets.UTF_8), file);
|
||||||
fiveFiles.put(entry.getKey(), file);
|
fiveFiles.put(entry.getKey(), file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@ package org.jclouds.blobstore.integration.internal;
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -54,8 +55,6 @@ import java.util.concurrent.TimeoutException;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.ws.rs.core.HttpHeaders;
|
import javax.ws.rs.core.HttpHeaders;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.apache.commons.io.output.ByteArrayOutputStream;
|
|
||||||
import org.jclouds.blobstore.AsyncBlobStore;
|
import org.jclouds.blobstore.AsyncBlobStore;
|
||||||
import org.jclouds.blobstore.ContainerNotFoundException;
|
import org.jclouds.blobstore.ContainerNotFoundException;
|
||||||
import org.jclouds.blobstore.KeyNotFoundException;
|
import org.jclouds.blobstore.KeyNotFoundException;
|
||||||
|
@ -93,6 +92,8 @@ import com.google.common.collect.Iterables;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
|
import com.google.common.io.ByteStreams;
|
||||||
|
import com.google.common.io.Closeables;
|
||||||
import com.google.inject.internal.Nullable;
|
import com.google.inject.internal.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -148,8 +149,8 @@ public class StubAsyncBlobStore implements AsyncBlobStore {
|
||||||
} else if (data instanceof File || data instanceof InputStream) {
|
} else if (data instanceof File || data instanceof InputStream) {
|
||||||
InputStream io = (data instanceof InputStream) ? (InputStream) data : new FileInputStream(
|
InputStream io = (data instanceof InputStream) ? (InputStream) data : new FileInputStream(
|
||||||
(File) data);
|
(File) data);
|
||||||
bytes = IOUtils.toByteArray(io);
|
bytes = ByteStreams.toByteArray(io);
|
||||||
IOUtils.closeQuietly(io);
|
Closeables.closeQuietly(io);
|
||||||
} else {
|
} else {
|
||||||
throw new UnsupportedOperationException("Content not supported " + data.getClass());
|
throw new UnsupportedOperationException("Content not supported " + data.getClass());
|
||||||
}
|
}
|
||||||
|
@ -594,7 +595,7 @@ public class StubAsyncBlobStore implements AsyncBlobStore {
|
||||||
if (options.getRanges() != null && options.getRanges().size() > 0) {
|
if (options.getRanges() != null && options.getRanges().size() > 0) {
|
||||||
byte[] data;
|
byte[] data;
|
||||||
try {
|
try {
|
||||||
data = IOUtils.toByteArray(returnVal.getPayload().getContent());
|
data = ByteStreams.toByteArray(returnVal.getPayload().getContent());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,13 +37,13 @@ import java.util.concurrent.Future;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.jclouds.blobstore.AsyncBlobStore;
|
import org.jclouds.blobstore.AsyncBlobStore;
|
||||||
import org.jclouds.blobstore.KeyNotFoundException;
|
import org.jclouds.blobstore.KeyNotFoundException;
|
||||||
import org.jclouds.blobstore.config.BlobStoreObjectModule;
|
import org.jclouds.blobstore.config.BlobStoreObjectModule;
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
import org.jclouds.blobstore.domain.Blob;
|
||||||
import org.jclouds.blobstore.domain.Blob.Factory;
|
import org.jclouds.blobstore.domain.Blob.Factory;
|
||||||
import org.jclouds.blobstore.integration.StubBlobStoreContextBuilder;
|
import org.jclouds.blobstore.integration.StubBlobStoreContextBuilder;
|
||||||
|
import org.jclouds.util.Utils;
|
||||||
import org.testng.annotations.BeforeTest;
|
import org.testng.annotations.BeforeTest;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
@ -86,7 +86,7 @@ public class RetryOnNotFoundGetAllBlobsStrategyTest {
|
||||||
map.ifNotFoundRetryOtherwiseAddToSet("container", "key", futureObject, objects);
|
map.ifNotFoundRetryOtherwiseAddToSet("container", "key", futureObject, objects);
|
||||||
// should have retried once
|
// should have retried once
|
||||||
assert System.currentTimeMillis() >= time + map.requestRetryMilliseconds;
|
assert System.currentTimeMillis() >= time + map.requestRetryMilliseconds;
|
||||||
assertEquals(IOUtils.toString((InputStream) objects.iterator().next().getContent()), "goo");
|
assertEquals(Utils.toStringAndClose((InputStream) objects.iterator().next().getContent()), "goo");
|
||||||
assert !objects.contains(null);
|
assert !objects.contains(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,10 +29,10 @@ import java.io.FileNotFoundException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.jclouds.codegen.ec2.queryapi.AmazonEC2QueryAPI;
|
import org.jclouds.codegen.ec2.queryapi.AmazonEC2QueryAPI;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
|
import com.google.common.io.Closeables;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts object models representing AWS API beans into Java classes.
|
* Converts object models representing AWS API beans into Java classes.
|
||||||
|
@ -65,7 +65,7 @@ public class AmazonEC2QueryAPIParser {
|
||||||
validator.validateCategories().validateCommands().validateDomain();
|
validator.validateCategories().validateCommands().validateDomain();
|
||||||
return validator.getModel();
|
return validator.getModel();
|
||||||
} finally {
|
} finally {
|
||||||
IOUtils.closeQuietly(in);
|
Closeables.closeQuietly(in);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -61,11 +61,6 @@
|
||||||
<artifactId>resteasy-jaxrs-client</artifactId>
|
<artifactId>resteasy-jaxrs-client</artifactId>
|
||||||
<version>1.1.GA</version>
|
<version>1.1.GA</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>commons-io</groupId>
|
|
||||||
<artifactId>commons-io</artifactId>
|
|
||||||
<version>1.4</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.google.code.guice</groupId>
|
<groupId>com.google.code.guice</groupId>
|
||||||
<artifactId>guice</artifactId>
|
<artifactId>guice</artifactId>
|
||||||
|
@ -79,7 +74,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.google.collections</groupId>
|
<groupId>com.google.collections</groupId>
|
||||||
<artifactId>google-collections</artifactId>
|
<artifactId>google-collections</artifactId>
|
||||||
<version>1.0-rc4</version>
|
<version>1.0-rc5</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>javax.annotation</groupId>
|
<groupId>javax.annotation</groupId>
|
||||||
|
|
|
@ -12,8 +12,9 @@ import java.security.NoSuchProviderException;
|
||||||
import javax.crypto.Mac;
|
import javax.crypto.Mac;
|
||||||
import javax.crypto.spec.SecretKeySpec;
|
import javax.crypto.spec.SecretKeySpec;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
import java.io.ByteArrayOutputStream;
|
||||||
import org.apache.commons.io.output.ByteArrayOutputStream;
|
|
||||||
|
import com.google.common.io.Closeables;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -75,7 +76,7 @@ public class JCEEncryptionService extends BaseEncryptionService {
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
} finally {
|
} finally {
|
||||||
IOUtils.closeQuietly(i);
|
Closeables.closeQuietly(i);
|
||||||
}
|
}
|
||||||
return eTag.digest();
|
return eTag.digest();
|
||||||
}
|
}
|
||||||
|
@ -102,8 +103,8 @@ public class JCEEncryptionService extends BaseEncryptionService {
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
} finally {
|
} finally {
|
||||||
IOUtils.closeQuietly(out);
|
Closeables.closeQuietly(out);
|
||||||
IOUtils.closeQuietly(toEncode);
|
Closeables.closeQuietly(toEncode);
|
||||||
}
|
}
|
||||||
return new MD5InputStreamResult(out.toByteArray(), eTag.digest(), length);
|
return new MD5InputStreamResult(out.toByteArray(), eTag.digest(), length);
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,6 @@ import java.util.regex.Pattern;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.jclouds.logging.Logger;
|
import org.jclouds.logging.Logger;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
|
@ -52,6 +51,8 @@ import com.google.common.collect.MapMaker;
|
||||||
import com.google.common.collect.Multimap;
|
import com.google.common.collect.Multimap;
|
||||||
import com.google.common.collect.SortedSetMultimap;
|
import com.google.common.collect.SortedSetMultimap;
|
||||||
import com.google.common.collect.TreeMultimap;
|
import com.google.common.collect.TreeMultimap;
|
||||||
|
import com.google.common.io.ByteStreams;
|
||||||
|
import com.google.common.io.Closeables;
|
||||||
|
|
||||||
public class HttpUtils {
|
public class HttpUtils {
|
||||||
public static final Pattern URI_PATTERN = Pattern.compile("([a-z0-9]+)://([^:]*):(.*)@(.*)");
|
public static final Pattern URI_PATTERN = Pattern.compile("([a-z0-9]+)://([^:]*):(.*)@(.*)");
|
||||||
|
@ -107,13 +108,13 @@ public class HttpUtils {
|
||||||
public static byte[] closeClientButKeepContentStream(HttpResponse response) {
|
public static byte[] closeClientButKeepContentStream(HttpResponse response) {
|
||||||
if (response.getContent() != null) {
|
if (response.getContent() != null) {
|
||||||
try {
|
try {
|
||||||
byte[] data = IOUtils.toByteArray(response.getContent());
|
byte[] data = ByteStreams.toByteArray(response.getContent());
|
||||||
response.setContent(new ByteArrayInputStream(data));
|
response.setContent(new ByteArrayInputStream(data));
|
||||||
return data;
|
return data;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.error(e, "Error consuming input");
|
logger.error(e, "Error consuming input");
|
||||||
} finally {
|
} finally {
|
||||||
IOUtils.closeQuietly(response.getContent());
|
Closeables.closeQuietly(response.getContent());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
@ -216,7 +217,7 @@ public class HttpUtils {
|
||||||
} while (numRead != -1);
|
} while (numRead != -1);
|
||||||
} finally {
|
} finally {
|
||||||
output.close();
|
output.close();
|
||||||
IOUtils.closeQuietly(input);
|
Closeables.closeQuietly(input);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,8 +30,8 @@ import java.io.FileNotFoundException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.jclouds.util.InputStreamChain;
|
import org.jclouds.util.InputStreamChain;
|
||||||
|
import org.jclouds.util.Utils;
|
||||||
|
|
||||||
import com.google.common.collect.Multimap;
|
import com.google.common.collect.Multimap;
|
||||||
|
|
||||||
|
@ -95,7 +95,7 @@ public class MultipartForm {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Part(Multimap<String, String> headers, String data) {
|
public Part(Multimap<String, String> headers, String data) {
|
||||||
this(headers, IOUtils.toInputStream(data), data.length());
|
this(headers, Utils.toInputStream(data), data.length());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Part(Multimap<String, String> headers, File data) throws FileNotFoundException {
|
public Part(Multimap<String, String> headers, File data) throws FileNotFoundException {
|
||||||
|
|
|
@ -131,7 +131,7 @@ public class TransformingHttpCommandImpl<T> implements TransformingHttpCommand<T
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* public void checkCode() { int code = getResponse().getStatusCode(); if (code >= 300) {
|
* public void checkCode() { int code = getResponse().getStatusCode(); if (code >= 300) {
|
||||||
* IOUtils.closeQuietly(getResponse().getContent()); throw new
|
* Closeables.closeQuietly(getResponse().getContent()); throw new
|
||||||
* IllegalStateException("incorrect code for this operation: " + getResponse()); } }
|
* IllegalStateException("incorrect code for this operation: " + getResponse()); } }
|
||||||
**/
|
**/
|
||||||
public HttpRequest getRequest() {
|
public HttpRequest getRequest() {
|
||||||
|
|
|
@ -25,7 +25,6 @@ package org.jclouds.http.functions;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.jclouds.encryption.internal.Base64;
|
import org.jclouds.encryption.internal.Base64;
|
||||||
import org.jclouds.http.HttpResponse;
|
import org.jclouds.http.HttpResponse;
|
||||||
import org.jclouds.logging.Logger;
|
import org.jclouds.logging.Logger;
|
||||||
|
@ -33,6 +32,7 @@ import org.jclouds.rest.InvocationContext;
|
||||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
|
import com.google.common.io.Closeables;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
|
@ -67,7 +67,7 @@ public class ParseContentMD5FromHeaders implements Function<HttpResponse, byte[]
|
||||||
private GeneratedHttpRequest<?> request;
|
private GeneratedHttpRequest<?> request;
|
||||||
|
|
||||||
public byte[] apply(HttpResponse from) {
|
public byte[] apply(HttpResponse from) {
|
||||||
IOUtils.closeQuietly(from.getContent());
|
Closeables.closeQuietly(from.getContent());
|
||||||
String contentMD5 = from.getFirstHeaderOrNull("Content-MD5");
|
String contentMD5 = from.getFirstHeaderOrNull("Content-MD5");
|
||||||
if (contentMD5 != null) {
|
if (contentMD5 != null) {
|
||||||
return Base64.decode(contentMD5);
|
return Base64.decode(contentMD5);
|
||||||
|
|
|
@ -26,11 +26,11 @@ package org.jclouds.http.functions;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
import javax.ws.rs.core.HttpHeaders;
|
import javax.ws.rs.core.HttpHeaders;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.jclouds.http.HttpException;
|
import org.jclouds.http.HttpException;
|
||||||
import org.jclouds.http.HttpResponse;
|
import org.jclouds.http.HttpResponse;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
|
import com.google.common.io.Closeables;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses an MD5 checksum from the header {@link HttpHeaders#ETAG}.
|
* Parses an MD5 checksum from the header {@link HttpHeaders#ETAG}.
|
||||||
|
@ -41,7 +41,7 @@ import com.google.common.base.Function;
|
||||||
public class ParseETagHeader implements Function<HttpResponse, String> {
|
public class ParseETagHeader implements Function<HttpResponse, String> {
|
||||||
|
|
||||||
public String apply(HttpResponse from) {
|
public String apply(HttpResponse from) {
|
||||||
IOUtils.closeQuietly(from.getContent());
|
Closeables.closeQuietly(from.getContent());
|
||||||
|
|
||||||
String eTag = from.getFirstHeaderOrNull(HttpHeaders.ETAG);
|
String eTag = from.getFirstHeaderOrNull(HttpHeaders.ETAG);
|
||||||
if (eTag == null) {
|
if (eTag == null) {
|
||||||
|
|
|
@ -28,12 +28,12 @@ import java.io.InputStream;
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.jclouds.http.HttpResponse;
|
import org.jclouds.http.HttpResponse;
|
||||||
import org.jclouds.http.HttpResponseException;
|
import org.jclouds.http.HttpResponseException;
|
||||||
import org.jclouds.logging.Logger;
|
import org.jclouds.logging.Logger;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
|
import com.google.common.io.Closeables;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -66,7 +66,7 @@ public abstract class ParseJson<T> implements Function<HttpResponse, T> {
|
||||||
logger.error(e, message.toString());
|
logger.error(e, message.toString());
|
||||||
throw new HttpResponseException(message.toString() + "\n" + from, null, from, e);
|
throw new HttpResponseException(message.toString() + "\n" + from, null, from, e);
|
||||||
} finally {
|
} finally {
|
||||||
IOUtils.closeQuietly(gson);
|
Closeables.closeQuietly(gson);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,6 @@ import java.io.InputStream;
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.jclouds.http.HttpException;
|
import org.jclouds.http.HttpException;
|
||||||
import org.jclouds.http.HttpResponse;
|
import org.jclouds.http.HttpResponse;
|
||||||
import org.jclouds.logging.Logger;
|
import org.jclouds.logging.Logger;
|
||||||
|
@ -41,6 +40,7 @@ import org.xml.sax.XMLReader;
|
||||||
import org.xml.sax.helpers.DefaultHandler;
|
import org.xml.sax.helpers.DefaultHandler;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
|
import com.google.common.io.Closeables;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This object will parse the body of an HttpResponse and return the result of type <T> back to the
|
* This object will parse the body of an HttpResponse and return the result of type <T> back to the
|
||||||
|
@ -99,7 +99,7 @@ public class ParseSax<T> implements Function<HttpResponse, T> {
|
||||||
Utils.<HttpException> rethrowIfRuntimeOrSameType(e);
|
Utils.<HttpException> rethrowIfRuntimeOrSameType(e);
|
||||||
throw new HttpException(message.toString(), e);
|
throw new HttpException(message.toString(), e);
|
||||||
} finally {
|
} finally {
|
||||||
IOUtils.closeQuietly(xml);
|
Closeables.closeQuietly(xml);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,10 +25,10 @@ package org.jclouds.http.functions;
|
||||||
|
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.jclouds.http.HttpResponse;
|
import org.jclouds.http.HttpResponse;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
|
import com.google.common.io.Closeables;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simply returns true when the http response code is in the range 200-299.
|
* Simply returns true when the http response code is in the range 200-299.
|
||||||
|
@ -39,7 +39,7 @@ import com.google.common.base.Function;
|
||||||
public class ReturnTrueIf2xx implements Function<HttpResponse, Boolean> {
|
public class ReturnTrueIf2xx implements Function<HttpResponse, Boolean> {
|
||||||
|
|
||||||
public Boolean apply(HttpResponse from) {
|
public Boolean apply(HttpResponse from) {
|
||||||
IOUtils.closeQuietly(from.getContent());
|
Closeables.closeQuietly(from.getContent());
|
||||||
int code = from.getStatusCode();
|
int code = from.getStatusCode();
|
||||||
if (code >= 300 || code < 200) {
|
if (code >= 300 || code < 200) {
|
||||||
throw new IllegalStateException("incorrect code for this operation: " + from);
|
throw new IllegalStateException("incorrect code for this operation: " + from);
|
||||||
|
|
|
@ -27,10 +27,10 @@ import java.lang.reflect.Constructor;
|
||||||
|
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.jclouds.http.HttpResponse;
|
import org.jclouds.http.HttpResponse;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
|
import com.google.common.io.Closeables;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simply returns true when the http response code is in the range 200-299.
|
* Simply returns true when the http response code is in the range 200-299.
|
||||||
|
@ -52,7 +52,7 @@ public class ReturnVoidIf2xx implements Function<HttpResponse, Void> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Void apply(HttpResponse from) {
|
public Void apply(HttpResponse from) {
|
||||||
IOUtils.closeQuietly(from.getContent());
|
Closeables.closeQuietly(from.getContent());
|
||||||
int code = from.getStatusCode();
|
int code = from.getStatusCode();
|
||||||
if (code >= 300 || code < 200) {
|
if (code >= 300 || code < 200) {
|
||||||
throw new IllegalStateException("incorrect code for this operation: " + from);
|
throw new IllegalStateException("incorrect code for this operation: " + from);
|
||||||
|
|
|
@ -26,7 +26,6 @@ package org.jclouds.http.handlers;
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.jclouds.http.HttpCommand;
|
import org.jclouds.http.HttpCommand;
|
||||||
import org.jclouds.http.HttpConstants;
|
import org.jclouds.http.HttpConstants;
|
||||||
import org.jclouds.http.HttpResponse;
|
import org.jclouds.http.HttpResponse;
|
||||||
|
@ -34,6 +33,7 @@ import org.jclouds.http.HttpRetryHandler;
|
||||||
import org.jclouds.http.TransformingHttpCommand;
|
import org.jclouds.http.TransformingHttpCommand;
|
||||||
import org.jclouds.logging.Logger;
|
import org.jclouds.logging.Logger;
|
||||||
|
|
||||||
|
import com.google.common.io.Closeables;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -85,7 +85,7 @@ public class BackoffLimitedRetryHandler implements HttpRetryHandler {
|
||||||
protected Logger logger = Logger.NULL;
|
protected Logger logger = Logger.NULL;
|
||||||
|
|
||||||
public boolean shouldRetryRequest(HttpCommand command, HttpResponse response) {
|
public boolean shouldRetryRequest(HttpCommand command, HttpResponse response) {
|
||||||
IOUtils.closeQuietly(response.getContent());
|
Closeables.closeQuietly(response.getContent());
|
||||||
|
|
||||||
command.incrementFailureCount();
|
command.incrementFailureCount();
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,6 @@ import javax.inject.Named;
|
||||||
import javax.ws.rs.core.HttpHeaders;
|
import javax.ws.rs.core.HttpHeaders;
|
||||||
import javax.ws.rs.core.UriBuilder;
|
import javax.ws.rs.core.UriBuilder;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.jclouds.http.HttpCommand;
|
import org.jclouds.http.HttpCommand;
|
||||||
import org.jclouds.http.HttpConstants;
|
import org.jclouds.http.HttpConstants;
|
||||||
import org.jclouds.http.HttpResponse;
|
import org.jclouds.http.HttpResponse;
|
||||||
|
@ -40,6 +39,8 @@ import org.jclouds.http.HttpRetryHandler;
|
||||||
import org.jclouds.logging.Logger;
|
import org.jclouds.logging.Logger;
|
||||||
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
|
import com.google.common.io.ByteStreams;
|
||||||
|
import com.google.common.io.Closeables;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -91,12 +92,12 @@ public class RedirectionRetryHandler implements HttpRetryHandler {
|
||||||
void closeClientButKeepContentStream(HttpResponse response) {
|
void closeClientButKeepContentStream(HttpResponse response) {
|
||||||
if (response.getContent() != null) {
|
if (response.getContent() != null) {
|
||||||
try {
|
try {
|
||||||
byte[] data = IOUtils.toByteArray(response.getContent());
|
byte[] data = ByteStreams.toByteArray(response.getContent());
|
||||||
response.setContent(new ByteArrayInputStream(data));
|
response.setContent(new ByteArrayInputStream(data));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.error(e, "Error consuming input");
|
logger.error(e, "Error consuming input");
|
||||||
} finally {
|
} finally {
|
||||||
IOUtils.closeQuietly(response.getContent());
|
Closeables.closeQuietly(response.getContent());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,6 @@ import javax.net.ssl.HttpsURLConnection;
|
||||||
import javax.net.ssl.SSLSession;
|
import javax.net.ssl.SSLSession;
|
||||||
import javax.ws.rs.core.HttpHeaders;
|
import javax.ws.rs.core.HttpHeaders;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.jclouds.http.HttpCommandExecutorService;
|
import org.jclouds.http.HttpCommandExecutorService;
|
||||||
import org.jclouds.http.HttpConstants;
|
import org.jclouds.http.HttpConstants;
|
||||||
import org.jclouds.http.HttpRequest;
|
import org.jclouds.http.HttpRequest;
|
||||||
|
@ -47,6 +46,7 @@ import org.jclouds.http.handlers.DelegatingErrorHandler;
|
||||||
import org.jclouds.http.handlers.DelegatingRetryHandler;
|
import org.jclouds.http.handlers.DelegatingRetryHandler;
|
||||||
|
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
|
import com.google.common.io.Closeables;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -135,7 +135,7 @@ public class JavaUrlHttpCommandExecutorService extends
|
||||||
try {
|
try {
|
||||||
request.getPayload().writeTo(out);
|
request.getPayload().writeTo(out);
|
||||||
} finally {
|
} finally {
|
||||||
IOUtils.closeQuietly(out);
|
Closeables.closeQuietly(out);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
connection.setRequestProperty(HttpHeaders.CONTENT_LENGTH, "0");
|
connection.setRequestProperty(HttpHeaders.CONTENT_LENGTH, "0");
|
||||||
|
|
|
@ -30,13 +30,16 @@ import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.jclouds.http.Payload;
|
import org.jclouds.http.Payload;
|
||||||
|
import org.jclouds.util.Utils;
|
||||||
|
|
||||||
|
import com.google.common.io.ByteStreams;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class ByteArrayPayload implements Payload {
|
public class ByteArrayPayload implements Payload {
|
||||||
|
|
||||||
private final byte[] content;
|
private final byte[] content;
|
||||||
|
|
||||||
public ByteArrayPayload(byte[] content) {
|
public ByteArrayPayload(byte[] content) {
|
||||||
|
@ -68,7 +71,7 @@ public class ByteArrayPayload implements Payload {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void writeTo(OutputStream outstream) throws IOException {
|
public void writeTo(OutputStream outstream) throws IOException {
|
||||||
IOUtils.write(content, outstream);
|
ByteStreams.write(content, Utils.newOutputStreamSupplier(outstream));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -33,9 +33,11 @@ import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.jclouds.http.Payload;
|
import org.jclouds.http.Payload;
|
||||||
|
|
||||||
|
import com.google.common.io.Closeables;
|
||||||
|
import com.google.common.io.Files;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
|
@ -78,9 +80,9 @@ public class FilePayload implements Payload {
|
||||||
public void writeTo(OutputStream outstream) throws IOException {
|
public void writeTo(OutputStream outstream) throws IOException {
|
||||||
InputStream in = getContent();
|
InputStream in = getContent();
|
||||||
try {
|
try {
|
||||||
IOUtils.copy(getContent(), outstream);
|
Files.copy(content, outstream);
|
||||||
} finally {
|
} finally {
|
||||||
IOUtils.closeQuietly(in);
|
Closeables.closeQuietly(in);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,9 +29,11 @@ import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.jclouds.http.Payload;
|
import org.jclouds.http.Payload;
|
||||||
|
|
||||||
|
import com.google.common.io.ByteStreams;
|
||||||
|
import com.google.common.io.Closeables;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
|
@ -69,9 +71,9 @@ public class InputStreamPayload implements Payload {
|
||||||
public void writeTo(OutputStream outstream) throws IOException {
|
public void writeTo(OutputStream outstream) throws IOException {
|
||||||
InputStream in = getContent();
|
InputStream in = getContent();
|
||||||
try {
|
try {
|
||||||
IOUtils.copy(getContent(), outstream);
|
ByteStreams.copy(getContent(), outstream);
|
||||||
} finally {
|
} finally {
|
||||||
IOUtils.closeQuietly(in);
|
Closeables.closeQuietly(in);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,8 +29,10 @@ import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.jclouds.http.Payload;
|
import org.jclouds.http.Payload;
|
||||||
|
import org.jclouds.util.Utils;
|
||||||
|
|
||||||
|
import com.google.common.io.ByteStreams;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
|
@ -51,7 +53,7 @@ public class StringPayload implements Payload {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public InputStream getContent() {
|
public InputStream getContent() {
|
||||||
return IOUtils.toInputStream(content);
|
return Utils.toInputStream(content);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -67,7 +69,7 @@ public class StringPayload implements Payload {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void writeTo(OutputStream outstream) throws IOException {
|
public void writeTo(OutputStream outstream) throws IOException {
|
||||||
IOUtils.write(content.getBytes(), outstream);
|
ByteStreams.copy(Utils.toInputStream(content), outstream);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -0,0 +1,209 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.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.io;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ported from org.apache.commons.io.input.TeeInputStream
|
||||||
|
*
|
||||||
|
* InputStream proxy that transparently writes a copy of all bytes read from the delegate stream to
|
||||||
|
* a given OutputStream. Using {@link #skip(long)} or {@link #mark(int)}/{@link #reset()} on the
|
||||||
|
* stream will result on some bytes from the input stream being skipped or duplicated in the output
|
||||||
|
* stream.
|
||||||
|
* <p>
|
||||||
|
* The delegate input stream is closed when the {@link #close()} method is called on this proxy. It
|
||||||
|
* is configurable whether the associated output stream will also closed.
|
||||||
|
*
|
||||||
|
* @see Commons IO 1.4
|
||||||
|
* @see org.apache.commons.io.input.TeeInputStream
|
||||||
|
*/
|
||||||
|
public class TeeInputStream extends InputStream {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The input stream to delegate to.
|
||||||
|
*/
|
||||||
|
private final InputStream delegate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The output stream that will receive a copy of all bytes read from the delegate input stream.
|
||||||
|
*/
|
||||||
|
private final OutputStream branch;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Flag for closing also the associated output stream when this stream is closed.
|
||||||
|
*/
|
||||||
|
private final boolean closeBranch;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a TeeInputStream that delegates to the given {@link InputStream} and copies all read
|
||||||
|
* bytes to the given {@link OutputStream}. The given output stream will not be closed when this
|
||||||
|
* stream gets closed.
|
||||||
|
*
|
||||||
|
* @param input
|
||||||
|
* input stream to be delegate
|
||||||
|
* @param branch
|
||||||
|
* output stream that will receive a copy of all bytes read
|
||||||
|
*/
|
||||||
|
public TeeInputStream(InputStream delegate, OutputStream branch) {
|
||||||
|
this(delegate, branch, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a TeeInputStream that proxies the given {@link InputStream} and copies all read bytes
|
||||||
|
* to the given {@link OutputStream}. The given output stream will be closed when this stream
|
||||||
|
* gets closed if the closeBranch parameter is <code>true</code>.
|
||||||
|
*
|
||||||
|
* @param input
|
||||||
|
* input stream to be delegate
|
||||||
|
* @param branch
|
||||||
|
* output stream that will receive a copy of all bytes read
|
||||||
|
* @param closeBranch
|
||||||
|
* flag for closing also the output stream when this stream is closed
|
||||||
|
*/
|
||||||
|
public TeeInputStream(InputStream delegate, OutputStream branch, boolean closeBranch) {
|
||||||
|
this.delegate = delegate;
|
||||||
|
this.branch = branch;
|
||||||
|
this.closeBranch = closeBranch;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Closes the delegate input stream and, if so configured, the associated output stream. An
|
||||||
|
* exception thrown from one stream will not prevent closing of the other stream.
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
* if either of the streams could not be closed
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void close() throws IOException {
|
||||||
|
try {
|
||||||
|
delegate.close();
|
||||||
|
} finally {
|
||||||
|
if (closeBranch) {
|
||||||
|
branch.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads a single byte from the delegate input stream and writes it to the associated output
|
||||||
|
* stream.
|
||||||
|
*
|
||||||
|
* @return next byte from the stream, or -1 if the stream has ended
|
||||||
|
* @throws IOException
|
||||||
|
* if the stream could not be read (or written)
|
||||||
|
*/
|
||||||
|
public int read() throws IOException {
|
||||||
|
int ch = delegate.read();
|
||||||
|
if (ch != -1) {
|
||||||
|
branch.write(ch);
|
||||||
|
}
|
||||||
|
return ch;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads bytes from the delegate input stream and writes the read bytes to the associated output
|
||||||
|
* stream.
|
||||||
|
*
|
||||||
|
* @param bts
|
||||||
|
* byte buffer
|
||||||
|
* @param st
|
||||||
|
* start offset within the buffer
|
||||||
|
* @param end
|
||||||
|
* maximum number of bytes to read
|
||||||
|
* @return number of bytes read, or -1 if the stream has ended
|
||||||
|
* @throws IOException
|
||||||
|
* if the stream could not be read (or written)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public int read(byte[] bts, int st, int end) throws IOException {
|
||||||
|
int n = delegate.read(bts, st, end);
|
||||||
|
if (n != -1) {
|
||||||
|
branch.write(bts, st, n);
|
||||||
|
}
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads bytes from the delegate input stream and writes the read bytes to the associated output
|
||||||
|
* stream.
|
||||||
|
*
|
||||||
|
* @param bts
|
||||||
|
* byte buffer
|
||||||
|
* @return number of bytes read, or -1 if the stream has ended
|
||||||
|
* @throws IOException
|
||||||
|
* if the stream could not be read (or written)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public int read(byte[] bts) throws IOException {
|
||||||
|
int n = delegate.read(bts);
|
||||||
|
if (n != -1) {
|
||||||
|
branch.write(bts, 0, n);
|
||||||
|
}
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public int available() throws IOException {
|
||||||
|
return delegate.available();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public synchronized void mark(int readlimit) {
|
||||||
|
delegate.mark(readlimit);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean markSupported() {
|
||||||
|
return delegate.markSupported();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public synchronized void reset() throws IOException {
|
||||||
|
delegate.reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public long skip(long n) throws IOException {
|
||||||
|
return delegate.skip(n);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -38,10 +38,12 @@ import java.util.concurrent.ExecutorService;
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.apache.commons.io.input.TeeInputStream;
|
|
||||||
import org.jclouds.concurrent.SingleThreaded;
|
import org.jclouds.concurrent.SingleThreaded;
|
||||||
|
import org.jclouds.io.TeeInputStream;
|
||||||
import org.jclouds.logging.Logger;
|
import org.jclouds.logging.Logger;
|
||||||
|
|
||||||
|
import com.google.common.io.ByteStreams;
|
||||||
|
import com.google.common.io.Closeables;
|
||||||
/**
|
/**
|
||||||
* Logs data to the wire LOG.
|
* Logs data to the wire LOG.
|
||||||
*
|
*
|
||||||
|
@ -98,13 +100,13 @@ public abstract class Wire {
|
||||||
|
|
||||||
public InputStream copy(final String header, InputStream instream) {
|
public InputStream copy(final String header, InputStream instream) {
|
||||||
try {
|
try {
|
||||||
byte[] data = IOUtils.toByteArray(instream);
|
byte[] data = ByteStreams.toByteArray(instream);
|
||||||
wire(header, new ByteArrayInputStream(data));
|
wire(header, new ByteArrayInputStream(data));
|
||||||
return new ByteArrayInputStream(data);
|
return new ByteArrayInputStream(data);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException("Error tapping line", e);
|
throw new RuntimeException("Error tapping line", e);
|
||||||
} finally {
|
} finally {
|
||||||
IOUtils.closeQuietly(instream);
|
Closeables.closeQuietly(instream);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,7 +121,7 @@ public abstract class Wire {
|
||||||
try {
|
try {
|
||||||
wire(header, line);
|
wire(header, line);
|
||||||
} finally {
|
} finally {
|
||||||
IOUtils.closeQuietly(line);
|
Closeables.closeQuietly(line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -166,7 +168,7 @@ public abstract class Wire {
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
logger.error(e, "Error tapping file: %s", out);
|
logger.error(e, "Error tapping file: %s", out);
|
||||||
} finally {
|
} finally {
|
||||||
IOUtils.closeQuietly(in);
|
Closeables.closeQuietly(in);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -27,8 +27,6 @@ import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link InputStream} implementation that allows chaining of various streams for seamless
|
* {@link InputStream} implementation that allows chaining of various streams for seamless
|
||||||
* sequential reading
|
* sequential reading
|
||||||
|
@ -83,7 +81,7 @@ public class InputStreamChain extends InputStream {
|
||||||
* @return instance of self (for fluent calls)
|
* @return instance of self (for fluent calls)
|
||||||
*/
|
*/
|
||||||
public InputStreamChain addAsInputStream(final String value) {
|
public InputStreamChain addAsInputStream(final String value) {
|
||||||
return addInputStream(IOUtils.toInputStream(value));
|
return addInputStream(Utils.toInputStream(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -23,8 +23,11 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.util;
|
package org.jclouds.util;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
|
@ -33,11 +36,14 @@ import java.util.regex.Pattern;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.jclouds.logging.Logger;
|
import org.jclouds.logging.Logger;
|
||||||
|
|
||||||
|
import com.google.common.base.Charsets;
|
||||||
import com.google.common.base.Supplier;
|
import com.google.common.base.Supplier;
|
||||||
import com.google.common.collect.ComputationException;
|
import com.google.common.collect.ComputationException;
|
||||||
|
import com.google.common.io.ByteStreams;
|
||||||
|
import com.google.common.io.Closeables;
|
||||||
|
import com.google.common.io.OutputSupplier;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* // TODO: Adrian: Document this!
|
* // TODO: Adrian: Document this!
|
||||||
|
@ -47,6 +53,23 @@ import com.google.common.collect.ComputationException;
|
||||||
public class Utils {
|
public class Utils {
|
||||||
public static final String UTF8_ENCODING = "UTF-8";
|
public static final String UTF8_ENCODING = "UTF-8";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a factory that will supply instances of {@link OutputStream} that read from the given
|
||||||
|
* outputStream.
|
||||||
|
*
|
||||||
|
* @param url
|
||||||
|
* the URL to read from
|
||||||
|
* @return the factory
|
||||||
|
*/
|
||||||
|
public static OutputSupplier<OutputStream> newOutputStreamSupplier(final OutputStream output) {
|
||||||
|
checkNotNull(output, "output");
|
||||||
|
return new OutputSupplier<OutputStream>() {
|
||||||
|
public OutputStream getOutput() throws IOException {
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean enventuallyTrue(Supplier<Boolean> assertion, long inconsistencyMillis)
|
public static boolean enventuallyTrue(Supplier<Boolean> assertion, long inconsistencyMillis)
|
||||||
throws InterruptedException {
|
throws InterruptedException {
|
||||||
|
|
||||||
|
@ -116,9 +139,18 @@ public class Utils {
|
||||||
|
|
||||||
public static String toStringAndClose(InputStream input) throws IOException {
|
public static String toStringAndClose(InputStream input) throws IOException {
|
||||||
try {
|
try {
|
||||||
return IOUtils.toString(input);
|
return new String(ByteStreams.toByteArray(input), Charsets.UTF_8);
|
||||||
} finally {
|
} finally {
|
||||||
IOUtils.closeQuietly(input);
|
Closeables.closeQuietly(input);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static InputStream toInputStream(String in) {
|
||||||
|
try {
|
||||||
|
return ByteStreams.newInputStreamSupplier(in.getBytes(Charsets.UTF_8)).getInput();
|
||||||
|
} catch (IOException e) {
|
||||||
|
logger.warn(e, "Failed to convert %s to an inputStream", in);
|
||||||
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,6 @@ import javax.ws.rs.PUT;
|
||||||
import javax.ws.rs.Path;
|
import javax.ws.rs.Path;
|
||||||
import javax.ws.rs.PathParam;
|
import javax.ws.rs.PathParam;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.jclouds.http.functions.ParseSax;
|
import org.jclouds.http.functions.ParseSax;
|
||||||
import org.jclouds.http.options.HttpRequestOptions;
|
import org.jclouds.http.options.HttpRequestOptions;
|
||||||
import org.jclouds.rest.annotations.BinderParam;
|
import org.jclouds.rest.annotations.BinderParam;
|
||||||
|
@ -48,6 +47,7 @@ import org.jclouds.rest.binders.BindMapToMatrixParams;
|
||||||
import org.jclouds.rest.binders.BindToJsonPayload;
|
import org.jclouds.rest.binders.BindToJsonPayload;
|
||||||
import org.jclouds.rest.binders.BindToStringPayload;
|
import org.jclouds.rest.binders.BindToStringPayload;
|
||||||
import org.jclouds.rest.internal.RestAnnotationProcessorTest.Localhost;
|
import org.jclouds.rest.internal.RestAnnotationProcessorTest.Localhost;
|
||||||
|
import org.jclouds.util.Utils;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
|
|
||||||
|
@ -108,7 +108,7 @@ public interface IntegrationTestAsyncClient {
|
||||||
@Override
|
@Override
|
||||||
public void bindToRequest(HttpRequest request, Object payload) {
|
public void bindToRequest(HttpRequest request, Object payload) {
|
||||||
super.bindToRequest(request, payload);
|
super.bindToRequest(request, payload);
|
||||||
request.setPayload(IOUtils.toInputStream(payload.toString()));
|
request.setPayload(Utils.toInputStream(payload.toString()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,10 +36,10 @@ import java.util.concurrent.TimeoutException;
|
||||||
|
|
||||||
import javax.ws.rs.ext.RuntimeDelegate;
|
import javax.ws.rs.ext.RuntimeDelegate;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.jclouds.http.HttpResponse;
|
import org.jclouds.http.HttpResponse;
|
||||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||||
import org.jclouds.rest.internal.RuntimeDelegateImpl;
|
import org.jclouds.rest.internal.RuntimeDelegateImpl;
|
||||||
|
import org.jclouds.util.Utils;
|
||||||
import org.mortbay.jetty.HttpHeaders;
|
import org.mortbay.jetty.HttpHeaders;
|
||||||
import org.testng.annotations.BeforeTest;
|
import org.testng.annotations.BeforeTest;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
@ -90,7 +90,7 @@ public class ParseURIFromListOrLocationHeaderIf20xTest {
|
||||||
HttpResponse response = createMock(HttpResponse.class);
|
HttpResponse response = createMock(HttpResponse.class);
|
||||||
expect(response.getStatusCode()).andReturn(200).atLeastOnce();
|
expect(response.getStatusCode()).andReturn(200).atLeastOnce();
|
||||||
expect(response.getFirstHeaderOrNull(HttpHeaders.CONTENT_TYPE)).andReturn("text/uri-list");
|
expect(response.getFirstHeaderOrNull(HttpHeaders.CONTENT_TYPE)).andReturn("text/uri-list");
|
||||||
expect(response.getContent()).andReturn(IOUtils.toInputStream("http://locahost"))
|
expect(response.getContent()).andReturn(Utils.toInputStream("http://locahost"))
|
||||||
.atLeastOnce();
|
.atLeastOnce();
|
||||||
replay(response);
|
replay(response);
|
||||||
assertEquals(function.apply(response), URI.create("http://locahost"));
|
assertEquals(function.apply(response), URI.create("http://locahost"));
|
||||||
|
|
|
@ -33,9 +33,8 @@ import java.io.IOException;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.jclouds.http.HttpResponse;
|
import org.jclouds.http.HttpResponse;
|
||||||
import org.jclouds.http.functions.ReturnStringIf200;
|
import org.jclouds.util.Utils;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
|
@ -81,7 +80,7 @@ public class ReturnStringIf200Test {
|
||||||
Function<HttpResponse, String> function = new ReturnStringIf200();
|
Function<HttpResponse, String> function = new ReturnStringIf200();
|
||||||
HttpResponse response = createMock(HttpResponse.class);
|
HttpResponse response = createMock(HttpResponse.class);
|
||||||
expect(response.getStatusCode()).andReturn(200).atLeastOnce();
|
expect(response.getStatusCode()).andReturn(200).atLeastOnce();
|
||||||
expect(response.getContent()).andReturn(IOUtils.toInputStream("hello"));
|
expect(response.getContent()).andReturn(Utils.toInputStream("hello"));
|
||||||
replay(response);
|
replay(response);
|
||||||
assertEquals(function.apply(response), "hello");
|
assertEquals(function.apply(response), "hello");
|
||||||
verify(response);
|
verify(response);
|
||||||
|
|
|
@ -37,13 +37,14 @@ import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.jclouds.concurrent.WithinThreadExecutorService;
|
import org.jclouds.concurrent.WithinThreadExecutorService;
|
||||||
import org.jclouds.encryption.EncryptionService;
|
import org.jclouds.encryption.EncryptionService;
|
||||||
import org.jclouds.encryption.internal.JCEEncryptionService;
|
import org.jclouds.encryption.internal.JCEEncryptionService;
|
||||||
import org.jclouds.logging.Logger;
|
import org.jclouds.logging.Logger;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import com.google.common.io.ByteStreams;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
|
@ -66,8 +67,8 @@ public class WireLiveTest {
|
||||||
public Void call() throws Exception {
|
public Void call() throws Exception {
|
||||||
HttpWire wire = setUp();
|
HttpWire wire = setUp();
|
||||||
InputStream in = wire.input(fromServer);
|
InputStream in = wire.input(fromServer);
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
ByteArrayOutputStream out = new ByteArrayOutputStream();//TODO
|
||||||
IOUtils.copy(in, out);
|
ByteStreams.copy(in, out);
|
||||||
byte[] compare = encryptionService.md5(new ByteArrayInputStream(out.toByteArray()));
|
byte[] compare = encryptionService.md5(new ByteArrayInputStream(out.toByteArray()));
|
||||||
Thread.sleep(100);
|
Thread.sleep(100);
|
||||||
assertEquals(encryptionService.toHexString(compare), checkNotNull(sysHttpStreamMd5,
|
assertEquals(encryptionService.toHexString(compare), checkNotNull(sysHttpStreamMd5,
|
||||||
|
|
|
@ -29,7 +29,6 @@ import static org.testng.Assert.assertNull;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.jclouds.concurrent.WithinThreadExecutorService;
|
import org.jclouds.concurrent.WithinThreadExecutorService;
|
||||||
import org.jclouds.concurrent.config.ExecutorServiceModule;
|
import org.jclouds.concurrent.config.ExecutorServiceModule;
|
||||||
import org.jclouds.http.HttpUtils;
|
import org.jclouds.http.HttpUtils;
|
||||||
|
@ -37,6 +36,7 @@ import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
|
||||||
import org.jclouds.rest.config.RestModule;
|
import org.jclouds.rest.config.RestModule;
|
||||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||||
|
import org.jclouds.util.Utils;
|
||||||
import org.testng.annotations.BeforeClass;
|
import org.testng.annotations.BeforeClass;
|
||||||
|
|
||||||
import com.google.inject.Guice;
|
import com.google.inject.Guice;
|
||||||
|
@ -71,7 +71,7 @@ public abstract class RestClientTest<T> {
|
||||||
if (httpMethod.getPayload() == null) {
|
if (httpMethod.getPayload() == null) {
|
||||||
assertNull(toMatch);
|
assertNull(toMatch);
|
||||||
} else {
|
} else {
|
||||||
String payload = IOUtils.toString(httpMethod.getPayload().getContent());
|
String payload = Utils.toStringAndClose(httpMethod.getPayload().getContent());
|
||||||
assertEquals(payload, toMatch);
|
assertEquals(payload, toMatch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,7 +60,6 @@ import javax.ws.rs.Produces;
|
||||||
import javax.ws.rs.QueryParam;
|
import javax.ws.rs.QueryParam;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.jclouds.concurrent.WithinThreadExecutorService;
|
import org.jclouds.concurrent.WithinThreadExecutorService;
|
||||||
import org.jclouds.concurrent.config.ExecutorServiceModule;
|
import org.jclouds.concurrent.config.ExecutorServiceModule;
|
||||||
import org.jclouds.date.DateService;
|
import org.jclouds.date.DateService;
|
||||||
|
@ -102,6 +101,7 @@ import org.jclouds.rest.binders.BindToJsonPayload;
|
||||||
import org.jclouds.rest.binders.BindToStringPayload;
|
import org.jclouds.rest.binders.BindToStringPayload;
|
||||||
import org.jclouds.rest.config.RestModule;
|
import org.jclouds.rest.config.RestModule;
|
||||||
import org.jclouds.util.Jsr330;
|
import org.jclouds.util.Jsr330;
|
||||||
|
import org.jclouds.util.Utils;
|
||||||
import org.mortbay.jetty.HttpHeaders;
|
import org.mortbay.jetty.HttpHeaders;
|
||||||
import org.testng.annotations.BeforeClass;
|
import org.testng.annotations.BeforeClass;
|
||||||
import org.testng.annotations.DataProvider;
|
import org.testng.annotations.DataProvider;
|
||||||
|
@ -1651,7 +1651,7 @@ public class RestAnnotationProcessorTest {
|
||||||
if (httpMethod.getPayload() == null) {
|
if (httpMethod.getPayload() == null) {
|
||||||
assertNull(toMatch);
|
assertNull(toMatch);
|
||||||
} else {
|
} else {
|
||||||
String payload = IOUtils.toString(httpMethod.getPayload().getContent());
|
String payload = Utils.toStringAndClose(httpMethod.getPayload().getContent());
|
||||||
assertEquals(payload, toMatch);
|
assertEquals(payload, toMatch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,6 @@ import java.util.Properties;
|
||||||
|
|
||||||
import javax.servlet.ServletContextEvent;
|
import javax.servlet.ServletContextEvent;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.jclouds.blobstore.BlobStoreContext;
|
import org.jclouds.blobstore.BlobStoreContext;
|
||||||
import org.jclouds.blobstore.BlobStoreContextBuilder;
|
import org.jclouds.blobstore.BlobStoreContextBuilder;
|
||||||
import org.jclouds.demo.tweetstore.controller.AddTweetsController;
|
import org.jclouds.demo.tweetstore.controller.AddTweetsController;
|
||||||
|
@ -50,6 +49,7 @@ import com.google.appengine.api.labs.taskqueue.QueueFactory;
|
||||||
import com.google.appengine.api.labs.taskqueue.TaskOptions.Method;
|
import com.google.appengine.api.labs.taskqueue.TaskOptions.Method;
|
||||||
import com.google.appengine.repackaged.com.google.common.collect.ImmutableList;
|
import com.google.appengine.repackaged.com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
|
import com.google.common.io.Closeables;
|
||||||
import com.google.inject.Guice;
|
import com.google.inject.Guice;
|
||||||
import com.google.inject.Injector;
|
import com.google.inject.Injector;
|
||||||
import com.google.inject.TypeLiteral;
|
import com.google.inject.TypeLiteral;
|
||||||
|
@ -123,7 +123,7 @@ public class GuiceServletConfig extends GuiceServletContextListener {
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
} finally {
|
} finally {
|
||||||
IOUtils.closeQuietly(input);
|
Closeables.closeQuietly(input);
|
||||||
}
|
}
|
||||||
return props;
|
return props;
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,6 @@ import java.util.SortedSet;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.jclouds.blobstore.BlobMap;
|
import org.jclouds.blobstore.BlobMap;
|
||||||
import org.jclouds.blobstore.BlobStoreContext;
|
import org.jclouds.blobstore.BlobStoreContext;
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
import org.jclouds.blobstore.domain.Blob;
|
||||||
|
@ -42,6 +41,7 @@ import org.jclouds.demo.tweetstore.reference.TweetStoreConstants;
|
||||||
import org.jclouds.twitter.TwitterClient;
|
import org.jclouds.twitter.TwitterClient;
|
||||||
import org.jclouds.twitter.domain.Status;
|
import org.jclouds.twitter.domain.Status;
|
||||||
import org.jclouds.twitter.domain.User;
|
import org.jclouds.twitter.domain.User;
|
||||||
|
import org.jclouds.util.Utils;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
@ -103,14 +103,14 @@ public class StoreTweetsControllerTest {
|
||||||
assertEquals(frankBlob.getMetadata().getUserMetadata()
|
assertEquals(frankBlob.getMetadata().getUserMetadata()
|
||||||
.get(TweetStoreConstants.SENDER_NAME), "frank");
|
.get(TweetStoreConstants.SENDER_NAME), "frank");
|
||||||
assertEquals(frankBlob.getMetadata().getContentType(), "text/plain");
|
assertEquals(frankBlob.getMetadata().getContentType(), "text/plain");
|
||||||
assertEquals(IOUtils.toString((InputStream) frankBlob.getContent()), "I love beans!");
|
assertEquals(Utils.toStringAndClose((InputStream) frankBlob.getContent()), "I love beans!");
|
||||||
|
|
||||||
Blob jimmyBlob = map.get("2");
|
Blob jimmyBlob = map.get("2");
|
||||||
assertEquals(jimmyBlob.getMetadata().getName(), "2");
|
assertEquals(jimmyBlob.getMetadata().getName(), "2");
|
||||||
assertEquals(jimmyBlob.getMetadata().getUserMetadata()
|
assertEquals(jimmyBlob.getMetadata().getUserMetadata()
|
||||||
.get(TweetStoreConstants.SENDER_NAME), "jimmy");
|
.get(TweetStoreConstants.SENDER_NAME), "jimmy");
|
||||||
assertEquals(jimmyBlob.getMetadata().getContentType(), "text/plain");
|
assertEquals(jimmyBlob.getMetadata().getContentType(), "text/plain");
|
||||||
assertEquals(IOUtils.toString((InputStream) jimmyBlob.getContent()), "cloud is king");
|
assertEquals(Utils.toStringAndClose((InputStream) jimmyBlob.getContent()), "cloud is king");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,6 @@ import java.util.Properties;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.jclouds.aws.s3.S3PropertiesBuilder;
|
import org.jclouds.aws.s3.S3PropertiesBuilder;
|
||||||
import org.jclouds.aws.s3.blobstore.S3BlobStoreContextBuilder;
|
import org.jclouds.aws.s3.blobstore.S3BlobStoreContextBuilder;
|
||||||
import org.jclouds.aws.s3.blobstore.S3BlobStoreContextFactory;
|
import org.jclouds.aws.s3.blobstore.S3BlobStoreContextFactory;
|
||||||
|
@ -55,6 +54,7 @@ import org.jclouds.rackspace.cloudfiles.CloudFilesPropertiesBuilder;
|
||||||
import org.jclouds.rackspace.cloudfiles.blobstore.CloudFilesBlobStoreContextBuilder;
|
import org.jclouds.rackspace.cloudfiles.blobstore.CloudFilesBlobStoreContextBuilder;
|
||||||
import org.jclouds.rackspace.cloudfiles.blobstore.CloudFilesBlobStoreContextFactory;
|
import org.jclouds.rackspace.cloudfiles.blobstore.CloudFilesBlobStoreContextFactory;
|
||||||
import org.jclouds.twitter.TwitterPropertiesBuilder;
|
import org.jclouds.twitter.TwitterPropertiesBuilder;
|
||||||
|
import org.jclouds.util.Utils;
|
||||||
import org.testng.annotations.BeforeClass;
|
import org.testng.annotations.BeforeClass;
|
||||||
import org.testng.annotations.BeforeTest;
|
import org.testng.annotations.BeforeTest;
|
||||||
import org.testng.annotations.Parameters;
|
import org.testng.annotations.Parameters;
|
||||||
|
@ -161,7 +161,7 @@ public class TweetStoreLiveTest {
|
||||||
@Test
|
@Test
|
||||||
public void shouldPass() throws InterruptedException, IOException {
|
public void shouldPass() throws InterruptedException, IOException {
|
||||||
InputStream i = url.openStream();
|
InputStream i = url.openStream();
|
||||||
String string = IOUtils.toString(i);
|
String string = Utils.toStringAndClose(i);
|
||||||
assert string.indexOf("Welcome") >= 0 : string;
|
assert string.indexOf("Welcome") >= 0 : string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -180,7 +180,7 @@ public class TweetStoreLiveTest {
|
||||||
connection.addRequestProperty("X-AppEngine-QueueName", "twitter");
|
connection.addRequestProperty("X-AppEngine-QueueName", "twitter");
|
||||||
connection.addRequestProperty("context", context);
|
connection.addRequestProperty("context", context);
|
||||||
InputStream i = connection.getInputStream();
|
InputStream i = connection.getInputStream();
|
||||||
String string = IOUtils.toString(i);
|
String string = Utils.toStringAndClose(i);
|
||||||
assert string.indexOf("Done!") >= 0 : string;
|
assert string.indexOf("Done!") >= 0 : string;
|
||||||
connection.disconnect();
|
connection.disconnect();
|
||||||
}
|
}
|
||||||
|
@ -197,7 +197,7 @@ public class TweetStoreLiveTest {
|
||||||
public void testSerial() throws InterruptedException, IOException {
|
public void testSerial() throws InterruptedException, IOException {
|
||||||
URL gurl = new URL(url, "/tweets/get");
|
URL gurl = new URL(url, "/tweets/get");
|
||||||
InputStream i = gurl.openStream();
|
InputStream i = gurl.openStream();
|
||||||
String string = IOUtils.toString(i);
|
String string = Utils.toStringAndClose(i);
|
||||||
assert string.indexOf("Tweets in Clouds") >= 0 : string;
|
assert string.indexOf("Tweets in Clouds") >= 0 : string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -205,7 +205,7 @@ public class TweetStoreLiveTest {
|
||||||
public void testParallel() throws InterruptedException, IOException {
|
public void testParallel() throws InterruptedException, IOException {
|
||||||
URL gurl = new URL(url, "/tweets/get");
|
URL gurl = new URL(url, "/tweets/get");
|
||||||
InputStream i = gurl.openStream();
|
InputStream i = gurl.openStream();
|
||||||
String string = IOUtils.toString(i);
|
String string = Utils.toStringAndClose(i);
|
||||||
assert string.indexOf("Tweets in Clouds") >= 0 : string;
|
assert string.indexOf("Tweets in Clouds") >= 0 : string;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.encryption.bouncycastle;
|
package org.jclouds.encryption.bouncycastle;
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -33,8 +34,6 @@ import java.security.NoSuchProviderException;
|
||||||
|
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.apache.commons.io.output.ByteArrayOutputStream;
|
|
||||||
import org.bouncycastle.crypto.Digest;
|
import org.bouncycastle.crypto.Digest;
|
||||||
import org.bouncycastle.crypto.digests.MD5Digest;
|
import org.bouncycastle.crypto.digests.MD5Digest;
|
||||||
import org.bouncycastle.crypto.digests.SHA1Digest;
|
import org.bouncycastle.crypto.digests.SHA1Digest;
|
||||||
|
@ -45,6 +44,8 @@ import org.bouncycastle.util.encoders.Base64;
|
||||||
import org.jclouds.encryption.internal.BaseEncryptionService;
|
import org.jclouds.encryption.internal.BaseEncryptionService;
|
||||||
import org.jclouds.util.Utils;
|
import org.jclouds.util.Utils;
|
||||||
|
|
||||||
|
import com.google.common.io.Closeables;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
|
@ -104,7 +105,7 @@ public class BouncyCastleEncryptionService extends BaseEncryptionService {
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
} finally {
|
} finally {
|
||||||
IOUtils.closeQuietly(i);
|
Closeables.closeQuietly(i);
|
||||||
}
|
}
|
||||||
eTag.doFinal(resBuf, 0);
|
eTag.doFinal(resBuf, 0);
|
||||||
return resBuf;
|
return resBuf;
|
||||||
|
@ -133,8 +134,8 @@ public class BouncyCastleEncryptionService extends BaseEncryptionService {
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
} finally {
|
} finally {
|
||||||
IOUtils.closeQuietly(out);
|
Closeables.closeQuietly(out);
|
||||||
IOUtils.closeQuietly(toEncode);
|
Closeables.closeQuietly(toEncode);
|
||||||
}
|
}
|
||||||
eTag.doFinal(resBuf, 0);
|
eTag.doFinal(resBuf, 0);
|
||||||
return new MD5InputStreamResult(out.toByteArray(), resBuf, length);
|
return new MD5InputStreamResult(out.toByteArray(), resBuf, length);
|
||||||
|
|
|
@ -36,7 +36,6 @@ import javax.inject.Inject;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
import javax.ws.rs.core.HttpHeaders;
|
import javax.ws.rs.core.HttpHeaders;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.jclouds.concurrent.SingleThreaded;
|
import org.jclouds.concurrent.SingleThreaded;
|
||||||
import org.jclouds.http.HttpCommand;
|
import org.jclouds.http.HttpCommand;
|
||||||
import org.jclouds.http.HttpCommandExecutorService;
|
import org.jclouds.http.HttpCommandExecutorService;
|
||||||
|
@ -59,6 +58,8 @@ import com.google.appengine.api.urlfetch.HTTPRequest;
|
||||||
import com.google.appengine.api.urlfetch.HTTPResponse;
|
import com.google.appengine.api.urlfetch.HTTPResponse;
|
||||||
import com.google.appengine.api.urlfetch.URLFetchService;
|
import com.google.appengine.api.urlfetch.URLFetchService;
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
|
import com.google.common.io.ByteStreams;
|
||||||
|
import com.google.common.io.Closeables;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Google App Engine version of {@link HttpCommandExecutorService}
|
* Google App Engine version of {@link HttpCommandExecutorService}
|
||||||
|
@ -99,9 +100,9 @@ public class GaeHttpCommandExecutorService extends BaseHttpCommandExecutorServic
|
||||||
} else if (content instanceof InputStreamPayload || content instanceof FilePayload) {
|
} else if (content instanceof InputStreamPayload || content instanceof FilePayload) {
|
||||||
InputStream i = content.getContent();
|
InputStream i = content.getContent();
|
||||||
try {
|
try {
|
||||||
request.setPayload(IOUtils.toByteArray(i));
|
request.setPayload(ByteStreams.toByteArray(i));
|
||||||
} finally {
|
} finally {
|
||||||
IOUtils.closeQuietly(i);
|
Closeables.closeQuietly(i);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new UnsupportedOperationException("Content not supported " + content.getClass());
|
throw new UnsupportedOperationException("Content not supported " + content.getClass());
|
||||||
|
|
|
@ -30,7 +30,6 @@ import static org.easymock.classextension.EasyMock.replay;
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
@ -42,13 +41,13 @@ import java.util.concurrent.ExecutorService;
|
||||||
import javax.ws.rs.HttpMethod;
|
import javax.ws.rs.HttpMethod;
|
||||||
import javax.ws.rs.core.HttpHeaders;
|
import javax.ws.rs.core.HttpHeaders;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.jclouds.http.HttpRequest;
|
import org.jclouds.http.HttpRequest;
|
||||||
import org.jclouds.http.HttpResponse;
|
import org.jclouds.http.HttpResponse;
|
||||||
import org.jclouds.http.Payloads;
|
import org.jclouds.http.Payloads;
|
||||||
import org.jclouds.http.handlers.DelegatingErrorHandler;
|
import org.jclouds.http.handlers.DelegatingErrorHandler;
|
||||||
import org.jclouds.http.handlers.DelegatingRetryHandler;
|
import org.jclouds.http.handlers.DelegatingRetryHandler;
|
||||||
import org.jclouds.http.internal.HttpWire;
|
import org.jclouds.http.internal.HttpWire;
|
||||||
|
import org.jclouds.util.Utils;
|
||||||
import org.testng.annotations.BeforeTest;
|
import org.testng.annotations.BeforeTest;
|
||||||
import org.testng.annotations.Parameters;
|
import org.testng.annotations.Parameters;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
@ -57,6 +56,8 @@ import com.google.appengine.api.urlfetch.HTTPHeader;
|
||||||
import com.google.appengine.api.urlfetch.HTTPRequest;
|
import com.google.appengine.api.urlfetch.HTTPRequest;
|
||||||
import com.google.appengine.api.urlfetch.HTTPResponse;
|
import com.google.appengine.api.urlfetch.HTTPResponse;
|
||||||
import com.google.appengine.api.urlfetch.URLFetchService;
|
import com.google.appengine.api.urlfetch.URLFetchService;
|
||||||
|
import com.google.appengine.repackaged.com.google.common.base.Charsets;
|
||||||
|
import com.google.common.io.Files;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -107,7 +108,7 @@ public class GaeHttpCommandExecutorServiceTest {
|
||||||
replay(gaeResponse);
|
replay(gaeResponse);
|
||||||
HttpResponse response = client.convert(gaeResponse);
|
HttpResponse response = client.convert(gaeResponse);
|
||||||
assertEquals(response.getStatusCode(), 200);
|
assertEquals(response.getStatusCode(), 200);
|
||||||
assertEquals(IOUtils.toString(response.getContent()), "hello");
|
assertEquals(Utils.toStringAndClose(response.getContent()), "hello");
|
||||||
assertEquals(response.getHeaders().size(), 1);
|
assertEquals(response.getHeaders().size(), 1);
|
||||||
assertEquals(response.getFirstHeaderOrNull(HttpHeaders.CONTENT_TYPE), "text/xml");
|
assertEquals(response.getFirstHeaderOrNull(HttpHeaders.CONTENT_TYPE), "text/xml");
|
||||||
}
|
}
|
||||||
|
@ -153,7 +154,7 @@ public class GaeHttpCommandExecutorServiceTest {
|
||||||
@Test
|
@Test
|
||||||
void testConvertRequestInputStreamContent() throws IOException {
|
void testConvertRequestInputStreamContent() throws IOException {
|
||||||
HttpRequest request = new HttpRequest(HttpMethod.GET, endPoint);
|
HttpRequest request = new HttpRequest(HttpMethod.GET, endPoint);
|
||||||
request.setPayload(IOUtils.toInputStream("hoot!"));
|
request.setPayload(Utils.toInputStream("hoot!"));
|
||||||
testHoot(request);
|
testHoot(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -177,7 +178,7 @@ public class GaeHttpCommandExecutorServiceTest {
|
||||||
HttpRequest request = new HttpRequest(HttpMethod.GET, endPoint);
|
HttpRequest request = new HttpRequest(HttpMethod.GET, endPoint);
|
||||||
File file = new File(basedir, "target/testfiles/hoot");
|
File file = new File(basedir, "target/testfiles/hoot");
|
||||||
file.getParentFile().mkdirs();
|
file.getParentFile().mkdirs();
|
||||||
IOUtils.write("hoot!", new FileOutputStream(file));
|
Files.write("hoot!".getBytes(Charsets.UTF_8), file);
|
||||||
request.setPayload(file);
|
request.setPayload(file);
|
||||||
testHoot(request);
|
testHoot(request);
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,5 +41,10 @@
|
||||||
<artifactId>jsch</artifactId>
|
<artifactId>jsch</artifactId>
|
||||||
<version>0.1.41</version>
|
<version>0.1.41</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>commons-io</groupId>
|
||||||
|
<artifactId>commons-io</artifactId>
|
||||||
|
<version>1.4</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -37,7 +37,6 @@ import javax.annotation.PreDestroy;
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.apache.commons.io.input.ProxyInputStream;
|
import org.apache.commons.io.input.ProxyInputStream;
|
||||||
import org.apache.commons.io.output.ByteArrayOutputStream;
|
import org.apache.commons.io.output.ByteArrayOutputStream;
|
||||||
import org.jclouds.logging.Logger;
|
import org.jclouds.logging.Logger;
|
||||||
|
@ -46,6 +45,7 @@ import org.jclouds.ssh.SshClient;
|
||||||
import org.jclouds.ssh.SshException;
|
import org.jclouds.ssh.SshException;
|
||||||
import org.jclouds.util.Utils;
|
import org.jclouds.util.Utils;
|
||||||
|
|
||||||
|
import com.google.common.io.Closeables;
|
||||||
import com.jcraft.jsch.ChannelExec;
|
import com.jcraft.jsch.ChannelExec;
|
||||||
import com.jcraft.jsch.ChannelSftp;
|
import com.jcraft.jsch.ChannelSftp;
|
||||||
import com.jcraft.jsch.JSch;
|
import com.jcraft.jsch.JSch;
|
||||||
|
@ -148,7 +148,7 @@ public class JschSshClient implements SshClient {
|
||||||
throw new SshException(String.format("%s@%s:%d: Error putting path: %s", username, host
|
throw new SshException(String.format("%s@%s:%d: Error putting path: %s", username, host
|
||||||
.getHostAddress(), port, path), e);
|
.getHostAddress(), port, path), e);
|
||||||
} finally {
|
} finally {
|
||||||
IOUtils.closeQuietly(contents);
|
Closeables.closeQuietly(contents);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,6 @@ import java.net.InetAddress;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.jclouds.ssh.ExecResponse;
|
import org.jclouds.ssh.ExecResponse;
|
||||||
import org.jclouds.ssh.SshClient;
|
import org.jclouds.ssh.SshClient;
|
||||||
import org.jclouds.ssh.jsch.config.JschSshClientModule;
|
import org.jclouds.ssh.jsch.config.JschSshClientModule;
|
||||||
|
@ -78,9 +77,9 @@ public class JschSshClientLiveTest {
|
||||||
|
|
||||||
public InputStream get(String path) {
|
public InputStream get(String path) {
|
||||||
if (path.equals("/etc/passwd")) {
|
if (path.equals("/etc/passwd")) {
|
||||||
return IOUtils.toInputStream("root");
|
return Utils.toInputStream("root");
|
||||||
} else if (path.equals(temp.getAbsolutePath())) {
|
} else if (path.equals(temp.getAbsolutePath())) {
|
||||||
return IOUtils.toInputStream("rabbit");
|
return Utils.toInputStream("rabbit");
|
||||||
}
|
}
|
||||||
throw new RuntimeException("path " + path + " not stubbed");
|
throw new RuntimeException("path " + path + " not stubbed");
|
||||||
}
|
}
|
||||||
|
@ -121,7 +120,7 @@ public class JschSshClientLiveTest {
|
||||||
temp = File.createTempFile("foo", "bar");
|
temp = File.createTempFile("foo", "bar");
|
||||||
temp.deleteOnExit();
|
temp.deleteOnExit();
|
||||||
SshClient client = setupClient();
|
SshClient client = setupClient();
|
||||||
client.put(temp.getAbsolutePath(), IOUtils.toInputStream("rabbit"));
|
client.put(temp.getAbsolutePath(), Utils.toInputStream("rabbit"));
|
||||||
InputStream input = setupClient().get(temp.getAbsolutePath());
|
InputStream input = setupClient().get(temp.getAbsolutePath());
|
||||||
String contents = Utils.toStringAndClose(input);
|
String contents = Utils.toStringAndClose(input);
|
||||||
assertEquals(contents, "rabbit");
|
assertEquals(contents, "rabbit");
|
||||||
|
|
|
@ -38,7 +38,6 @@ import java.util.concurrent.TimeoutException;
|
||||||
|
|
||||||
import javax.ws.rs.core.UriBuilder;
|
import javax.ws.rs.core.UriBuilder;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.jclouds.blobstore.KeyNotFoundException;
|
import org.jclouds.blobstore.KeyNotFoundException;
|
||||||
import org.jclouds.blobstore.domain.ResourceType;
|
import org.jclouds.blobstore.domain.ResourceType;
|
||||||
import org.jclouds.blobstore.integration.internal.BaseBlobStoreIntegrationTest;
|
import org.jclouds.blobstore.integration.internal.BaseBlobStoreIntegrationTest;
|
||||||
|
@ -48,6 +47,7 @@ import org.jclouds.mezeo.pcs2.domain.ContainerList;
|
||||||
import org.jclouds.mezeo.pcs2.domain.FileInfoWithMetadata;
|
import org.jclouds.mezeo.pcs2.domain.FileInfoWithMetadata;
|
||||||
import org.jclouds.mezeo.pcs2.domain.PCSFile;
|
import org.jclouds.mezeo.pcs2.domain.PCSFile;
|
||||||
import org.jclouds.mezeo.pcs2.domain.ResourceInfo;
|
import org.jclouds.mezeo.pcs2.domain.ResourceInfo;
|
||||||
|
import org.jclouds.util.Utils;
|
||||||
import org.testng.annotations.BeforeGroups;
|
import org.testng.annotations.BeforeGroups;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
@ -178,7 +178,7 @@ public class PCSClientLiveTest {
|
||||||
}
|
}
|
||||||
// Test GET of object (including updated metadata)
|
// Test GET of object (including updated metadata)
|
||||||
InputStream file = connection.downloadFile(objectURI);
|
InputStream file = connection.downloadFile(objectURI);
|
||||||
assertEquals(IOUtils.toString(file), data);
|
assertEquals(Utils.toStringAndClose(file), data);
|
||||||
validateFileInfoAndNameIsInMetadata(container, objectURI, "object", new Long(data.length()));
|
validateFileInfoAndNameIsInMetadata(container, objectURI, "object", new Long(data.length()));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -210,7 +210,7 @@ public class PCSClientLiveTest {
|
||||||
validateFileInfoAndNameIsInMetadata(container, objectURI, name, new Long(data.length()));
|
validateFileInfoAndNameIsInMetadata(container, objectURI, name, new Long(data.length()));
|
||||||
|
|
||||||
file = connection.downloadFile(objectURI);
|
file = connection.downloadFile(objectURI);
|
||||||
assertEquals(IOUtils.toString(file), data);
|
assertEquals(Utils.toStringAndClose(file), data);
|
||||||
|
|
||||||
// change data in an existing file
|
// change data in an existing file
|
||||||
data = "Here is my datum";
|
data = "Here is my datum";
|
||||||
|
@ -219,7 +219,7 @@ public class PCSClientLiveTest {
|
||||||
validateFileInfoAndNameIsInMetadata(container, objectURI, name, new Long(data.length()));
|
validateFileInfoAndNameIsInMetadata(container, objectURI, name, new Long(data.length()));
|
||||||
|
|
||||||
file = connection.downloadFile(objectURI);
|
file = connection.downloadFile(objectURI);
|
||||||
assertEquals(IOUtils.toString(file), data);
|
assertEquals(Utils.toStringAndClose(file), data);
|
||||||
|
|
||||||
connection.deleteFile(objectURI);
|
connection.deleteFile(objectURI);
|
||||||
connection.deleteContainer(container);
|
connection.deleteContainer(container);
|
||||||
|
|
|
@ -83,7 +83,7 @@ public class AddMetadataAndReturnIdTest {
|
||||||
// AddMetadataAndReturnId function = new AddMetadataAndReturnId(fileCache, connection);
|
// AddMetadataAndReturnId function = new AddMetadataAndReturnId(fileCache, connection);
|
||||||
// function.setContext(factory.createRequest(method, "container", new PCSFile("key"), URI
|
// function.setContext(factory.createRequest(method, "container", new PCSFile("key"), URI
|
||||||
// .create("http://localhost:8080")));
|
// .create("http://localhost:8080")));
|
||||||
// response.setContent(IOUtils
|
// response.setContent(Utils
|
||||||
// .toInputStream("http://localhost/contents/7F143552-AAF5-11DE-BBB0-0BC388ED913B"));
|
// .toInputStream("http://localhost/contents/7F143552-AAF5-11DE-BBB0-0BC388ED913B"));
|
||||||
// String eTag = function.apply(response);
|
// String eTag = function.apply(response);
|
||||||
// assertEquals(eTag, "7F143552-AAF5-11DE-BBB0-0BC388ED913B");
|
// assertEquals(eTag, "7F143552-AAF5-11DE-BBB0-0BC388ED913B");
|
||||||
|
@ -98,7 +98,7 @@ public class AddMetadataAndReturnIdTest {
|
||||||
//
|
//
|
||||||
// function.setContext(factory.createRequest(method, "container", pcsFile, URI
|
// function.setContext(factory.createRequest(method, "container", pcsFile, URI
|
||||||
// .create("http://localhost:8080")));
|
// .create("http://localhost:8080")));
|
||||||
// response.setContent(IOUtils
|
// response.setContent(Utils
|
||||||
// .toInputStream("http://localhost/contents/7F143552-AAF5-11DE-BBB0-0BC388ED913B"));
|
// .toInputStream("http://localhost/contents/7F143552-AAF5-11DE-BBB0-0BC388ED913B"));
|
||||||
// String eTag = function.apply(response);
|
// String eTag = function.apply(response);
|
||||||
// assertEquals(eTag, "7F143552-AAF5-11DE-BBB0-0BC388ED913B");
|
// assertEquals(eTag, "7F143552-AAF5-11DE-BBB0-0BC388ED913B");
|
||||||
|
|
|
@ -37,7 +37,6 @@ import java.util.SortedSet;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.jclouds.blobstore.ContainerNotFoundException;
|
import org.jclouds.blobstore.ContainerNotFoundException;
|
||||||
import org.jclouds.blobstore.KeyNotFoundException;
|
import org.jclouds.blobstore.KeyNotFoundException;
|
||||||
import org.jclouds.blobstore.domain.ListResponse;
|
import org.jclouds.blobstore.domain.ListResponse;
|
||||||
|
@ -54,6 +53,7 @@ import org.jclouds.rackspace.cloudfiles.domain.MutableObjectInfoWithMetadata;
|
||||||
import org.jclouds.rackspace.cloudfiles.domain.ObjectInfo;
|
import org.jclouds.rackspace.cloudfiles.domain.ObjectInfo;
|
||||||
import org.jclouds.rackspace.cloudfiles.options.ListCdnContainerOptions;
|
import org.jclouds.rackspace.cloudfiles.options.ListCdnContainerOptions;
|
||||||
import org.jclouds.rackspace.cloudfiles.options.ListContainerOptions;
|
import org.jclouds.rackspace.cloudfiles.options.ListContainerOptions;
|
||||||
|
import org.jclouds.util.Utils;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
|
@ -345,7 +345,7 @@ public class CloudFilesClientLiveTest extends
|
||||||
}
|
}
|
||||||
// Test GET of object (including updated metadata)
|
// Test GET of object (including updated metadata)
|
||||||
CFObject getBlob = context.getApi().getObject(containerName, object.getInfo().getName());
|
CFObject getBlob = context.getApi().getObject(containerName, object.getInfo().getName());
|
||||||
assertEquals(IOUtils.toString(getBlob.getContent()), data);
|
assertEquals(Utils.toStringAndClose(getBlob.getContent()), data);
|
||||||
// TODO assertEquals(getBlob.getName(), object.getMetadata().getName());
|
// TODO assertEquals(getBlob.getName(), object.getMetadata().getName());
|
||||||
assertEquals(getBlob.getContentLength(), new Long(data.length()));
|
assertEquals(getBlob.getContentLength(), new Long(data.length()));
|
||||||
assertEquals(getBlob.getInfo().getContentType(), "text/plain");
|
assertEquals(getBlob.getInfo().getContentType(), "text/plain");
|
||||||
|
@ -390,7 +390,7 @@ public class CloudFilesClientLiveTest extends
|
||||||
assertEquals(getBlob.getInfo().getHash(), encryptionService.fromHexString(newEtag));
|
assertEquals(getBlob.getInfo().getHash(), encryptionService.fromHexString(newEtag));
|
||||||
getBlob = context.getApi().getObject(containerName, object.getInfo().getName(),
|
getBlob = context.getApi().getObject(containerName, object.getInfo().getName(),
|
||||||
GetOptions.Builder.startAt(8));
|
GetOptions.Builder.startAt(8));
|
||||||
assertEquals(IOUtils.toString(getBlob.getContent()), data.substring(8));
|
assertEquals(Utils.toStringAndClose(getBlob.getContent()), data.substring(8));
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
returnContainer(containerName);
|
returnContainer(containerName);
|
||||||
|
|
|
@ -31,7 +31,6 @@ import java.net.URI;
|
||||||
import javax.ws.rs.core.HttpHeaders;
|
import javax.ws.rs.core.HttpHeaders;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
import org.jclouds.blobstore.domain.Blob;
|
||||||
import org.jclouds.blobstore.domain.Blob.Factory;
|
import org.jclouds.blobstore.domain.Blob.Factory;
|
||||||
import org.jclouds.http.HttpRequest;
|
import org.jclouds.http.HttpRequest;
|
||||||
|
@ -39,6 +38,7 @@ import org.jclouds.rackspace.cloudfiles.CloudFilesContextBuilder;
|
||||||
import org.jclouds.rackspace.cloudfiles.CloudFilesPropertiesBuilder;
|
import org.jclouds.rackspace.cloudfiles.CloudFilesPropertiesBuilder;
|
||||||
import org.jclouds.rackspace.cloudfiles.blobstore.functions.BlobToObject;
|
import org.jclouds.rackspace.cloudfiles.blobstore.functions.BlobToObject;
|
||||||
import org.jclouds.rackspace.cloudfiles.domain.CFObject;
|
import org.jclouds.rackspace.cloudfiles.domain.CFObject;
|
||||||
|
import org.jclouds.util.Utils;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import com.google.inject.Injector;
|
import com.google.inject.Injector;
|
||||||
|
@ -84,7 +84,7 @@ public class BindCFObjectToPayloadTest {
|
||||||
HttpRequest request = new HttpRequest("GET", URI.create("http://localhost:8001"));
|
HttpRequest request = new HttpRequest("GET", URI.create("http://localhost:8001"));
|
||||||
binder.bindToRequest(request, testBlob());
|
binder.bindToRequest(request, testBlob());
|
||||||
|
|
||||||
assertEquals(IOUtils.toString(request.getPayload().getContent()), "hello");
|
assertEquals(Utils.toStringAndClose(request.getPayload().getContent()), "hello");
|
||||||
assertEquals(request.getFirstHeaderOrNull(HttpHeaders.CONTENT_LENGTH), 5 + "");
|
assertEquals(request.getFirstHeaderOrNull(HttpHeaders.CONTENT_LENGTH), 5 + "");
|
||||||
assertEquals(request.getFirstHeaderOrNull(HttpHeaders.CONTENT_TYPE), MediaType.TEXT_PLAIN);
|
assertEquals(request.getFirstHeaderOrNull(HttpHeaders.CONTENT_TYPE), MediaType.TEXT_PLAIN);
|
||||||
}
|
}
|
||||||
|
@ -98,7 +98,7 @@ public class BindCFObjectToPayloadTest {
|
||||||
HttpRequest request = new HttpRequest("GET", URI.create("http://localhost:8001"));
|
HttpRequest request = new HttpRequest("GET", URI.create("http://localhost:8001"));
|
||||||
binder.bindToRequest(request, blob);
|
binder.bindToRequest(request, blob);
|
||||||
|
|
||||||
assertEquals(IOUtils.toString(request.getPayload().getContent()), "hello");
|
assertEquals(Utils.toStringAndClose(request.getPayload().getContent()), "hello");
|
||||||
assertEquals(request.getFirstHeaderOrNull(HttpHeaders.CONTENT_LENGTH), 5 + "");
|
assertEquals(request.getFirstHeaderOrNull(HttpHeaders.CONTENT_LENGTH), 5 + "");
|
||||||
assertEquals(request.getFirstHeaderOrNull(HttpHeaders.ETAG),
|
assertEquals(request.getFirstHeaderOrNull(HttpHeaders.ETAG),
|
||||||
"5d41402abc4b2a76b9719d911017c592");
|
"5d41402abc4b2a76b9719d911017c592");
|
||||||
|
|
|
@ -28,9 +28,9 @@ import static org.testng.Assert.assertEquals;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.jclouds.http.functions.config.ParserModule;
|
import org.jclouds.http.functions.config.ParserModule;
|
||||||
import org.jclouds.rackspace.cloudfiles.domain.ContainerMetadata;
|
import org.jclouds.rackspace.cloudfiles.domain.ContainerMetadata;
|
||||||
|
import org.jclouds.util.Utils;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
|
@ -49,7 +49,7 @@ public class ParseContainerListFromJsonResponseTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testApplyInputStream() {
|
public void testApplyInputStream() {
|
||||||
InputStream is = IOUtils
|
InputStream is = Utils
|
||||||
.toInputStream("[ {\"name\":\"test_container_1\",\"count\":2,\"bytes\":78}, {\"name\":\"test_container_2\",\"count\":1,\"bytes\":17} ] ");
|
.toInputStream("[ {\"name\":\"test_container_1\",\"count\":2,\"bytes\":78}, {\"name\":\"test_container_2\",\"count\":1,\"bytes\":17} ] ");
|
||||||
|
|
||||||
List<ContainerMetadata> expects = ImmutableList.of(new ContainerMetadata("test_container_1",
|
List<ContainerMetadata> expects = ImmutableList.of(new ContainerMetadata("test_container_1",
|
||||||
|
|
|
@ -28,11 +28,11 @@ import static org.testng.Assert.assertEquals;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.jclouds.http.functions.config.ParserModule;
|
import org.jclouds.http.functions.config.ParserModule;
|
||||||
import org.jclouds.rackspace.cloudservers.domain.BackupSchedule;
|
import org.jclouds.rackspace.cloudservers.domain.BackupSchedule;
|
||||||
import org.jclouds.rackspace.cloudservers.domain.DailyBackup;
|
import org.jclouds.rackspace.cloudservers.domain.DailyBackup;
|
||||||
import org.jclouds.rackspace.cloudservers.domain.WeeklyBackup;
|
import org.jclouds.rackspace.cloudservers.domain.WeeklyBackup;
|
||||||
|
import org.jclouds.util.Utils;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
|
@ -63,7 +63,7 @@ public class ParseBackupScheduleFromJsonResponseTest {
|
||||||
|
|
||||||
ParseBackupScheduleFromJsonResponse parser = new ParseBackupScheduleFromJsonResponse(i
|
ParseBackupScheduleFromJsonResponse parser = new ParseBackupScheduleFromJsonResponse(i
|
||||||
.getInstance(Gson.class));
|
.getInstance(Gson.class));
|
||||||
BackupSchedule response = parser.apply(IOUtils
|
BackupSchedule response = parser.apply(Utils
|
||||||
.toInputStream("{\"backupSchedule\":{\"enabled\" : false}}"));
|
.toInputStream("{\"backupSchedule\":{\"enabled\" : false}}"));
|
||||||
assertEquals(new BackupSchedule(), response);
|
assertEquals(new BackupSchedule(), response);
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,10 +36,11 @@ import java.net.URI;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.jclouds.blobstore.util.BlobStoreUtils;
|
import org.jclouds.blobstore.util.BlobStoreUtils;
|
||||||
import org.jclouds.http.HttpUtils;
|
import org.jclouds.http.HttpUtils;
|
||||||
|
|
||||||
|
import com.google.common.io.ByteStreams;
|
||||||
|
import com.google.common.io.Closeables;
|
||||||
import com.google.common.io.Resources;
|
import com.google.common.io.Resources;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -96,14 +97,14 @@ public class GetPath {
|
||||||
input = entry.getValue();
|
input = entry.getValue();
|
||||||
File file = new File(destinationDir, entry.getKey());
|
File file = new File(destinationDir, entry.getKey());
|
||||||
OutputStream out = new FileOutputStream(file);
|
OutputStream out = new FileOutputStream(file);
|
||||||
IOUtils.copyLarge(input, out);
|
ByteStreams.copy(input, out);
|
||||||
out.flush();
|
out.flush();
|
||||||
out.close();
|
out.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
// Close connecton
|
// Close connecton
|
||||||
IOUtils.closeQuietly(input);
|
Closeables.closeQuietly(input);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,6 @@ import java.io.IOException;
|
||||||
|
|
||||||
import junit.framework.Test;
|
import junit.framework.Test;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.apache.commons.vfs.AllFileSelector;
|
import org.apache.commons.vfs.AllFileSelector;
|
||||||
import org.apache.commons.vfs.FileContent;
|
import org.apache.commons.vfs.FileContent;
|
||||||
import org.apache.commons.vfs.FileObject;
|
import org.apache.commons.vfs.FileObject;
|
||||||
|
@ -37,10 +36,13 @@ import org.apache.commons.vfs.impl.DefaultFileSystemManager;
|
||||||
import org.apache.commons.vfs.test.AbstractProviderTestConfig;
|
import org.apache.commons.vfs.test.AbstractProviderTestConfig;
|
||||||
import org.jclouds.blobstore.BlobStore;
|
import org.jclouds.blobstore.BlobStore;
|
||||||
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
||||||
|
import org.jclouds.util.Utils;
|
||||||
import org.jclouds.vfs.provider.blobstore.BlobStoreFileObject;
|
import org.jclouds.vfs.provider.blobstore.BlobStoreFileObject;
|
||||||
import org.jclouds.vfs.provider.blobstore.BlobStoreFileProvider;
|
import org.jclouds.vfs.provider.blobstore.BlobStoreFileProvider;
|
||||||
|
|
||||||
|
import com.google.common.base.Charsets;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import com.google.common.io.CharStreams;
|
||||||
import com.google.inject.Module;
|
import com.google.inject.Module;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -111,7 +113,8 @@ public class BlobStoreProviderTestCase extends AbstractProviderTestConfig {
|
||||||
IOException {
|
IOException {
|
||||||
FileObject file = base.resolveFile(name);
|
FileObject file = base.resolveFile(name);
|
||||||
FileContent content = file.getContent();
|
FileContent content = file.getContent();
|
||||||
IOUtils.write(value, content.getOutputStream());
|
CharStreams.write(value, CharStreams.newWriterSupplier(Utils.newOutputStreamSupplier(content
|
||||||
|
.getOutputStream()), Charsets.UTF_8));
|
||||||
content.close();
|
content.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,6 @@ import javax.inject.Named;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
import javax.ws.rs.core.HttpHeaders;
|
import javax.ws.rs.core.HttpHeaders;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||||
import org.jclouds.util.Jsr330;
|
import org.jclouds.util.Jsr330;
|
||||||
import org.jclouds.util.Utils;
|
import org.jclouds.util.Utils;
|
||||||
|
@ -93,7 +92,7 @@ public class BindInstantiateVAppTemplateParamsToXmlPayloadTest {
|
||||||
});
|
});
|
||||||
|
|
||||||
public void testApplyInputStream1() throws IOException {
|
public void testApplyInputStream1() throws IOException {
|
||||||
String expected = IOUtils.toString(getClass().getResourceAsStream(
|
String expected = Utils.toStringAndClose(getClass().getResourceAsStream(
|
||||||
"/newvapp-hosting.xml"));
|
"/newvapp-hosting.xml"));
|
||||||
Multimap<String, String> headers = Multimaps
|
Multimap<String, String> headers = Multimaps
|
||||||
.synchronizedMultimap(HashMultimap.<String, String> create());
|
.synchronizedMultimap(HashMultimap.<String, String> create());
|
||||||
|
@ -125,7 +124,7 @@ public class BindInstantiateVAppTemplateParamsToXmlPayloadTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testApplyInputStream2() throws IOException {
|
public void testApplyInputStream2() throws IOException {
|
||||||
String expected = IOUtils.toString(getClass().getResourceAsStream(
|
String expected = Utils.toStringAndClose(getClass().getResourceAsStream(
|
||||||
"/newvapp-hosting.xml"));
|
"/newvapp-hosting.xml"));
|
||||||
Multimap<String, String> headers = Multimaps
|
Multimap<String, String> headers = Multimaps
|
||||||
.synchronizedMultimap(HashMultimap.<String, String> create());
|
.synchronizedMultimap(HashMultimap.<String, String> create());
|
||||||
|
|
|
@ -43,7 +43,6 @@ import javax.inject.Named;
|
||||||
import javax.inject.Provider;
|
import javax.inject.Provider;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.jclouds.http.functions.ParseSax;
|
import org.jclouds.http.functions.ParseSax;
|
||||||
import org.jclouds.http.functions.ReturnVoidIf2xx;
|
import org.jclouds.http.functions.ReturnVoidIf2xx;
|
||||||
import org.jclouds.logging.Logger;
|
import org.jclouds.logging.Logger;
|
||||||
|
@ -115,7 +114,7 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest<TerremarkVClo
|
||||||
assertHeadersEqual(
|
assertHeadersEqual(
|
||||||
httpMethod,
|
httpMethod,
|
||||||
"Content-Length: 2270\nContent-Type: application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml\n");
|
"Content-Length: 2270\nContent-Type: application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml\n");
|
||||||
assertPayloadEquals(httpMethod, IOUtils.toString(getClass().getResourceAsStream(
|
assertPayloadEquals(httpMethod, Utils.toStringAndClose(getClass().getResourceAsStream(
|
||||||
"/terremark/InstantiateVAppTemplateParams-test.xml")));
|
"/terremark/InstantiateVAppTemplateParams-test.xml")));
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
|
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
|
||||||
|
@ -137,7 +136,7 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest<TerremarkVClo
|
||||||
assertHeadersEqual(
|
assertHeadersEqual(
|
||||||
httpMethod,
|
httpMethod,
|
||||||
"Content-Length: 2239\nContent-Type: application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml\n");
|
"Content-Length: 2239\nContent-Type: application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml\n");
|
||||||
assertPayloadEquals(httpMethod, IOUtils.toString(getClass().getResourceAsStream(
|
assertPayloadEquals(httpMethod, Utils.toStringAndClose(getClass().getResourceAsStream(
|
||||||
"/terremark/InstantiateVAppTemplateParams-options-test.xml")));
|
"/terremark/InstantiateVAppTemplateParams-options-test.xml")));
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
|
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
|
||||||
|
@ -157,7 +156,7 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest<TerremarkVClo
|
||||||
|
|
||||||
assertRequestLineEquals(httpMethod, "POST http://vdc/internetServices HTTP/1.1");
|
assertRequestLineEquals(httpMethod, "POST http://vdc/internetServices HTTP/1.1");
|
||||||
assertHeadersEqual(httpMethod, "Content-Length: 303\nContent-Type: application/xml\n");
|
assertHeadersEqual(httpMethod, "Content-Length: 303\nContent-Type: application/xml\n");
|
||||||
assertPayloadEquals(httpMethod, IOUtils.toString(getClass().getResourceAsStream(
|
assertPayloadEquals(httpMethod, Utils.toStringAndClose(getClass().getResourceAsStream(
|
||||||
"/terremark/CreateInternetService-test2.xml")));
|
"/terremark/CreateInternetService-test2.xml")));
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
|
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
|
||||||
|
@ -177,7 +176,7 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest<TerremarkVClo
|
||||||
|
|
||||||
assertRequestLineEquals(httpMethod, "POST http://vdc/internetServices HTTP/1.1");
|
assertRequestLineEquals(httpMethod, "POST http://vdc/internetServices HTTP/1.1");
|
||||||
assertHeadersEqual(httpMethod, "Content-Length: 341\nContent-Type: application/xml\n");
|
assertHeadersEqual(httpMethod, "Content-Length: 341\nContent-Type: application/xml\n");
|
||||||
assertPayloadEquals(httpMethod, IOUtils.toString(getClass().getResourceAsStream(
|
assertPayloadEquals(httpMethod, Utils.toStringAndClose(getClass().getResourceAsStream(
|
||||||
"/terremark/CreateInternetService-options-test.xml")));
|
"/terremark/CreateInternetService-options-test.xml")));
|
||||||
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
|
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
|
||||||
assertSaxResponseParserClassEquals(method, InternetServiceHandler.class);
|
assertSaxResponseParserClassEquals(method, InternetServiceHandler.class);
|
||||||
|
@ -248,7 +247,7 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest<TerremarkVClo
|
||||||
assertRequestLineEquals(httpMethod,
|
assertRequestLineEquals(httpMethod,
|
||||||
"POST http://vcloud/publicIps/12/InternetServices HTTP/1.1");
|
"POST http://vcloud/publicIps/12/InternetServices HTTP/1.1");
|
||||||
assertHeadersEqual(httpMethod, "Content-Length: 303\nContent-Type: application/xml\n");
|
assertHeadersEqual(httpMethod, "Content-Length: 303\nContent-Type: application/xml\n");
|
||||||
assertPayloadEquals(httpMethod, IOUtils.toString(getClass().getResourceAsStream(
|
assertPayloadEquals(httpMethod, Utils.toStringAndClose(getClass().getResourceAsStream(
|
||||||
"/terremark/CreateInternetService-test2.xml")));
|
"/terremark/CreateInternetService-test2.xml")));
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
|
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
|
||||||
|
@ -269,7 +268,7 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest<TerremarkVClo
|
||||||
assertRequestLineEquals(httpMethod,
|
assertRequestLineEquals(httpMethod,
|
||||||
"POST http://vcloud/publicIps/12/InternetServices HTTP/1.1");
|
"POST http://vcloud/publicIps/12/InternetServices HTTP/1.1");
|
||||||
assertHeadersEqual(httpMethod, "Content-Length: 341\nContent-Type: application/xml\n");
|
assertHeadersEqual(httpMethod, "Content-Length: 341\nContent-Type: application/xml\n");
|
||||||
assertPayloadEquals(httpMethod, IOUtils.toString(getClass().getResourceAsStream(
|
assertPayloadEquals(httpMethod, Utils.toStringAndClose(getClass().getResourceAsStream(
|
||||||
"/terremark/CreateInternetService-options-test.xml")));
|
"/terremark/CreateInternetService-options-test.xml")));
|
||||||
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
|
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
|
||||||
assertSaxResponseParserClassEquals(method, InternetServiceHandler.class);
|
assertSaxResponseParserClassEquals(method, InternetServiceHandler.class);
|
||||||
|
@ -287,7 +286,7 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest<TerremarkVClo
|
||||||
|
|
||||||
assertRequestLineEquals(httpMethod, "POST http://vcloud/internetServices/12/nodes HTTP/1.1");
|
assertRequestLineEquals(httpMethod, "POST http://vcloud/internetServices/12/nodes HTTP/1.1");
|
||||||
assertHeadersEqual(httpMethod, "Content-Length: 298\nContent-Type: application/xml\n");
|
assertHeadersEqual(httpMethod, "Content-Length: 298\nContent-Type: application/xml\n");
|
||||||
assertPayloadEquals(httpMethod, IOUtils.toString(getClass().getResourceAsStream(
|
assertPayloadEquals(httpMethod, Utils.toStringAndClose(getClass().getResourceAsStream(
|
||||||
"/terremark/CreateNodeService-test2.xml")));
|
"/terremark/CreateNodeService-test2.xml")));
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
|
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
|
||||||
|
@ -307,7 +306,7 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest<TerremarkVClo
|
||||||
|
|
||||||
assertRequestLineEquals(httpMethod, "POST http://vcloud/internetServices/12/nodes HTTP/1.1");
|
assertRequestLineEquals(httpMethod, "POST http://vcloud/internetServices/12/nodes HTTP/1.1");
|
||||||
assertHeadersEqual(httpMethod, "Content-Length: 336\nContent-Type: application/xml\n");
|
assertHeadersEqual(httpMethod, "Content-Length: 336\nContent-Type: application/xml\n");
|
||||||
assertPayloadEquals(httpMethod, IOUtils.toString(getClass().getResourceAsStream(
|
assertPayloadEquals(httpMethod, Utils.toStringAndClose(getClass().getResourceAsStream(
|
||||||
"/terremark/CreateNodeService-options-test.xml")));
|
"/terremark/CreateNodeService-options-test.xml")));
|
||||||
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
|
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
|
||||||
assertSaxResponseParserClassEquals(method, NodeHandler.class);
|
assertSaxResponseParserClassEquals(method, NodeHandler.class);
|
||||||
|
|
|
@ -34,7 +34,6 @@ import javax.inject.Named;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
import javax.ws.rs.core.HttpHeaders;
|
import javax.ws.rs.core.HttpHeaders;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.jclouds.http.HttpRequest;
|
import org.jclouds.http.HttpRequest;
|
||||||
import org.jclouds.util.Utils;
|
import org.jclouds.util.Utils;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
@ -69,7 +68,7 @@ public class BindAddInternetServiceToXmlPayloadTest {
|
||||||
});
|
});
|
||||||
|
|
||||||
public void testApplyInputStream() throws IOException {
|
public void testApplyInputStream() throws IOException {
|
||||||
String expected = IOUtils.toString(getClass().getResourceAsStream(
|
String expected = Utils.toStringAndClose(getClass().getResourceAsStream(
|
||||||
"/terremark/CreateInternetService-test.xml"));
|
"/terremark/CreateInternetService-test.xml"));
|
||||||
HttpRequest request = new HttpRequest("GET", URI.create("http://test"));
|
HttpRequest request = new HttpRequest("GET", URI.create("http://test"));
|
||||||
BindAddInternetServiceToXmlPayload binder = injector
|
BindAddInternetServiceToXmlPayload binder = injector
|
||||||
|
|
|
@ -34,7 +34,6 @@ import javax.inject.Named;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
import javax.ws.rs.core.HttpHeaders;
|
import javax.ws.rs.core.HttpHeaders;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.jclouds.http.HttpRequest;
|
import org.jclouds.http.HttpRequest;
|
||||||
import org.jclouds.util.Utils;
|
import org.jclouds.util.Utils;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
@ -69,7 +68,7 @@ public class BindAddNodeServiceToXmlPayloadTest {
|
||||||
});
|
});
|
||||||
|
|
||||||
public void testApplyInputStream() throws IOException {
|
public void testApplyInputStream() throws IOException {
|
||||||
String expected = IOUtils.toString(getClass().getResourceAsStream(
|
String expected = Utils.toStringAndClose(getClass().getResourceAsStream(
|
||||||
"/terremark/CreateNodeService-test.xml"));
|
"/terremark/CreateNodeService-test.xml"));
|
||||||
HttpRequest request = new HttpRequest("GET", URI.create("http://test"));
|
HttpRequest request = new HttpRequest("GET", URI.create("http://test"));
|
||||||
BindAddNodeServiceToXmlPayload binder = injector
|
BindAddNodeServiceToXmlPayload binder = injector
|
||||||
|
|
|
@ -41,7 +41,6 @@ import java.util.Map;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||||
import org.jclouds.util.Jsr330;
|
import org.jclouds.util.Jsr330;
|
||||||
import org.jclouds.util.Utils;
|
import org.jclouds.util.Utils;
|
||||||
|
@ -104,7 +103,7 @@ public class TerremarkBindInstantiateVAppTemplateParamsToXmlPayloadTest {
|
||||||
|
|
||||||
public void testApplyInputStream() throws IOException {
|
public void testApplyInputStream() throws IOException {
|
||||||
|
|
||||||
String expected = IOUtils.toString(getClass().getResourceAsStream(
|
String expected = Utils.toStringAndClose(getClass().getResourceAsStream(
|
||||||
"/terremark/InstantiateVAppTemplateParams-test-2.xml"));
|
"/terremark/InstantiateVAppTemplateParams-test-2.xml"));
|
||||||
Multimap<String, String> headers = Multimaps
|
Multimap<String, String> headers = Multimaps
|
||||||
.synchronizedMultimap(HashMultimap.<String, String> create());
|
.synchronizedMultimap(HashMultimap.<String, String> create());
|
||||||
|
@ -135,7 +134,7 @@ public class TerremarkBindInstantiateVAppTemplateParamsToXmlPayloadTest {
|
||||||
|
|
||||||
public void testApplyInputStream2() throws IOException {
|
public void testApplyInputStream2() throws IOException {
|
||||||
|
|
||||||
String expected = IOUtils.toString(getClass().getResourceAsStream(
|
String expected = Utils.toStringAndClose(getClass().getResourceAsStream(
|
||||||
"/terremark/InstantiateVAppTemplateParams-test-2.xml"));
|
"/terremark/InstantiateVAppTemplateParams-test-2.xml"));
|
||||||
Multimap<String, String> headers = Multimaps
|
Multimap<String, String> headers = Multimaps
|
||||||
.synchronizedMultimap(HashMultimap.<String, String> create());
|
.synchronizedMultimap(HashMultimap.<String, String> create());
|
||||||
|
|
|
@ -121,7 +121,7 @@ public class TerremarkVCloudComputeClientLiveTest {
|
||||||
// bug creating more than one internet service returns 503 or 500
|
// bug creating more than one internet service returns 503 or 500
|
||||||
// InetAddress publicIp = client.createPublicAddressMappedToPorts(tmClient.getVApp(id), 22,
|
// InetAddress publicIp = client.createPublicAddressMappedToPorts(tmClient.getVApp(id), 22,
|
||||||
// 80,
|
// 80,
|
||||||
// 8080);
|
// 8080);
|
||||||
InetAddress publicIp = client.createPublicAddressMappedToPorts(tmClient.getVApp(id), 22);
|
InetAddress publicIp = client.createPublicAddressMappedToPorts(tmClient.getVApp(id), 22);
|
||||||
assert addressTester.apply(publicIp);
|
assert addressTester.apply(publicIp);
|
||||||
// client.exec(publicIp, "uname -a");
|
// client.exec(publicIp, "uname -a");
|
||||||
|
|
Loading…
Reference in New Issue