converted http methods to enums

git-svn-id: http://jclouds.googlecode.com/svn/trunk@1449 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
adrian.f.cole 2009-06-21 00:22:04 +00:00
parent 3f7833c2c3
commit 8bd15c7fc9
28 changed files with 412 additions and 359 deletions

View File

@ -177,7 +177,7 @@ public abstract class BaseEC2RequestOptions<T extends EC2RequestOptions> extends
// 4. Separate the name-value pairs with an ampersand.
// -- buildQueryString() does this.
StringBuilder toSign = new StringBuilder();
toSign.append("GET").append("\n").append(host.toLowerCase()).append("\n").append("/").append(
toSign.append(HttpMethod.GET).append("\n").append(host.toLowerCase()).append("\n").append("/").append(
"\n");
String canonicalizedQueryString = super.buildQueryString().replaceFirst("\\?", "");
toSign.append(canonicalizedQueryString);

View File

@ -29,6 +29,7 @@ import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import org.jclouds.http.HttpMethod;
import org.jclouds.http.HttpResponseException;
import org.jclouds.http.commands.callables.ReturnTrueIf2xx;
@ -45,42 +46,39 @@ import com.google.inject.name.Named;
*/
public class BucketExists extends S3FutureCommand<Boolean> {
@Inject
public BucketExists(@Named("jclouds.http.address") String amazonHost,
ReturnTrueIf2xx callable, @Assisted String s3Bucket) {
super("HEAD", "/" + maxResults(0).buildQueryString(), callable,
amazonHost, s3Bucket);
}
@Inject
public BucketExists(@Named("jclouds.http.address") String amazonHost, ReturnTrueIf2xx callable,
@Assisted String s3Bucket) {
super(HttpMethod.HEAD, "/" + maxResults(0).buildQueryString(), callable, amazonHost, s3Bucket);
}
@Override
public Boolean get() throws InterruptedException, ExecutionException {
try {
return super.get();
} catch (ExecutionException e) {
return attemptNotFound(e);
}
}
@Override
public Boolean get() throws InterruptedException, ExecutionException {
try {
return super.get();
} catch (ExecutionException e) {
return attemptNotFound(e);
}
}
@VisibleForTesting
Boolean attemptNotFound(ExecutionException e) throws ExecutionException {
if (e.getCause() != null
&& e.getCause() instanceof HttpResponseException) {
HttpResponseException responseException = (HttpResponseException) e
.getCause();
if (responseException.getResponse().getStatusCode() == 404) {
return false;
}
}
throw e;
}
@VisibleForTesting
Boolean attemptNotFound(ExecutionException e) throws ExecutionException {
if (e.getCause() != null && e.getCause() instanceof HttpResponseException) {
HttpResponseException responseException = (HttpResponseException) e.getCause();
if (responseException.getResponse().getStatusCode() == 404) {
return false;
}
}
throw e;
}
@Override
public Boolean get(long l, TimeUnit timeUnit) throws InterruptedException,
ExecutionException, TimeoutException {
try {
return super.get(l, timeUnit);
} catch (ExecutionException e) {
return attemptNotFound(e);
}
}
@Override
public Boolean get(long l, TimeUnit timeUnit) throws InterruptedException, ExecutionException,
TimeoutException {
try {
return super.get(l, timeUnit);
} catch (ExecutionException e) {
return attemptNotFound(e);
}
}
}

View File

@ -28,6 +28,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
import org.jclouds.aws.s3.commands.options.CopyObjectOptions;
import org.jclouds.aws.s3.domain.S3Object;
import org.jclouds.aws.s3.xml.CopyObjectHandler;
import org.jclouds.http.HttpMethod;
import org.jclouds.http.commands.callables.xml.ParseSax;
import org.jclouds.util.Utils;
@ -63,7 +64,7 @@ public class CopyObject extends S3FutureCommand<S3Object.Metadata> {
@Assisted("destinationObject") String destinationObject,
@Assisted CopyObjectOptions options)
{
super("PUT",
super(HttpMethod.PUT,
"/" + checkNotNull(destinationObject, "destinationObject"),
callable, amazonHost, destinationBucket);
CopyObjectHandler handler = (CopyObjectHandler) callable.getHandler();

View File

@ -28,6 +28,7 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import org.jclouds.aws.AWSResponseException;
import org.jclouds.http.HttpMethod;
import org.jclouds.http.commands.callables.ReturnTrueIf2xx;
import com.google.common.annotations.VisibleForTesting;
@ -51,7 +52,7 @@ public class DeleteBucket extends S3FutureCommand<Boolean> {
@Inject
public DeleteBucket(@Named("jclouds.http.address") String amazonHost, ReturnTrueIf2xx callable,
@Assisted String s3Bucket) {
super("DELETE", "/", callable, amazonHost, s3Bucket);
super(HttpMethod.DELETE, "/", callable, amazonHost, s3Bucket);
}
@Override

View File

@ -25,6 +25,7 @@ package org.jclouds.aws.s3.commands;
import static com.google.common.base.Preconditions.checkNotNull;
import org.jclouds.http.HttpMethod;
import org.jclouds.http.commands.callables.ReturnTrueIf2xx;
import com.google.inject.Inject;
@ -32,8 +33,8 @@ import com.google.inject.assistedinject.Assisted;
import com.google.inject.name.Named;
/**
* The DELETE request operation removes the specified object from Amazon S3.
* Once deleted, there is no method to restore or undelete an object.
* The DELETE request operation removes the specified object from Amazon S3. Once deleted, there is
* no method to restore or undelete an object.
*
* @see <a href="http://docs.amazonwebservices.com/AmazonS3/2006-03-01/index.html?
* RESTObjectDELETE.html" />
@ -41,10 +42,9 @@ import com.google.inject.name.Named;
*/
public class DeleteObject extends S3FutureCommand<Boolean> {
@Inject
public DeleteObject(@Named("jclouds.http.address") String amazonHost,
ReturnTrueIf2xx callable, @Assisted("bucketName") String bucket,
@Assisted("key") String key) {
super("DELETE", "/" + checkNotNull(key), callable, amazonHost, bucket);
}
@Inject
public DeleteObject(@Named("jclouds.http.address") String amazonHost, ReturnTrueIf2xx callable,
@Assisted("bucketName") String bucket, @Assisted("key") String key) {
super(HttpMethod.DELETE, "/" + checkNotNull(key), callable, amazonHost, bucket);
}
}

View File

@ -29,6 +29,7 @@ import java.util.concurrent.TimeoutException;
import org.jclouds.aws.AWSResponseException;
import org.jclouds.aws.s3.domain.AccessControlList;
import org.jclouds.http.HttpMethod;
import org.jclouds.http.commands.callables.xml.ParseSax;
import com.google.common.annotations.VisibleForTesting;
@ -51,14 +52,14 @@ public class GetAccessControlList extends S3FutureCommand<AccessControlList> {
public GetAccessControlList(@Named("jclouds.http.address") String amazonHost,
ParseSax<AccessControlList> accessControlListParser,
@Assisted("bucketName") String bucket) {
super("GET", "/?acl", accessControlListParser, amazonHost, bucket);
super(HttpMethod.GET, "/?acl", accessControlListParser, amazonHost, bucket);
}
@Inject
public GetAccessControlList(@Named("jclouds.http.address") String amazonHost,
ParseSax<AccessControlList> accessControlListParser,
@Assisted("bucketName") String bucket, @Assisted("objectKey") String objectKey) {
super("GET", "/" + objectKey + "?acl", accessControlListParser, amazonHost, bucket);
super(HttpMethod.GET, "/" + objectKey + "?acl", accessControlListParser, amazonHost, bucket);
}
@Override

View File

@ -33,6 +33,7 @@ import org.jclouds.aws.AWSResponseException;
import org.jclouds.aws.s3.commands.callables.ParseObjectFromHeadersAndHttpContent;
import org.jclouds.aws.s3.commands.options.GetObjectOptions;
import org.jclouds.aws.s3.domain.S3Object;
import org.jclouds.http.HttpMethod;
import com.google.common.annotations.VisibleForTesting;
import com.google.inject.Inject;
@ -68,7 +69,7 @@ public class GetObject extends S3FutureCommand<S3Object> {
public GetObject(@Named("jclouds.http.address") String amazonHost,
ParseObjectFromHeadersAndHttpContent callable, @Assisted("bucketName") String s3Bucket,
@Assisted("key") String key, @Assisted GetObjectOptions options) {
super("GET", "/" + checkNotNull(key), callable, amazonHost, s3Bucket);
super(HttpMethod.GET, "/" + checkNotNull(key), callable, amazonHost, s3Bucket);
this.getRequest().getHeaders().putAll(options.buildRequestHeaders());
callable.setKey(key);
}

View File

@ -31,6 +31,7 @@ import java.util.concurrent.TimeoutException;
import org.jclouds.aws.s3.commands.callables.ParseMetadataFromHeaders;
import org.jclouds.aws.s3.domain.S3Object;
import org.jclouds.http.HttpMethod;
import org.jclouds.http.HttpResponseException;
import com.google.common.annotations.VisibleForTesting;
@ -43,58 +44,54 @@ import com.google.inject.name.Named;
* {@link org.jclouds.aws.s3.domain.S3Object.Metadata#NOT_FOUND} if not available.
*
* <p/>
* The HEAD operation is used to retrieve information about a specific object or
* object size, without actually fetching the object itself. This is useful if
* you're only interested in the object metadata, and don't want to waste
* bandwidth on the object data.
* The HEAD operation is used to retrieve information about a specific object or object size,
* without actually fetching the object itself. This is useful if you're only interested in the
* object metadata, and don't want to waste bandwidth on the object data.
*
* @see GetObject
* @see <a href="http://docs.amazonwebservices.com/AmazonS3/2006-03-01/index.html?RESTObjectHEAD.html"
* @see <a
* href="http://docs.amazonwebservices.com/AmazonS3/2006-03-01/index.html?RESTObjectHEAD.html"
* />
* @author Adrian Cole
*
*/
public class HeadObject extends S3FutureCommand<S3Object.Metadata> {
@Inject
public HeadObject(@Named("jclouds.http.address") String amazonHost,
ParseMetadataFromHeaders callable,
@Assisted("bucketName") String bucket, @Assisted("key") String key) {
super("HEAD", "/" + checkNotNull(key), callable, amazonHost, bucket);
callable.setKey(key);
}
@Inject
public HeadObject(@Named("jclouds.http.address") String amazonHost,
ParseMetadataFromHeaders callable, @Assisted("bucketName") String bucket,
@Assisted("key") String key) {
super(HttpMethod.HEAD, "/" + checkNotNull(key), callable, amazonHost, bucket);
callable.setKey(key);
}
@Override
public S3Object.Metadata get() throws InterruptedException,
ExecutionException {
try {
return super.get();
} catch (ExecutionException e) {
return attemptNotFound(e);
}
}
@Override
public S3Object.Metadata get() throws InterruptedException, ExecutionException {
try {
return super.get();
} catch (ExecutionException e) {
return attemptNotFound(e);
}
}
@VisibleForTesting
S3Object.Metadata attemptNotFound(ExecutionException e)
throws ExecutionException {
if (e.getCause() != null
&& e.getCause() instanceof HttpResponseException) {
HttpResponseException responseException = (HttpResponseException) e
.getCause();
if (responseException.getResponse().getStatusCode() == 404) {
return S3Object.Metadata.NOT_FOUND;
}
}
throw e;
}
@VisibleForTesting
S3Object.Metadata attemptNotFound(ExecutionException e) throws ExecutionException {
if (e.getCause() != null && e.getCause() instanceof HttpResponseException) {
HttpResponseException responseException = (HttpResponseException) e.getCause();
if (responseException.getResponse().getStatusCode() == 404) {
return S3Object.Metadata.NOT_FOUND;
}
}
throw e;
}
@Override
public S3Object.Metadata get(long l, TimeUnit timeUnit)
throws InterruptedException, ExecutionException, TimeoutException {
try {
return super.get(l, timeUnit);
} catch (ExecutionException e) {
return attemptNotFound(e);
}
}
@Override
public S3Object.Metadata get(long l, TimeUnit timeUnit) throws InterruptedException,
ExecutionException, TimeoutException {
try {
return super.get(l, timeUnit);
} catch (ExecutionException e) {
return attemptNotFound(e);
}
}
}

View File

@ -31,6 +31,7 @@ import org.jclouds.aws.AWSResponseException;
import org.jclouds.aws.s3.commands.options.ListBucketOptions;
import org.jclouds.aws.s3.domain.S3Bucket;
import org.jclouds.aws.s3.xml.ListBucketHandler;
import org.jclouds.http.HttpMethod;
import org.jclouds.http.commands.callables.xml.ParseSax;
import com.google.common.annotations.VisibleForTesting;
@ -58,7 +59,7 @@ public class ListBucket extends S3FutureCommand<S3Bucket> {
public ListBucket(@Named("jclouds.http.address") String amazonHost,
ParseSax<S3Bucket> bucketParser, @Assisted String bucket,
@Assisted ListBucketOptions options) {
super("GET", "/" + options.buildQueryString(), bucketParser, amazonHost, bucket);
super(HttpMethod.GET, "/" + options.buildQueryString(), bucketParser, amazonHost, bucket);
ListBucketHandler handler = (ListBucketHandler) bucketParser.getHandler();
handler.setBucketName(bucket);
}

View File

@ -26,26 +26,27 @@ package org.jclouds.aws.s3.commands;
import java.util.List;
import org.jclouds.aws.s3.domain.S3Bucket;
import org.jclouds.http.HttpMethod;
import org.jclouds.http.commands.callables.xml.ParseSax;
import com.google.inject.Inject;
import com.google.inject.name.Named;
/**
* Returns a list of all of the buckets owned by the authenticated sender of the
* request.
* Returns a list of all of the buckets owned by the authenticated sender of the request.
*
* @see <a href="http://docs.amazonwebservices.com/AmazonS3/2006-03-01/index.html?RESTServiceGET.html"
* @see <a
* href="http://docs.amazonwebservices.com/AmazonS3/2006-03-01/index.html?RESTServiceGET.html"
* />
* @author Adrian Cole
*
*/
public class ListOwnedBuckets extends S3FutureCommand<List<S3Bucket.Metadata>> {
@Inject
public ListOwnedBuckets(@Named("jclouds.http.address") String amazonHost,
ParseSax<List<S3Bucket.Metadata>> callable) {
super("GET", "/", callable, amazonHost);
}
@Inject
public ListOwnedBuckets(@Named("jclouds.http.address") String amazonHost,
ParseSax<List<S3Bucket.Metadata>> callable) {
super(HttpMethod.GET, "/", callable, amazonHost);
}
}

View File

@ -31,6 +31,7 @@ import org.jclouds.aws.AWSResponseException;
import org.jclouds.aws.s3.commands.options.PutBucketOptions;
import org.jclouds.aws.s3.util.S3Utils;
import org.jclouds.http.HttpHeaders;
import org.jclouds.http.HttpMethod;
import org.jclouds.http.commands.callables.ReturnTrueIf2xx;
import com.google.common.annotations.VisibleForTesting;
@ -58,7 +59,7 @@ public class PutBucket extends S3FutureCommand<Boolean> {
@Inject
public PutBucket(@Named("jclouds.http.address") String amazonHost, ReturnTrueIf2xx callable,
@Assisted String bucketName, @Assisted PutBucketOptions options) {
super("PUT", "/", callable, amazonHost, S3Utils.validateBucketName(bucketName));
super(HttpMethod.PUT, "/", callable, amazonHost, S3Utils.validateBucketName(bucketName));
getRequest().getHeaders().putAll(options.buildRequestHeaders());
String payload = options.buildPayload();
if (payload != null) {
@ -77,7 +78,8 @@ public class PutBucket extends S3FutureCommand<Boolean> {
}
@VisibleForTesting
static Boolean eventualConsistencyAlreadyOwnedIsOk(ExecutionException e) throws ExecutionException {
static Boolean eventualConsistencyAlreadyOwnedIsOk(ExecutionException e)
throws ExecutionException {
if (e.getCause() != null && e.getCause() instanceof AWSResponseException) {
AWSResponseException responseException = (AWSResponseException) e.getCause();
if ("BucketAlreadyOwnedByYou".equals(responseException.getError().getCode())) {

View File

@ -28,6 +28,7 @@ import javax.annotation.Resource;
import org.jclouds.aws.s3.domain.AccessControlList;
import org.jclouds.aws.s3.xml.AccessControlListBuilder;
import org.jclouds.http.HttpHeaders;
import org.jclouds.http.HttpMethod;
import org.jclouds.http.commands.callables.ReturnTrueIf2xx;
import org.jclouds.logging.Logger;
@ -52,7 +53,7 @@ public class PutBucketAccessControlList extends S3FutureCommand<Boolean> {
public PutBucketAccessControlList(@Named("jclouds.http.address") String amazonHost,
ReturnTrueIf2xx callable, @Assisted("bucketName") String bucket,
@Assisted AccessControlList acl) {
super("PUT", "/?acl", callable, amazonHost, bucket);
super(HttpMethod.PUT, "/?acl", callable, amazonHost, bucket);
String aclPayload = "";
try {

View File

@ -31,6 +31,7 @@ import org.jclouds.aws.s3.commands.options.PutObjectOptions;
import org.jclouds.aws.s3.domain.S3Object;
import org.jclouds.aws.s3.util.S3Utils;
import org.jclouds.http.HttpHeaders;
import org.jclouds.http.HttpMethod;
import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted;
@ -43,56 +44,54 @@ import com.google.inject.name.Named;
* This returns a byte[] of the md5 hash of what Amazon S3 received
* <p />
* <p/>
* This command allows you to specify {@link PutObjectOptions} to control
* delivery of content.
* This command allows you to specify {@link PutObjectOptions} to control delivery of content.
*
*
* @see PutObjectOptions
* @see <a href="http://docs.amazonwebservices.com/AmazonS3/2006-03-01/index.html?RESTObjectPUT.html"
* @see <a
* href="http://docs.amazonwebservices.com/AmazonS3/2006-03-01/index.html?RESTObjectPUT.html"
* />
* @author Adrian Cole
*/
public class PutObject extends S3FutureCommand<byte[]> {
@Inject
public PutObject(@Named("jclouds.http.address") String amazonHost,
ParseMd5FromETagHeader callable, @Assisted String s3Bucket,
@Assisted S3Object object, @Assisted PutObjectOptions options) {
super("PUT", "/" + checkNotNull(object.getKey()), callable, amazonHost,
s3Bucket);
checkArgument(object.getMetadata().getSize() >= 0, "size must be set");
@Inject
public PutObject(@Named("jclouds.http.address") String amazonHost,
ParseMd5FromETagHeader callable, @Assisted String s3Bucket, @Assisted S3Object object,
@Assisted PutObjectOptions options) {
super(HttpMethod.PUT, "/" + checkNotNull(object.getKey()), callable, amazonHost, s3Bucket);
checkArgument(object.getMetadata().getSize() >= 0, "size must be set");
getRequest().setPayload(
checkNotNull(object.getData(), "object.getContent()"));
getRequest().setPayload(checkNotNull(object.getData(), "object.getContent()"));
getRequest().getHeaders().put(
HttpHeaders.CONTENT_TYPE,
checkNotNull(object.getMetadata().getContentType(),
"object.metadata.contentType()"));
getRequest().getHeaders()
.put(
HttpHeaders.CONTENT_TYPE,
checkNotNull(object.getMetadata().getContentType(),
"object.metadata.contentType()"));
getRequest().getHeaders().put(HttpHeaders.CONTENT_LENGTH,
object.getMetadata().getSize() + "");
getRequest().getHeaders()
.put(HttpHeaders.CONTENT_LENGTH, object.getMetadata().getSize() + "");
if (object.getMetadata().getCacheControl() != null) {
getRequest().getHeaders().put(HttpHeaders.CACHE_CONTROL,
object.getMetadata().getCacheControl());
}
if (object.getMetadata().getContentDisposition() != null) {
getRequest().getHeaders().put(HttpHeaders.CONTENT_DISPOSITION,
object.getMetadata().getContentDisposition());
}
if (object.getMetadata().getContentEncoding() != null) {
getRequest().getHeaders().put(HttpHeaders.CONTENT_ENCODING,
object.getMetadata().getContentEncoding());
}
if (object.getMetadata().getCacheControl() != null) {
getRequest().getHeaders().put(HttpHeaders.CACHE_CONTROL,
object.getMetadata().getCacheControl());
}
if (object.getMetadata().getContentDisposition() != null) {
getRequest().getHeaders().put(HttpHeaders.CONTENT_DISPOSITION,
object.getMetadata().getContentDisposition());
}
if (object.getMetadata().getContentEncoding() != null) {
getRequest().getHeaders().put(HttpHeaders.CONTENT_ENCODING,
object.getMetadata().getContentEncoding());
}
if (object.getMetadata().getMd5() != null)
getRequest().getHeaders().put(HttpHeaders.CONTENT_MD5,
S3Utils.toBase64String(object.getMetadata().getMd5()));
if (object.getMetadata().getMd5() != null)
getRequest().getHeaders().put(HttpHeaders.CONTENT_MD5,
S3Utils.toBase64String(object.getMetadata().getMd5()));
getRequest().getHeaders()
.putAll(object.getMetadata().getUserMetadata());
getRequest().getHeaders().putAll(options.buildRequestHeaders());
getRequest().getHeaders().putAll(object.getMetadata().getUserMetadata());
getRequest().getHeaders().putAll(options.buildRequestHeaders());
}
}
}

View File

@ -28,6 +28,7 @@ import javax.annotation.Resource;
import org.jclouds.aws.s3.domain.AccessControlList;
import org.jclouds.aws.s3.xml.AccessControlListBuilder;
import org.jclouds.http.HttpHeaders;
import org.jclouds.http.HttpMethod;
import org.jclouds.http.commands.callables.ReturnTrueIf2xx;
import org.jclouds.logging.Logger;
@ -36,8 +37,8 @@ import com.google.inject.assistedinject.Assisted;
import com.google.inject.name.Named;
/**
* A PUT request operation directed at an object URI with the "acl" parameter
* sets the Access Control List (ACL) settings for that S3 item.
* A PUT request operation directed at an object URI with the "acl" parameter sets the Access
* Control List (ACL) settings for that S3 item.
* <p />
* To set a bucket or object's ACL, you must have WRITE_ACP or FULL_CONTROL access to the item.
*
@ -51,9 +52,8 @@ public class PutObjectAccessControlList extends S3FutureCommand<Boolean> {
@Inject
public PutObjectAccessControlList(@Named("jclouds.http.address") String amazonHost,
ReturnTrueIf2xx callable, @Assisted("bucketName") String bucket,
@Assisted("key") String objectKey, @Assisted AccessControlList acl)
{
super("PUT", "/" + objectKey + "?acl", callable, amazonHost, bucket);
@Assisted("key") String objectKey, @Assisted AccessControlList acl) {
super(HttpMethod.PUT, "/" + objectKey + "?acl", callable, amazonHost, bucket);
String aclPayload = "";
try {
@ -63,8 +63,7 @@ public class PutObjectAccessControlList extends S3FutureCommand<Boolean> {
logger.error(e, "Unable to build XML document for Access Control List: " + acl);
}
getRequest().setPayload(aclPayload);
getRequest().getHeaders().put(
HttpHeaders.CONTENT_LENGTH, aclPayload.getBytes().length + "");
getRequest().getHeaders().put(HttpHeaders.CONTENT_LENGTH, aclPayload.getBytes().length + "");
}
}

View File

@ -26,6 +26,7 @@ package org.jclouds.aws.s3.commands;
import static com.google.common.base.Preconditions.checkNotNull;
import org.jclouds.http.HttpFutureCommand;
import org.jclouds.http.HttpMethod;
/**
* Conditionally adds the amazon host header to requests.
@ -36,13 +37,13 @@ import org.jclouds.http.HttpFutureCommand;
*/
public class S3FutureCommand<T> extends HttpFutureCommand<T> {
public S3FutureCommand(String method, String uri, ResponseCallable<T> responseCallable,
public S3FutureCommand(HttpMethod method, String uri, ResponseCallable<T> responseCallable,
String amazonHost, String bucketName) {
super(method, uri, responseCallable);
addHostHeader(checkNotNull(amazonHost, "amazonHost"), checkNotNull(bucketName, "bucketName"));
}
public S3FutureCommand(String method, String uri, ResponseCallable<T> responseCallable,
public S3FutureCommand(HttpMethod method, String uri, ResponseCallable<T> responseCallable,
String amazonHost) {
super(method, uri, responseCallable);
addHostHeader(checkNotNull(amazonHost, "amazonHost"));

View File

@ -39,7 +39,7 @@ import org.jclouds.logging.Logger;
*/
public class HttpFutureCommand<T> extends FutureCommand<HttpRequest, HttpResponse, T> {
public HttpFutureCommand(String method, String uri, ResponseCallable<T> responseCallable) {
public HttpFutureCommand(HttpMethod method, String uri, ResponseCallable<T> responseCallable) {
super(new HttpRequest(checkNotNull(method, "method"), checkNotNull(uri, "uri")),
responseCallable);
}

View File

@ -0,0 +1,33 @@
/**
*
* 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.http;
/**
* {@code HttpMethod} is an enumeration of HTTP methods used in {@link HttpFutureCommand}
*
* @author Adrian Cole
*/
public enum HttpMethod {
DELETE, GET, HEAD, POST, PUT
}

View File

@ -33,60 +33,59 @@ import org.jclouds.logging.Logger;
import org.jclouds.util.Utils;
/**
* Represents a request that can be executed within
* {@link HttpFutureCommandClient}
* Represents a request that can be executed within {@link HttpFutureCommandClient}
*
* @author Adrian Cole
*/
public class HttpRequest extends HttpMessage {
private final String method;
private final String uri;
Object payload;
private final HttpMethod method;
private final String uri;
Object payload;
@Resource
protected Logger logger = Logger.NULL;
@Resource
protected Logger logger = Logger.NULL;
public HttpRequest(String method, String uri) {
this.method = checkNotNull(method, "method");
this.uri = Utils.encodeUriPath(checkNotNull(uri, "uri"));
}
public HttpRequest(HttpMethod method, String uri) {
this.method = checkNotNull(method, "method");
this.uri = Utils.encodeUriPath(checkNotNull(uri, "uri"));
}
@Override
public String toString() {
final StringBuilder sb = new StringBuilder();
sb.append("HttpRequest");
sb.append("{method='").append(method).append('\'');
sb.append(", uri='").append(uri).append('\'');
sb.append(", headers=").append(headers);
sb.append(", payload set=").append(payload != null);
sb.append('}');
return sb.toString();
}
@Override
public String toString() {
final StringBuilder sb = new StringBuilder();
sb.append("HttpRequest");
sb.append("{method='").append(method).append('\'');
sb.append(", uri='").append(uri).append('\'');
sb.append(", headers=").append(headers);
sb.append(", payload set=").append(payload != null);
sb.append('}');
return sb.toString();
}
public String getMethod() {
return method;
}
public HttpMethod getMethod() {
return method;
}
public String getUri() {
return uri;
}
public String getUri() {
return uri;
}
public boolean isReplayable() {
Object content = getPayload();
if (content != null && content instanceof InputStream) {
logger.warn("%1$s: InputStreams are not replayable", toString());
return false;
}
return true;
}
public boolean isReplayable() {
Object content = getPayload();
if (content != null && content instanceof InputStream) {
logger.warn("%1$s: InputStreams are not replayable", toString());
return false;
}
return true;
}
public Object getPayload() {
return payload;
}
public Object getPayload() {
return payload;
}
public void setPayload(Object content) {
this.payload = content;
}
public void setPayload(Object content) {
this.payload = content;
}
}

View File

@ -24,6 +24,7 @@
package org.jclouds.http.commands;
import org.jclouds.http.HttpFutureCommand;
import org.jclouds.http.HttpMethod;
import org.jclouds.http.commands.callables.xml.ParseSax;
/**
@ -33,7 +34,7 @@ import org.jclouds.http.commands.callables.xml.ParseSax;
*/
public class GetAndParseSax<T> extends HttpFutureCommand<T> {
public GetAndParseSax(String uri, ParseSax<T> callable) {
super("GET", uri, callable);
}
public GetAndParseSax(String uri, ParseSax<T> callable) {
super(HttpMethod.GET, uri, callable);
}
}

View File

@ -23,10 +23,12 @@
*/
package org.jclouds.http.commands;
import org.jclouds.http.HttpFutureCommand;
import org.jclouds.http.HttpMethod;
import org.jclouds.http.commands.callables.ReturnStringIf200;
import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted;
import org.jclouds.http.HttpFutureCommand;
import org.jclouds.http.commands.callables.ReturnStringIf200;
/**
* // TODO: Adrian: Document this!
@ -35,8 +37,8 @@ import org.jclouds.http.commands.callables.ReturnStringIf200;
*/
public class GetString extends HttpFutureCommand<String> {
@Inject
public GetString(ReturnStringIf200 callable, @Assisted String uri) {
super("GET", uri, callable);
}
@Inject
public GetString(ReturnStringIf200 callable, @Assisted String uri) {
super(HttpMethod.GET, uri, callable);
}
}

View File

@ -23,10 +23,12 @@
*/
package org.jclouds.http.commands;
import org.jclouds.http.HttpFutureCommand;
import org.jclouds.http.HttpMethod;
import org.jclouds.http.commands.callables.ReturnTrueIf2xx;
import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted;
import org.jclouds.http.HttpFutureCommand;
import org.jclouds.http.commands.callables.ReturnTrueIf2xx;
/**
* // TODO: Adrian: Document this!
@ -35,8 +37,8 @@ import org.jclouds.http.commands.callables.ReturnTrueIf2xx;
*/
public class Head extends HttpFutureCommand<Boolean> {
@Inject
public Head(ReturnTrueIf2xx callable, @Assisted String uri) {
super("HEAD", uri, callable);
}
@Inject
public Head(ReturnTrueIf2xx callable, @Assisted String uri) {
super(HttpMethod.HEAD, uri, callable);
}
}

View File

@ -23,10 +23,12 @@
*/
package org.jclouds.http.commands;
import org.jclouds.http.HttpFutureCommand;
import org.jclouds.http.HttpMethod;
import org.jclouds.http.commands.callables.ReturnTrueIf2xx;
import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted;
import org.jclouds.http.HttpFutureCommand;
import org.jclouds.http.commands.callables.ReturnTrueIf2xx;
/**
* PUT a string and respond with true if successful.
@ -38,7 +40,7 @@ public class Put extends HttpFutureCommand<Boolean> {
@Inject
public Put(ReturnTrueIf2xx callable, @Assisted("uri") String uri,
@Assisted("payload") String payload) {
super("PUT", uri, callable);
super(HttpMethod.PUT, uri, callable);
this.getRequest().setPayload(payload);
}
}

View File

@ -37,6 +37,7 @@ import org.apache.commons.io.IOUtils;
import org.jclouds.http.HttpConstants;
import org.jclouds.http.HttpFutureCommand;
import org.jclouds.http.HttpFutureCommandClient;
import org.jclouds.http.HttpMethod;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpRequestFilter;
import org.jclouds.http.HttpResponse;
@ -79,7 +80,7 @@ public class JavaUrlHttpFutureCommandClient extends BaseHttpFutureCommandClient
} finally {
// DO NOT disconnect, as it will also close the unconsumed
// outputStream from above.
if (request.getMethod().equals("HEAD"))
if (request.getMethod().equals(HttpMethod.HEAD))
connection.disconnect();
}
}
@ -110,7 +111,7 @@ public class JavaUrlHttpFutureCommandClient extends BaseHttpFutureCommandClient
connection.setDoOutput(true);
connection.setAllowUserInteraction(false);
connection.setInstanceFollowRedirects(true);
connection.setRequestMethod(request.getMethod());
connection.setRequestMethod(request.getMethod().toString());
for (String header : request.getHeaders().keySet()) {
for (String value : request.getHeaders().get(header))
connection.setRequestProperty(header, value);

View File

@ -23,6 +23,7 @@
*/
package org.jclouds.http.commands;
import org.jclouds.http.HttpMethod;
import org.jclouds.http.commands.callables.ReturnStringIf200;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
@ -56,6 +57,6 @@ public class GetStringTest {
public void testConstructor() {
assert get.getResponseFuture() != null;
assert get.getRequest().getUri().equals(GOOD_PATH);
assert get.getRequest().getMethod().equals("GET");
assert get.getRequest().getMethod().equals(HttpMethod.GET);
}
}

View File

@ -30,6 +30,7 @@ import java.io.IOException;
import java.io.InputStream;
import org.jclouds.http.HttpFutureCommand;
import org.jclouds.http.HttpMethod;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.commands.callables.ReturnStringIf200;
import org.testng.annotations.Test;
@ -41,52 +42,67 @@ public class BackoffLimitedRetryHandlerTest {
@Test
void testExponentialBackoffDelay() throws InterruptedException {
long acceptableDelay = 25; // Delay to forgive if tests run long.
long acceptableDelay = 25; // Delay to forgive if tests run long.
long startTime = System.currentTimeMillis();
handler.imposeBackoffExponentialDelay(1, "TEST FAILURE: 1");
long elapsedTime = System.currentTimeMillis() - startTime;
assertTrue(elapsedTime >= 50);
assertTrue(elapsedTime < 50 + acceptableDelay);
long startTime = System.currentTimeMillis();
handler.imposeBackoffExponentialDelay(1, "TEST FAILURE: 1");
long elapsedTime = System.currentTimeMillis() - startTime;
assertTrue(elapsedTime >= 50);
assertTrue(elapsedTime < 50 + acceptableDelay);
startTime = System.currentTimeMillis();
handler.imposeBackoffExponentialDelay(2, "TEST FAILURE: 2");
elapsedTime = System.currentTimeMillis() - startTime;
assertTrue(elapsedTime >= 200);
assertTrue(elapsedTime < 200 + acceptableDelay);
startTime = System.currentTimeMillis();
handler.imposeBackoffExponentialDelay(2, "TEST FAILURE: 2");
elapsedTime = System.currentTimeMillis() - startTime;
assertTrue(elapsedTime >= 200);
assertTrue(elapsedTime < 200 + acceptableDelay);
startTime = System.currentTimeMillis();
handler.imposeBackoffExponentialDelay(3, "TEST FAILURE: 3");
elapsedTime = System.currentTimeMillis() - startTime;
assertTrue(elapsedTime >= 450);
assertTrue(elapsedTime < 450 + acceptableDelay);
startTime = System.currentTimeMillis();
handler.imposeBackoffExponentialDelay(3, "TEST FAILURE: 3");
elapsedTime = System.currentTimeMillis() - startTime;
assertTrue(elapsedTime >= 450);
assertTrue(elapsedTime < 450 + acceptableDelay);
startTime = System.currentTimeMillis();
handler.imposeBackoffExponentialDelay(4, "TEST FAILURE: 4");
elapsedTime = System.currentTimeMillis() - startTime;
assertTrue(elapsedTime >= 800);
assertTrue(elapsedTime < 800 + acceptableDelay);
startTime = System.currentTimeMillis();
handler.imposeBackoffExponentialDelay(4, "TEST FAILURE: 4");
elapsedTime = System.currentTimeMillis() - startTime;
assertTrue(elapsedTime >= 800);
assertTrue(elapsedTime < 800 + acceptableDelay);
startTime = System.currentTimeMillis();
handler.imposeBackoffExponentialDelay(5, "TEST FAILURE: 5");
elapsedTime = System.currentTimeMillis() - startTime;
assertTrue(elapsedTime >= 1250);
assertTrue(elapsedTime < 1250 + acceptableDelay);
startTime = System.currentTimeMillis();
handler.imposeBackoffExponentialDelay(5, "TEST FAILURE: 5");
elapsedTime = System.currentTimeMillis() - startTime;
assertTrue(elapsedTime >= 1250);
assertTrue(elapsedTime < 1250 + acceptableDelay);
}
@Test
void testClosesInputStream() throws InterruptedException, IOException {
HttpFutureCommand<String> command =
new HttpFutureCommand<String>("method", "uri", new ReturnStringIf200());
HttpFutureCommand<String> command = new HttpFutureCommand<String>(HttpMethod.HEAD, "uri",
new ReturnStringIf200());
HttpResponse response = new HttpResponse();
InputStream inputStream = new InputStream() {
boolean isOpen = true;
@Override
public void close() { this.isOpen = false; }
@Override
public int read() throws IOException { if (this.isOpen) return 1; else return -1; }
@Override
public int available() throws IOException { if (this.isOpen) return 1; else return 0; }
boolean isOpen = true;
@Override
public void close() {
this.isOpen = false;
}
@Override
public int read() throws IOException {
if (this.isOpen)
return 1;
else
return -1;
}
@Override
public int available() throws IOException {
if (this.isOpen)
return 1;
else
return 0;
}
};
response.setContent(inputStream);
@ -101,8 +117,8 @@ public class BackoffLimitedRetryHandlerTest {
@Test
void testIncrementsFailureCount() throws InterruptedException {
HttpFutureCommand<String> command =
new HttpFutureCommand<String>("method", "uri", new ReturnStringIf200());
HttpFutureCommand<String> command = new HttpFutureCommand<String>(HttpMethod.HEAD, "uri",
new ReturnStringIf200());
HttpResponse response = new HttpResponse();
handler.retryRequest(command, response);
@ -117,21 +133,21 @@ public class BackoffLimitedRetryHandlerTest {
@Test
void testDisallowsExcessiveRetries() throws InterruptedException {
HttpFutureCommand<String> command =
new HttpFutureCommand<String>("method", "uri", new ReturnStringIf200());
HttpFutureCommand<String> command = new HttpFutureCommand<String>(HttpMethod.HEAD, "uri",
new ReturnStringIf200());
HttpResponse response = new HttpResponse();
assertEquals(handler.retryRequest(command, response), true); // Failure 1
assertEquals(handler.retryRequest(command, response), true); // Failure 1
assertEquals(handler.retryRequest(command, response), true); // Failure 2
assertEquals(handler.retryRequest(command, response), true); // Failure 2
assertEquals(handler.retryRequest(command, response), true); // Failure 3
assertEquals(handler.retryRequest(command, response), true); // Failure 3
assertEquals(handler.retryRequest(command, response), true); // Failure 4
assertEquals(handler.retryRequest(command, response), true); // Failure 4
assertEquals(handler.retryRequest(command, response), true); // Failure 5
assertEquals(handler.retryRequest(command, response), true); // Failure 5
assertEquals(handler.retryRequest(command, response), false); // Failure 6
assertEquals(handler.retryRequest(command, response), false); // Failure 6
}
}

View File

@ -171,8 +171,8 @@ public class URLFetchServiceClient extends BaseHttpFutureCommandClient {
FetchOptions options = disallowTruncate();
followRedirectsUnlessRequestContainsPayload(request, options);
HTTPRequest gaeRequest = new HTTPRequest(url, HTTPMethod.valueOf(request.getMethod()),
options);
HTTPRequest gaeRequest = new HTTPRequest(url, HTTPMethod.valueOf(request.getMethod()
.toString()), options);
for (String header : request.getHeaders().keySet()) {
// GAE/J v1.2.1 re-writes the host header, so we'll skip it.

View File

@ -40,6 +40,7 @@ import java.util.List;
import org.apache.commons.io.IOUtils;
import org.jclouds.http.HttpHeaders;
import org.jclouds.http.HttpMethod;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.testng.annotations.BeforeTest;
@ -100,21 +101,21 @@ public class URLFetchServiceClientTest {
@Test
void testConvertRequestGetsTargetAndUri() throws IOException {
HttpRequest request = new HttpRequest("GET", "foo");
HttpRequest request = new HttpRequest(HttpMethod.GET, "foo");
HTTPRequest gaeRequest = client.convert(request);
assertEquals(gaeRequest.getURL().getPath(), "/foo");
}
@Test
void testConvertRequestSetsFetchOptions() throws IOException {
HttpRequest request = new HttpRequest("GET", "foo");
HttpRequest request = new HttpRequest(HttpMethod.GET, "foo");
HTTPRequest gaeRequest = client.convert(request);
assert gaeRequest.getFetchOptions() != null;
}
@Test
void testConvertRequestSetsHeaders() throws IOException {
HttpRequest request = new HttpRequest("GET", "foo");
HttpRequest request = new HttpRequest(HttpMethod.GET, "foo");
request.getHeaders().put("foo", "bar");
HTTPRequest gaeRequest = client.convert(request);
assertEquals(gaeRequest.getHeaders().get(0).getName(), "foo");
@ -123,36 +124,36 @@ public class URLFetchServiceClientTest {
@Test
void testConvertRequestNoContent() throws IOException {
HttpRequest request = new HttpRequest("GET", "foo");
HttpRequest request = new HttpRequest(HttpMethod.GET, "foo");
HTTPRequest gaeRequest = client.convert(request);
assert gaeRequest.getPayload() == null;
assertEquals(gaeRequest.getHeaders().size(), 1);//content length
assertEquals(gaeRequest.getHeaders().size(), 1);// content length
}
@Test
void testConvertRequestStringContent() throws IOException {
HttpRequest request = new HttpRequest("GET", "foo");
HttpRequest request = new HttpRequest(HttpMethod.GET, "foo");
request.setPayload("hoot!");
testHoot(request);
}
@Test
void testConvertRequestInputStreamContent() throws IOException {
HttpRequest request = new HttpRequest("GET", "foo");
HttpRequest request = new HttpRequest(HttpMethod.GET, "foo");
request.setPayload(IOUtils.toInputStream("hoot!"));
testHoot(request);
}
@Test
void testConvertRequestBytesContent() throws IOException {
HttpRequest request = new HttpRequest("GET", "foo");
HttpRequest request = new HttpRequest(HttpMethod.GET, "foo");
request.setPayload("hoot!".getBytes());
testHoot(request);
}
@Test(expectedExceptions = UnsupportedOperationException.class)
void testConvertRequestBadContent() throws IOException {
HttpRequest request = new HttpRequest("GET", "foo");
HttpRequest request = new HttpRequest(HttpMethod.GET, "foo");
request.setPayload(new Date());
client.convert(request);
@ -164,7 +165,7 @@ public class URLFetchServiceClientTest {
File file = new File(basedir, "target/testfiles/hoot");
file.getParentFile().mkdirs();
IOUtils.write("hoot!", new FileOutputStream(file));
HttpRequest request = new HttpRequest("GET", "foo");
HttpRequest request = new HttpRequest(HttpMethod.GET, "foo");
request.setPayload(file);
testHoot(request);
}

View File

@ -41,79 +41,71 @@ import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
public class HttpNioUtils {
public static HttpEntityEnclosingRequest convertToApacheRequest(
HttpRequest object) {
BasicHttpEntityEnclosingRequest apacheRequest = new BasicHttpEntityEnclosingRequest(
object.getMethod(), object.getUri(), HttpVersion.HTTP_1_1);
public static HttpEntityEnclosingRequest convertToApacheRequest(HttpRequest object) {
BasicHttpEntityEnclosingRequest apacheRequest = new BasicHttpEntityEnclosingRequest(object
.getMethod().toString(), object.getUri(), HttpVersion.HTTP_1_1);
Object content = object.getPayload();
Object content = object.getPayload();
// Since we may remove headers, ensure they are added to the apache
// request after this block
if (content != null) {
long contentLength = Long.parseLong(object
.getFirstHeaderOrNull(HttpHeaders.CONTENT_LENGTH));
object.getHeaders().removeAll(HttpHeaders.CONTENT_LENGTH);
String contentType = object
.getFirstHeaderOrNull(HttpHeaders.CONTENT_TYPE);
object.getHeaders().removeAll(HttpHeaders.CONTENT_TYPE);
addEntityForContent(apacheRequest, content, contentType,
contentLength);
}
// Since we may remove headers, ensure they are added to the apache
// request after this block
if (content != null) {
long contentLength = Long.parseLong(object
.getFirstHeaderOrNull(HttpHeaders.CONTENT_LENGTH));
object.getHeaders().removeAll(HttpHeaders.CONTENT_LENGTH);
String contentType = object.getFirstHeaderOrNull(HttpHeaders.CONTENT_TYPE);
object.getHeaders().removeAll(HttpHeaders.CONTENT_TYPE);
addEntityForContent(apacheRequest, content, contentType, contentLength);
}
for (String header : object.getHeaders().keySet()) {
for (String value : object.getHeaders().get(header))
apacheRequest.addHeader(header, value);
}
return apacheRequest;
}
for (String header : object.getHeaders().keySet()) {
for (String value : object.getHeaders().get(header))
apacheRequest.addHeader(header, value);
}
return apacheRequest;
}
public static void addEntityForContent(
BasicHttpEntityEnclosingRequest apacheRequest, Object content,
String contentType, long length) {
if (content instanceof InputStream) {
InputStream inputStream = (InputStream) content;
if (length == -1)
throw new IllegalArgumentException(
"you must specify size when content is an InputStream");
InputStreamEntity entity = new InputStreamEntity(inputStream,
length);
entity.setContentType(contentType);
apacheRequest.setEntity(entity);
} else if (content instanceof String) {
NStringEntity nStringEntity = null;
try {
nStringEntity = new NStringEntity((String) content);
} catch (UnsupportedEncodingException e) {
throw new UnsupportedOperationException(
"Encoding not supported", e);
}
nStringEntity.setContentType(contentType);
apacheRequest.setEntity(nStringEntity);
} else if (content instanceof File) {
apacheRequest.setEntity(new NFileEntity((File) content,
contentType, true));
} else if (content instanceof byte[]) {
NByteArrayEntity entity = new NByteArrayEntity((byte[]) content);
entity.setContentType(contentType);
apacheRequest.setEntity(entity);
} else {
throw new UnsupportedOperationException(
"Content class not supported: "
+ content.getClass().getName());
}
}
public static void addEntityForContent(BasicHttpEntityEnclosingRequest apacheRequest,
Object content, String contentType, long length) {
if (content instanceof InputStream) {
InputStream inputStream = (InputStream) content;
if (length == -1)
throw new IllegalArgumentException(
"you must specify size when content is an InputStream");
InputStreamEntity entity = new InputStreamEntity(inputStream, length);
entity.setContentType(contentType);
apacheRequest.setEntity(entity);
} else if (content instanceof String) {
NStringEntity nStringEntity = null;
try {
nStringEntity = new NStringEntity((String) content);
} catch (UnsupportedEncodingException e) {
throw new UnsupportedOperationException("Encoding not supported", e);
}
nStringEntity.setContentType(contentType);
apacheRequest.setEntity(nStringEntity);
} else if (content instanceof File) {
apacheRequest.setEntity(new NFileEntity((File) content, contentType, true));
} else if (content instanceof byte[]) {
NByteArrayEntity entity = new NByteArrayEntity((byte[]) content);
entity.setContentType(contentType);
apacheRequest.setEntity(entity);
} else {
throw new UnsupportedOperationException("Content class not supported: "
+ content.getClass().getName());
}
}
public static HttpResponse convertToJavaCloudsResponse(
org.apache.http.HttpResponse apacheResponse) throws IOException {
HttpResponse response = new HttpResponse();
if (apacheResponse.getEntity() != null) {
response.setContent(apacheResponse.getEntity().getContent());
}
for (Header header : apacheResponse.getAllHeaders()) {
response.getHeaders().put(header.getName(), header.getValue());
}
response.setStatusCode(apacheResponse.getStatusLine().getStatusCode());
return response;
}
public static HttpResponse convertToJavaCloudsResponse(
org.apache.http.HttpResponse apacheResponse) throws IOException {
HttpResponse response = new HttpResponse();
if (apacheResponse.getEntity() != null) {
response.setContent(apacheResponse.getEntity().getContent());
}
for (Header header : apacheResponse.getAllHeaders()) {
response.getHeaders().put(header.getName(), header.getValue());
}
response.setStatusCode(apacheResponse.getStatusLine().getStatusCode());
return response;
}
}