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:
adrian.f.cole 2009-09-27 19:28:37 +00:00
parent 7c2804dee6
commit 2de58bb5b9
39 changed files with 517 additions and 202 deletions

View File

@ -31,7 +31,7 @@ import org.jclouds.aws.s3.internal.GuiceS3Context;
import org.jclouds.aws.s3.internal.LiveS3InputStreamMap;
import org.jclouds.aws.s3.internal.LiveS3ObjectMap;
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.TypeLiteral;

View File

@ -29,7 +29,7 @@ import javax.ws.rs.core.HttpHeaders;
import org.jclouds.aws.s3.domain.ObjectMetadata;
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.HttpUtils;
import org.jclouds.util.DateService;
@ -44,7 +44,7 @@ import javax.inject.Named;
* @see <a href="http://docs.amazonwebservices.com/AmazonS3/latest/RESTObjectGET.html" />
* @author Adrian Cole
*/
public class ParseObjectMetadataFromHeaders extends ParseBlobMetadataFromHeaders<ObjectMetadata> {
public class ParseObjectMetadataFromHeaders extends ParseSystemAndUserMetadataFromHeaders<ObjectMetadata> {
@Inject
public ParseObjectMetadataFromHeaders(DateService dateParser,

View File

@ -40,7 +40,7 @@ import org.jclouds.aws.s3.domain.ObjectMetadata;
import org.jclouds.aws.s3.domain.S3Object;
import org.jclouds.aws.s3.internal.GuiceS3Context;
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.testng.annotations.Test;

View File

@ -27,7 +27,6 @@ import static org.testng.Assert.assertEquals;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import org.jclouds.aws.domain.AWSError;
import org.jclouds.aws.s3.reference.S3Constants;
@ -72,7 +71,7 @@ public class S3UtilsTest {
});
utils = injector.getInstance(S3Utils.class);
response = new HttpResponse(URI.create("http://localhost")); // TODO: Get real object URL?
response = new HttpResponse();
response.setStatusCode(400);
response.getHeaders().put(S3Headers.REQUEST_ID, "requestid");
response.getHeaders().put(S3Headers.REQUEST_TOKEN, "requesttoken");

View File

@ -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;
import java.net.URI;

View File

@ -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.LiveAzureBlobObjectMap;
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.TypeLiteral;

View File

@ -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.BlobMetadata;
import org.jclouds.blobstore.functions.ParseBlobMetadataFromHeaders;
import org.jclouds.blobstore.functions.ParseSystemAndUserMetadataFromHeaders;
import javax.inject.Inject;
/**
* Parses response headers and creates a new Azure Blob from them and the HTTP content.
*
* @see ParseBlobMetadataFromHeaders
* @see ParseSystemAndUserMetadataFromHeaders
* @author Adrian Cole
*/
public class ParseBlobFromHeadersAndHttpContent extends
org.jclouds.blobstore.functions.ParseBlobFromHeadersAndHttpContent<BlobMetadata, Blob> {
@Inject
public ParseBlobFromHeadersAndHttpContent(
ParseBlobMetadataFromHeaders<BlobMetadata> metadataParser,
ParseSystemAndUserMetadataFromHeaders<BlobMetadata> metadataParser,
BlobFactory<BlobMetadata, Blob> blobFactory) {
super(metadataParser, blobFactory);
}

View File

@ -40,7 +40,7 @@ import javax.inject.Named;
*
* @author Adrian Cole
*/
public class ParseBlobMetadataFromHeaders extends org.jclouds.blobstore.functions.ParseBlobMetadataFromHeaders<BlobMetadata> {
public class ParseBlobMetadataFromHeaders extends org.jclouds.blobstore.functions.ParseSystemAndUserMetadataFromHeaders<BlobMetadata> {
@Inject
public ParseBlobMetadataFromHeaders(DateService dateParser,

View File

@ -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;
import org.jclouds.azure.storage.reference.AzureStorageConstants;

View File

@ -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.reference.AzureStorageConstants;
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.testng.annotations.Test;

View File

@ -77,7 +77,8 @@ public class AzureBlobStoreTest {
assertEquals(httpMethod.getHeaders().size(), 1);
assertEquals(httpMethod.getHeaders().get("x-ms-version"), Collections
.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
assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null);
}
@ -97,7 +98,8 @@ public class AzureBlobStoreTest {
assertEquals(httpMethod.getHeaders().size(), 1);
assertEquals(httpMethod.getHeaders().get("x-ms-version"), Collections
.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
assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null);
}
@ -114,7 +116,8 @@ public class AzureBlobStoreTest {
assertEquals(httpMethod.getHeaders().get("x-ms-version"), Collections
.singletonList("2009-07-17"));
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
assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(),
ReturnTrueIfContainerAlreadyExists.class);
@ -131,7 +134,8 @@ public class AzureBlobStoreTest {
assertEquals(httpMethod.getHeaders().size(), 1);
assertEquals(httpMethod.getHeaders().get("x-ms-version"), Collections
.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
assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(),
ReturnTrueOn404.class);
@ -154,7 +158,8 @@ public class AzureBlobStoreTest {
assertEquals(httpMethod.getHeaders().get("x-ms-prop-publicaccess"), Collections
.singletonList("true"));
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
assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(),
ReturnTrueIfContainerAlreadyExists.class);
@ -172,7 +177,8 @@ public class AzureBlobStoreTest {
assertEquals(httpMethod.getHeaders().get("x-ms-version"), Collections
.singletonList("2009-07-17"));
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
assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(),
ReturnTrueIfContainerAlreadyExists.class);
@ -189,7 +195,8 @@ public class AzureBlobStoreTest {
assertEquals(httpMethod.getHeaders().size(), 1);
assertEquals(httpMethod.getHeaders().get("x-ms-version"), Collections
.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
assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(),
ReturnTrueOn404.class);
@ -211,7 +218,8 @@ public class AzureBlobStoreTest {
assertEquals(httpMethod.getHeaders().get("x-ms-prop-publicaccess"), Collections
.singletonList("true"));
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
assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(),
ReturnTrueIfContainerAlreadyExists.class);
@ -228,7 +236,8 @@ public class AzureBlobStoreTest {
assertEquals(httpMethod.getHeaders().size(), 1);
assertEquals(httpMethod.getHeaders().get("x-ms-version"), Collections
.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
assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null);
}
@ -244,7 +253,8 @@ public class AzureBlobStoreTest {
assertEquals(httpMethod.getHeaders().size(), 1);
assertEquals(httpMethod.getHeaders().get("x-ms-version"), Collections
.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
assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null);
}

View File

@ -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;
import java.lang.annotation.ElementType;

View File

@ -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;
import java.lang.annotation.ElementType;

View File

@ -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;
import java.lang.annotation.ElementType;

View File

@ -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;
import java.net.URI;

View File

@ -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;
import org.jclouds.azure.storage.reference.AzureStorageConstants;

View File

@ -78,7 +78,8 @@ public class AzureQueueConnectionTest {
assertEquals(httpMethod.getHeaders().size(), 1);
assertEquals(httpMethod.getHeaders().get("x-ms-version"), Collections
.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
assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null);
}
@ -98,7 +99,8 @@ public class AzureQueueConnectionTest {
assertEquals(httpMethod.getHeaders().size(), 1);
assertEquals(httpMethod.getHeaders().get("x-ms-version"), Collections
.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
assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null);
}
@ -116,7 +118,8 @@ public class AzureQueueConnectionTest {
assertEquals(httpMethod.getHeaders().get("x-ms-version"), Collections
.singletonList("2009-07-17"));
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
assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null);
}
@ -132,7 +135,8 @@ public class AzureQueueConnectionTest {
assertEquals(httpMethod.getHeaders().size(), 1);
assertEquals(httpMethod.getHeaders().get("x-ms-version"), Collections
.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
assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null);
}
@ -152,7 +156,8 @@ public class AzureQueueConnectionTest {
.singletonList("2009-07-17"));
assertEquals(httpMethod.getHeaders().get("x-ms-meta-foo"), Collections.singletonList("bar"));
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
assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null);
}

View File

@ -23,6 +23,7 @@
*/
package org.jclouds.blobstore.functions;
import javax.inject.Inject;
import javax.ws.rs.core.HttpHeaders;
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.base.Function;
import javax.inject.Inject;
/**
* Parses response headers and creates a new Blob from them and the HTTP content.
*
* @see ParseBlobMetadataFromHeaders
* @see ParseSystemAndUserMetadataFromHeaders
* @author Adrian Cole
*/
public class ParseBlobFromHeadersAndHttpContent<M extends BlobMetadata, B extends Blob<M>>
implements Function<HttpResponse, B> {
private final ParseBlobMetadataFromHeaders<M> metadataParser;
private final ParseContentTypeFromHeaders<M> metadataParser;
private final BlobFactory<M, B> blobFactory;
public static interface BlobFactory<M extends BlobMetadata, B extends Blob<M>> {
@ -50,14 +50,14 @@ public class ParseBlobFromHeadersAndHttpContent<M extends BlobMetadata, B extend
}
@Inject
public ParseBlobFromHeadersAndHttpContent(ParseBlobMetadataFromHeaders<M> metadataParser,
public ParseBlobFromHeadersAndHttpContent(ParseContentTypeFromHeaders<M> metadataParser,
BlobFactory<M, B> blobFactory) {
this.metadataParser = metadataParser;
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
* {@link Blob} result.
@ -69,22 +69,22 @@ public class ParseBlobFromHeadersAndHttpContent<M extends BlobMetadata, B extend
B object = blobFactory.create(metadata);
assert object.getMetadata() == metadata;
object.setData(from.getContent());
parseContentLengthOrThrowException(from, object);
attemptToParseSizeAndRangeFromHeaders(from, object);
return object;
}
@VisibleForTesting
void parseContentLengthOrThrowException(HttpResponse from, B object) throws HttpException {
void attemptToParseSizeAndRangeFromHeaders(HttpResponse from, B object) throws HttpException {
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");
if (contentRange == null) {
if (contentLength != null) {
object.setContentLength(Long.parseLong(contentLength));
}
if (contentRange == null && contentLength != null) {
object.getMetadata().setSize(object.getContentLength());
} else {
} else if (contentRange != null ) {
object.setContentRange(contentRange);
object.getMetadata().setSize(
Long.parseLong(contentRange.substring(contentRange.lastIndexOf('/') + 1)));

View File

@ -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;
}
}

View File

@ -27,6 +27,8 @@ import static org.jclouds.blobstore.reference.BlobStoreConstants.PROPERTY_USER_M
import java.util.Map.Entry;
import javax.inject.Inject;
import javax.inject.Named;
import javax.ws.rs.core.HttpHeaders;
import org.jclouds.blobstore.domain.BlobMetadata;
@ -36,63 +38,42 @@ import org.jclouds.http.HttpUtils;
import org.jclouds.util.DateService;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Function;
import javax.inject.Inject;
import javax.inject.Named;
/**
* @author Adrian Cole
*/
public class ParseBlobMetadataFromHeaders<M extends BlobMetadata> implements
Function<HttpResponse, M> {
private final DateService dateParser;
public class ParseSystemAndUserMetadataFromHeaders<M extends BlobMetadata> extends
ParseContentTypeFromHeaders<M> {
private final String metadataPrefix;
private final BlobMetadataFactory<M> metadataFactory;
public static interface BlobMetadataFactory<M extends BlobMetadata> {
M create(String key);
}
private final DateService dateParser;
@Inject
public ParseBlobMetadataFromHeaders(DateService dateParser,
public ParseSystemAndUserMetadataFromHeaders(DateService dateParser,
@Named(PROPERTY_USER_METADATA_PREFIX) String metadataPrefix,
BlobMetadataFactory<M> metadataFactory) {
super(metadataFactory);
this.dateParser = dateParser;
this.metadataPrefix = metadataPrefix;
this.metadataFactory = metadataFactory;
}
public M apply(HttpResponse from) {
String objectKey = from.getRequestURL().getPath();
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);
M to = super.apply(from);
addETagTo(from, to);
addContentMD5To(from, to);
parseLastModifiedOrThrowException(from, to);
setContentTypeOrThrowException(from, to);
setContentLengthOrThrowException(from, to);
addUserMetadataTo(from, to);
return to;
}
@VisibleForTesting
void addAllHeadersTo(HttpResponse from, M metadata) {
metadata.getAllHeaders().putAll(from.getHeaders());
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());
}
@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
@ -107,6 +88,9 @@ public class ParseBlobMetadataFromHeaders<M extends BlobMetadata> implements
@VisibleForTesting
void parseLastModifiedOrThrowException(HttpResponse from, M metadata) throws HttpException {
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));
if (metadata.getLastModified() == null)
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));
}
}
@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());
}
}
}

View File

@ -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);
}
}
}

View File

@ -47,7 +47,7 @@ public class ParseBlobFromHeadersAndHttpContentTest {
@SuppressWarnings("unchecked")
@Test(expectedExceptions = NullPointerException.class)
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<BlobMetadata, Blob<BlobMetadata>> callable = new ParseBlobFromHeadersAndHttpContent(
metadataParser, objectFactory);
@ -63,7 +63,7 @@ public class ParseBlobFromHeadersAndHttpContentTest {
@SuppressWarnings("unchecked")
@Test
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>>() {
public Blob<BlobMetadata> create(BlobMetadata metadata) {

View File

@ -32,8 +32,9 @@ import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
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.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.HttpUtils;
import org.jclouds.util.DateService;
@ -45,31 +46,44 @@ import com.google.common.collect.Multimap;
public class ParseBlobMetadataFromHeadersTest {
private ParseBlobMetadataFromHeaders<BlobMetadata> parser;
private ParseSystemAndUserMetadataFromHeaders<BlobMetadata> parser;
@BeforeTest
void setUp() {
parser = new ParseBlobMetadataFromHeaders<BlobMetadata>(new DateService(), "prefix",
parser = new ParseSystemAndUserMetadataFromHeaders<BlobMetadata>(new DateService(), "prefix",
new BlobMetadataFactory<BlobMetadata>() {
public BlobMetadata create(String key) {
return new BlobMetadata(key);
}
});
parser
.setContext(new HttpRequest("GET", URI.create("http://localhost/key")),
new Object[] {});
}
@Test
public void testAddAllHeadersTo() {
Multimap<String, String> allHeaders = ImmutableMultimap.of("key", "value");
HttpResponse from = new HttpResponse(URI.create("http://localhost"));
HttpResponse from = new HttpResponse();
from.setHeaders(allHeaders);
BlobMetadata metadata = new BlobMetadata("test");
parser.addAllHeadersTo(from, metadata);
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
public void testSetContentLength() {
HttpResponse from = new HttpResponse(URI.create("http://localhost"));
HttpResponse from = new HttpResponse();
from.getHeaders().put(HttpHeaders.CONTENT_LENGTH, "100");
BlobMetadata metadata = new BlobMetadata("test");
parser.setContentLengthOrThrowException(from, metadata);
@ -78,14 +92,14 @@ public class ParseBlobMetadataFromHeadersTest {
@Test(expectedExceptions = HttpException.class)
public void testSetContentLengthException() {
HttpResponse from = new HttpResponse(URI.create("http://localhost"));
HttpResponse from = new HttpResponse();
BlobMetadata metadata = new BlobMetadata("test");
parser.setContentLengthOrThrowException(from, metadata);
}
@Test
public void testSetContentType() {
HttpResponse from = new HttpResponse(URI.create("http://localhost"));
HttpResponse from = new HttpResponse();
from.getHeaders().put(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
BlobMetadata metadata = new BlobMetadata("test");
parser.setContentTypeOrThrowException(from, metadata);
@ -94,14 +108,14 @@ public class ParseBlobMetadataFromHeadersTest {
@Test(expectedExceptions = HttpException.class)
public void testSetContentTypeException() {
HttpResponse from = new HttpResponse(URI.create("http://localhost"));
HttpResponse from = new HttpResponse();
BlobMetadata metadata = new BlobMetadata("test");
parser.setContentTypeOrThrowException(from, metadata);
}
@Test
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");
BlobMetadata metadata = new BlobMetadata("test");
parser.parseLastModifiedOrThrowException(from, metadata);
@ -109,16 +123,16 @@ public class ParseBlobMetadataFromHeadersTest {
.rfc822DateParse("Wed, 09 Sep 2009 19:50:23 GMT"));
}
@Test(expectedExceptions = NullPointerException.class)
@Test(expectedExceptions = HttpException.class)
public void testSetLastModifiedException() {
HttpResponse from = new HttpResponse(URI.create("http://localhost"));
HttpResponse from = new HttpResponse();
BlobMetadata metadata = new BlobMetadata("test");
parser.parseLastModifiedOrThrowException(from, metadata);
}
@Test
public void testAddETagTo() {
HttpResponse from = new HttpResponse(URI.create("http://localhost"));
HttpResponse from = new HttpResponse();
from.getHeaders().put(HttpHeaders.ETAG, "0xfeb");
BlobMetadata metadata = new BlobMetadata("test");
parser.addETagTo(from, metadata);
@ -128,7 +142,7 @@ public class ParseBlobMetadataFromHeadersTest {
@Test
public void testAddUserMetadataTo() {
Multimap<String, String> allHeaders = ImmutableMultimap.of("prefix" + "key", "value");
HttpResponse from = new HttpResponse(URI.create("http://localhost"));
HttpResponse from = new HttpResponse();
from.setHeaders(allHeaders);
BlobMetadata metadata = new BlobMetadata("test");
parser.addUserMetadataTo(from, metadata);

View File

@ -34,7 +34,6 @@ import java.io.ObjectInput;
import java.io.ObjectInputStream;
import java.io.ObjectOutput;
import java.io.ObjectOutputStream;
import java.net.URI;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
@ -217,7 +216,7 @@ public abstract class StubBlobStore<C extends ContainerMetadata, M extends BlobM
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) {
return false;
}
@ -321,7 +320,7 @@ public abstract class StubBlobStore<C extends ContainerMetadata, M extends BlobM
protected void throwResponseException(int code) throws ExecutionException {
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);
throw new ExecutionException(new HttpResponseException(new HttpCommand() {

View File

@ -24,7 +24,6 @@
package org.jclouds.http;
import java.io.InputStream;
import java.net.URI;
/**
* Represents a response produced from {@link HttpCommandExecutorService}
@ -32,15 +31,10 @@ import java.net.URI;
* @author Adrian Cole
*/
public class HttpResponse extends HttpMessage {
private URI requestURL;
private int statusCode;
private String message;
private InputStream content;
public HttpResponse(URI requestURL) {
this.requestURL = requestURL;
}
@Override
public String toString() {
final StringBuilder sb = new StringBuilder();
@ -77,8 +71,4 @@ public class HttpResponse extends HttpMessage {
this.content = content;
}
public URI getRequestURL() {
return this.requestURL;
}
}

View File

@ -30,11 +30,12 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import javax.inject.Inject;
import javax.inject.Named;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLSession;
@ -49,8 +50,6 @@ import org.jclouds.http.handlers.DelegatingErrorHandler;
import org.jclouds.http.handlers.DelegatingRetryHandler;
import com.google.common.collect.Maps;
import javax.inject.Inject;
import javax.inject.Named;
/**
* Basic implementation of a {@link HttpCommandExecutorService}.
@ -91,12 +90,7 @@ public class JavaUrlHttpCommandExecutorService extends
protected HttpResponse invoke(HttpURLConnection connection) throws IOException {
logger.trace("%s - submitting request %s; %s", connection.getURL().getHost(), connection
.getURL(), connection.getHeaderFields().toString());
HttpResponse response;
try {
response = new HttpResponse(connection.getURL().toURI());
} catch (URISyntaxException e1) {
throw new RuntimeException(e1);
}
HttpResponse response = new HttpResponse();
InputStream in;
try {
in = connection.getInputStream();

View File

@ -99,7 +99,7 @@ public class BackoffLimitedRetryHandlerTest {
void testClosesInputStream() throws InterruptedException, IOException {
HttpCommand command = createCommand();
HttpResponse response = new HttpResponse(URI.create("http://localhost"));
HttpResponse response = new HttpResponse();
InputStream inputStream = new InputStream() {
boolean isOpen = true;
@ -150,7 +150,7 @@ public class BackoffLimitedRetryHandlerTest {
@Test
void testIncrementsFailureCount() throws InterruptedException, IOException {
HttpCommand command = createCommand();
HttpResponse response = new HttpResponse(URI.create("http://localhost"));
HttpResponse response = new HttpResponse();
handler.shouldRetryRequest(command, response);
assertEquals(command.getFailureCount(), 1);
@ -165,7 +165,7 @@ public class BackoffLimitedRetryHandlerTest {
@Test
void testDisallowsExcessiveRetries() throws InterruptedException, IOException {
HttpCommand command = createCommand();
HttpResponse response = new HttpResponse(URI.create("http://localhost"));
HttpResponse response = new HttpResponse();
assertEquals(handler.shouldRetryRequest(command, response), true); // Failure 1

View File

@ -30,13 +30,12 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.inject.Inject;
import javax.ws.rs.core.HttpHeaders;
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.URLFetchService;
import com.google.common.annotations.VisibleForTesting;
import javax.inject.Inject;
/**
* Google App Engine version of {@link HttpCommandExecutorService}
@ -108,8 +106,8 @@ public class GaeHttpCommandExecutorService extends BaseHttpCommandExecutorServic
}
@VisibleForTesting
protected HttpResponse convert(URI uri, HTTPResponse gaeResponse) {
HttpResponse response = new HttpResponse(uri);
protected HttpResponse convert(HTTPResponse gaeResponse) {
HttpResponse response = new HttpResponse();
response.setStatusCode(gaeResponse.getResponseCode());
for (HTTPHeader header : gaeResponse.getHeaders()) {
response.getHeaders().put(header.getName(), header.getValue());
@ -176,11 +174,7 @@ public class GaeHttpCommandExecutorService extends BaseHttpCommandExecutorServic
HTTPResponse response = urlFetchService.fetch(request);
logger.trace("%s - received response code %s, headers: %s", request.getURL().getHost(),
response.getResponseCode(), headersAsString(response.getHeaders()));
try {
return convert(request.getURL().toURI(), response);
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
return convert(response);
}
String headersAsString(List<HTTPHeader> headers) {

View File

@ -87,7 +87,7 @@ public class GaeHttpCommandExecutorServiceTest {
expect(gaeResponse.getHeaders()).andReturn(headers);
expect(gaeResponse.getContent()).andReturn(null).atLeastOnce();
replay(gaeResponse);
HttpResponse response = client.convert(URI.create("http://localhost"), gaeResponse);
HttpResponse response = client.convert(gaeResponse);
assertEquals(response.getStatusCode(), 200);
assertEquals(response.getContent(), null);
assertEquals(response.getHeaders().size(), 1);
@ -103,7 +103,7 @@ public class GaeHttpCommandExecutorServiceTest {
expect(gaeResponse.getHeaders()).andReturn(headers);
expect(gaeResponse.getContent()).andReturn("hello".getBytes()).atLeastOnce();
replay(gaeResponse);
HttpResponse response = client.convert(URI.create("http://localhost"), gaeResponse);
HttpResponse response = client.convert(gaeResponse);
assertEquals(response.getStatusCode(), 200);
assertEquals(IOUtils.toString(response.getContent()), "hello");
assertEquals(response.getHeaders().size(), 1);

View File

@ -27,6 +27,7 @@ import java.io.IOException;
import java.util.concurrent.BlockingQueue;
import javax.annotation.Resource;
import javax.inject.Inject;
import org.apache.http.HttpEntity;
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.logging.Logger;
import javax.inject.Inject;
/**
* // TODO: Adrian: Document this!
*
@ -106,8 +105,8 @@ public class NioHttpCommandExecutionHandler implements NHttpRequestExecutionHand
try {
HttpCommandRendezvous<?> rendezvous = handle.getCommandRendezvous();
HttpCommand command = rendezvous.getCommand();
org.jclouds.http.HttpResponse response = NioHttpUtils.convertToJavaCloudsResponse(
command.getRequest().getEndpoint(), apacheResponse);
org.jclouds.http.HttpResponse response = NioHttpUtils
.convertToJavaCloudsResponse(apacheResponse);
int statusCode = response.getStatusCode();
// TODO determine how to get the original request here so we don't need to build each
// time

View File

@ -27,7 +27,6 @@ import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.URI;
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 {
HttpResponse response = new HttpResponse(uri);
HttpResponse response = new HttpResponse();
if (apacheResponse.getEntity() != null) {
response.setContent(apacheResponse.getEntity().getContent());
}

View File

@ -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;
import java.net.URI;

View File

@ -26,7 +26,7 @@ package org.jclouds.rackspace.cloudfiles.config;
import org.jclouds.blobstore.domain.Blob;
import org.jclouds.blobstore.domain.BlobMetadata;
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.http.RequiresHttp;
import org.jclouds.rackspace.cloudfiles.CloudFilesBlobStore;

View File

@ -26,14 +26,14 @@ package org.jclouds.rackspace.cloudfiles.functions;
import org.jclouds.blobstore.domain.Blob;
import org.jclouds.blobstore.domain.BlobMetadata;
import org.jclouds.blobstore.functions.ParseBlobFromHeadersAndHttpContent;
import org.jclouds.blobstore.functions.ParseBlobMetadataFromHeaders;
import org.jclouds.blobstore.functions.ParseSystemAndUserMetadataFromHeaders;
import javax.inject.Inject;
/**
* Parses response headers and creates a new Rackspace object from them and the HTTP content.
*
* @see ParseBlobMetadataFromHeaders
* @see ParseSystemAndUserMetadataFromHeaders
* @author Adrian Cole
*/
public class ParseObjectFromHeadersAndHttpContent extends

View File

@ -26,7 +26,7 @@ package org.jclouds.rackspace.cloudfiles.functions;
import static org.jclouds.blobstore.reference.BlobStoreConstants.PROPERTY_USER_METADATA_PREFIX;
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.HttpUtils;
import org.jclouds.util.DateService;
@ -38,7 +38,7 @@ import javax.inject.Named;
/**
* @author Adrian Cole
*/
public class ParseObjectMetadataFromHeaders extends ParseBlobMetadataFromHeaders<BlobMetadata> {
public class ParseObjectMetadataFromHeaders extends ParseSystemAndUserMetadataFromHeaders<BlobMetadata> {
@Inject
public ParseObjectMetadataFromHeaders(DateService dateParser,

View File

@ -33,7 +33,7 @@ import java.util.List;
import org.jclouds.blobstore.domain.Blob;
import org.jclouds.blobstore.domain.BlobMetadata;
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.rackspace.cloudfiles.config.RestCloudFilesBlobStoreModule;
import org.jclouds.rackspace.cloudfiles.internal.GuiceCloudFilesContext;

View File

@ -26,10 +26,8 @@ package org.jclouds.rackspace.cloudfiles.functions;
import static org.easymock.classextension.EasyMock.createNiceMock;
import static org.testng.Assert.assertNotNull;
import java.net.URI;
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.util.DateService;
import org.testng.annotations.Test;
@ -50,7 +48,7 @@ public class ParseObjectMetadataFromHeadersTest {
}
});
BlobMetadata md = new BlobMetadata("hello");
HttpResponse response = new HttpResponse(URI.create("http://localhost"));
HttpResponse response = new HttpResponse();
response.getHeaders().put("Etag", "feb1");
parser.addETagTo(response, md);
assertNotNull(md.getETag());

View File

@ -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;
import java.net.URI;

View File

@ -105,7 +105,7 @@ public class CloudServersConnectionTest {
HttpRequest httpMethod = processor.createRequest(method, new Object[] { "ralphie", 2, 1 });
assertEquals("{\"server\":{\"name\":\"ralphie\",\"imageId\":2,\"flavorId\":1}}", httpMethod
.getEntity());
validateCreateServer(method, httpMethod);
validateCreateServer(method, httpMethod, null);
}
public void testCreateServerWithIpGroup() throws SecurityException, NoSuchMethodException {
@ -117,7 +117,7 @@ public class CloudServersConnectionTest {
assertEquals(
"{\"server\":{\"name\":\"ralphie\",\"imageId\":2,\"flavorId\":1,\"sharedIpGroupId\":2}}",
httpMethod.getEntity());
validateCreateServer(method, httpMethod);
validateCreateServer(method, httpMethod, null);
}
public void testCreateServerWithFile() throws SecurityException, NoSuchMethodException {
@ -129,7 +129,7 @@ public class CloudServersConnectionTest {
assertEquals(
"{\"server\":{\"name\":\"ralphie\",\"imageId\":2,\"flavorId\":1,\"personality\":[{\"path\":\"/etc/jclouds\",\"contents\":\"Zm9v\"}]}}",
httpMethod.getEntity());
validateCreateServer(method, httpMethod);
validateCreateServer(method, httpMethod, null);
}
public void testCreateServerWithMetadata() throws SecurityException, NoSuchMethodException {
@ -141,7 +141,7 @@ public class CloudServersConnectionTest {
assertEquals(
"{\"server\":{\"name\":\"ralphie\",\"imageId\":2,\"flavorId\":1,\"metadata\":{\"foo\":\"bar\"}}}",
httpMethod.getEntity());
validateCreateServer(method, httpMethod);
validateCreateServer(method, httpMethod, null);
}
public void testCreateServerWithIpGroupAndSharedIp() throws SecurityException,
@ -158,10 +158,10 @@ public class CloudServersConnectionTest {
assertEquals(
"{\"server\":{\"name\":\"ralphie\",\"imageId\":2,\"flavorId\":1,\"sharedIpGroupId\":2,\"addresses\":{\"public\":[\"127.0.0.1\"]}}}",
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().getPath(), "/servers");
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
@ -171,7 +171,7 @@ public class CloudServersConnectionTest {
.singletonList(httpMethod.getEntity().toString().getBytes().length + ""));
assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections
.singletonList(MediaType.APPLICATION_JSON));
assertEquals(processor.createResponseParser(method).getClass(),
assertEquals(processor.createResponseParser(method, httpMethod, args).getClass(),
ParseServerFromJsonResponse.class);
assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null);
assertNotNull(processor.getMapEntityBinderOrNull(method, new Object[] { "", 1, 2,
@ -188,7 +188,7 @@ public class CloudServersConnectionTest {
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
assertEquals(httpMethod.getHeaders().size(), 0);
assertEquals(processor.createResponseParser(method).getClass(),
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
ParseServerListFromJsonResponse.class);
assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null);
}
@ -207,7 +207,7 @@ public class CloudServersConnectionTest {
+ now.getMillis() / 1000 + "&offset=2");
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
assertEquals(httpMethod.getHeaders().size(), 0);
assertEquals(processor.createResponseParser(method).getClass(),
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
ParseServerListFromJsonResponse.class);
assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null);
}
@ -222,7 +222,7 @@ public class CloudServersConnectionTest {
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
assertEquals(httpMethod.getHeaders().size(), 0);
assertEquals(processor.createResponseParser(method).getClass(),
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
ParseServerListFromJsonResponse.class);
assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null);
}
@ -236,7 +236,7 @@ public class CloudServersConnectionTest {
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
assertEquals(httpMethod.getHeaders().size(), 0);
assertEquals(processor.createResponseParser(method).getClass(),
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
ParseServerFromJsonResponse.class);
assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(),
ReturnServerNotFoundOn404.class);
@ -252,7 +252,7 @@ public class CloudServersConnectionTest {
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
assertEquals(httpMethod.getHeaders().size(), 0);
assertEquals(processor.createResponseParser(method).getClass(),
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
ParseFlavorListFromJsonResponse.class);
assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null);
}
@ -269,7 +269,7 @@ public class CloudServersConnectionTest {
+ now.getMillis() / 1000 + "&offset=2");
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
assertEquals(httpMethod.getHeaders().size(), 0);
assertEquals(processor.createResponseParser(method).getClass(),
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
ParseFlavorListFromJsonResponse.class);
assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null);
}
@ -284,7 +284,7 @@ public class CloudServersConnectionTest {
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
assertEquals(httpMethod.getHeaders().size(), 0);
assertEquals(processor.createResponseParser(method).getClass(),
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
ParseFlavorListFromJsonResponse.class);
assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null);
}
@ -301,7 +301,7 @@ public class CloudServersConnectionTest {
+ now.getMillis() / 1000 + "&offset=2");
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
assertEquals(httpMethod.getHeaders().size(), 0);
assertEquals(processor.createResponseParser(method).getClass(),
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
ParseFlavorListFromJsonResponse.class);
assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null);
}
@ -315,7 +315,7 @@ public class CloudServersConnectionTest {
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
assertEquals(httpMethod.getHeaders().size(), 0);
assertEquals(processor.createResponseParser(method).getClass(),
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
ParseFlavorFromJsonResponse.class);
assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(),
ReturnFlavorNotFoundOn404.class);
@ -330,7 +330,7 @@ public class CloudServersConnectionTest {
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
assertEquals(httpMethod.getHeaders().size(), 0);
assertEquals(processor.createResponseParser(method).getClass(),
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
ParseImageListFromJsonResponse.class);
assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null);
}
@ -344,7 +344,7 @@ public class CloudServersConnectionTest {
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
assertEquals(httpMethod.getHeaders().size(), 0);
assertEquals(processor.createResponseParser(method).getClass(),
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
ParseImageListFromJsonResponse.class);
assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null);
}
@ -360,7 +360,7 @@ public class CloudServersConnectionTest {
+ now.getMillis() / 1000 + "&offset=2");
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
assertEquals(httpMethod.getHeaders().size(), 0);
assertEquals(processor.createResponseParser(method).getClass(),
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
ParseImageListFromJsonResponse.class);
assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null);
}
@ -376,7 +376,7 @@ public class CloudServersConnectionTest {
+ now.getMillis() / 1000 + "&offset=2");
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
assertEquals(httpMethod.getHeaders().size(), 0);
assertEquals(processor.createResponseParser(method).getClass(),
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
ParseImageListFromJsonResponse.class);
assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null);
}
@ -390,7 +390,7 @@ public class CloudServersConnectionTest {
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
assertEquals(httpMethod.getHeaders().size(), 0);
assertEquals(processor.createResponseParser(method).getClass(),
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
ParseImageFromJsonResponse.class);
assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(),
ReturnImageNotFoundOn404.class);
@ -406,7 +406,8 @@ public class CloudServersConnectionTest {
assertEquals(httpMethod.getHeaders().size(), 0);
assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(),
ReturnFalseOn404.class);
assertEquals(processor.createResponseParser(method).getClass(), ReturnTrueIf2xx.class);
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
ReturnTrueIf2xx.class);
}
public void testShareIpNoConfig() throws SecurityException, NoSuchMethodException,
@ -427,7 +428,8 @@ public class CloudServersConnectionTest {
assertEquals("{\"shareIp\":{\"sharedIpGroupId\":3}}", httpMethod.getEntity());
assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(),
ReturnFalseOn404.class);
assertEquals(processor.createResponseParser(method).getClass(), ReturnTrueIf2xx.class);
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
ReturnTrueIf2xx.class);
}
public void testShareIpConfig() throws SecurityException, NoSuchMethodException,
@ -449,7 +451,8 @@ public class CloudServersConnectionTest {
.getEntity());
assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(),
ReturnFalseOn404.class);
assertEquals(processor.createResponseParser(method).getClass(), ReturnTrueIf2xx.class);
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
ReturnTrueIf2xx.class);
}
public void testUnshareIpNoConfig() throws SecurityException, NoSuchMethodException,
@ -465,7 +468,8 @@ public class CloudServersConnectionTest {
assertEquals(httpMethod.getHeaders().size(), 0);
assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(),
ReturnFalseOn404.class);
assertEquals(processor.createResponseParser(method).getClass(), ReturnTrueIf2xx.class);
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
ReturnTrueIf2xx.class);
}
public void testReplaceBackupSchedule() throws SecurityException, NoSuchMethodException {
@ -487,7 +491,8 @@ public class CloudServersConnectionTest {
httpMethod.getEntity());
assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(),
ReturnFalseOn404.class);
assertEquals(processor.createResponseParser(method).getClass(), ReturnTrueIf2xx.class);
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
ReturnTrueIf2xx.class);
}
public void testDeleteBackupSchedule() throws SecurityException, NoSuchMethodException {
@ -500,7 +505,8 @@ public class CloudServersConnectionTest {
assertEquals(httpMethod.getHeaders().size(), 0);
assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(),
ReturnFalseOn404.class);
assertEquals(processor.createResponseParser(method).getClass(), ReturnTrueIf2xx.class);
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
ReturnTrueIf2xx.class);
}
public void testChangeAdminPass() throws SecurityException, NoSuchMethodException {
@ -519,7 +525,8 @@ public class CloudServersConnectionTest {
assertEquals("{\"server\":{\"adminPass\":\"foo\"}}", httpMethod.getEntity());
assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(),
ReturnFalseOn404.class);
assertEquals(processor.createResponseParser(method).getClass(), ReturnTrueIf2xx.class);
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
ReturnTrueIf2xx.class);
}
public void testChangeServerName() throws SecurityException, NoSuchMethodException {
@ -538,7 +545,8 @@ public class CloudServersConnectionTest {
assertEquals("{\"server\":{\"name\":\"foo\"}}", httpMethod.getEntity());
assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(),
ReturnFalseOn404.class);
assertEquals(processor.createResponseParser(method).getClass(), ReturnTrueIf2xx.class);
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
ReturnTrueIf2xx.class);
}
public void testListSharedIpGroups() throws SecurityException, NoSuchMethodException {
@ -551,7 +559,7 @@ public class CloudServersConnectionTest {
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
assertEquals(httpMethod.getHeaders().size(), 0);
assertEquals(processor.createResponseParser(method).getClass(),
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
ParseSharedIpGroupListFromJsonResponse.class);
assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null);
}
@ -568,7 +576,7 @@ public class CloudServersConnectionTest {
+ now.getMillis() / 1000 + "&offset=2");
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
assertEquals(httpMethod.getHeaders().size(), 0);
assertEquals(processor.createResponseParser(method).getClass(),
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
ParseSharedIpGroupListFromJsonResponse.class);
assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null);
}
@ -583,7 +591,7 @@ public class CloudServersConnectionTest {
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
assertEquals(httpMethod.getHeaders().size(), 0);
assertEquals(processor.createResponseParser(method).getClass(),
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
ParseSharedIpGroupListFromJsonResponse.class);
assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null);
}
@ -601,7 +609,7 @@ public class CloudServersConnectionTest {
+ now.getMillis() / 1000 + "&offset=2");
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
assertEquals(httpMethod.getHeaders().size(), 0);
assertEquals(processor.createResponseParser(method).getClass(),
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
ParseSharedIpGroupListFromJsonResponse.class);
assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null);
}
@ -615,7 +623,7 @@ public class CloudServersConnectionTest {
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
assertEquals(httpMethod.getHeaders().size(), 0);
assertEquals(processor.createResponseParser(method).getClass(),
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
ParseSharedIpGroupFromJsonResponse.class);
assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(),
ReturnSharedIpGroupNotFoundOn404.class);
@ -654,7 +662,7 @@ public class CloudServersConnectionTest {
.singletonList(httpMethod.getEntity().toString().getBytes().length + ""));
assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections
.singletonList(MediaType.APPLICATION_JSON));
assertEquals(processor.createResponseParser(method).getClass(),
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
ParseSharedIpGroupFromJsonResponse.class);
assertEquals(processor.createExceptionParserOrNullIfNotFound(method), null);
assertNotNull(processor.getMapEntityBinderOrNull(method, new Object[] { "",
@ -671,7 +679,8 @@ public class CloudServersConnectionTest {
assertEquals(httpMethod.getHeaders().size(), 0);
assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(),
ReturnFalseOn404.class);
assertEquals(processor.createResponseParser(method).getClass(), ReturnTrueIf2xx.class);
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
ReturnTrueIf2xx.class);
}
public void testListAddresses() throws SecurityException, NoSuchMethodException {
@ -683,7 +692,7 @@ public class CloudServersConnectionTest {
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
assertEquals(httpMethod.getHeaders().size(), 0);
assertEquals(processor.createResponseParser(method).getClass(),
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
ParseAddressesFromJsonResponse.class);
}
@ -696,7 +705,7 @@ public class CloudServersConnectionTest {
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
assertEquals(httpMethod.getHeaders().size(), 0);
assertEquals(processor.createResponseParser(method).getClass(),
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
ParseInetAddressListFromJsonResponse.class);
}
@ -709,7 +718,7 @@ public class CloudServersConnectionTest {
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
assertEquals(httpMethod.getHeaders().size(), 0);
assertEquals(processor.createResponseParser(method).getClass(),
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
ParseInetAddressListFromJsonResponse.class);
}
@ -722,7 +731,7 @@ public class CloudServersConnectionTest {
assertEquals(httpMethod.getEndpoint().getQuery(), "format=json");
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
assertEquals(httpMethod.getHeaders().size(), 0);
assertEquals(processor.createResponseParser(method).getClass(),
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
ParseBackupScheduleFromJsonResponse.class);
}
@ -741,7 +750,7 @@ public class CloudServersConnectionTest {
.singletonList(httpMethod.getEntity().toString().getBytes().length + ""));
assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections
.singletonList(MediaType.APPLICATION_JSON));
assertEquals(processor.createResponseParser(method).getClass(),
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
ParseImageFromJsonResponse.class);
assertNotNull(processor.createExceptionParserOrNullIfNotFound(method));
assertNotNull(processor.getMapEntityBinderOrNull(method, new Object[] { "", 2 }));
@ -780,7 +789,8 @@ public class CloudServersConnectionTest {
.singletonList(MediaType.APPLICATION_JSON));
assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(),
ReturnFalseOn404.class);
assertEquals(processor.createResponseParser(method).getClass(), ReturnTrueIf2xx.class);
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
ReturnTrueIf2xx.class);
assertNotNull(processor.getMapEntityBinderOrNull(method, new Object[] { "",
new RebuildServerOptions[] { withImage(2) } }));
}
@ -801,7 +811,8 @@ public class CloudServersConnectionTest {
assertEquals("{\"reboot\":{\"type\":\"HARD\"}}", httpMethod.getEntity());
assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(),
ReturnFalseOn404.class);
assertEquals(processor.createResponseParser(method).getClass(), ReturnTrueIf2xx.class);
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
ReturnTrueIf2xx.class);
}
public void testResize() throws SecurityException, NoSuchMethodException {
@ -819,7 +830,8 @@ public class CloudServersConnectionTest {
assertEquals("{\"resize\":{\"flavorId\":3}}", httpMethod.getEntity());
assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(),
ReturnFalseOn404.class);
assertEquals(processor.createResponseParser(method).getClass(), ReturnTrueIf2xx.class);
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
ReturnTrueIf2xx.class);
}
public void testConfirmResize() throws SecurityException, NoSuchMethodException {
@ -837,7 +849,8 @@ public class CloudServersConnectionTest {
assertEquals("{\"confirmResize\":null}", httpMethod.getEntity());
assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(),
ReturnFalseOn404.class);
assertEquals(processor.createResponseParser(method).getClass(), ReturnTrueIf2xx.class);
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
ReturnTrueIf2xx.class);
}
public void testRevertResize() throws SecurityException, NoSuchMethodException {
@ -854,7 +867,8 @@ public class CloudServersConnectionTest {
assertEquals("{\"revertResize\":null}", httpMethod.getEntity());
assertEquals(processor.createExceptionParserOrNullIfNotFound(method).getClass(),
ReturnFalseOn404.class);
assertEquals(processor.createResponseParser(method).getClass(), ReturnTrueIf2xx.class);
assertEquals(processor.createResponseParser(method, httpMethod, null).getClass(),
ReturnTrueIf2xx.class);
}
JaxrsAnnotationProcessor processor;