Skip to content
Permalink
Browse files
JCLOUDS-592: Explicitly specify region for BlobStore related APIs
  • Loading branch information
Jeremy Daggett authored and etoews committed Oct 13, 2014
1 parent b183a18 commit 89aa821f0ae5b3e3b03bb423019910444d5b7cfd
Showing 1 changed file with 31 additions and 14 deletions.
@@ -18,26 +18,33 @@
*/
package org.jclouds.examples.rackspace.cloudfiles;

import com.google.common.io.ByteSource;
import com.google.common.io.Closeables;
import com.google.common.io.Files;
import static org.jclouds.examples.rackspace.cloudfiles.Constants.CONTAINER;
import static org.jclouds.examples.rackspace.cloudfiles.Constants.PROVIDER;
import static org.jclouds.examples.rackspace.cloudfiles.Constants.REGION;

import java.io.Closeable;
import java.io.File;
import java.io.IOException;
import java.util.Set;

import org.jclouds.ContextBuilder;
import org.jclouds.blobstore.BlobStore;
import org.jclouds.blobstore.domain.Blob;
import org.jclouds.domain.Location;
import org.jclouds.domain.LocationBuilder;
import org.jclouds.domain.LocationScope;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.HttpResponseException;
import org.jclouds.io.Payload;
import org.jclouds.io.Payloads;
import org.jclouds.location.predicates.LocationPredicates;
import org.jclouds.openstack.swift.v1.blobstore.RegionScopedBlobStoreContext;

import java.io.Closeable;
import java.io.File;
import java.io.IOException;

import static org.jclouds.examples.rackspace.cloudfiles.Constants.CONTAINER;
import static org.jclouds.examples.rackspace.cloudfiles.Constants.PROVIDER;
import static org.jclouds.examples.rackspace.cloudfiles.Constants.REGION;
import com.google.common.collect.Sets;
import com.google.common.io.ByteSource;
import com.google.common.io.Closeables;
import com.google.common.io.Files;

/**
* The Temporary URL feature (TempURL) allows you to create limited-time Internet addresses which allow you to grant
@@ -72,6 +79,7 @@ public static void main(String[] args) throws IOException {
GenerateTempURL generateTempURL = new GenerateTempURL(args[0], args[1]);

try {
generateTempURL.createContainer();
generateTempURL.generatePutTempURL();
generateTempURL.generateGetTempURL();
generateTempURL.generateDeleteTempURL();
@@ -91,6 +99,15 @@ public GenerateTempURL(String username, String apiKey) {
blobStore = blobStoreContext.getBlobStore(REGION);
}

private void createContainer() throws IOException {
// Ensure that the container exists
Location location = new LocationBuilder().scope(LocationScope.REGION).id(REGION).description("region").build();
if (!blobStore.containerExists(CONTAINER)) {
blobStore.createContainerInLocation(location, CONTAINER);
System.out.format("Created container in %s%n", REGION);
}
}

private void generatePutTempURL() throws IOException {
System.out.format("Generate PUT Temp URL%n");

@@ -101,7 +118,7 @@ private void generatePutTempURL() throws IOException {

// Create the Blob
Blob blob = blobStore.blobBuilder(FILENAME).payload(payload).contentType("text/plain").build();
HttpRequest request = blobStoreContext.getSigner().signPutBlob(CONTAINER, blob, TEN_MINUTES);
HttpRequest request = blobStoreContext.getSigner(REGION).signPutBlob(CONTAINER, blob, TEN_MINUTES);

System.out.format(" %s %s%n", request.getMethod(), request.getEndpoint());

@@ -120,7 +137,7 @@ private void generatePutTempURL() throws IOException {
private void generateGetTempURL() throws IOException {
System.out.format("Generate GET Temp URL%n");

HttpRequest request = blobStoreContext.getSigner().signGetBlob(CONTAINER, FILENAME, TEN_MINUTES);
HttpRequest request = blobStoreContext.getSigner(REGION).signGetBlob(CONTAINER, FILENAME, TEN_MINUTES);

System.out.format(" %s %s%n", request.getMethod(), request.getEndpoint());

@@ -141,7 +158,7 @@ private void generateGetTempURL() throws IOException {
private void generateDeleteTempURL() throws IOException {
System.out.format("Generate DELETE Temp URL%n");

HttpRequest request = blobStoreContext.getSigner().signRemoveBlob(CONTAINER, FILENAME);
HttpRequest request = blobStoreContext.getSigner(REGION).signRemoveBlob(CONTAINER, FILENAME);

System.out.format(" %s %s%n", request.getMethod(), request.getEndpoint());

@@ -150,7 +167,7 @@ private void generateDeleteTempURL() throws IOException {
int statusCode = response.getStatusCode();

if (statusCode >= 200 && statusCode < 299) {
System.out.format(" DELETE Success (%s)", statusCode);
System.out.format(" DELETE Success (%s)%n", statusCode);
}
else {
throw new HttpResponseException(null, response);

0 comments on commit 89aa821

Please sign in to comment.