mirror of https://github.com/apache/jclouds.git
Issue 102: refactor to use RestContext instead of httpresponse.request
git-svn-id: http://jclouds.googlecode.com/svn/trunk@1935 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
parent
7c2804dee6
commit
2de58bb5b9
|
@ -31,7 +31,7 @@ import org.jclouds.aws.s3.internal.GuiceS3Context;
|
||||||
import org.jclouds.aws.s3.internal.LiveS3InputStreamMap;
|
import org.jclouds.aws.s3.internal.LiveS3InputStreamMap;
|
||||||
import org.jclouds.aws.s3.internal.LiveS3ObjectMap;
|
import org.jclouds.aws.s3.internal.LiveS3ObjectMap;
|
||||||
import org.jclouds.blobstore.functions.ParseBlobFromHeadersAndHttpContent.BlobFactory;
|
import org.jclouds.blobstore.functions.ParseBlobFromHeadersAndHttpContent.BlobFactory;
|
||||||
import org.jclouds.blobstore.functions.ParseBlobMetadataFromHeaders.BlobMetadataFactory;
|
import org.jclouds.blobstore.functions.ParseContentTypeFromHeaders.BlobMetadataFactory;
|
||||||
|
|
||||||
import com.google.inject.AbstractModule;
|
import com.google.inject.AbstractModule;
|
||||||
import com.google.inject.TypeLiteral;
|
import com.google.inject.TypeLiteral;
|
||||||
|
|
|
@ -29,7 +29,7 @@ import javax.ws.rs.core.HttpHeaders;
|
||||||
|
|
||||||
import org.jclouds.aws.s3.domain.ObjectMetadata;
|
import org.jclouds.aws.s3.domain.ObjectMetadata;
|
||||||
import org.jclouds.aws.s3.reference.S3Headers;
|
import org.jclouds.aws.s3.reference.S3Headers;
|
||||||
import org.jclouds.blobstore.functions.ParseBlobMetadataFromHeaders;
|
import org.jclouds.blobstore.functions.ParseSystemAndUserMetadataFromHeaders;
|
||||||
import org.jclouds.http.HttpResponse;
|
import org.jclouds.http.HttpResponse;
|
||||||
import org.jclouds.http.HttpUtils;
|
import org.jclouds.http.HttpUtils;
|
||||||
import org.jclouds.util.DateService;
|
import org.jclouds.util.DateService;
|
||||||
|
@ -44,7 +44,7 @@ import javax.inject.Named;
|
||||||
* @see <a href="http://docs.amazonwebservices.com/AmazonS3/latest/RESTObjectGET.html" />
|
* @see <a href="http://docs.amazonwebservices.com/AmazonS3/latest/RESTObjectGET.html" />
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class ParseObjectMetadataFromHeaders extends ParseBlobMetadataFromHeaders<ObjectMetadata> {
|
public class ParseObjectMetadataFromHeaders extends ParseSystemAndUserMetadataFromHeaders<ObjectMetadata> {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public ParseObjectMetadataFromHeaders(DateService dateParser,
|
public ParseObjectMetadataFromHeaders(DateService dateParser,
|
||||||
|
|
|
@ -40,7 +40,7 @@ import org.jclouds.aws.s3.domain.ObjectMetadata;
|
||||||
import org.jclouds.aws.s3.domain.S3Object;
|
import org.jclouds.aws.s3.domain.S3Object;
|
||||||
import org.jclouds.aws.s3.internal.GuiceS3Context;
|
import org.jclouds.aws.s3.internal.GuiceS3Context;
|
||||||
import org.jclouds.blobstore.functions.ParseBlobFromHeadersAndHttpContent.BlobFactory;
|
import org.jclouds.blobstore.functions.ParseBlobFromHeadersAndHttpContent.BlobFactory;
|
||||||
import org.jclouds.blobstore.functions.ParseBlobMetadataFromHeaders.BlobMetadataFactory;
|
import org.jclouds.blobstore.functions.ParseContentTypeFromHeaders.BlobMetadataFactory;
|
||||||
import org.jclouds.cloud.CloudContext;
|
import org.jclouds.cloud.CloudContext;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,6 @@ import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.URI;
|
|
||||||
|
|
||||||
import org.jclouds.aws.domain.AWSError;
|
import org.jclouds.aws.domain.AWSError;
|
||||||
import org.jclouds.aws.s3.reference.S3Constants;
|
import org.jclouds.aws.s3.reference.S3Constants;
|
||||||
|
@ -72,7 +71,7 @@ public class S3UtilsTest {
|
||||||
|
|
||||||
});
|
});
|
||||||
utils = injector.getInstance(S3Utils.class);
|
utils = injector.getInstance(S3Utils.class);
|
||||||
response = new HttpResponse(URI.create("http://localhost")); // TODO: Get real object URL?
|
response = new HttpResponse();
|
||||||
response.setStatusCode(400);
|
response.setStatusCode(400);
|
||||||
response.getHeaders().put(S3Headers.REQUEST_ID, "requestid");
|
response.getHeaders().put(S3Headers.REQUEST_ID, "requestid");
|
||||||
response.getHeaders().put(S3Headers.REQUEST_TOKEN, "requesttoken");
|
response.getHeaders().put(S3Headers.REQUEST_TOKEN, "requesttoken");
|
||||||
|
|
|
@ -1,3 +1,26 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
* ====================================================================
|
||||||
|
*/
|
||||||
package org.jclouds.azure.storage.blob;
|
package org.jclouds.azure.storage.blob;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
|
|
@ -31,7 +31,7 @@ import org.jclouds.azure.storage.blob.internal.GuiceAzureBlobContext;
|
||||||
import org.jclouds.azure.storage.blob.internal.LiveAzureBlobInputStreamMap;
|
import org.jclouds.azure.storage.blob.internal.LiveAzureBlobInputStreamMap;
|
||||||
import org.jclouds.azure.storage.blob.internal.LiveAzureBlobObjectMap;
|
import org.jclouds.azure.storage.blob.internal.LiveAzureBlobObjectMap;
|
||||||
import org.jclouds.blobstore.functions.ParseBlobFromHeadersAndHttpContent.BlobFactory;
|
import org.jclouds.blobstore.functions.ParseBlobFromHeadersAndHttpContent.BlobFactory;
|
||||||
import org.jclouds.blobstore.functions.ParseBlobMetadataFromHeaders.BlobMetadataFactory;
|
import org.jclouds.blobstore.functions.ParseContentTypeFromHeaders.BlobMetadataFactory;
|
||||||
|
|
||||||
import com.google.inject.AbstractModule;
|
import com.google.inject.AbstractModule;
|
||||||
import com.google.inject.TypeLiteral;
|
import com.google.inject.TypeLiteral;
|
||||||
|
|
|
@ -25,21 +25,21 @@ package org.jclouds.azure.storage.blob.functions;
|
||||||
|
|
||||||
import org.jclouds.azure.storage.blob.domain.Blob;
|
import org.jclouds.azure.storage.blob.domain.Blob;
|
||||||
import org.jclouds.azure.storage.blob.domain.BlobMetadata;
|
import org.jclouds.azure.storage.blob.domain.BlobMetadata;
|
||||||
import org.jclouds.blobstore.functions.ParseBlobMetadataFromHeaders;
|
import org.jclouds.blobstore.functions.ParseSystemAndUserMetadataFromHeaders;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses response headers and creates a new Azure Blob from them and the HTTP content.
|
* Parses response headers and creates a new Azure Blob from them and the HTTP content.
|
||||||
*
|
*
|
||||||
* @see ParseBlobMetadataFromHeaders
|
* @see ParseSystemAndUserMetadataFromHeaders
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class ParseBlobFromHeadersAndHttpContent extends
|
public class ParseBlobFromHeadersAndHttpContent extends
|
||||||
org.jclouds.blobstore.functions.ParseBlobFromHeadersAndHttpContent<BlobMetadata, Blob> {
|
org.jclouds.blobstore.functions.ParseBlobFromHeadersAndHttpContent<BlobMetadata, Blob> {
|
||||||
@Inject
|
@Inject
|
||||||
public ParseBlobFromHeadersAndHttpContent(
|
public ParseBlobFromHeadersAndHttpContent(
|
||||||
ParseBlobMetadataFromHeaders<BlobMetadata> metadataParser,
|
ParseSystemAndUserMetadataFromHeaders<BlobMetadata> metadataParser,
|
||||||
BlobFactory<BlobMetadata, Blob> blobFactory) {
|
BlobFactory<BlobMetadata, Blob> blobFactory) {
|
||||||
super(metadataParser, blobFactory);
|
super(metadataParser, blobFactory);
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,7 @@ import javax.inject.Named;
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class ParseBlobMetadataFromHeaders extends org.jclouds.blobstore.functions.ParseBlobMetadataFromHeaders<BlobMetadata> {
|
public class ParseBlobMetadataFromHeaders extends org.jclouds.blobstore.functions.ParseSystemAndUserMetadataFromHeaders<BlobMetadata> {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public ParseBlobMetadataFromHeaders(DateService dateParser,
|
public ParseBlobMetadataFromHeaders(DateService dateParser,
|
||||||
|
|
|
@ -1,3 +1,26 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
* ====================================================================
|
||||||
|
*/
|
||||||
package org.jclouds.azure.storage.blob.reference;
|
package org.jclouds.azure.storage.blob.reference;
|
||||||
|
|
||||||
import org.jclouds.azure.storage.reference.AzureStorageConstants;
|
import org.jclouds.azure.storage.reference.AzureStorageConstants;
|
||||||
|
|
|
@ -37,7 +37,7 @@ import org.jclouds.azure.storage.blob.domain.BlobMetadata;
|
||||||
import org.jclouds.azure.storage.blob.internal.GuiceAzureBlobContext;
|
import org.jclouds.azure.storage.blob.internal.GuiceAzureBlobContext;
|
||||||
import org.jclouds.azure.storage.reference.AzureStorageConstants;
|
import org.jclouds.azure.storage.reference.AzureStorageConstants;
|
||||||
import org.jclouds.blobstore.functions.ParseBlobFromHeadersAndHttpContent.BlobFactory;
|
import org.jclouds.blobstore.functions.ParseBlobFromHeadersAndHttpContent.BlobFactory;
|
||||||
import org.jclouds.blobstore.functions.ParseBlobMetadataFromHeaders.BlobMetadataFactory;
|
import org.jclouds.blobstore.functions.ParseContentTypeFromHeaders.BlobMetadataFactory;
|
||||||
import org.jclouds.cloud.CloudContext;
|
import org.jclouds.cloud.CloudContext;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
|
|
@ -77,7 +77,8 @@ public class AzureBlobStoreTest {
|
||||||
assertEquals(httpMethod.getHeaders().size(), 1);
|
assertEquals(httpMethod.getHeaders().size(), 1);
|
||||||
assertEquals(httpMethod.getHeaders().get("x-ms-version"), Collections
|
assertEquals(httpMethod.getHeaders().get("x-ms-version"), Collections
|
||||||
.singletonList("2009-07-17"));
|
.singletonList("2009-07-17"));
|
||||||
assertEquals(processor.createResponseParser(method).getClass(), ParseSax.class);
|
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
|
||||||
|
ParseSax.class);
|
||||||
// TODO check generic type of response parser
|
// TODO check generic type of response parser
|
||||||
assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null);
|
assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null);
|
||||||
}
|
}
|
||||||
|
@ -97,7 +98,8 @@ public class AzureBlobStoreTest {
|
||||||
assertEquals(httpMethod.getHeaders().size(), 1);
|
assertEquals(httpMethod.getHeaders().size(), 1);
|
||||||
assertEquals(httpMethod.getHeaders().get("x-ms-version"), Collections
|
assertEquals(httpMethod.getHeaders().get("x-ms-version"), Collections
|
||||||
.singletonList("2009-07-17"));
|
.singletonList("2009-07-17"));
|
||||||
assertEquals(processor.createResponseParser(method).getClass(), ParseSax.class);
|
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
|
||||||
|
ParseSax.class);
|
||||||
// TODO check generic type of response parser
|
// TODO check generic type of response parser
|
||||||
assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null);
|
assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null);
|
||||||
}
|
}
|
||||||
|
@ -114,7 +116,8 @@ public class AzureBlobStoreTest {
|
||||||
assertEquals(httpMethod.getHeaders().get("x-ms-version"), Collections
|
assertEquals(httpMethod.getHeaders().get("x-ms-version"), Collections
|
||||||
.singletonList("2009-07-17"));
|
.singletonList("2009-07-17"));
|
||||||
assertEquals(httpMethod.getHeaders().get("Content-Length"), Collections.singletonList("0"));
|
assertEquals(httpMethod.getHeaders().get("Content-Length"), Collections.singletonList("0"));
|
||||||
assertEquals(processor.createResponseParser(method).getClass(), ReturnTrueIf2xx.class);
|
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
|
||||||
|
ReturnTrueIf2xx.class);
|
||||||
// TODO check generic type of response parser
|
// TODO check generic type of response parser
|
||||||
assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(),
|
assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(),
|
||||||
ReturnTrueIfContainerAlreadyExists.class);
|
ReturnTrueIfContainerAlreadyExists.class);
|
||||||
|
@ -131,7 +134,8 @@ public class AzureBlobStoreTest {
|
||||||
assertEquals(httpMethod.getHeaders().size(), 1);
|
assertEquals(httpMethod.getHeaders().size(), 1);
|
||||||
assertEquals(httpMethod.getHeaders().get("x-ms-version"), Collections
|
assertEquals(httpMethod.getHeaders().get("x-ms-version"), Collections
|
||||||
.singletonList("2009-07-17"));
|
.singletonList("2009-07-17"));
|
||||||
assertEquals(processor.createResponseParser(method).getClass(), ReturnTrueIf2xx.class);
|
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
|
||||||
|
ReturnTrueIf2xx.class);
|
||||||
// TODO check generic type of response parser
|
// TODO check generic type of response parser
|
||||||
assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(),
|
assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(),
|
||||||
ReturnTrueOn404.class);
|
ReturnTrueOn404.class);
|
||||||
|
@ -154,7 +158,8 @@ public class AzureBlobStoreTest {
|
||||||
assertEquals(httpMethod.getHeaders().get("x-ms-prop-publicaccess"), Collections
|
assertEquals(httpMethod.getHeaders().get("x-ms-prop-publicaccess"), Collections
|
||||||
.singletonList("true"));
|
.singletonList("true"));
|
||||||
assertEquals(httpMethod.getHeaders().get("Content-Length"), Collections.singletonList("0"));
|
assertEquals(httpMethod.getHeaders().get("Content-Length"), Collections.singletonList("0"));
|
||||||
assertEquals(processor.createResponseParser(method).getClass(), ReturnTrueIf2xx.class);
|
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
|
||||||
|
ReturnTrueIf2xx.class);
|
||||||
// TODO check generic type of response parser
|
// TODO check generic type of response parser
|
||||||
assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(),
|
assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(),
|
||||||
ReturnTrueIfContainerAlreadyExists.class);
|
ReturnTrueIfContainerAlreadyExists.class);
|
||||||
|
@ -172,7 +177,8 @@ public class AzureBlobStoreTest {
|
||||||
assertEquals(httpMethod.getHeaders().get("x-ms-version"), Collections
|
assertEquals(httpMethod.getHeaders().get("x-ms-version"), Collections
|
||||||
.singletonList("2009-07-17"));
|
.singletonList("2009-07-17"));
|
||||||
assertEquals(httpMethod.getHeaders().get("Content-Length"), Collections.singletonList("0"));
|
assertEquals(httpMethod.getHeaders().get("Content-Length"), Collections.singletonList("0"));
|
||||||
assertEquals(processor.createResponseParser(method).getClass(), ReturnTrueIf2xx.class);
|
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
|
||||||
|
ReturnTrueIf2xx.class);
|
||||||
// TODO check generic type of response parser
|
// TODO check generic type of response parser
|
||||||
assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(),
|
assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(),
|
||||||
ReturnTrueIfContainerAlreadyExists.class);
|
ReturnTrueIfContainerAlreadyExists.class);
|
||||||
|
@ -189,7 +195,8 @@ public class AzureBlobStoreTest {
|
||||||
assertEquals(httpMethod.getHeaders().size(), 1);
|
assertEquals(httpMethod.getHeaders().size(), 1);
|
||||||
assertEquals(httpMethod.getHeaders().get("x-ms-version"), Collections
|
assertEquals(httpMethod.getHeaders().get("x-ms-version"), Collections
|
||||||
.singletonList("2009-07-17"));
|
.singletonList("2009-07-17"));
|
||||||
assertEquals(processor.createResponseParser(method).getClass(), ReturnTrueIf2xx.class);
|
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
|
||||||
|
ReturnTrueIf2xx.class);
|
||||||
// TODO check generic type of response parser
|
// TODO check generic type of response parser
|
||||||
assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(),
|
assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(),
|
||||||
ReturnTrueOn404.class);
|
ReturnTrueOn404.class);
|
||||||
|
@ -211,7 +218,8 @@ public class AzureBlobStoreTest {
|
||||||
assertEquals(httpMethod.getHeaders().get("x-ms-prop-publicaccess"), Collections
|
assertEquals(httpMethod.getHeaders().get("x-ms-prop-publicaccess"), Collections
|
||||||
.singletonList("true"));
|
.singletonList("true"));
|
||||||
assertEquals(httpMethod.getHeaders().get("Content-Length"), Collections.singletonList("0"));
|
assertEquals(httpMethod.getHeaders().get("Content-Length"), Collections.singletonList("0"));
|
||||||
assertEquals(processor.createResponseParser(method).getClass(), ReturnTrueIf2xx.class);
|
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
|
||||||
|
ReturnTrueIf2xx.class);
|
||||||
// TODO check generic type of response parser
|
// TODO check generic type of response parser
|
||||||
assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(),
|
assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(),
|
||||||
ReturnTrueIfContainerAlreadyExists.class);
|
ReturnTrueIfContainerAlreadyExists.class);
|
||||||
|
@ -228,7 +236,8 @@ public class AzureBlobStoreTest {
|
||||||
assertEquals(httpMethod.getHeaders().size(), 1);
|
assertEquals(httpMethod.getHeaders().size(), 1);
|
||||||
assertEquals(httpMethod.getHeaders().get("x-ms-version"), Collections
|
assertEquals(httpMethod.getHeaders().get("x-ms-version"), Collections
|
||||||
.singletonList("2009-07-17"));
|
.singletonList("2009-07-17"));
|
||||||
assertEquals(processor.createResponseParser(method).getClass(), ParseSax.class);
|
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
|
||||||
|
ParseSax.class);
|
||||||
// TODO check generic type of response parser
|
// TODO check generic type of response parser
|
||||||
assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null);
|
assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null);
|
||||||
}
|
}
|
||||||
|
@ -244,7 +253,8 @@ public class AzureBlobStoreTest {
|
||||||
assertEquals(httpMethod.getHeaders().size(), 1);
|
assertEquals(httpMethod.getHeaders().size(), 1);
|
||||||
assertEquals(httpMethod.getHeaders().get("x-ms-version"), Collections
|
assertEquals(httpMethod.getHeaders().get("x-ms-version"), Collections
|
||||||
.singletonList("2009-07-17"));
|
.singletonList("2009-07-17"));
|
||||||
assertEquals(processor.createResponseParser(method).getClass(), ParseSax.class);
|
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
|
||||||
|
ParseSax.class);
|
||||||
// TODO check generic type of response parser
|
// TODO check generic type of response parser
|
||||||
assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null);
|
assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,26 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
* ====================================================================
|
||||||
|
*/
|
||||||
package org.jclouds.azure.storage;
|
package org.jclouds.azure.storage;
|
||||||
|
|
||||||
import java.lang.annotation.ElementType;
|
import java.lang.annotation.ElementType;
|
||||||
|
|
|
@ -1,3 +1,26 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
* ====================================================================
|
||||||
|
*/
|
||||||
package org.jclouds.azure.storage;
|
package org.jclouds.azure.storage;
|
||||||
|
|
||||||
import java.lang.annotation.ElementType;
|
import java.lang.annotation.ElementType;
|
||||||
|
|
|
@ -1,3 +1,26 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
* ====================================================================
|
||||||
|
*/
|
||||||
package org.jclouds.azure.storage;
|
package org.jclouds.azure.storage;
|
||||||
|
|
||||||
import java.lang.annotation.ElementType;
|
import java.lang.annotation.ElementType;
|
||||||
|
|
|
@ -1,3 +1,26 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
* ====================================================================
|
||||||
|
*/
|
||||||
package org.jclouds.azure.storage.queue;
|
package org.jclouds.azure.storage.queue;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
|
|
@ -1,3 +1,26 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
* ====================================================================
|
||||||
|
*/
|
||||||
package org.jclouds.azure.storage.queue.reference;
|
package org.jclouds.azure.storage.queue.reference;
|
||||||
|
|
||||||
import org.jclouds.azure.storage.reference.AzureStorageConstants;
|
import org.jclouds.azure.storage.reference.AzureStorageConstants;
|
||||||
|
|
|
@ -78,7 +78,8 @@ public class AzureQueueConnectionTest {
|
||||||
assertEquals(httpMethod.getHeaders().size(), 1);
|
assertEquals(httpMethod.getHeaders().size(), 1);
|
||||||
assertEquals(httpMethod.getHeaders().get("x-ms-version"), Collections
|
assertEquals(httpMethod.getHeaders().get("x-ms-version"), Collections
|
||||||
.singletonList("2009-07-17"));
|
.singletonList("2009-07-17"));
|
||||||
assertEquals(processor.createResponseParser(method).getClass(), ParseSax.class);
|
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
|
||||||
|
ParseSax.class);
|
||||||
// TODO check generic type of response parser
|
// TODO check generic type of response parser
|
||||||
assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null);
|
assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null);
|
||||||
}
|
}
|
||||||
|
@ -98,7 +99,8 @@ public class AzureQueueConnectionTest {
|
||||||
assertEquals(httpMethod.getHeaders().size(), 1);
|
assertEquals(httpMethod.getHeaders().size(), 1);
|
||||||
assertEquals(httpMethod.getHeaders().get("x-ms-version"), Collections
|
assertEquals(httpMethod.getHeaders().get("x-ms-version"), Collections
|
||||||
.singletonList("2009-07-17"));
|
.singletonList("2009-07-17"));
|
||||||
assertEquals(processor.createResponseParser(method).getClass(), ParseSax.class);
|
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
|
||||||
|
ParseSax.class);
|
||||||
// TODO check generic type of response parser
|
// TODO check generic type of response parser
|
||||||
assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null);
|
assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null);
|
||||||
}
|
}
|
||||||
|
@ -116,7 +118,8 @@ public class AzureQueueConnectionTest {
|
||||||
assertEquals(httpMethod.getHeaders().get("x-ms-version"), Collections
|
assertEquals(httpMethod.getHeaders().get("x-ms-version"), Collections
|
||||||
.singletonList("2009-07-17"));
|
.singletonList("2009-07-17"));
|
||||||
assertEquals(httpMethod.getHeaders().get("Content-Length"), Collections.singletonList("0"));
|
assertEquals(httpMethod.getHeaders().get("Content-Length"), Collections.singletonList("0"));
|
||||||
assertEquals(processor.createResponseParser(method).getClass(), ReturnTrueIf2xx.class);
|
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
|
||||||
|
ReturnTrueIf2xx.class);
|
||||||
// TODO check generic type of response parser
|
// TODO check generic type of response parser
|
||||||
assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null);
|
assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null);
|
||||||
}
|
}
|
||||||
|
@ -132,7 +135,8 @@ public class AzureQueueConnectionTest {
|
||||||
assertEquals(httpMethod.getHeaders().size(), 1);
|
assertEquals(httpMethod.getHeaders().size(), 1);
|
||||||
assertEquals(httpMethod.getHeaders().get("x-ms-version"), Collections
|
assertEquals(httpMethod.getHeaders().get("x-ms-version"), Collections
|
||||||
.singletonList("2009-07-17"));
|
.singletonList("2009-07-17"));
|
||||||
assertEquals(processor.createResponseParser(method).getClass(), ReturnTrueIf2xx.class);
|
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
|
||||||
|
ReturnTrueIf2xx.class);
|
||||||
// TODO check generic type of response parser
|
// TODO check generic type of response parser
|
||||||
assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null);
|
assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null);
|
||||||
}
|
}
|
||||||
|
@ -152,7 +156,8 @@ public class AzureQueueConnectionTest {
|
||||||
.singletonList("2009-07-17"));
|
.singletonList("2009-07-17"));
|
||||||
assertEquals(httpMethod.getHeaders().get("x-ms-meta-foo"), Collections.singletonList("bar"));
|
assertEquals(httpMethod.getHeaders().get("x-ms-meta-foo"), Collections.singletonList("bar"));
|
||||||
assertEquals(httpMethod.getHeaders().get("Content-Length"), Collections.singletonList("0"));
|
assertEquals(httpMethod.getHeaders().get("Content-Length"), Collections.singletonList("0"));
|
||||||
assertEquals(processor.createResponseParser(method).getClass(), ReturnTrueIf2xx.class);
|
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
|
||||||
|
ReturnTrueIf2xx.class);
|
||||||
// TODO check generic type of response parser
|
// TODO check generic type of response parser
|
||||||
assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null);
|
assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null);
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.blobstore.functions;
|
package org.jclouds.blobstore.functions;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
import javax.ws.rs.core.HttpHeaders;
|
import javax.ws.rs.core.HttpHeaders;
|
||||||
|
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
import org.jclouds.blobstore.domain.Blob;
|
||||||
|
@ -32,17 +33,16 @@ import org.jclouds.http.HttpResponse;
|
||||||
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import javax.inject.Inject;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses response headers and creates a new Blob from them and the HTTP content.
|
* Parses response headers and creates a new Blob from them and the HTTP content.
|
||||||
*
|
*
|
||||||
* @see ParseBlobMetadataFromHeaders
|
* @see ParseSystemAndUserMetadataFromHeaders
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class ParseBlobFromHeadersAndHttpContent<M extends BlobMetadata, B extends Blob<M>>
|
public class ParseBlobFromHeadersAndHttpContent<M extends BlobMetadata, B extends Blob<M>>
|
||||||
implements Function<HttpResponse, B> {
|
implements Function<HttpResponse, B> {
|
||||||
private final ParseBlobMetadataFromHeaders<M> metadataParser;
|
private final ParseContentTypeFromHeaders<M> metadataParser;
|
||||||
private final BlobFactory<M, B> blobFactory;
|
private final BlobFactory<M, B> blobFactory;
|
||||||
|
|
||||||
public static interface BlobFactory<M extends BlobMetadata, B extends Blob<M>> {
|
public static interface BlobFactory<M extends BlobMetadata, B extends Blob<M>> {
|
||||||
|
@ -50,14 +50,14 @@ public class ParseBlobFromHeadersAndHttpContent<M extends BlobMetadata, B extend
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public ParseBlobFromHeadersAndHttpContent(ParseBlobMetadataFromHeaders<M> metadataParser,
|
public ParseBlobFromHeadersAndHttpContent(ParseContentTypeFromHeaders<M> metadataParser,
|
||||||
BlobFactory<M, B> blobFactory) {
|
BlobFactory<M, B> blobFactory) {
|
||||||
this.metadataParser = metadataParser;
|
this.metadataParser = metadataParser;
|
||||||
this.blobFactory = blobFactory;
|
this.blobFactory = blobFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* First, calls {@link ParseBlobMetadataFromHeaders}.
|
* First, calls {@link ParseSystemAndUserMetadataFromHeaders}.
|
||||||
*
|
*
|
||||||
* Then, sets the object size based on the Content-Length header and adds the content to the
|
* Then, sets the object size based on the Content-Length header and adds the content to the
|
||||||
* {@link Blob} result.
|
* {@link Blob} result.
|
||||||
|
@ -69,22 +69,22 @@ public class ParseBlobFromHeadersAndHttpContent<M extends BlobMetadata, B extend
|
||||||
B object = blobFactory.create(metadata);
|
B object = blobFactory.create(metadata);
|
||||||
assert object.getMetadata() == metadata;
|
assert object.getMetadata() == metadata;
|
||||||
object.setData(from.getContent());
|
object.setData(from.getContent());
|
||||||
parseContentLengthOrThrowException(from, object);
|
attemptToParseSizeAndRangeFromHeaders(from, object);
|
||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
void parseContentLengthOrThrowException(HttpResponse from, B object) throws HttpException {
|
void attemptToParseSizeAndRangeFromHeaders(HttpResponse from, B object) throws HttpException {
|
||||||
String contentLength = from.getFirstHeaderOrNull(HttpHeaders.CONTENT_LENGTH);
|
String contentLength = from.getFirstHeaderOrNull(HttpHeaders.CONTENT_LENGTH);
|
||||||
if (contentLength == null)
|
|
||||||
throw new HttpException(HttpHeaders.CONTENT_LENGTH + " header not present in headers: "
|
|
||||||
+ from.getHeaders());
|
|
||||||
object.setContentLength(Long.parseLong(contentLength));
|
|
||||||
|
|
||||||
String contentRange = from.getFirstHeaderOrNull("Content-Range");
|
String contentRange = from.getFirstHeaderOrNull("Content-Range");
|
||||||
if (contentRange == null) {
|
|
||||||
|
if (contentLength != null) {
|
||||||
|
object.setContentLength(Long.parseLong(contentLength));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (contentRange == null && contentLength != null) {
|
||||||
object.getMetadata().setSize(object.getContentLength());
|
object.getMetadata().setSize(object.getContentLength());
|
||||||
} else {
|
} else if (contentRange != null ) {
|
||||||
object.setContentRange(contentRange);
|
object.setContentRange(contentRange);
|
||||||
object.getMetadata().setSize(
|
object.getMetadata().setSize(
|
||||||
Long.parseLong(contentRange.substring(contentRange.lastIndexOf('/') + 1)));
|
Long.parseLong(contentRange.substring(contentRange.lastIndexOf('/') + 1)));
|
||||||
|
|
|
@ -0,0 +1,100 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
* ====================================================================
|
||||||
|
*/
|
||||||
|
package org.jclouds.blobstore.functions;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.ws.rs.core.HttpHeaders;
|
||||||
|
|
||||||
|
import org.jclouds.blobstore.domain.BlobMetadata;
|
||||||
|
import org.jclouds.http.HttpException;
|
||||||
|
import org.jclouds.http.HttpRequest;
|
||||||
|
import org.jclouds.http.HttpResponse;
|
||||||
|
import org.jclouds.rest.RestContext;
|
||||||
|
|
||||||
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
|
import com.google.common.base.Function;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
public class ParseContentTypeFromHeaders<M extends BlobMetadata> implements
|
||||||
|
Function<HttpResponse, M>, RestContext {
|
||||||
|
private final BlobMetadataFactory<M> metadataFactory;
|
||||||
|
private HttpRequest request;
|
||||||
|
private Object[] args;
|
||||||
|
|
||||||
|
public static interface BlobMetadataFactory<M extends BlobMetadata> {
|
||||||
|
M create(String key);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public ParseContentTypeFromHeaders(BlobMetadataFactory<M> metadataFactory) {
|
||||||
|
this.metadataFactory = metadataFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public M apply(HttpResponse from) {
|
||||||
|
String objectKey = getKeyFor(from);
|
||||||
|
M to = metadataFactory.create(objectKey);
|
||||||
|
addAllHeadersTo(from, to);
|
||||||
|
setContentTypeOrThrowException(from, to);
|
||||||
|
return to;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String getKeyFor(HttpResponse from) {
|
||||||
|
String objectKey = getRequest().getEndpoint().getPath();
|
||||||
|
if (objectKey.startsWith("/")) {
|
||||||
|
// Trim initial slash from object key name.
|
||||||
|
objectKey = objectKey.substring(1);
|
||||||
|
}
|
||||||
|
return objectKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
void addAllHeadersTo(HttpResponse from, M metadata) {
|
||||||
|
metadata.getAllHeaders().putAll(from.getHeaders());
|
||||||
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
void setContentTypeOrThrowException(HttpResponse from, M metadata) throws HttpException {
|
||||||
|
String contentType = from.getFirstHeaderOrNull(HttpHeaders.CONTENT_TYPE);
|
||||||
|
if (contentType == null)
|
||||||
|
throw new HttpException(HttpHeaders.CONTENT_TYPE + " not found in headers");
|
||||||
|
else
|
||||||
|
metadata.setContentType(contentType);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object[] getArgs() {
|
||||||
|
return args;
|
||||||
|
}
|
||||||
|
|
||||||
|
public HttpRequest getRequest() {
|
||||||
|
return request;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setContext(HttpRequest request, Object[] args) {
|
||||||
|
this.request = request;
|
||||||
|
this.args = args;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -27,6 +27,8 @@ import static org.jclouds.blobstore.reference.BlobStoreConstants.PROPERTY_USER_M
|
||||||
|
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Named;
|
||||||
import javax.ws.rs.core.HttpHeaders;
|
import javax.ws.rs.core.HttpHeaders;
|
||||||
|
|
||||||
import org.jclouds.blobstore.domain.BlobMetadata;
|
import org.jclouds.blobstore.domain.BlobMetadata;
|
||||||
|
@ -36,63 +38,42 @@ import org.jclouds.http.HttpUtils;
|
||||||
import org.jclouds.util.DateService;
|
import org.jclouds.util.DateService;
|
||||||
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
import com.google.common.base.Function;
|
|
||||||
import javax.inject.Inject;
|
|
||||||
import javax.inject.Named;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class ParseBlobMetadataFromHeaders<M extends BlobMetadata> implements
|
public class ParseSystemAndUserMetadataFromHeaders<M extends BlobMetadata> extends
|
||||||
Function<HttpResponse, M> {
|
ParseContentTypeFromHeaders<M> {
|
||||||
private final DateService dateParser;
|
|
||||||
private final String metadataPrefix;
|
private final String metadataPrefix;
|
||||||
private final BlobMetadataFactory<M> metadataFactory;
|
private final DateService dateParser;
|
||||||
|
|
||||||
public static interface BlobMetadataFactory<M extends BlobMetadata> {
|
|
||||||
M create(String key);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public ParseBlobMetadataFromHeaders(DateService dateParser,
|
public ParseSystemAndUserMetadataFromHeaders(DateService dateParser,
|
||||||
@Named(PROPERTY_USER_METADATA_PREFIX) String metadataPrefix,
|
@Named(PROPERTY_USER_METADATA_PREFIX) String metadataPrefix,
|
||||||
BlobMetadataFactory<M> metadataFactory) {
|
BlobMetadataFactory<M> metadataFactory) {
|
||||||
|
super(metadataFactory);
|
||||||
this.dateParser = dateParser;
|
this.dateParser = dateParser;
|
||||||
this.metadataPrefix = metadataPrefix;
|
this.metadataPrefix = metadataPrefix;
|
||||||
this.metadataFactory = metadataFactory;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public M apply(HttpResponse from) {
|
public M apply(HttpResponse from) {
|
||||||
String objectKey = from.getRequestURL().getPath();
|
M to = super.apply(from);
|
||||||
if (objectKey.startsWith("/")) {
|
|
||||||
// Trim initial slash from object key name.
|
|
||||||
objectKey = objectKey.substring(1);
|
|
||||||
}
|
|
||||||
M to = metadataFactory.create(objectKey);
|
|
||||||
addAllHeadersTo(from, to);
|
|
||||||
|
|
||||||
addUserMetadataTo(from, to);
|
|
||||||
addETagTo(from, to);
|
addETagTo(from, to);
|
||||||
addContentMD5To(from, to);
|
addContentMD5To(from, to);
|
||||||
|
|
||||||
parseLastModifiedOrThrowException(from, to);
|
parseLastModifiedOrThrowException(from, to);
|
||||||
setContentTypeOrThrowException(from, to);
|
|
||||||
setContentLengthOrThrowException(from, to);
|
setContentLengthOrThrowException(from, to);
|
||||||
|
addUserMetadataTo(from, to);
|
||||||
return to;
|
return to;
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
void addAllHeadersTo(HttpResponse from, M metadata) {
|
void addUserMetadataTo(HttpResponse from, M metadata) {
|
||||||
metadata.getAllHeaders().putAll(from.getHeaders());
|
for (Entry<String, String> header : from.getHeaders().entries()) {
|
||||||
|
if (header.getKey() != null && header.getKey().startsWith(metadataPrefix))
|
||||||
|
metadata.getUserMetadata().put(
|
||||||
|
(header.getKey().substring(metadataPrefix.length())).toLowerCase(),
|
||||||
|
header.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
|
||||||
void setContentTypeOrThrowException(HttpResponse from, M metadata) throws HttpException {
|
|
||||||
String contentType = from.getFirstHeaderOrNull(HttpHeaders.CONTENT_TYPE);
|
|
||||||
if (contentType == null)
|
|
||||||
throw new HttpException(HttpHeaders.CONTENT_TYPE + " not found in headers");
|
|
||||||
else
|
|
||||||
metadata.setContentType(contentType);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
|
@ -107,6 +88,9 @@ public class ParseBlobMetadataFromHeaders<M extends BlobMetadata> implements
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
void parseLastModifiedOrThrowException(HttpResponse from, M metadata) throws HttpException {
|
void parseLastModifiedOrThrowException(HttpResponse from, M metadata) throws HttpException {
|
||||||
String lastModified = from.getFirstHeaderOrNull(HttpHeaders.LAST_MODIFIED);
|
String lastModified = from.getFirstHeaderOrNull(HttpHeaders.LAST_MODIFIED);
|
||||||
|
if (lastModified == null)
|
||||||
|
throw new HttpException(HttpHeaders.LAST_MODIFIED + " header not present in response: "
|
||||||
|
+ from);
|
||||||
metadata.setLastModified(dateParser.rfc822DateParse(lastModified));
|
metadata.setLastModified(dateParser.rfc822DateParse(lastModified));
|
||||||
if (metadata.getLastModified() == null)
|
if (metadata.getLastModified() == null)
|
||||||
throw new HttpException("could not parse: " + HttpHeaders.LAST_MODIFIED + ": "
|
throw new HttpException("could not parse: " + HttpHeaders.LAST_MODIFIED + ": "
|
||||||
|
@ -128,15 +112,4 @@ public class ParseBlobMetadataFromHeaders<M extends BlobMetadata> implements
|
||||||
metadata.setContentMD5(HttpUtils.fromBase64String(contentMD5));
|
metadata.setContentMD5(HttpUtils.fromBase64String(contentMD5));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
|
||||||
void addUserMetadataTo(HttpResponse from, M metadata) {
|
|
||||||
for (Entry<String, String> header : from.getHeaders().entries()) {
|
|
||||||
if (header.getKey() != null && header.getKey().startsWith(metadataPrefix))
|
|
||||||
metadata.getUserMetadata().put(
|
|
||||||
(header.getKey().substring(metadataPrefix.length())).toLowerCase(),
|
|
||||||
header.getValue());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
package org.jclouds.blobstore.functions;
|
||||||
|
|
||||||
|
import org.jclouds.blobstore.KeyNotFoundException;
|
||||||
|
import org.jclouds.http.functions.ReturnTrueOn404;
|
||||||
|
|
||||||
|
import com.google.common.base.Function;
|
||||||
|
|
||||||
|
public class ReturnTrueOnKeyNotFoundOr404 implements Function<Exception, Boolean> {
|
||||||
|
ReturnTrueOn404 rto404 = new ReturnTrueOn404();
|
||||||
|
|
||||||
|
public Boolean apply(Exception from) {
|
||||||
|
if (from instanceof KeyNotFoundException) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return rto404.apply(from);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -47,7 +47,7 @@ public class ParseBlobFromHeadersAndHttpContentTest {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Test(expectedExceptions = NullPointerException.class)
|
@Test(expectedExceptions = NullPointerException.class)
|
||||||
public void testCall() throws HttpException {
|
public void testCall() throws HttpException {
|
||||||
ParseBlobMetadataFromHeaders<BlobMetadata> metadataParser = createMock(ParseBlobMetadataFromHeaders.class);
|
ParseSystemAndUserMetadataFromHeaders<BlobMetadata> metadataParser = createMock(ParseSystemAndUserMetadataFromHeaders.class);
|
||||||
ParseBlobFromHeadersAndHttpContent.BlobFactory<BlobMetadata, Blob<BlobMetadata>> objectFactory = createMock(ParseBlobFromHeadersAndHttpContent.BlobFactory.class);
|
ParseBlobFromHeadersAndHttpContent.BlobFactory<BlobMetadata, Blob<BlobMetadata>> objectFactory = createMock(ParseBlobFromHeadersAndHttpContent.BlobFactory.class);
|
||||||
ParseBlobFromHeadersAndHttpContent<BlobMetadata, Blob<BlobMetadata>> callable = new ParseBlobFromHeadersAndHttpContent(
|
ParseBlobFromHeadersAndHttpContent<BlobMetadata, Blob<BlobMetadata>> callable = new ParseBlobFromHeadersAndHttpContent(
|
||||||
metadataParser, objectFactory);
|
metadataParser, objectFactory);
|
||||||
|
@ -63,7 +63,7 @@ public class ParseBlobFromHeadersAndHttpContentTest {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Test
|
@Test
|
||||||
public void testParseContentLengthWhenContentRangeSet() throws HttpException {
|
public void testParseContentLengthWhenContentRangeSet() throws HttpException {
|
||||||
ParseBlobMetadataFromHeaders<BlobMetadata> metadataParser = createMock(ParseBlobMetadataFromHeaders.class);
|
ParseSystemAndUserMetadataFromHeaders<BlobMetadata> metadataParser = createMock(ParseSystemAndUserMetadataFromHeaders.class);
|
||||||
ParseBlobFromHeadersAndHttpContent.BlobFactory<BlobMetadata, Blob<BlobMetadata>> objectFactory = new ParseBlobFromHeadersAndHttpContent.BlobFactory<BlobMetadata, Blob<BlobMetadata>>() {
|
ParseBlobFromHeadersAndHttpContent.BlobFactory<BlobMetadata, Blob<BlobMetadata>> objectFactory = new ParseBlobFromHeadersAndHttpContent.BlobFactory<BlobMetadata, Blob<BlobMetadata>>() {
|
||||||
|
|
||||||
public Blob<BlobMetadata> create(BlobMetadata metadata) {
|
public Blob<BlobMetadata> create(BlobMetadata metadata) {
|
||||||
|
|
|
@ -32,8 +32,9 @@ import javax.ws.rs.core.HttpHeaders;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
|
|
||||||
import org.jclouds.blobstore.domain.BlobMetadata;
|
import org.jclouds.blobstore.domain.BlobMetadata;
|
||||||
import org.jclouds.blobstore.functions.ParseBlobMetadataFromHeaders.BlobMetadataFactory;
|
import org.jclouds.blobstore.functions.ParseContentTypeFromHeaders.BlobMetadataFactory;
|
||||||
import org.jclouds.http.HttpException;
|
import org.jclouds.http.HttpException;
|
||||||
|
import org.jclouds.http.HttpRequest;
|
||||||
import org.jclouds.http.HttpResponse;
|
import org.jclouds.http.HttpResponse;
|
||||||
import org.jclouds.http.HttpUtils;
|
import org.jclouds.http.HttpUtils;
|
||||||
import org.jclouds.util.DateService;
|
import org.jclouds.util.DateService;
|
||||||
|
@ -45,31 +46,44 @@ import com.google.common.collect.Multimap;
|
||||||
|
|
||||||
public class ParseBlobMetadataFromHeadersTest {
|
public class ParseBlobMetadataFromHeadersTest {
|
||||||
|
|
||||||
private ParseBlobMetadataFromHeaders<BlobMetadata> parser;
|
private ParseSystemAndUserMetadataFromHeaders<BlobMetadata> parser;
|
||||||
|
|
||||||
@BeforeTest
|
@BeforeTest
|
||||||
void setUp() {
|
void setUp() {
|
||||||
parser = new ParseBlobMetadataFromHeaders<BlobMetadata>(new DateService(), "prefix",
|
parser = new ParseSystemAndUserMetadataFromHeaders<BlobMetadata>(new DateService(), "prefix",
|
||||||
new BlobMetadataFactory<BlobMetadata>() {
|
new BlobMetadataFactory<BlobMetadata>() {
|
||||||
public BlobMetadata create(String key) {
|
public BlobMetadata create(String key) {
|
||||||
return new BlobMetadata(key);
|
return new BlobMetadata(key);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
parser
|
||||||
|
.setContext(new HttpRequest("GET", URI.create("http://localhost/key")),
|
||||||
|
new Object[] {});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAddAllHeadersTo() {
|
public void testAddAllHeadersTo() {
|
||||||
Multimap<String, String> allHeaders = ImmutableMultimap.of("key", "value");
|
Multimap<String, String> allHeaders = ImmutableMultimap.of("key", "value");
|
||||||
HttpResponse from = new HttpResponse(URI.create("http://localhost"));
|
HttpResponse from = new HttpResponse();
|
||||||
from.setHeaders(allHeaders);
|
from.setHeaders(allHeaders);
|
||||||
BlobMetadata metadata = new BlobMetadata("test");
|
BlobMetadata metadata = new BlobMetadata("test");
|
||||||
parser.addAllHeadersTo(from, metadata);
|
parser.addAllHeadersTo(from, metadata);
|
||||||
assertEquals(metadata.getAllHeaders().get("key"), Collections.singletonList("value"));
|
assertEquals(metadata.getAllHeaders().get("key"), Collections.singletonList("value"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testApplySetsKey() {
|
||||||
|
HttpResponse from = new HttpResponse();
|
||||||
|
from.getHeaders().put(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
|
||||||
|
from.getHeaders().put(HttpHeaders.LAST_MODIFIED, "Wed, 09 Sep 2009 19:50:23 GMT");
|
||||||
|
from.getHeaders().put(HttpHeaders.CONTENT_LENGTH, "100");
|
||||||
|
BlobMetadata metadata = parser.apply(from);
|
||||||
|
assertEquals(metadata.getKey(), "key");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetContentLength() {
|
public void testSetContentLength() {
|
||||||
HttpResponse from = new HttpResponse(URI.create("http://localhost"));
|
HttpResponse from = new HttpResponse();
|
||||||
from.getHeaders().put(HttpHeaders.CONTENT_LENGTH, "100");
|
from.getHeaders().put(HttpHeaders.CONTENT_LENGTH, "100");
|
||||||
BlobMetadata metadata = new BlobMetadata("test");
|
BlobMetadata metadata = new BlobMetadata("test");
|
||||||
parser.setContentLengthOrThrowException(from, metadata);
|
parser.setContentLengthOrThrowException(from, metadata);
|
||||||
|
@ -78,14 +92,14 @@ public class ParseBlobMetadataFromHeadersTest {
|
||||||
|
|
||||||
@Test(expectedExceptions = HttpException.class)
|
@Test(expectedExceptions = HttpException.class)
|
||||||
public void testSetContentLengthException() {
|
public void testSetContentLengthException() {
|
||||||
HttpResponse from = new HttpResponse(URI.create("http://localhost"));
|
HttpResponse from = new HttpResponse();
|
||||||
BlobMetadata metadata = new BlobMetadata("test");
|
BlobMetadata metadata = new BlobMetadata("test");
|
||||||
parser.setContentLengthOrThrowException(from, metadata);
|
parser.setContentLengthOrThrowException(from, metadata);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetContentType() {
|
public void testSetContentType() {
|
||||||
HttpResponse from = new HttpResponse(URI.create("http://localhost"));
|
HttpResponse from = new HttpResponse();
|
||||||
from.getHeaders().put(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
|
from.getHeaders().put(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
|
||||||
BlobMetadata metadata = new BlobMetadata("test");
|
BlobMetadata metadata = new BlobMetadata("test");
|
||||||
parser.setContentTypeOrThrowException(from, metadata);
|
parser.setContentTypeOrThrowException(from, metadata);
|
||||||
|
@ -94,14 +108,14 @@ public class ParseBlobMetadataFromHeadersTest {
|
||||||
|
|
||||||
@Test(expectedExceptions = HttpException.class)
|
@Test(expectedExceptions = HttpException.class)
|
||||||
public void testSetContentTypeException() {
|
public void testSetContentTypeException() {
|
||||||
HttpResponse from = new HttpResponse(URI.create("http://localhost"));
|
HttpResponse from = new HttpResponse();
|
||||||
BlobMetadata metadata = new BlobMetadata("test");
|
BlobMetadata metadata = new BlobMetadata("test");
|
||||||
parser.setContentTypeOrThrowException(from, metadata);
|
parser.setContentTypeOrThrowException(from, metadata);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetLastModified() {
|
public void testSetLastModified() {
|
||||||
HttpResponse from = new HttpResponse(URI.create("http://localhost"));
|
HttpResponse from = new HttpResponse();
|
||||||
from.getHeaders().put(HttpHeaders.LAST_MODIFIED, "Wed, 09 Sep 2009 19:50:23 GMT");
|
from.getHeaders().put(HttpHeaders.LAST_MODIFIED, "Wed, 09 Sep 2009 19:50:23 GMT");
|
||||||
BlobMetadata metadata = new BlobMetadata("test");
|
BlobMetadata metadata = new BlobMetadata("test");
|
||||||
parser.parseLastModifiedOrThrowException(from, metadata);
|
parser.parseLastModifiedOrThrowException(from, metadata);
|
||||||
|
@ -109,16 +123,16 @@ public class ParseBlobMetadataFromHeadersTest {
|
||||||
.rfc822DateParse("Wed, 09 Sep 2009 19:50:23 GMT"));
|
.rfc822DateParse("Wed, 09 Sep 2009 19:50:23 GMT"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expectedExceptions = NullPointerException.class)
|
@Test(expectedExceptions = HttpException.class)
|
||||||
public void testSetLastModifiedException() {
|
public void testSetLastModifiedException() {
|
||||||
HttpResponse from = new HttpResponse(URI.create("http://localhost"));
|
HttpResponse from = new HttpResponse();
|
||||||
BlobMetadata metadata = new BlobMetadata("test");
|
BlobMetadata metadata = new BlobMetadata("test");
|
||||||
parser.parseLastModifiedOrThrowException(from, metadata);
|
parser.parseLastModifiedOrThrowException(from, metadata);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAddETagTo() {
|
public void testAddETagTo() {
|
||||||
HttpResponse from = new HttpResponse(URI.create("http://localhost"));
|
HttpResponse from = new HttpResponse();
|
||||||
from.getHeaders().put(HttpHeaders.ETAG, "0xfeb");
|
from.getHeaders().put(HttpHeaders.ETAG, "0xfeb");
|
||||||
BlobMetadata metadata = new BlobMetadata("test");
|
BlobMetadata metadata = new BlobMetadata("test");
|
||||||
parser.addETagTo(from, metadata);
|
parser.addETagTo(from, metadata);
|
||||||
|
@ -128,7 +142,7 @@ public class ParseBlobMetadataFromHeadersTest {
|
||||||
@Test
|
@Test
|
||||||
public void testAddUserMetadataTo() {
|
public void testAddUserMetadataTo() {
|
||||||
Multimap<String, String> allHeaders = ImmutableMultimap.of("prefix" + "key", "value");
|
Multimap<String, String> allHeaders = ImmutableMultimap.of("prefix" + "key", "value");
|
||||||
HttpResponse from = new HttpResponse(URI.create("http://localhost"));
|
HttpResponse from = new HttpResponse();
|
||||||
from.setHeaders(allHeaders);
|
from.setHeaders(allHeaders);
|
||||||
BlobMetadata metadata = new BlobMetadata("test");
|
BlobMetadata metadata = new BlobMetadata("test");
|
||||||
parser.addUserMetadataTo(from, metadata);
|
parser.addUserMetadataTo(from, metadata);
|
||||||
|
|
|
@ -34,7 +34,6 @@ import java.io.ObjectInput;
|
||||||
import java.io.ObjectInputStream;
|
import java.io.ObjectInputStream;
|
||||||
import java.io.ObjectOutput;
|
import java.io.ObjectOutput;
|
||||||
import java.io.ObjectOutputStream;
|
import java.io.ObjectOutputStream;
|
||||||
import java.net.URI;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -217,7 +216,7 @@ public abstract class StubBlobStore<C extends ContainerMetadata, M extends BlobM
|
||||||
return getContainerToBlobs().containsKey(container);
|
return getContainerToBlobs().containsKey(container);
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract class FutureBase<V> implements Future<V> {
|
public static abstract class FutureBase<V> implements Future<V> {
|
||||||
public boolean cancel(boolean b) {
|
public boolean cancel(boolean b) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -321,7 +320,7 @@ public abstract class StubBlobStore<C extends ContainerMetadata, M extends BlobM
|
||||||
|
|
||||||
protected void throwResponseException(int code) throws ExecutionException {
|
protected void throwResponseException(int code) throws ExecutionException {
|
||||||
HttpResponse response = null;
|
HttpResponse response = null;
|
||||||
response = new HttpResponse(URI.create("http://localhost")); // TODO: Get real object URL?
|
response = new HttpResponse(); // TODO: Get real object URL?
|
||||||
response.setStatusCode(code);
|
response.setStatusCode(code);
|
||||||
throw new ExecutionException(new HttpResponseException(new HttpCommand() {
|
throw new ExecutionException(new HttpResponseException(new HttpCommand() {
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,6 @@
|
||||||
package org.jclouds.http;
|
package org.jclouds.http;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.URI;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a response produced from {@link HttpCommandExecutorService}
|
* Represents a response produced from {@link HttpCommandExecutorService}
|
||||||
|
@ -32,15 +31,10 @@ import java.net.URI;
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class HttpResponse extends HttpMessage {
|
public class HttpResponse extends HttpMessage {
|
||||||
private URI requestURL;
|
|
||||||
private int statusCode;
|
private int statusCode;
|
||||||
private String message;
|
private String message;
|
||||||
private InputStream content;
|
private InputStream content;
|
||||||
|
|
||||||
public HttpResponse(URI requestURL) {
|
|
||||||
this.requestURL = requestURL;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
final StringBuilder sb = new StringBuilder();
|
final StringBuilder sb = new StringBuilder();
|
||||||
|
@ -77,8 +71,4 @@ public class HttpResponse extends HttpMessage {
|
||||||
this.content = content;
|
this.content = content;
|
||||||
}
|
}
|
||||||
|
|
||||||
public URI getRequestURL() {
|
|
||||||
return this.requestURL;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -30,11 +30,12 @@ import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.io.OutputStreamWriter;
|
import java.io.OutputStreamWriter;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.URISyntaxException;
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Named;
|
||||||
import javax.net.ssl.HostnameVerifier;
|
import javax.net.ssl.HostnameVerifier;
|
||||||
import javax.net.ssl.HttpsURLConnection;
|
import javax.net.ssl.HttpsURLConnection;
|
||||||
import javax.net.ssl.SSLSession;
|
import javax.net.ssl.SSLSession;
|
||||||
|
@ -49,8 +50,6 @@ 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 javax.inject.Inject;
|
|
||||||
import javax.inject.Named;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Basic implementation of a {@link HttpCommandExecutorService}.
|
* Basic implementation of a {@link HttpCommandExecutorService}.
|
||||||
|
@ -91,12 +90,7 @@ public class JavaUrlHttpCommandExecutorService extends
|
||||||
protected HttpResponse invoke(HttpURLConnection connection) throws IOException {
|
protected HttpResponse invoke(HttpURLConnection connection) throws IOException {
|
||||||
logger.trace("%s - submitting request %s; %s", connection.getURL().getHost(), connection
|
logger.trace("%s - submitting request %s; %s", connection.getURL().getHost(), connection
|
||||||
.getURL(), connection.getHeaderFields().toString());
|
.getURL(), connection.getHeaderFields().toString());
|
||||||
HttpResponse response;
|
HttpResponse response = new HttpResponse();
|
||||||
try {
|
|
||||||
response = new HttpResponse(connection.getURL().toURI());
|
|
||||||
} catch (URISyntaxException e1) {
|
|
||||||
throw new RuntimeException(e1);
|
|
||||||
}
|
|
||||||
InputStream in;
|
InputStream in;
|
||||||
try {
|
try {
|
||||||
in = connection.getInputStream();
|
in = connection.getInputStream();
|
||||||
|
|
|
@ -99,7 +99,7 @@ public class BackoffLimitedRetryHandlerTest {
|
||||||
void testClosesInputStream() throws InterruptedException, IOException {
|
void testClosesInputStream() throws InterruptedException, IOException {
|
||||||
HttpCommand command = createCommand();
|
HttpCommand command = createCommand();
|
||||||
|
|
||||||
HttpResponse response = new HttpResponse(URI.create("http://localhost"));
|
HttpResponse response = new HttpResponse();
|
||||||
InputStream inputStream = new InputStream() {
|
InputStream inputStream = new InputStream() {
|
||||||
boolean isOpen = true;
|
boolean isOpen = true;
|
||||||
|
|
||||||
|
@ -150,7 +150,7 @@ public class BackoffLimitedRetryHandlerTest {
|
||||||
@Test
|
@Test
|
||||||
void testIncrementsFailureCount() throws InterruptedException, IOException {
|
void testIncrementsFailureCount() throws InterruptedException, IOException {
|
||||||
HttpCommand command = createCommand();
|
HttpCommand command = createCommand();
|
||||||
HttpResponse response = new HttpResponse(URI.create("http://localhost"));
|
HttpResponse response = new HttpResponse();
|
||||||
|
|
||||||
handler.shouldRetryRequest(command, response);
|
handler.shouldRetryRequest(command, response);
|
||||||
assertEquals(command.getFailureCount(), 1);
|
assertEquals(command.getFailureCount(), 1);
|
||||||
|
@ -165,7 +165,7 @@ public class BackoffLimitedRetryHandlerTest {
|
||||||
@Test
|
@Test
|
||||||
void testDisallowsExcessiveRetries() throws InterruptedException, IOException {
|
void testDisallowsExcessiveRetries() throws InterruptedException, IOException {
|
||||||
HttpCommand command = createCommand();
|
HttpCommand command = createCommand();
|
||||||
HttpResponse response = new HttpResponse(URI.create("http://localhost"));
|
HttpResponse response = new HttpResponse();
|
||||||
|
|
||||||
assertEquals(handler.shouldRetryRequest(command, response), true); // Failure 1
|
assertEquals(handler.shouldRetryRequest(command, response), true); // Failure 1
|
||||||
|
|
||||||
|
|
|
@ -30,13 +30,12 @@ import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.URI;
|
|
||||||
import java.net.URISyntaxException;
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
|
|
||||||
|
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.IOUtils;
|
||||||
|
@ -56,7 +55,6 @@ 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 javax.inject.Inject;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Google App Engine version of {@link HttpCommandExecutorService}
|
* Google App Engine version of {@link HttpCommandExecutorService}
|
||||||
|
@ -108,8 +106,8 @@ public class GaeHttpCommandExecutorService extends BaseHttpCommandExecutorServic
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
protected HttpResponse convert(URI uri, HTTPResponse gaeResponse) {
|
protected HttpResponse convert(HTTPResponse gaeResponse) {
|
||||||
HttpResponse response = new HttpResponse(uri);
|
HttpResponse response = new HttpResponse();
|
||||||
response.setStatusCode(gaeResponse.getResponseCode());
|
response.setStatusCode(gaeResponse.getResponseCode());
|
||||||
for (HTTPHeader header : gaeResponse.getHeaders()) {
|
for (HTTPHeader header : gaeResponse.getHeaders()) {
|
||||||
response.getHeaders().put(header.getName(), header.getValue());
|
response.getHeaders().put(header.getName(), header.getValue());
|
||||||
|
@ -176,11 +174,7 @@ public class GaeHttpCommandExecutorService extends BaseHttpCommandExecutorServic
|
||||||
HTTPResponse response = urlFetchService.fetch(request);
|
HTTPResponse response = urlFetchService.fetch(request);
|
||||||
logger.trace("%s - received response code %s, headers: %s", request.getURL().getHost(),
|
logger.trace("%s - received response code %s, headers: %s", request.getURL().getHost(),
|
||||||
response.getResponseCode(), headersAsString(response.getHeaders()));
|
response.getResponseCode(), headersAsString(response.getHeaders()));
|
||||||
try {
|
return convert(response);
|
||||||
return convert(request.getURL().toURI(), response);
|
|
||||||
} catch (URISyntaxException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String headersAsString(List<HTTPHeader> headers) {
|
String headersAsString(List<HTTPHeader> headers) {
|
||||||
|
|
|
@ -87,7 +87,7 @@ public class GaeHttpCommandExecutorServiceTest {
|
||||||
expect(gaeResponse.getHeaders()).andReturn(headers);
|
expect(gaeResponse.getHeaders()).andReturn(headers);
|
||||||
expect(gaeResponse.getContent()).andReturn(null).atLeastOnce();
|
expect(gaeResponse.getContent()).andReturn(null).atLeastOnce();
|
||||||
replay(gaeResponse);
|
replay(gaeResponse);
|
||||||
HttpResponse response = client.convert(URI.create("http://localhost"), gaeResponse);
|
HttpResponse response = client.convert(gaeResponse);
|
||||||
assertEquals(response.getStatusCode(), 200);
|
assertEquals(response.getStatusCode(), 200);
|
||||||
assertEquals(response.getContent(), null);
|
assertEquals(response.getContent(), null);
|
||||||
assertEquals(response.getHeaders().size(), 1);
|
assertEquals(response.getHeaders().size(), 1);
|
||||||
|
@ -103,7 +103,7 @@ public class GaeHttpCommandExecutorServiceTest {
|
||||||
expect(gaeResponse.getHeaders()).andReturn(headers);
|
expect(gaeResponse.getHeaders()).andReturn(headers);
|
||||||
expect(gaeResponse.getContent()).andReturn("hello".getBytes()).atLeastOnce();
|
expect(gaeResponse.getContent()).andReturn("hello".getBytes()).atLeastOnce();
|
||||||
replay(gaeResponse);
|
replay(gaeResponse);
|
||||||
HttpResponse response = client.convert(URI.create("http://localhost"), gaeResponse);
|
HttpResponse response = client.convert(gaeResponse);
|
||||||
assertEquals(response.getStatusCode(), 200);
|
assertEquals(response.getStatusCode(), 200);
|
||||||
assertEquals(IOUtils.toString(response.getContent()), "hello");
|
assertEquals(IOUtils.toString(response.getContent()), "hello");
|
||||||
assertEquals(response.getHeaders().size(), 1);
|
assertEquals(response.getHeaders().size(), 1);
|
||||||
|
|
|
@ -27,6 +27,7 @@ import java.io.IOException;
|
||||||
import java.util.concurrent.BlockingQueue;
|
import java.util.concurrent.BlockingQueue;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import org.apache.http.HttpEntity;
|
import org.apache.http.HttpEntity;
|
||||||
import org.apache.http.HttpEntityEnclosingRequest;
|
import org.apache.http.HttpEntityEnclosingRequest;
|
||||||
|
@ -43,8 +44,6 @@ import org.jclouds.http.handlers.DelegatingRetryHandler;
|
||||||
import org.jclouds.http.httpnio.util.NioHttpUtils;
|
import org.jclouds.http.httpnio.util.NioHttpUtils;
|
||||||
import org.jclouds.logging.Logger;
|
import org.jclouds.logging.Logger;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* // TODO: Adrian: Document this!
|
* // TODO: Adrian: Document this!
|
||||||
*
|
*
|
||||||
|
@ -106,8 +105,8 @@ public class NioHttpCommandExecutionHandler implements NHttpRequestExecutionHand
|
||||||
try {
|
try {
|
||||||
HttpCommandRendezvous<?> rendezvous = handle.getCommandRendezvous();
|
HttpCommandRendezvous<?> rendezvous = handle.getCommandRendezvous();
|
||||||
HttpCommand command = rendezvous.getCommand();
|
HttpCommand command = rendezvous.getCommand();
|
||||||
org.jclouds.http.HttpResponse response = NioHttpUtils.convertToJavaCloudsResponse(
|
org.jclouds.http.HttpResponse response = NioHttpUtils
|
||||||
command.getRequest().getEndpoint(), apacheResponse);
|
.convertToJavaCloudsResponse(apacheResponse);
|
||||||
int statusCode = response.getStatusCode();
|
int statusCode = response.getStatusCode();
|
||||||
// TODO determine how to get the original request here so we don't need to build each
|
// TODO determine how to get the original request here so we don't need to build each
|
||||||
// time
|
// time
|
||||||
|
|
|
@ -27,7 +27,6 @@ import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.net.URI;
|
|
||||||
|
|
||||||
import javax.ws.rs.core.HttpHeaders;
|
import javax.ws.rs.core.HttpHeaders;
|
||||||
|
|
||||||
|
@ -105,9 +104,9 @@ public class NioHttpUtils {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HttpResponse convertToJavaCloudsResponse(URI uri,
|
public static HttpResponse convertToJavaCloudsResponse(
|
||||||
org.apache.http.HttpResponse apacheResponse) throws IOException {
|
org.apache.http.HttpResponse apacheResponse) throws IOException {
|
||||||
HttpResponse response = new HttpResponse(uri);
|
HttpResponse response = new HttpResponse();
|
||||||
if (apacheResponse.getEntity() != null) {
|
if (apacheResponse.getEntity() != null) {
|
||||||
response.setContent(apacheResponse.getEntity().getContent());
|
response.setContent(apacheResponse.getEntity().getContent());
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,26 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
* ====================================================================
|
||||||
|
*/
|
||||||
package org.jclouds.rackspace.cloudfiles;
|
package org.jclouds.rackspace.cloudfiles;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
|
|
@ -26,7 +26,7 @@ package org.jclouds.rackspace.cloudfiles.config;
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
import org.jclouds.blobstore.domain.Blob;
|
||||||
import org.jclouds.blobstore.domain.BlobMetadata;
|
import org.jclouds.blobstore.domain.BlobMetadata;
|
||||||
import org.jclouds.blobstore.functions.ParseBlobFromHeadersAndHttpContent.BlobFactory;
|
import org.jclouds.blobstore.functions.ParseBlobFromHeadersAndHttpContent.BlobFactory;
|
||||||
import org.jclouds.blobstore.functions.ParseBlobMetadataFromHeaders.BlobMetadataFactory;
|
import org.jclouds.blobstore.functions.ParseContentTypeFromHeaders.BlobMetadataFactory;
|
||||||
import org.jclouds.cloud.ConfiguresCloudConnection;
|
import org.jclouds.cloud.ConfiguresCloudConnection;
|
||||||
import org.jclouds.http.RequiresHttp;
|
import org.jclouds.http.RequiresHttp;
|
||||||
import org.jclouds.rackspace.cloudfiles.CloudFilesBlobStore;
|
import org.jclouds.rackspace.cloudfiles.CloudFilesBlobStore;
|
||||||
|
|
|
@ -26,14 +26,14 @@ package org.jclouds.rackspace.cloudfiles.functions;
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
import org.jclouds.blobstore.domain.Blob;
|
||||||
import org.jclouds.blobstore.domain.BlobMetadata;
|
import org.jclouds.blobstore.domain.BlobMetadata;
|
||||||
import org.jclouds.blobstore.functions.ParseBlobFromHeadersAndHttpContent;
|
import org.jclouds.blobstore.functions.ParseBlobFromHeadersAndHttpContent;
|
||||||
import org.jclouds.blobstore.functions.ParseBlobMetadataFromHeaders;
|
import org.jclouds.blobstore.functions.ParseSystemAndUserMetadataFromHeaders;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses response headers and creates a new Rackspace object from them and the HTTP content.
|
* Parses response headers and creates a new Rackspace object from them and the HTTP content.
|
||||||
*
|
*
|
||||||
* @see ParseBlobMetadataFromHeaders
|
* @see ParseSystemAndUserMetadataFromHeaders
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class ParseObjectFromHeadersAndHttpContent extends
|
public class ParseObjectFromHeadersAndHttpContent extends
|
||||||
|
|
|
@ -26,7 +26,7 @@ package org.jclouds.rackspace.cloudfiles.functions;
|
||||||
import static org.jclouds.blobstore.reference.BlobStoreConstants.PROPERTY_USER_METADATA_PREFIX;
|
import static org.jclouds.blobstore.reference.BlobStoreConstants.PROPERTY_USER_METADATA_PREFIX;
|
||||||
|
|
||||||
import org.jclouds.blobstore.domain.BlobMetadata;
|
import org.jclouds.blobstore.domain.BlobMetadata;
|
||||||
import org.jclouds.blobstore.functions.ParseBlobMetadataFromHeaders;
|
import org.jclouds.blobstore.functions.ParseSystemAndUserMetadataFromHeaders;
|
||||||
import org.jclouds.http.HttpResponse;
|
import org.jclouds.http.HttpResponse;
|
||||||
import org.jclouds.http.HttpUtils;
|
import org.jclouds.http.HttpUtils;
|
||||||
import org.jclouds.util.DateService;
|
import org.jclouds.util.DateService;
|
||||||
|
@ -38,7 +38,7 @@ import javax.inject.Named;
|
||||||
/**
|
/**
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class ParseObjectMetadataFromHeaders extends ParseBlobMetadataFromHeaders<BlobMetadata> {
|
public class ParseObjectMetadataFromHeaders extends ParseSystemAndUserMetadataFromHeaders<BlobMetadata> {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public ParseObjectMetadataFromHeaders(DateService dateParser,
|
public ParseObjectMetadataFromHeaders(DateService dateParser,
|
||||||
|
|
|
@ -33,7 +33,7 @@ import java.util.List;
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
import org.jclouds.blobstore.domain.Blob;
|
||||||
import org.jclouds.blobstore.domain.BlobMetadata;
|
import org.jclouds.blobstore.domain.BlobMetadata;
|
||||||
import org.jclouds.blobstore.functions.ParseBlobFromHeadersAndHttpContent.BlobFactory;
|
import org.jclouds.blobstore.functions.ParseBlobFromHeadersAndHttpContent.BlobFactory;
|
||||||
import org.jclouds.blobstore.functions.ParseBlobMetadataFromHeaders.BlobMetadataFactory;
|
import org.jclouds.blobstore.functions.ParseContentTypeFromHeaders.BlobMetadataFactory;
|
||||||
import org.jclouds.cloud.CloudContext;
|
import org.jclouds.cloud.CloudContext;
|
||||||
import org.jclouds.rackspace.cloudfiles.config.RestCloudFilesBlobStoreModule;
|
import org.jclouds.rackspace.cloudfiles.config.RestCloudFilesBlobStoreModule;
|
||||||
import org.jclouds.rackspace.cloudfiles.internal.GuiceCloudFilesContext;
|
import org.jclouds.rackspace.cloudfiles.internal.GuiceCloudFilesContext;
|
||||||
|
|
|
@ -26,10 +26,8 @@ package org.jclouds.rackspace.cloudfiles.functions;
|
||||||
import static org.easymock.classextension.EasyMock.createNiceMock;
|
import static org.easymock.classextension.EasyMock.createNiceMock;
|
||||||
import static org.testng.Assert.assertNotNull;
|
import static org.testng.Assert.assertNotNull;
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
|
|
||||||
import org.jclouds.blobstore.domain.BlobMetadata;
|
import org.jclouds.blobstore.domain.BlobMetadata;
|
||||||
import org.jclouds.blobstore.functions.ParseBlobMetadataFromHeaders.BlobMetadataFactory;
|
import org.jclouds.blobstore.functions.ParseContentTypeFromHeaders.BlobMetadataFactory;
|
||||||
import org.jclouds.http.HttpResponse;
|
import org.jclouds.http.HttpResponse;
|
||||||
import org.jclouds.util.DateService;
|
import org.jclouds.util.DateService;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
@ -50,7 +48,7 @@ public class ParseObjectMetadataFromHeadersTest {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
BlobMetadata md = new BlobMetadata("hello");
|
BlobMetadata md = new BlobMetadata("hello");
|
||||||
HttpResponse response = new HttpResponse(URI.create("http://localhost"));
|
HttpResponse response = new HttpResponse();
|
||||||
response.getHeaders().put("Etag", "feb1");
|
response.getHeaders().put("Etag", "feb1");
|
||||||
parser.addETagTo(response, md);
|
parser.addETagTo(response, md);
|
||||||
assertNotNull(md.getETag());
|
assertNotNull(md.getETag());
|
||||||
|
|
|
@ -1,3 +1,26 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
* ====================================================================
|
||||||
|
*/
|
||||||
package org.jclouds.rackspace.cloudservers;
|
package org.jclouds.rackspace.cloudservers;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
|
|
@ -105,7 +105,7 @@ public class CloudServersConnectionTest {
|
||||||
HttpRequest httpMethod = processor.createRequest(method, new Object[] { "ralphie", 2, 1 });
|
HttpRequest httpMethod = processor.createRequest(method, new Object[] { "ralphie", 2, 1 });
|
||||||
assertEquals("{\"server\":{\"name\":\"ralphie\",\"imageId\":2,\"flavorId\":1}}", httpMethod
|
assertEquals("{\"server\":{\"name\":\"ralphie\",\"imageId\":2,\"flavorId\":1}}", httpMethod
|
||||||
.getEntity());
|
.getEntity());
|
||||||
validateCreateServer(method, httpMethod);
|
validateCreateServer(method, httpMethod, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCreateServerWithIpGroup() throws SecurityException, NoSuchMethodException {
|
public void testCreateServerWithIpGroup() throws SecurityException, NoSuchMethodException {
|
||||||
|
@ -117,7 +117,7 @@ public class CloudServersConnectionTest {
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"{\"server\":{\"name\":\"ralphie\",\"imageId\":2,\"flavorId\":1,\"sharedIpGroupId\":2}}",
|
"{\"server\":{\"name\":\"ralphie\",\"imageId\":2,\"flavorId\":1,\"sharedIpGroupId\":2}}",
|
||||||
httpMethod.getEntity());
|
httpMethod.getEntity());
|
||||||
validateCreateServer(method, httpMethod);
|
validateCreateServer(method, httpMethod, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCreateServerWithFile() throws SecurityException, NoSuchMethodException {
|
public void testCreateServerWithFile() throws SecurityException, NoSuchMethodException {
|
||||||
|
@ -129,7 +129,7 @@ public class CloudServersConnectionTest {
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"{\"server\":{\"name\":\"ralphie\",\"imageId\":2,\"flavorId\":1,\"personality\":[{\"path\":\"/etc/jclouds\",\"contents\":\"Zm9v\"}]}}",
|
"{\"server\":{\"name\":\"ralphie\",\"imageId\":2,\"flavorId\":1,\"personality\":[{\"path\":\"/etc/jclouds\",\"contents\":\"Zm9v\"}]}}",
|
||||||
httpMethod.getEntity());
|
httpMethod.getEntity());
|
||||||
validateCreateServer(method, httpMethod);
|
validateCreateServer(method, httpMethod, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCreateServerWithMetadata() throws SecurityException, NoSuchMethodException {
|
public void testCreateServerWithMetadata() throws SecurityException, NoSuchMethodException {
|
||||||
|
@ -141,7 +141,7 @@ public class CloudServersConnectionTest {
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"{\"server\":{\"name\":\"ralphie\",\"imageId\":2,\"flavorId\":1,\"metadata\":{\"foo\":\"bar\"}}}",
|
"{\"server\":{\"name\":\"ralphie\",\"imageId\":2,\"flavorId\":1,\"metadata\":{\"foo\":\"bar\"}}}",
|
||||||
httpMethod.getEntity());
|
httpMethod.getEntity());
|
||||||
validateCreateServer(method, httpMethod);
|
validateCreateServer(method, httpMethod, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCreateServerWithIpGroupAndSharedIp() throws SecurityException,
|
public void testCreateServerWithIpGroupAndSharedIp() throws SecurityException,
|
||||||
|
@ -158,10 +158,10 @@ public class CloudServersConnectionTest {
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"{\"server\":{\"name\":\"ralphie\",\"imageId\":2,\"flavorId\":1,\"sharedIpGroupId\":2,\"addresses\":{\"public\":[\"127.0.0.1\"]}}}",
|
"{\"server\":{\"name\":\"ralphie\",\"imageId\":2,\"flavorId\":1,\"sharedIpGroupId\":2,\"addresses\":{\"public\":[\"127.0.0.1\"]}}}",
|
||||||
httpMethod.getEntity());
|
httpMethod.getEntity());
|
||||||
validateCreateServer(method, httpMethod);
|
validateCreateServer(method, httpMethod, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void validateCreateServer(Method method, HttpRequest httpMethod) {
|
private void validateCreateServer(Method method, HttpRequest httpMethod, Object[] args) {
|
||||||
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
||||||
assertEquals(httpMethod.getEndpoint().getPath(), "/servers");
|
assertEquals(httpMethod.getEndpoint().getPath(), "/servers");
|
||||||
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
|
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
|
||||||
|
@ -171,7 +171,7 @@ public class CloudServersConnectionTest {
|
||||||
.singletonList(httpMethod.getEntity().toString().getBytes().length + ""));
|
.singletonList(httpMethod.getEntity().toString().getBytes().length + ""));
|
||||||
assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections
|
assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections
|
||||||
.singletonList(MediaType.APPLICATION_JSON));
|
.singletonList(MediaType.APPLICATION_JSON));
|
||||||
assertEquals(processor.createResponseParser(method).getClass(),
|
assertEquals(processor.createResponseParser(method, httpMethod, args).getClass(),
|
||||||
ParseServerFromJsonResponse.class);
|
ParseServerFromJsonResponse.class);
|
||||||
assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null);
|
assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null);
|
||||||
assertNotNull(processor.getMapEntityBinderOrNull(method, new Object[] { "", 1, 2,
|
assertNotNull(processor.getMapEntityBinderOrNull(method, new Object[] { "", 1, 2,
|
||||||
|
@ -188,7 +188,7 @@ public class CloudServersConnectionTest {
|
||||||
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
|
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
|
||||||
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
|
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
|
||||||
assertEquals(httpMethod.getHeaders().size(), 0);
|
assertEquals(httpMethod.getHeaders().size(), 0);
|
||||||
assertEquals(processor.createResponseParser(method).getClass(),
|
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
|
||||||
ParseServerListFromJsonResponse.class);
|
ParseServerListFromJsonResponse.class);
|
||||||
assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null);
|
assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null);
|
||||||
}
|
}
|
||||||
|
@ -207,7 +207,7 @@ public class CloudServersConnectionTest {
|
||||||
+ now.getMillis() / 1000 + "&offset=2");
|
+ now.getMillis() / 1000 + "&offset=2");
|
||||||
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
|
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
|
||||||
assertEquals(httpMethod.getHeaders().size(), 0);
|
assertEquals(httpMethod.getHeaders().size(), 0);
|
||||||
assertEquals(processor.createResponseParser(method).getClass(),
|
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
|
||||||
ParseServerListFromJsonResponse.class);
|
ParseServerListFromJsonResponse.class);
|
||||||
assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null);
|
assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null);
|
||||||
}
|
}
|
||||||
|
@ -222,7 +222,7 @@ public class CloudServersConnectionTest {
|
||||||
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
|
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
|
||||||
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
|
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
|
||||||
assertEquals(httpMethod.getHeaders().size(), 0);
|
assertEquals(httpMethod.getHeaders().size(), 0);
|
||||||
assertEquals(processor.createResponseParser(method).getClass(),
|
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
|
||||||
ParseServerListFromJsonResponse.class);
|
ParseServerListFromJsonResponse.class);
|
||||||
assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null);
|
assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null);
|
||||||
}
|
}
|
||||||
|
@ -236,7 +236,7 @@ public class CloudServersConnectionTest {
|
||||||
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
|
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
|
||||||
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
|
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
|
||||||
assertEquals(httpMethod.getHeaders().size(), 0);
|
assertEquals(httpMethod.getHeaders().size(), 0);
|
||||||
assertEquals(processor.createResponseParser(method).getClass(),
|
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
|
||||||
ParseServerFromJsonResponse.class);
|
ParseServerFromJsonResponse.class);
|
||||||
assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(),
|
assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(),
|
||||||
ReturnServerNotFoundOn404.class);
|
ReturnServerNotFoundOn404.class);
|
||||||
|
@ -252,7 +252,7 @@ public class CloudServersConnectionTest {
|
||||||
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
|
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
|
||||||
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
|
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
|
||||||
assertEquals(httpMethod.getHeaders().size(), 0);
|
assertEquals(httpMethod.getHeaders().size(), 0);
|
||||||
assertEquals(processor.createResponseParser(method).getClass(),
|
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
|
||||||
ParseFlavorListFromJsonResponse.class);
|
ParseFlavorListFromJsonResponse.class);
|
||||||
assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null);
|
assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null);
|
||||||
}
|
}
|
||||||
|
@ -269,7 +269,7 @@ public class CloudServersConnectionTest {
|
||||||
+ now.getMillis() / 1000 + "&offset=2");
|
+ now.getMillis() / 1000 + "&offset=2");
|
||||||
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
|
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
|
||||||
assertEquals(httpMethod.getHeaders().size(), 0);
|
assertEquals(httpMethod.getHeaders().size(), 0);
|
||||||
assertEquals(processor.createResponseParser(method).getClass(),
|
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
|
||||||
ParseFlavorListFromJsonResponse.class);
|
ParseFlavorListFromJsonResponse.class);
|
||||||
assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null);
|
assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null);
|
||||||
}
|
}
|
||||||
|
@ -284,7 +284,7 @@ public class CloudServersConnectionTest {
|
||||||
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
|
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
|
||||||
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
|
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
|
||||||
assertEquals(httpMethod.getHeaders().size(), 0);
|
assertEquals(httpMethod.getHeaders().size(), 0);
|
||||||
assertEquals(processor.createResponseParser(method).getClass(),
|
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
|
||||||
ParseFlavorListFromJsonResponse.class);
|
ParseFlavorListFromJsonResponse.class);
|
||||||
assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null);
|
assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null);
|
||||||
}
|
}
|
||||||
|
@ -301,7 +301,7 @@ public class CloudServersConnectionTest {
|
||||||
+ now.getMillis() / 1000 + "&offset=2");
|
+ now.getMillis() / 1000 + "&offset=2");
|
||||||
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
|
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
|
||||||
assertEquals(httpMethod.getHeaders().size(), 0);
|
assertEquals(httpMethod.getHeaders().size(), 0);
|
||||||
assertEquals(processor.createResponseParser(method).getClass(),
|
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
|
||||||
ParseFlavorListFromJsonResponse.class);
|
ParseFlavorListFromJsonResponse.class);
|
||||||
assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null);
|
assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null);
|
||||||
}
|
}
|
||||||
|
@ -315,7 +315,7 @@ public class CloudServersConnectionTest {
|
||||||
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
|
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
|
||||||
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
|
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
|
||||||
assertEquals(httpMethod.getHeaders().size(), 0);
|
assertEquals(httpMethod.getHeaders().size(), 0);
|
||||||
assertEquals(processor.createResponseParser(method).getClass(),
|
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
|
||||||
ParseFlavorFromJsonResponse.class);
|
ParseFlavorFromJsonResponse.class);
|
||||||
assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(),
|
assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(),
|
||||||
ReturnFlavorNotFoundOn404.class);
|
ReturnFlavorNotFoundOn404.class);
|
||||||
|
@ -330,7 +330,7 @@ public class CloudServersConnectionTest {
|
||||||
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
|
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
|
||||||
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
|
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
|
||||||
assertEquals(httpMethod.getHeaders().size(), 0);
|
assertEquals(httpMethod.getHeaders().size(), 0);
|
||||||
assertEquals(processor.createResponseParser(method).getClass(),
|
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
|
||||||
ParseImageListFromJsonResponse.class);
|
ParseImageListFromJsonResponse.class);
|
||||||
assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null);
|
assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null);
|
||||||
}
|
}
|
||||||
|
@ -344,7 +344,7 @@ public class CloudServersConnectionTest {
|
||||||
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
|
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
|
||||||
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
|
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
|
||||||
assertEquals(httpMethod.getHeaders().size(), 0);
|
assertEquals(httpMethod.getHeaders().size(), 0);
|
||||||
assertEquals(processor.createResponseParser(method).getClass(),
|
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
|
||||||
ParseImageListFromJsonResponse.class);
|
ParseImageListFromJsonResponse.class);
|
||||||
assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null);
|
assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null);
|
||||||
}
|
}
|
||||||
|
@ -360,7 +360,7 @@ public class CloudServersConnectionTest {
|
||||||
+ now.getMillis() / 1000 + "&offset=2");
|
+ now.getMillis() / 1000 + "&offset=2");
|
||||||
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
|
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
|
||||||
assertEquals(httpMethod.getHeaders().size(), 0);
|
assertEquals(httpMethod.getHeaders().size(), 0);
|
||||||
assertEquals(processor.createResponseParser(method).getClass(),
|
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
|
||||||
ParseImageListFromJsonResponse.class);
|
ParseImageListFromJsonResponse.class);
|
||||||
assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null);
|
assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null);
|
||||||
}
|
}
|
||||||
|
@ -376,7 +376,7 @@ public class CloudServersConnectionTest {
|
||||||
+ now.getMillis() / 1000 + "&offset=2");
|
+ now.getMillis() / 1000 + "&offset=2");
|
||||||
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
|
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
|
||||||
assertEquals(httpMethod.getHeaders().size(), 0);
|
assertEquals(httpMethod.getHeaders().size(), 0);
|
||||||
assertEquals(processor.createResponseParser(method).getClass(),
|
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
|
||||||
ParseImageListFromJsonResponse.class);
|
ParseImageListFromJsonResponse.class);
|
||||||
assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null);
|
assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null);
|
||||||
}
|
}
|
||||||
|
@ -390,7 +390,7 @@ public class CloudServersConnectionTest {
|
||||||
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
|
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
|
||||||
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
|
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
|
||||||
assertEquals(httpMethod.getHeaders().size(), 0);
|
assertEquals(httpMethod.getHeaders().size(), 0);
|
||||||
assertEquals(processor.createResponseParser(method).getClass(),
|
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
|
||||||
ParseImageFromJsonResponse.class);
|
ParseImageFromJsonResponse.class);
|
||||||
assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(),
|
assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(),
|
||||||
ReturnImageNotFoundOn404.class);
|
ReturnImageNotFoundOn404.class);
|
||||||
|
@ -406,7 +406,8 @@ public class CloudServersConnectionTest {
|
||||||
assertEquals(httpMethod.getHeaders().size(), 0);
|
assertEquals(httpMethod.getHeaders().size(), 0);
|
||||||
assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(),
|
assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(),
|
||||||
ReturnFalseOn404.class);
|
ReturnFalseOn404.class);
|
||||||
assertEquals(processor.createResponseParser(method).getClass(), ReturnTrueIf2xx.class);
|
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
|
||||||
|
ReturnTrueIf2xx.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testShareIpNoConfig() throws SecurityException, NoSuchMethodException,
|
public void testShareIpNoConfig() throws SecurityException, NoSuchMethodException,
|
||||||
|
@ -427,7 +428,8 @@ public class CloudServersConnectionTest {
|
||||||
assertEquals("{\"shareIp\":{\"sharedIpGroupId\":3}}", httpMethod.getEntity());
|
assertEquals("{\"shareIp\":{\"sharedIpGroupId\":3}}", httpMethod.getEntity());
|
||||||
assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(),
|
assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(),
|
||||||
ReturnFalseOn404.class);
|
ReturnFalseOn404.class);
|
||||||
assertEquals(processor.createResponseParser(method).getClass(), ReturnTrueIf2xx.class);
|
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
|
||||||
|
ReturnTrueIf2xx.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testShareIpConfig() throws SecurityException, NoSuchMethodException,
|
public void testShareIpConfig() throws SecurityException, NoSuchMethodException,
|
||||||
|
@ -449,7 +451,8 @@ public class CloudServersConnectionTest {
|
||||||
.getEntity());
|
.getEntity());
|
||||||
assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(),
|
assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(),
|
||||||
ReturnFalseOn404.class);
|
ReturnFalseOn404.class);
|
||||||
assertEquals(processor.createResponseParser(method).getClass(), ReturnTrueIf2xx.class);
|
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
|
||||||
|
ReturnTrueIf2xx.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testUnshareIpNoConfig() throws SecurityException, NoSuchMethodException,
|
public void testUnshareIpNoConfig() throws SecurityException, NoSuchMethodException,
|
||||||
|
@ -465,7 +468,8 @@ public class CloudServersConnectionTest {
|
||||||
assertEquals(httpMethod.getHeaders().size(), 0);
|
assertEquals(httpMethod.getHeaders().size(), 0);
|
||||||
assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(),
|
assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(),
|
||||||
ReturnFalseOn404.class);
|
ReturnFalseOn404.class);
|
||||||
assertEquals(processor.createResponseParser(method).getClass(), ReturnTrueIf2xx.class);
|
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
|
||||||
|
ReturnTrueIf2xx.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testReplaceBackupSchedule() throws SecurityException, NoSuchMethodException {
|
public void testReplaceBackupSchedule() throws SecurityException, NoSuchMethodException {
|
||||||
|
@ -487,7 +491,8 @@ public class CloudServersConnectionTest {
|
||||||
httpMethod.getEntity());
|
httpMethod.getEntity());
|
||||||
assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(),
|
assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(),
|
||||||
ReturnFalseOn404.class);
|
ReturnFalseOn404.class);
|
||||||
assertEquals(processor.createResponseParser(method).getClass(), ReturnTrueIf2xx.class);
|
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
|
||||||
|
ReturnTrueIf2xx.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDeleteBackupSchedule() throws SecurityException, NoSuchMethodException {
|
public void testDeleteBackupSchedule() throws SecurityException, NoSuchMethodException {
|
||||||
|
@ -500,7 +505,8 @@ public class CloudServersConnectionTest {
|
||||||
assertEquals(httpMethod.getHeaders().size(), 0);
|
assertEquals(httpMethod.getHeaders().size(), 0);
|
||||||
assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(),
|
assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(),
|
||||||
ReturnFalseOn404.class);
|
ReturnFalseOn404.class);
|
||||||
assertEquals(processor.createResponseParser(method).getClass(), ReturnTrueIf2xx.class);
|
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
|
||||||
|
ReturnTrueIf2xx.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testChangeAdminPass() throws SecurityException, NoSuchMethodException {
|
public void testChangeAdminPass() throws SecurityException, NoSuchMethodException {
|
||||||
|
@ -519,7 +525,8 @@ public class CloudServersConnectionTest {
|
||||||
assertEquals("{\"server\":{\"adminPass\":\"foo\"}}", httpMethod.getEntity());
|
assertEquals("{\"server\":{\"adminPass\":\"foo\"}}", httpMethod.getEntity());
|
||||||
assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(),
|
assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(),
|
||||||
ReturnFalseOn404.class);
|
ReturnFalseOn404.class);
|
||||||
assertEquals(processor.createResponseParser(method).getClass(), ReturnTrueIf2xx.class);
|
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
|
||||||
|
ReturnTrueIf2xx.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testChangeServerName() throws SecurityException, NoSuchMethodException {
|
public void testChangeServerName() throws SecurityException, NoSuchMethodException {
|
||||||
|
@ -538,7 +545,8 @@ public class CloudServersConnectionTest {
|
||||||
assertEquals("{\"server\":{\"name\":\"foo\"}}", httpMethod.getEntity());
|
assertEquals("{\"server\":{\"name\":\"foo\"}}", httpMethod.getEntity());
|
||||||
assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(),
|
assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(),
|
||||||
ReturnFalseOn404.class);
|
ReturnFalseOn404.class);
|
||||||
assertEquals(processor.createResponseParser(method).getClass(), ReturnTrueIf2xx.class);
|
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
|
||||||
|
ReturnTrueIf2xx.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testListSharedIpGroups() throws SecurityException, NoSuchMethodException {
|
public void testListSharedIpGroups() throws SecurityException, NoSuchMethodException {
|
||||||
|
@ -551,7 +559,7 @@ public class CloudServersConnectionTest {
|
||||||
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
|
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
|
||||||
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
|
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
|
||||||
assertEquals(httpMethod.getHeaders().size(), 0);
|
assertEquals(httpMethod.getHeaders().size(), 0);
|
||||||
assertEquals(processor.createResponseParser(method).getClass(),
|
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
|
||||||
ParseSharedIpGroupListFromJsonResponse.class);
|
ParseSharedIpGroupListFromJsonResponse.class);
|
||||||
assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null);
|
assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null);
|
||||||
}
|
}
|
||||||
|
@ -568,7 +576,7 @@ public class CloudServersConnectionTest {
|
||||||
+ now.getMillis() / 1000 + "&offset=2");
|
+ now.getMillis() / 1000 + "&offset=2");
|
||||||
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
|
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
|
||||||
assertEquals(httpMethod.getHeaders().size(), 0);
|
assertEquals(httpMethod.getHeaders().size(), 0);
|
||||||
assertEquals(processor.createResponseParser(method).getClass(),
|
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
|
||||||
ParseSharedIpGroupListFromJsonResponse.class);
|
ParseSharedIpGroupListFromJsonResponse.class);
|
||||||
assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null);
|
assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null);
|
||||||
}
|
}
|
||||||
|
@ -583,7 +591,7 @@ public class CloudServersConnectionTest {
|
||||||
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
|
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
|
||||||
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
|
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
|
||||||
assertEquals(httpMethod.getHeaders().size(), 0);
|
assertEquals(httpMethod.getHeaders().size(), 0);
|
||||||
assertEquals(processor.createResponseParser(method).getClass(),
|
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
|
||||||
ParseSharedIpGroupListFromJsonResponse.class);
|
ParseSharedIpGroupListFromJsonResponse.class);
|
||||||
assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null);
|
assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null);
|
||||||
}
|
}
|
||||||
|
@ -601,7 +609,7 @@ public class CloudServersConnectionTest {
|
||||||
+ now.getMillis() / 1000 + "&offset=2");
|
+ now.getMillis() / 1000 + "&offset=2");
|
||||||
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
|
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
|
||||||
assertEquals(httpMethod.getHeaders().size(), 0);
|
assertEquals(httpMethod.getHeaders().size(), 0);
|
||||||
assertEquals(processor.createResponseParser(method).getClass(),
|
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
|
||||||
ParseSharedIpGroupListFromJsonResponse.class);
|
ParseSharedIpGroupListFromJsonResponse.class);
|
||||||
assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null);
|
assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null);
|
||||||
}
|
}
|
||||||
|
@ -615,7 +623,7 @@ public class CloudServersConnectionTest {
|
||||||
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
|
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
|
||||||
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
|
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
|
||||||
assertEquals(httpMethod.getHeaders().size(), 0);
|
assertEquals(httpMethod.getHeaders().size(), 0);
|
||||||
assertEquals(processor.createResponseParser(method).getClass(),
|
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
|
||||||
ParseSharedIpGroupFromJsonResponse.class);
|
ParseSharedIpGroupFromJsonResponse.class);
|
||||||
assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(),
|
assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(),
|
||||||
ReturnSharedIpGroupNotFoundOn404.class);
|
ReturnSharedIpGroupNotFoundOn404.class);
|
||||||
|
@ -654,7 +662,7 @@ public class CloudServersConnectionTest {
|
||||||
.singletonList(httpMethod.getEntity().toString().getBytes().length + ""));
|
.singletonList(httpMethod.getEntity().toString().getBytes().length + ""));
|
||||||
assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections
|
assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections
|
||||||
.singletonList(MediaType.APPLICATION_JSON));
|
.singletonList(MediaType.APPLICATION_JSON));
|
||||||
assertEquals(processor.createResponseParser(method).getClass(),
|
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
|
||||||
ParseSharedIpGroupFromJsonResponse.class);
|
ParseSharedIpGroupFromJsonResponse.class);
|
||||||
assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null);
|
assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null);
|
||||||
assertNotNull(processor.getMapEntityBinderOrNull(method, new Object[] { "",
|
assertNotNull(processor.getMapEntityBinderOrNull(method, new Object[] { "",
|
||||||
|
@ -671,7 +679,8 @@ public class CloudServersConnectionTest {
|
||||||
assertEquals(httpMethod.getHeaders().size(), 0);
|
assertEquals(httpMethod.getHeaders().size(), 0);
|
||||||
assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(),
|
assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(),
|
||||||
ReturnFalseOn404.class);
|
ReturnFalseOn404.class);
|
||||||
assertEquals(processor.createResponseParser(method).getClass(), ReturnTrueIf2xx.class);
|
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
|
||||||
|
ReturnTrueIf2xx.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testListAddresses() throws SecurityException, NoSuchMethodException {
|
public void testListAddresses() throws SecurityException, NoSuchMethodException {
|
||||||
|
@ -683,7 +692,7 @@ public class CloudServersConnectionTest {
|
||||||
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
|
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
|
||||||
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
|
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
|
||||||
assertEquals(httpMethod.getHeaders().size(), 0);
|
assertEquals(httpMethod.getHeaders().size(), 0);
|
||||||
assertEquals(processor.createResponseParser(method).getClass(),
|
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
|
||||||
ParseAddressesFromJsonResponse.class);
|
ParseAddressesFromJsonResponse.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -696,7 +705,7 @@ public class CloudServersConnectionTest {
|
||||||
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
|
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
|
||||||
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
|
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
|
||||||
assertEquals(httpMethod.getHeaders().size(), 0);
|
assertEquals(httpMethod.getHeaders().size(), 0);
|
||||||
assertEquals(processor.createResponseParser(method).getClass(),
|
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
|
||||||
ParseInetAddressListFromJsonResponse.class);
|
ParseInetAddressListFromJsonResponse.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -709,7 +718,7 @@ public class CloudServersConnectionTest {
|
||||||
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
|
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
|
||||||
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
|
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
|
||||||
assertEquals(httpMethod.getHeaders().size(), 0);
|
assertEquals(httpMethod.getHeaders().size(), 0);
|
||||||
assertEquals(processor.createResponseParser(method).getClass(),
|
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
|
||||||
ParseInetAddressListFromJsonResponse.class);
|
ParseInetAddressListFromJsonResponse.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -722,7 +731,7 @@ public class CloudServersConnectionTest {
|
||||||
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
|
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
|
||||||
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
|
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
|
||||||
assertEquals(httpMethod.getHeaders().size(), 0);
|
assertEquals(httpMethod.getHeaders().size(), 0);
|
||||||
assertEquals(processor.createResponseParser(method).getClass(),
|
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
|
||||||
ParseBackupScheduleFromJsonResponse.class);
|
ParseBackupScheduleFromJsonResponse.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -741,7 +750,7 @@ public class CloudServersConnectionTest {
|
||||||
.singletonList(httpMethod.getEntity().toString().getBytes().length + ""));
|
.singletonList(httpMethod.getEntity().toString().getBytes().length + ""));
|
||||||
assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections
|
assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections
|
||||||
.singletonList(MediaType.APPLICATION_JSON));
|
.singletonList(MediaType.APPLICATION_JSON));
|
||||||
assertEquals(processor.createResponseParser(method).getClass(),
|
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
|
||||||
ParseImageFromJsonResponse.class);
|
ParseImageFromJsonResponse.class);
|
||||||
assertNotNull(processor.createExceptionParserOrNullIfNotFound(method));
|
assertNotNull(processor.createExceptionParserOrNullIfNotFound(method));
|
||||||
assertNotNull(processor.getMapEntityBinderOrNull(method, new Object[] { "", 2 }));
|
assertNotNull(processor.getMapEntityBinderOrNull(method, new Object[] { "", 2 }));
|
||||||
|
@ -780,7 +789,8 @@ public class CloudServersConnectionTest {
|
||||||
.singletonList(MediaType.APPLICATION_JSON));
|
.singletonList(MediaType.APPLICATION_JSON));
|
||||||
assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(),
|
assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(),
|
||||||
ReturnFalseOn404.class);
|
ReturnFalseOn404.class);
|
||||||
assertEquals(processor.createResponseParser(method).getClass(), ReturnTrueIf2xx.class);
|
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
|
||||||
|
ReturnTrueIf2xx.class);
|
||||||
assertNotNull(processor.getMapEntityBinderOrNull(method, new Object[] { "",
|
assertNotNull(processor.getMapEntityBinderOrNull(method, new Object[] { "",
|
||||||
new RebuildServerOptions[] { withImage(2) } }));
|
new RebuildServerOptions[] { withImage(2) } }));
|
||||||
}
|
}
|
||||||
|
@ -801,7 +811,8 @@ public class CloudServersConnectionTest {
|
||||||
assertEquals("{\"reboot\":{\"type\":\"HARD\"}}", httpMethod.getEntity());
|
assertEquals("{\"reboot\":{\"type\":\"HARD\"}}", httpMethod.getEntity());
|
||||||
assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(),
|
assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(),
|
||||||
ReturnFalseOn404.class);
|
ReturnFalseOn404.class);
|
||||||
assertEquals(processor.createResponseParser(method).getClass(), ReturnTrueIf2xx.class);
|
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
|
||||||
|
ReturnTrueIf2xx.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testResize() throws SecurityException, NoSuchMethodException {
|
public void testResize() throws SecurityException, NoSuchMethodException {
|
||||||
|
@ -819,7 +830,8 @@ public class CloudServersConnectionTest {
|
||||||
assertEquals("{\"resize\":{\"flavorId\":3}}", httpMethod.getEntity());
|
assertEquals("{\"resize\":{\"flavorId\":3}}", httpMethod.getEntity());
|
||||||
assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(),
|
assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(),
|
||||||
ReturnFalseOn404.class);
|
ReturnFalseOn404.class);
|
||||||
assertEquals(processor.createResponseParser(method).getClass(), ReturnTrueIf2xx.class);
|
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
|
||||||
|
ReturnTrueIf2xx.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testConfirmResize() throws SecurityException, NoSuchMethodException {
|
public void testConfirmResize() throws SecurityException, NoSuchMethodException {
|
||||||
|
@ -837,7 +849,8 @@ public class CloudServersConnectionTest {
|
||||||
assertEquals("{\"confirmResize\":null}", httpMethod.getEntity());
|
assertEquals("{\"confirmResize\":null}", httpMethod.getEntity());
|
||||||
assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(),
|
assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(),
|
||||||
ReturnFalseOn404.class);
|
ReturnFalseOn404.class);
|
||||||
assertEquals(processor.createResponseParser(method).getClass(), ReturnTrueIf2xx.class);
|
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
|
||||||
|
ReturnTrueIf2xx.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRevertResize() throws SecurityException, NoSuchMethodException {
|
public void testRevertResize() throws SecurityException, NoSuchMethodException {
|
||||||
|
@ -854,7 +867,8 @@ public class CloudServersConnectionTest {
|
||||||
assertEquals("{\"revertResize\":null}", httpMethod.getEntity());
|
assertEquals("{\"revertResize\":null}", httpMethod.getEntity());
|
||||||
assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(),
|
assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(),
|
||||||
ReturnFalseOn404.class);
|
ReturnFalseOn404.class);
|
||||||
assertEquals(processor.createResponseParser(method).getClass(), ReturnTrueIf2xx.class);
|
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
|
||||||
|
ReturnTrueIf2xx.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
JaxrsAnnotationProcessor processor;
|
JaxrsAnnotationProcessor processor;
|
||||||
|
|
Loading…
Reference in New Issue