added forSigning to blobBuilder

This commit is contained in:
Adrian Cole 2011-04-01 11:38:10 -07:00
parent c352895ae2
commit 5ddf9aabca
5 changed files with 34 additions and 26 deletions

View File

@ -23,13 +23,14 @@ import static org.testng.Assert.assertEquals;
import java.io.IOException;
import javax.inject.Provider;
import org.jclouds.blobstore.BlobRequestSigner;
import org.jclouds.blobstore.domain.Blob;
import org.jclouds.blobstore.domain.Blob.Factory;
import org.jclouds.blobstore.domain.BlobBuilder;
import org.jclouds.date.TimeStamp;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.RequiresHttp;
import org.jclouds.io.payloads.PhantomPayload;
import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.jclouds.s3.BaseS3AsyncClientTest;
@ -59,7 +60,7 @@ public class S3BlobRequestSignerTest extends BaseS3AsyncClientTest<S3AsyncClient
}
private BlobRequestSigner signer;
private Factory blobFactory;
private Provider<BlobBuilder> blobFactory;
public void testSignGetBlob() throws ArrayIndexOutOfBoundsException, SecurityException, IllegalArgumentException,
NoSuchMethodException, IOException {
@ -89,12 +90,8 @@ public class S3BlobRequestSignerTest extends BaseS3AsyncClientTest<S3AsyncClient
public void testSignPutBlob() throws ArrayIndexOutOfBoundsException, SecurityException, IllegalArgumentException,
NoSuchMethodException, IOException {
Blob blob = blobFactory.create(null);
blob.getMetadata().setName("name");
blob.setPayload(new PhantomPayload());
blob.getPayload().getContentMetadata().setContentLength(2l);
blob.getPayload().getContentMetadata().setContentMD5(new byte[] { 0, 2, 4, 8 });
blob.getPayload().getContentMetadata().setContentType("text/plain");
Blob blob = blobFactory.get().name("name").forSigning().contentLength(2l).contentMD5(new byte[] { 0, 2, 4, 8 }).contentType(
"text/plain").build();
HttpRequest request = signer.signPutBlob("container", blob);
@ -111,7 +108,7 @@ public class S3BlobRequestSignerTest extends BaseS3AsyncClientTest<S3AsyncClient
@BeforeClass
protected void setupFactory() throws IOException {
super.setupFactory();
this.blobFactory = injector.getInstance(Blob.Factory.class);
this.blobFactory = injector.getProvider(BlobBuilder.class);
this.signer = injector.getInstance(BlobRequestSigner.class);
}

View File

@ -20,9 +20,9 @@
package org.jclouds.blobstore;
import org.jclouds.blobstore.domain.Blob;
import org.jclouds.blobstore.domain.BlobBuilder;
import org.jclouds.blobstore.internal.RequestSigningUnsupported;
import org.jclouds.http.HttpRequest;
import org.jclouds.io.payloads.PhantomPayload;
import com.google.inject.ImplementedBy;
@ -65,10 +65,8 @@ public interface BlobRequestSigner {
* client.
*
* <pre>
* Blob blob = context.getBlobStore.newBlob();
* blob.getMetadata().setName(&quot;name&quot;);
* blob.setPayload(new PhantomPayload(length, md5));
* blob.getPayload().setContentType(&quot;text/plain&quot;);
* Blob blob = context.getBlobStore.blobBuilder().name(&quot;name&quot;).forSigning().contentType(&quot;text/plain&quot;)
* .contentLength(length).build();
* </pre>
*
* @param container
@ -77,7 +75,7 @@ public interface BlobRequestSigner {
* what to upload
* @throws UnsupportedOperationException
* if not supported by the provider
* @see PhantomPayload
* @see BlobBuilder#forSigning
*/
HttpRequest signPutBlob(String container, Blob blob);
}

View File

@ -71,6 +71,11 @@ public interface BlobBuilder {
*/
PayloadBlobBuilder payload(InputStream payload);
/**
* If you are creating a blob only for signing, use this. {@see BlobRequestSigner}
*/
PayloadBlobBuilder forSigning();
/**
*
* @param payload

View File

@ -38,6 +38,7 @@ import org.jclouds.blobstore.domain.StorageType;
import org.jclouds.crypto.Crypto;
import org.jclouds.io.Payload;
import org.jclouds.io.Payloads;
import org.jclouds.io.payloads.PhantomPayload;
import com.google.common.base.Throwables;
import com.google.common.collect.Maps;
@ -225,5 +226,15 @@ public class BlobBuilderImpl implements BlobBuilder {
return this;
}
@Override
public PayloadBlobBuilder forSigning() {
return builder.forSigning();
}
}
@Override
public PayloadBlobBuilder forSigning() {
return payload(new PhantomPayload());
}
}

View File

@ -24,10 +24,11 @@ import static org.testng.Assert.assertEquals;
import java.io.IOException;
import java.util.Properties;
import javax.inject.Provider;
import org.jclouds.blobstore.domain.Blob;
import org.jclouds.blobstore.domain.Blob.Factory;
import org.jclouds.blobstore.domain.BlobBuilder;
import org.jclouds.http.HttpRequest;
import org.jclouds.io.payloads.PhantomPayload;
import org.jclouds.rest.RestClientTest;
import org.jclouds.rest.RestContextFactory;
import org.jclouds.rest.RestContextSpec;
@ -47,7 +48,7 @@ import com.google.inject.TypeLiteral;
public class TransientBlobRequestSignerTest extends RestClientTest<TransientAsyncBlobStore> {
private BlobRequestSigner signer;
private Factory blobFactory;
private Provider<BlobBuilder> blobFactory;
public void testSignGetBlob() throws ArrayIndexOutOfBoundsException, SecurityException, IllegalArgumentException,
NoSuchMethodException, IOException {
@ -73,12 +74,8 @@ public class TransientBlobRequestSignerTest extends RestClientTest<TransientAsyn
public void testSignPutBlob() throws ArrayIndexOutOfBoundsException, SecurityException, IllegalArgumentException,
NoSuchMethodException, IOException {
Blob blob = blobFactory.create(null);
blob.getMetadata().setName("name");
blob.setPayload(new PhantomPayload());
blob.getPayload().getContentMetadata().setContentLength(2l);
blob.getPayload().getContentMetadata().setContentMD5(new byte[] { 0, 2, 4, 8 });
blob.getPayload().getContentMetadata().setContentType("text/plain");
Blob blob = blobFactory.get().name("name").forSigning().contentLength(2l).contentMD5(new byte[] { 0, 2, 4, 8 })
.contentType("text/plain").build();
HttpRequest request = signer.signPutBlob("container", blob);
@ -94,7 +91,7 @@ public class TransientBlobRequestSignerTest extends RestClientTest<TransientAsyn
@BeforeClass
protected void setupFactory() throws IOException {
super.setupFactory();
this.blobFactory = injector.getInstance(Blob.Factory.class);
this.blobFactory = injector.getProvider(BlobBuilder.class);
this.signer = injector.getInstance(BlobRequestSigner.class);
}