mirror of https://github.com/apache/jclouds.git
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:
parent
3f7833c2c3
commit
8bd15c7fc9
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
@ -46,10 +47,9 @@ 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);
|
||||
public BucketExists(@Named("jclouds.http.address") String amazonHost, ReturnTrueIf2xx callable,
|
||||
@Assisted String s3Bucket) {
|
||||
super(HttpMethod.HEAD, "/" + maxResults(0).buildQueryString(), callable, amazonHost, s3Bucket);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -63,10 +63,8 @@ public class BucketExists extends S3FutureCommand<Boolean> {
|
|||
|
||||
@VisibleForTesting
|
||||
Boolean attemptNotFound(ExecutionException e) throws ExecutionException {
|
||||
if (e.getCause() != null
|
||||
&& e.getCause() instanceof HttpResponseException) {
|
||||
HttpResponseException responseException = (HttpResponseException) e
|
||||
.getCause();
|
||||
if (e.getCause() != null && e.getCause() instanceof HttpResponseException) {
|
||||
HttpResponseException responseException = (HttpResponseException) e.getCause();
|
||||
if (responseException.getResponse().getStatusCode() == 404) {
|
||||
return false;
|
||||
}
|
||||
|
@ -75,8 +73,8 @@ public class BucketExists extends S3FutureCommand<Boolean> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Boolean get(long l, TimeUnit timeUnit) throws InterruptedException,
|
||||
ExecutionException, TimeoutException {
|
||||
public Boolean get(long l, TimeUnit timeUnit) throws InterruptedException, ExecutionException,
|
||||
TimeoutException {
|
||||
try {
|
||||
return super.get(l, timeUnit);
|
||||
} catch (ExecutionException e) {
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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" />
|
||||
|
@ -42,9 +43,8 @@ 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);
|
||||
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);
|
||||
}
|
||||
}
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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,13 +44,13 @@ 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
|
||||
*
|
||||
|
@ -58,15 +59,14 @@ 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);
|
||||
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 {
|
||||
public S3Object.Metadata get() throws InterruptedException, ExecutionException {
|
||||
try {
|
||||
return super.get();
|
||||
} catch (ExecutionException e) {
|
||||
|
@ -75,12 +75,9 @@ public class HeadObject extends S3FutureCommand<S3Object.Metadata> {
|
|||
}
|
||||
|
||||
@VisibleForTesting
|
||||
S3Object.Metadata attemptNotFound(ExecutionException e)
|
||||
throws ExecutionException {
|
||||
if (e.getCause() != null
|
||||
&& e.getCause() instanceof HttpResponseException) {
|
||||
HttpResponseException responseException = (HttpResponseException) e
|
||||
.getCause();
|
||||
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;
|
||||
}
|
||||
|
@ -89,8 +86,8 @@ public class HeadObject extends S3FutureCommand<S3Object.Metadata> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public S3Object.Metadata get(long l, TimeUnit timeUnit)
|
||||
throws InterruptedException, ExecutionException, TimeoutException {
|
||||
public S3Object.Metadata get(long l, TimeUnit timeUnit) throws InterruptedException,
|
||||
ExecutionException, TimeoutException {
|
||||
try {
|
||||
return super.get(l, timeUnit);
|
||||
} catch (ExecutionException e) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -26,16 +26,17 @@ 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
|
||||
*
|
||||
|
@ -45,7 +46,7 @@ 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);
|
||||
super(HttpMethod.GET, "/", callable, amazonHost);
|
||||
}
|
||||
|
||||
}
|
|
@ -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())) {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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,12 +44,12 @@ 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
|
||||
*/
|
||||
|
@ -56,22 +57,21 @@ 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);
|
||||
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(
|
||||
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,
|
||||
|
@ -90,8 +90,7 @@ public class PutObject extends S3FutureCommand<byte[]> {
|
|||
getRequest().getHeaders().put(HttpHeaders.CONTENT_MD5,
|
||||
S3Utils.toBase64String(object.getMetadata().getMd5()));
|
||||
|
||||
getRequest().getHeaders()
|
||||
.putAll(object.getMetadata().getUserMetadata());
|
||||
getRequest().getHeaders().putAll(object.getMetadata().getUserMetadata());
|
||||
getRequest().getHeaders().putAll(options.buildRequestHeaders());
|
||||
|
||||
}
|
||||
|
|
|
@ -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 + "");
|
||||
}
|
||||
|
||||
}
|
|
@ -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"));
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
|
@ -33,21 +33,20 @@ 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 HttpMethod method;
|
||||
private final String uri;
|
||||
Object payload;
|
||||
|
||||
@Resource
|
||||
protected Logger logger = Logger.NULL;
|
||||
|
||||
public HttpRequest(String method, String uri) {
|
||||
public HttpRequest(HttpMethod method, String uri) {
|
||||
this.method = checkNotNull(method, "method");
|
||||
this.uri = Utils.encodeUriPath(checkNotNull(uri, "uri"));
|
||||
}
|
||||
|
@ -64,7 +63,7 @@ public class HttpRequest extends HttpMessage {
|
|||
return sb.toString();
|
||||
}
|
||||
|
||||
public String getMethod() {
|
||||
public HttpMethod getMethod() {
|
||||
return method;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
/**
|
||||
|
@ -34,6 +35,6 @@ 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);
|
||||
super(HttpMethod.GET, uri, callable);
|
||||
}
|
||||
}
|
|
@ -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!
|
||||
|
@ -37,6 +39,6 @@ public class GetString extends HttpFutureCommand<String> {
|
|||
|
||||
@Inject
|
||||
public GetString(ReturnStringIf200 callable, @Assisted String uri) {
|
||||
super("GET", uri, callable);
|
||||
super(HttpMethod.GET, uri, callable);
|
||||
}
|
||||
}
|
|
@ -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!
|
||||
|
@ -37,6 +39,6 @@ public class Head extends HttpFutureCommand<Boolean> {
|
|||
|
||||
@Inject
|
||||
public Head(ReturnTrueIf2xx callable, @Assisted String uri) {
|
||||
super("HEAD", uri, callable);
|
||||
super(HttpMethod.HEAD, uri, callable);
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
@ -76,17 +77,32 @@ public class BackoffLimitedRetryHandlerTest {
|
|||
|
||||
@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; }
|
||||
public void close() {
|
||||
this.isOpen = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read() throws IOException { if (this.isOpen) return 1; else return -1; }
|
||||
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; }
|
||||
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,8 +133,8 @@ 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
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -41,10 +41,9 @@ 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();
|
||||
|
||||
|
@ -54,11 +53,9 @@ public class HttpNioUtils {
|
|||
long contentLength = Long.parseLong(object
|
||||
.getFirstHeaderOrNull(HttpHeaders.CONTENT_LENGTH));
|
||||
object.getHeaders().removeAll(HttpHeaders.CONTENT_LENGTH);
|
||||
String contentType = object
|
||||
.getFirstHeaderOrNull(HttpHeaders.CONTENT_TYPE);
|
||||
String contentType = object.getFirstHeaderOrNull(HttpHeaders.CONTENT_TYPE);
|
||||
object.getHeaders().removeAll(HttpHeaders.CONTENT_TYPE);
|
||||
addEntityForContent(apacheRequest, content, contentType,
|
||||
contentLength);
|
||||
addEntityForContent(apacheRequest, content, contentType, contentLength);
|
||||
}
|
||||
|
||||
for (String header : object.getHeaders().keySet()) {
|
||||
|
@ -68,16 +65,14 @@ public class HttpNioUtils {
|
|||
return apacheRequest;
|
||||
}
|
||||
|
||||
public static void addEntityForContent(
|
||||
BasicHttpEntityEnclosingRequest apacheRequest, Object content,
|
||||
String contentType, long length) {
|
||||
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);
|
||||
InputStreamEntity entity = new InputStreamEntity(inputStream, length);
|
||||
entity.setContentType(contentType);
|
||||
apacheRequest.setEntity(entity);
|
||||
} else if (content instanceof String) {
|
||||
|
@ -85,21 +80,18 @@ public class HttpNioUtils {
|
|||
try {
|
||||
nStringEntity = new NStringEntity((String) content);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new UnsupportedOperationException(
|
||||
"Encoding not supported", 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));
|
||||
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: "
|
||||
throw new UnsupportedOperationException("Content class not supported: "
|
||||
+ content.getClass().getName());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue