diff --git a/ChangeLog.txt b/ChangeLog.txt
index 8e6701c15656..17345e70ce1a 100644
--- a/ChangeLog.txt
+++ b/ChangeLog.txt
@@ -1,3 +1,14 @@
+2012.09.11 Version 0.3.1
+ * Added Javadocs to 1.7 Storage Support from 0.3.0 release
+ * Fixed bug where getqueue for an invalid queue returns 200 and the exception is not wrapped in a ServiceException
+ * Fixed the error when deleting a blob snapshot in the Service Layer
+ * Changed the PageBlob length parameter from an int to a long
+ * Return an Etag for create and copy Blob in Service Layer
+ * Updated the BlobRestProxy.copyBlob to correctly honor source access conditions
+ * Updated the BlobRestProxy.getBlob to correctly honor setComputeRangeMD5 option
+ * Added international support for ServiceBus URIs
+ * Added encoding for special characters when serializing entity to XML in Table Service Layer
+
2012.06.02 Version 0.3.0
* Added 1.7 Storage Support
* Added Javadocs for com.microsoft.windowsazure.services.table
diff --git a/README.md b/README.md
index 07c59ee7dee6..8bed4e62a948 100644
--- a/README.md
+++ b/README.md
@@ -41,7 +41,7 @@ within your project you can also have them installed by the Java package manager
com.microsoft.windowsazuremicrosoft-windowsazure-api
- 0.3.0
+ 0.3.1
##Minimum Requirements
@@ -62,61 +62,62 @@ deployment tools.
The following is a quick example on how to set up a Azure blob using the API
and uploading a file to it. For additional information on using the client libraries to access Azure services see the How To guides listed [here](http://www.windowsazure.com/en-us/develop/java/).
- import com.microsoft.windowsazure.services.core.storage.*;
- import com.microsoft.windowsazure.services.blob.client.*;
-
- public class BlobSample {
-
- public static final String storageConnectionString =
- "DefaultEndpointsProtocol=http;" +
- "AccountName=your_account_name;" +
- "AccountKey= your_account_name";
-
- public static void main(String[] args)
- {
- try
- {
- CloudStorageAccount account;
- CloudBlobClient serviceClient;
- CloudBlobContainer container;
- CloudBlockBlob blob;
-
- account = CloudStorageAccount.parse(storageConnectionString);
- serviceClient = account.createCloudBlobClient();
- // Container name must be lower case.
- container = serviceClient.getContainerReference("blobsample");
- container.createIfNotExist();
-
- // Set anonymous access on the container.
- BlobContainerPermissions containerPermissions;
- containerPermissions = new BlobContainerPermissions();
-
- // Upload an image file.
- blob = container.getBlockBlobReference("image1.jpg");
- File fileReference = new File ("c:\\myimages\\image1.jpg");
- blob.upload(new FileInputStream(fileReference), fileReference.length());
- }
- catch (FileNotFoundException fileNotFoundException)
- {
- System.out.print("FileNotFoundException encountered: ");
- System.out.println(fileNotFoundException.getMessage());
- System.exit(-1);
- }
- catch (StorageException storageException)
- {
- System.out.print("StorageException encountered: ");
- System.out.println(storageException.getMessage());
- System.exit(-1);
- }
- catch (Exception e)
- {
- System.out.print("Exception encountered: ");
- System.out.println(e.getMessage());
- System.exit(-1);
- }
+
+ import com.microsoft.windowsazure.services.core.storage.*;
+ import com.microsoft.windowsazure.services.blob.client.*;
+
+ public class BlobSample {
+ public static final String storageConnectionString =
+ "DefaultEndpointsProtocol=http;" +
+ "AccountName=your_account_name;" +
+ "AccountKey= your_account_name";
+
+ public static void main(String[] args)
+ {
+ try
+ {
+ CloudStorageAccount account;
+ CloudBlobClient serviceClient;
+ CloudBlobContainer container;
+ CloudBlockBlob blob;
- }
- }
+ account = CloudStorageAccount.parse(storageConnectionString);
+ serviceClient = account.createCloudBlobClient();
+ // Container name must be lower case.
+ container = serviceClient.getContainerReference("blobsample");
+ container.createIfNotExist();
+
+ // Set anonymous access on the container.
+ BlobContainerPermissions containerPermissions;
+ containerPermissions = new BlobContainerPermissions();
+
+ // Upload an image file.
+ blob = container.getBlockBlobReference("image1.jpg");
+ File fileReference = new File ("c:\\myimages\\image1.jpg");
+ blob.upload(new FileInputStream(fileReference), fileReference.length());
+ }
+ catch (FileNotFoundException fileNotFoundException)
+ {
+ System.out.print("FileNotFoundException encountered: ");
+ System.out.println(fileNotFoundException.getMessage());
+ System.exit(-1);
+ }
+ catch (StorageException storageException)
+ {
+ System.out.print("StorageException encountered: ");
+ System.out.println(storageException.getMessage());
+ System.exit(-1);
+ }
+ catch (Exception e)
+ {
+ System.out.print("Exception encountered: ");
+ System.out.println(e.getMessage());
+ System.exit(-1);
+ }
+
+ }
+ }
+
#Need Help?
diff --git a/microsoft-azure-api/pom.xml b/microsoft-azure-api/pom.xml
index dbc6cd094ba1..3a87dc3b06b6 100644
--- a/microsoft-azure-api/pom.xml
+++ b/microsoft-azure-api/pom.xml
@@ -17,7 +17,7 @@
4.0.0com.microsoft.windowsazuremicrosoft-windowsazure-api
- 0.3.0
+ 0.3.1jarMicrosoft Windows Azure Client API
diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/client/BlobAttributes.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/client/BlobAttributes.java
index f0f782200ab7..64f83ee08e53 100644
--- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/client/BlobAttributes.java
+++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/client/BlobAttributes.java
@@ -44,38 +44,74 @@ final class BlobAttributes {
public String snapshotID;
/**
- * Holds the URI of the blob, Setting this is RESERVED for internal use.
+ * Holds the URI of the blob. RESERVED for internal use.
*/
protected URI uri;
- /**
- * Initializes a new instance of the BlobAttributes class
+ /**
+ * Initializes a new instance of the BlobAttributes class. RESERVED FOR INTERNAL USE.
+ *
+ * @param type
+ * The type of blob to set.
*/
public BlobAttributes(final BlobType type) {
this.setMetadata(new HashMap());
this.setProperties(new BlobProperties(type));
}
+ /**
+ * Gets the metadata for the blob. RESERVED FOR INTERNAL USE.
+ *
+ * @return A HashMap object containing the metadata for the blob.
+ */
public HashMap getMetadata() {
return this.metadata;
}
+ /**
+ * Gets the copy state of the blob. RESERVED FOR INTERNAL USE.
+ *
+ * @return A CopyState object representing the copy state.
+ */
public CopyState getCopyState() {
return this.copyState;
}
+ /**
+ * Gets the properties for the blob. RESERVED FOR INTERNAL USE.
+ *
+ * @return A BlobProperties object that represents the blob properties.
+ */
public BlobProperties getProperties() {
return this.properties;
}
+ /**
+ * Sets the metadata for a blob. RESERVED FOR INTERNAL USE.
+ *
+ * @param metadata
+ * The blob meta data to set.
+ */
protected void setMetadata(final HashMap metadata) {
this.metadata = metadata;
}
+ /**
+ * Sets the properties for a blob. RESERVED FOR INTERNAL USE.
+ *
+ * @param properties
+ * The blob properties to set.
+ */
protected void setProperties(final BlobProperties properties) {
this.properties = properties;
}
+ /**
+ * Sets the copy state for a blob. RESERVED FOR INTERNAL USE.
+ *
+ * @param copyState
+ * The blob copy state to set.
+ */
public void setCopyState(final CopyState copyState) {
this.copyState = copyState;
}
diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/client/BlobContainerProperties.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/client/BlobContainerProperties.java
index 4b34574466fd..599687b285d7 100644
--- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/client/BlobContainerProperties.java
+++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/client/BlobContainerProperties.java
@@ -72,67 +72,77 @@ public Date getLastModified() {
}
/**
- * @return the leaseStatus
+ * Gets the lease status of the container.
+ *
+ * @return The lease status as a LeaseStatus object.
*/
public LeaseStatus getLeaseStatus() {
return this.leaseStatus;
}
/**
- * @return the leaseState
+ * Gets the lease state of the container.
+ *
+ * @return The lease state as a LeaseState object.
*/
public LeaseState getLeaseState() {
return this.leaseState;
}
/**
- * @return the leaseDuration
+ * Gets the lease duration of the container.
+ *
+ * @return The lease duration as a LeaseDuration object.
*/
public LeaseDuration getLeaseDuration() {
return this.leaseDuration;
}
/**
+ * Sets the ETag value on the container.
+ *
* @param etag
- * the etag to set
+ * The ETag value to set, as a string.
*/
public void setEtag(final String etag) {
this.etag = etag;
}
/**
+ * Sets the last modified time on the container.
+ *
* @param lastModified
- * the lastModified to set
+ * The last modified time to set, as a Date object.
*/
public void setLastModified(final Date lastModified) {
this.lastModified = lastModified;
}
/**
- * Reserved for internal use.
+ * Sets the lease status on the container. Reserved for internal use.
*
* @param leaseStatus
- * the leaseStatus to set
+ * The lease status to set, as a LeaseStatus object.
*/
public void setLeaseStatus(final LeaseStatus leaseStatus) {
this.leaseStatus = leaseStatus;
}
/**
- * Reserved for internal use.
+ * Sets the lease status on the container. Reserved for internal use.
*
* @param LeaseState
- * the LeaseState to set
+ * The lease state to set, as a LeaseState object.
*/
public void setLeaseState(final LeaseState leaseState) {
this.leaseState = leaseState;
}
/**
- * Reserved for internal use.
+ * Sets the lease duration on the container. Reserved for internal use.
*
* @param LeaseDuration
- * the LeaseDuration to set
+ * The lease duration to set, as a LeaseDuration object.
*/
public void setLeaseDuration(final LeaseDuration leaseDuration) {
this.leaseDuration = leaseDuration;
diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/client/BlobProperties.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/client/BlobProperties.java
index 81c3faae35c5..9bb09d0b23f6 100644
--- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/client/BlobProperties.java
+++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/client/BlobProperties.java
@@ -141,189 +141,221 @@ public BlobType getBlobType() {
}
/**
- * @return the cacheControl
+ * Returns the cache control value for the blob.
+ *
+ * @return A string that represents the cache control value for the blob.
*/
public String getCacheControl() {
return this.cacheControl;
}
/**
- * @return the contentEncoding
+ * Gets the content encoding value for the blob.
+ *
+ * @return A string containing the content encoding, or null if content encoding has not been set
+ * on the blob.
*/
public String getContentEncoding() {
return this.contentEncoding;
}
/**
- * @return the contentLanguage
+ * Gets the content language value for the blob.
+ *
+ * @return A string containing the content language, or null if content language has not been set on
+ * the blob.
*/
public String getContentLanguage() {
return this.contentLanguage;
}
/**
- * @return the contentMD5
+ * Gets the content MD5 value for the blob.
+ *
+ * @return A string containing the content MD5 value.
*/
public String getContentMD5() {
return this.contentMD5;
}
/**
- * @return the contentType
+ * Gets the content type value for the blob.
+ *
+ * @return A string containing content type, or null if the content type has not be set for the blob.
*/
public String getContentType() {
return this.contentType;
}
/**
- * @return the etag
+ * Gets the ETag value for the blob.
+ *
+ * @return A string containing the ETag value.
*/
public String getEtag() {
return this.etag;
}
/**
- * @return the lastModified
+ * Gets the last modified time for the blob.
+ *
+ * @return A Date containing the last modified time for the blob.
*/
public Date getLastModified() {
return this.lastModified;
}
/**
- * Reserved for internal use.
+ * Gets the lease status for the blob. Reserved for internal use.
*
- * @return the leaseStatus
+ * @return A LeaseStatus object representing the lease status.
*/
public LeaseStatus getLeaseStatus() {
return this.leaseStatus;
}
/**
- * @return the leaseState
+ * Gets the lease state for the blob.
+ *
+ * @return A LeaseState object representing the lease state.
*/
public LeaseState getLeaseState() {
return this.leaseState;
}
/**
- * @return the leaseDuration
+ * Gets the lease duration for the blob.
+ *
+ * @return A LeaseDuration object representing the lease duration.
*/
public LeaseDuration getLeaseDuration() {
return this.leaseDuration;
}
/**
- * @return the length
+ * Gets the size, in bytes, of the blob.
+ *
+ * @return The length of the blob.
*/
public long getLength() {
return this.length;
}
/**
- * Reserved for internal use.
+ * Sets the blob type. Reserved for internal use.
*
* @param blobType
- * the blobType to set
+ * The blob type to set, represented by a BlobType object.
*/
protected void setBlobType(final BlobType blobType) {
this.blobType = blobType;
}
/**
+ * Sets the cache control value for the blob.
+ *
* @param cacheControl
- * the cacheControl to set
+ * The cache control value to set.
*/
public void setCacheControl(final String cacheControl) {
this.cacheControl = cacheControl;
}
/**
+ * Sets the content encoding value for the blob.
+ *
* @param contentEncoding
- * the contentEncoding to set
+ * The content encoding value to set.
*/
public void setContentEncoding(final String contentEncoding) {
this.contentEncoding = contentEncoding;
}
/**
+ * Sets the content language for the blob.
+ *
* @param contentLanguage
- * the contentLanguage to set
+ * The content language value to set.
*/
public void setContentLanguage(final String contentLanguage) {
this.contentLanguage = contentLanguage;
}
/**
+ * Sets the content MD5 value for the blob.
+ *
* @param contentMD5
- * the contentMD5 to set
+ * The content MD5 value to set.
*/
public void setContentMD5(final String contentMD5) {
this.contentMD5 = contentMD5;
}
/**
+ * Sets the content type value for the blob.
+ *
* @param contentType
- * the contentType to set
+ * The content type value to set.
*/
public void setContentType(final String contentType) {
this.contentType = contentType;
}
/**
- * Reserved for internal use.
+ * Sets the ETag value for the blob. Reserved for internal use.
*
* @param etag
- * the etag to set
+ * The ETag value to set.
*/
public void setEtag(final String etag) {
this.etag = etag;
}
/**
- * Reserved for internal use.
+ * Sets the last modified time for the blob. Reserved for internal use.
*
* @param lastModified
- * the lastModified to set
+ * The last modified time to set.
*/
public void setLastModified(final Date lastModified) {
this.lastModified = lastModified;
}
/**
- * Reserved for internal use.
+ * Sets the lease status for the blob. Reserved for internal use.
*
* @param leaseStatus
- * the leaseStatus to set
+ * The lease status to set, represented by a LeaseStatus object.
*/
public void setLeaseStatus(final LeaseStatus leaseStatus) {
this.leaseStatus = leaseStatus;
}
/**
- * Reserved for internal use.
+ * Sets the lease state for the blob. Reserved for internal use.
*
* @param LeaseState
- * the LeaseState to set
+ * The lease state to set, represented by a LeaseState object.
*/
public void setLeaseState(final LeaseState leaseState) {
this.leaseState = leaseState;
}
/**
- * Reserved for internal use.
+ * Sets the lease duration for the blob. Reserved for internal use.
*
* @param LeaseDuration
- * the LeaseDuration to set
+ * The lease duration value to set, represented by a LeaseDuration object.
*/
public void setLeaseDuration(final LeaseDuration leaseDuration) {
this.leaseDuration = leaseDuration;
}
/**
- * Reserved for internal use.
+ * Sets the content length, in bytes, for the blob. Reserved for internal use.
*
* @param length
- * the length to set
+ * The length to set.
*/
public void setLength(final long length) {
this.length = length;
diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/client/CloudBlob.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/client/CloudBlob.java
index a434b75f3de7..bc87cebfa32c 100644
--- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/client/CloudBlob.java
+++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/client/CloudBlob.java
@@ -217,11 +217,12 @@ protected CloudBlob(final CloudBlob otherBlob) {
}
/**
- * Acquires a new lease on the blob.
+ * Acquires a new lease on the blob with the specified lease time and proposed lease ID.
*
- * @param visibilityTimeoutInSeconds
- * Specifies the the span of time for which to acquire the lease, in seconds.
- * If null, an infinite lease will be acquired. If not null, this must be greater than zero.
+ * @param leaseTimeInSeconds
+ * Specifies the span of time for which to acquire the lease, in seconds.
+ * If null, an infinite lease will be acquired. If not null, the value must be greater than
+ * zero.
*
* @param proposedLeaseId
* A String that represents the proposed lease ID for the new lease,
@@ -239,11 +240,13 @@ public final String acquireLease(final Integer leaseTimeInSeconds, final String
}
/**
- * Acquires a new lease on the blob using the specified request options and operation context.
+ * Acquires a new lease on the blob with the specified lease time, proposed lease ID, request
+ * options, and operation context.
*
- * @param visibilityTimeoutInSeconds
- * Specifies the the span of time for which to acquire the lease, in seconds.
- * If null, an infinite lease will be acquired. If not null, this must be greater than zero.
+ * @param leaseTimeInSeconds
+ * Specifies the span of time for which to acquire the lease, in seconds.
+ * If null, an infinite lease will be acquired. If not null, the value must be greater than
+ * zero.
*
* @param proposedLeaseId
* A String that represents the proposed lease ID for the new lease,
@@ -251,12 +254,14 @@ public final String acquireLease(final Integer leaseTimeInSeconds, final String
*
* @param accessCondition
* An {@link AccessCondition} object that represents the access conditions for the blob.
+ *
* @param options
* A {@link BlobRequestOptions} object that specifies any additional options for the request. Specifying
- * null will use the default request options from the associated service client (
- * {@link CloudBlobClient}).
+ * null will use the default request options from the associated service client
+ * ({@link CloudBlobClient}).
+ *
* @param opContext
- * An {@link OperationContext} object that represents the context for the current operation. This object
+ * An {@link OperationContext} object that represents the context for the current operation. The context
* is used to track requests to the storage service, and to provide additional runtime information about
* the operation.
*
@@ -338,11 +343,11 @@ protected final void assertCorrectBlobType() throws StorageException {
}
/**
- * Breaks the lease but ensures that another client cannot acquire a new lease until the current lease period has
- * expired.
+ * Breaks the lease and ensures that another client cannot acquire a new lease until the current lease period
+ * has expired.
*
* @param breakPeriodInSeconds
- * Specifies the amount of time to allow the lease to remain, in seconds.
+ * Specifies the time to wait, in seconds, until the current lease is broken.
* If null, the break period is the remainder of the current lease, or zero for infinite leases.
*
* @return The time, in seconds, remaining in the lease period.
@@ -356,21 +361,21 @@ public final long breakLease(final Integer breakPeriodInSeconds) throws StorageE
}
/**
- * Breaks the lease, using the specified request options and operation context, but ensures that another client
- * cannot acquire a new lease until the current lease period has expired.
+ * Breaks the existing lease, using the specified request options and operation context, and ensures that another
+ * client cannot acquire a new lease until the current lease period has expired.
*
* @param breakPeriodInSeconds
- * Specifies the amount of time to allow the lease to remain, in seconds.
+ * Specifies the time to wait, in seconds, until the current lease is broken.
* If null, the break period is the remainder of the current lease, or zero for infinite leases.
*
* @param accessCondition
* An {@link AccessCondition} object that represents the access conditions for the blob.
* @param options
* A {@link BlobRequestOptions} object that specifies any additional options for the request. Specifying
- * null will use the default request options from the associated service client (
- * {@link CloudBlobClient}).
+ * null will use the default request options from the associated service client
+ * ({@link CloudBlobClient}).
* @param opContext
- * An {@link OperationContext} object that represents the context for the current operation. This object
+ * An {@link OperationContext} object that represents the context for the current operation. The context
* is used to track requests to the storage service, and to provide additional runtime information about
* the operation.
*
@@ -2000,15 +2005,15 @@ public Void execute(final CloudBlobClient client, final CloudBlob blob, final Op
}
/**
- * Changes an existing lease.
+ * Changes the existing lease ID to the proposed lease ID.
*
* @param proposedLeaseId
* A String that represents the proposed lease ID for the new lease,
* or null if no lease ID is proposed.
*
* @param accessCondition
- * An {@link AccessCondition} object that represents the access conditions for the blob. The LeaseID is
- * required to be set on the AccessCondition.
+ * An {@link AccessCondition} object that represents the access conditions for the blob. The lease ID is
+ * required to be set with an access condition.
*
* @throws StorageException
* If a storage service error occurred.
@@ -2020,21 +2025,22 @@ public final void changeLease(final String proposedLeaseId, final AccessConditio
}
/**
- * Changes an existing lease using the specified proposedLeaseId, request options and operation context.
+ * Changes the existing lease ID to the proposed lease Id with the specified access conditions, request options,
+ * and operation context.
*
* @param proposedLeaseId
* A String that represents the proposed lease ID for the new lease,
* or null if no lease ID is proposed.
*
* @param accessCondition
- * An {@link AccessCondition} object that represents the access conditions for the blob. The LeaseID is
- * required to be set on the AccessCondition.
+ * An {@link AccessCondition} object that represents the access conditions for the blob. The lease ID is
+ * required to be set with an access condition.
* @param options
* A {@link BlobRequestOptions} object that specifies any additional options for the request. Specifying
- * null will use the default request options from the associated service client (
- * {@link CloudBlobClient}).
+ * null will use the default request options from the associated service client
+ * ({@link CloudBlobClient}).
* @param opContext
- * An {@link OperationContext} object that represents the context for the current operation. This object
+ * An {@link OperationContext} object that represents the context for the current operation. The context
* is used to track requests to the storage service, and to provide additional runtime information about
* the operation.
*
diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/client/CloudBlobContainer.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/client/CloudBlobContainer.java
index ab8bd64df564..6cd9752c046e 100644
--- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/client/CloudBlobContainer.java
+++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/client/CloudBlobContainer.java
@@ -1629,11 +1629,12 @@ public Void execute(final CloudBlobClient client, final CloudBlobContainer conta
}
/**
- * Acquires a new lease on the container.
+ * Acquires a new lease on the container with the specified lease time and proposed lease ID.
*
- * @param visibilityTimeoutInSeconds
- * Specifies the the span of time for which to acquire the lease, in seconds.
- * If null, an infinite lease will be acquired. If not null, this must be greater than zero.
+ * @param leaseTimeInSeconds
+ * Specifies the span of time for which to acquire the lease, in seconds.
+ * If null, an infinite lease will be acquired. If not null, the value must be greater than
+ * zero.
*
* @param proposedLeaseId
* A String that represents the proposed lease ID for the new lease,
@@ -1651,25 +1652,28 @@ public final String acquireLease(final Integer leaseTimeInSeconds, final String
}
/**
- * Acquires a new lease on the container using the specified visibilityTimeoutInSeconds, proposedLeaseId, request
- * options and operation context.
+ * Acquires a new lease on the container with the specified lease time, proposed lease ID, request
+ * options, and operation context.
*
- * @param visibilityTimeoutInSeconds
- * Specifies the the span of time for which to acquire the lease, in seconds.
- * If null, an infinite lease will be acquired. If not null, this must be greater than zero.
+ * @param leaseTimeInSeconds
+ * Specifies the span of time for which to acquire the lease, in seconds.
+ * If null, an infinite lease will be acquired. If not null, the value must be greater than
+ * zero.
*
* @param proposedLeaseId
* A String that represents the proposed lease ID for the new lease,
* or null if no lease ID is proposed.
*
* @param accessCondition
- * An {@link AccessCondition} object that represents the access conditions for the blob.
+ * An {@link AccessCondition} object that represents the access conditions for the container.
+ *
* @param options
* A {@link BlobRequestOptions} object that specifies any additional options for the request. Specifying
- * null will use the default request options from the associated service client (
- * {@link CloudBlobClient}).
+ * null will use the default request options from the associated service client
+ * ({@link CloudBlobClient}).
+ *
* @param opContext
- * An {@link OperationContext} object that represents the context for the current operation. This object
+ * An {@link OperationContext} object that represents the context for the current operation. The context
* is used to track requests to the storage service, and to provide additional runtime information about
* the operation.
*
@@ -1724,11 +1728,11 @@ public String execute(final CloudBlobClient client, final CloudBlobContainer con
}
/**
- * Renews an existing lease.
+ * Renews an existing lease with the specified access conditions.
*
* @param accessCondition
- * An {@link AccessCondition} object that represents the access conditions for the container. The LeaseID
- * is required to be set on the AccessCondition.
+ * An {@link AccessCondition} object that represents the access conditions for the container. The lease ID is
+ * required to be set with an access condition.
*
* @throws StorageException
* If a storage service error occurred.
@@ -1739,17 +1743,19 @@ public final void renewLease(final AccessCondition accessCondition) throws Stora
}
/**
- * Renews an existing lease using the specified request options and operation context.
+ * Renews an existing lease with the specified access conditions, request options, and operation context.
*
* @param accessCondition
- * An {@link AccessCondition} object that represents the access conditions for the blob. The LeaseID is
- * required to be set on the AccessCondition.
+ * An {@link AccessCondition} object that represents the access conditions for the blob. The lease ID is
+ * required to be set with an access condition.
+ *
* @param options
* A {@link BlobRequestOptions} object that specifies any additional options for the request. Specifying
- * null will use the default request options from the associated service client (
- * {@link CloudBlobClient}).
+ * null will use the default request options from the associated service client
+ * ({@link CloudBlobClient}).
+ *
* @param opContext
- * An {@link OperationContext} object that represents the context for the current operation. This object
+ * An {@link OperationContext} object that represents the context for the current operation. The context
* is used to track requests to the storage service, and to provide additional runtime information about
* the operation.
*
@@ -1806,8 +1812,8 @@ public Void execute(final CloudBlobClient client, final CloudBlobContainer conta
* Releases the lease on the container.
*
* @param accessCondition
- * An {@link AccessCondition} object that represents the access conditions for the blob. The LeaseID is
- * required to be set on the AccessCondition.
+ * An {@link AccessCondition} object that represents the access conditions for the blob. The lease ID is
+ * required to be set with an access condition.
*
* @throws StorageException
* If a storage service error occurred.
@@ -1818,17 +1824,19 @@ public final void releaseLease(final AccessCondition accessCondition) throws Sto
}
/**
- * Releases the lease on the container using the specified request options and operation context.
+ * Releases the lease on the container using the specified access conditions, request options, and operation context.
*
* @param accessCondition
- * An {@link AccessCondition} object that represents the access conditions for the blob.The LeaseID is
- * required to be set on the AccessCondition.
+ * An {@link AccessCondition} object that represents the access conditions for the blob. The lease ID is
+ * required to be set with an access condition.
+ *
* @param options
* A {@link BlobRequestOptions} object that specifies any additional options for the request. Specifying
- * null will use the default request options from the associated service client (
- * {@link CloudBlobClient}).
+ * null will use the default request options from the associated service client
+ * ({@link CloudBlobClient}).
+ *
* @param opContext
- * An {@link OperationContext} object that represents the context for the current operation. This object
+ * An {@link OperationContext} object that represents the context for the current operation. The context
* is used to track requests to the storage service, and to provide additional runtime information about
* the operation.
*
@@ -1882,11 +1890,11 @@ public Void execute(final CloudBlobClient client, final CloudBlobContainer conta
}
/**
- * Breaks the lease but ensures that another client cannot acquire a new lease until the current lease period has
- * expired.
+ * Breaks the lease and ensures that another client cannot acquire a new lease until the current lease
+ * period has expired.
*
* @param breakPeriodInSeconds
- * Specifies the amount of time to allow the lease to remain, in seconds.
+ * Specifies the time to wait, in seconds, until the current lease is broken.
* If null, the break period is the remainder of the current lease, or zero for infinite leases.
*
* @return The time, in seconds, remaining in the lease period.
@@ -1900,21 +1908,21 @@ public final long breakLease(final Integer breakPeriodInSeconds) throws StorageE
}
/**
- * Breaks the lease, using the specified request options and operation context, but ensures that another client
- * cannot acquire a new lease until the current lease period has expired.
+ * Breaks the existing lease, using the specified request options and operation context, and ensures that
+ * another client cannot acquire a new lease until the current lease period has expired.
*
* @param breakPeriodInSeconds
- * Specifies the amount of time to allow the lease to remain, in seconds.
+ * Specifies the time to wait, in seconds, until the current lease is broken.
* If null, the break period is the remainder of the current lease, or zero for infinite leases.
*
* @param accessCondition
* An {@link AccessCondition} object that represents the access conditions for the blob.
* @param options
* A {@link BlobRequestOptions} object that specifies any additional options for the request. Specifying
- * null will use the default request options from the associated service client (
- * {@link CloudBlobClient}).
+ * null will use the default request options from the associated service client
+ * ({@link CloudBlobClient}).
* @param opContext
- * An {@link OperationContext} object that represents the context for the current operation. This object
+ * An {@link OperationContext} object that represents the context for the current operation. The context
* is used to track requests to the storage service, and to provide additional runtime information about
* the operation.
*
@@ -1968,15 +1976,15 @@ public Long execute(final CloudBlobClient client, final CloudBlobContainer conta
}
/**
- * Changes an existing lease.
+ * Changes the existing lease ID to the proposed lease ID.
*
* @param proposedLeaseId
* A String that represents the proposed lease ID for the new lease,
* or null if no lease ID is proposed.
*
* @param accessCondition
- * An {@link AccessCondition} object that represents the access conditions for the blob. The LeaseID is
- * required to be set on the AccessCondition.
+ * An {@link AccessCondition} object that represents the access conditions for the blob. The lease ID is
+ * required to be set with an access condition.
*
* @throws StorageException
* If a storage service error occurred.
@@ -1988,21 +1996,24 @@ public final void changeLease(final String proposedLeaseId, final AccessConditio
}
/**
- * Changes an existing lease using the specified proposedLeaseId, request options and operation context.
+ * Changes the existing lease ID to the proposed lease Id with the specified access conditions, request options,
+ * and operation context.
*
* @param proposedLeaseId
* A String that represents the proposed lease ID for the new lease,
* or null if no lease ID is proposed.
*
* @param accessCondition
- * An {@link AccessCondition} object that represents the access conditions for the blob. The LeaseID is
- * required to be set on the AccessCondition.
+ * An {@link AccessCondition} object that represents the access conditions for the blob. The lease ID is
+ * required to be set with an access condition.
+ *
* @param options
* A {@link BlobRequestOptions} object that specifies any additional options for the request. Specifying
- * null will use the default request options from the associated service client (
- * {@link CloudBlobClient}).
+ * null will use the default request options from the associated service client
+ * ({@link CloudBlobClient}).
+ *
* @param opContext
- * An {@link OperationContext} object that represents the context for the current operation. This object
+ * An {@link OperationContext} object that represents the context for the current operation. The context
* is used to track requests to the storage service, and to provide additional runtime information about
* the operation.
*
diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/client/CopyState.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/client/CopyState.java
index 6c1a9e921afe..a8d60323e9fe 100644
--- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/client/CopyState.java
+++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/client/CopyState.java
@@ -23,7 +23,7 @@
*/
public final class CopyState {
/**
- * Holds the Name of the Container
+ * Holds the name of the container.
*/
private String copyId;
@@ -59,27 +59,52 @@ public final class CopyState {
private String statusDescription;
/**
- * Initializes a new instance of the CopyState class
+ * Initializes a new instance of the CopyState class.
*/
public CopyState() {
}
+ /**
+ * Gets the copy ID of the container.
+ *
+ * @return A string containing the copy ID of the container.
+ */
public String getCopyId() {
return this.copyId;
}
+ /**
+ * Gets the time that the copy operation completed.
+ *
+ * @return The time that the copy operation completed.
+ */
public Date getCompletionTime() {
return this.completionTime;
}
+ /**
+ * Gets the status of the copy operation.
+ *
+ * @return A CopyStatus object representing the status of the copy operation.
+ */
public CopyStatus getStatus() {
return this.status;
}
+ /**
+ * Gets the source URI of the copy operation.
+ *
+ * @return The source URI of the copy operation in a string.
+ */
public URI getSource() {
return this.source;
}
+ /**
+ * Gets the number of bytes copied in the operation so far.
+ *
+ * @return The number of bytes copied so far.
+ */
public Long getBytesCopied() {
return this.bytesCopied;
}
@@ -88,34 +113,82 @@ public Long getTotalBytes() {
return this.totalBytes;
}
+ /**
+ * Gets the status description of the copy operation.
+ *
+ * @return A string containing the status description.
+ */
public String getStatusDescription() {
return this.statusDescription;
}
+ /**
+ * Sets the copy ID of the container.
+ *
+ * @param copyId
+ * The copy ID of the container to set.
+ *
+ */
public void setCopyId(final String copyId) {
this.copyId = copyId;
}
+ /**
+ * Sets the time that the copy operation completed.
+ *
+ * @param completionTime
+ * The completion time to set.
+ */
public void setCompletionTime(final Date completionTime) {
this.completionTime = completionTime;
}
+ /**
+ * Sets the status of the copy operation.
+ *
+ * @param status
+ * The copy operation status to set, as a CopyStatus object.
+ */
public void setStatus(final CopyStatus status) {
this.status = status;
}
+ /**
+ * Sets the source URI of the copy operation.
+ *
+ * @param source
+ * The source URI to set.
+ */
public void setSource(final URI source) {
this.source = source;
}
+ /**
+ * Sets the number of bytes copied so far.
+ *
+ * @param bytesCopied
+ * The number of bytes copied to set.
+ */
public void setBytesCopied(final Long bytesCopied) {
this.bytesCopied = bytesCopied;
}
+ /**
+ * Sets the total number of bytes in the source to copy.
+ *
+ * @param totalBytes
+ * The number of bytes to set.
+ */
public void setTotalBytes(final Long totalBytes) {
this.totalBytes = totalBytes;
}
+ /**
+ * Sets the current status of the copy operation.
+ *
+ * @param statusDescription
+ * The current status to set.
+ */
public void setStatusDescription(final String statusDescription) {
this.statusDescription = statusDescription;
}
diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/client/CopyStatus.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/client/CopyStatus.java
index 9e4d13c91dab..33809c15c10c 100644
--- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/client/CopyStatus.java
+++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/client/CopyStatus.java
@@ -23,7 +23,7 @@
*/
public enum CopyStatus {
/**
- * The copy status is not specified..
+ * The copy status is not specified.
*/
UNSPECIFIED,
diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/client/SharedAccessBlobPermissions.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/client/SharedAccessBlobPermissions.java
index c8dc1c17dff8..5475705a29fd 100644
--- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/client/SharedAccessBlobPermissions.java
+++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/client/SharedAccessBlobPermissions.java
@@ -45,7 +45,7 @@ public enum SharedAccessBlobPermissions {
*
* @param value
* The byte value to convert to the corresponding enum set.
- * @return A java.util.EnumSet object that contains the SharedAccessPermissions values
+ * @return A java.util.EnumSet object that contains the SharedAccessBlobPermissions values
* corresponding to the specified byte value.
*/
protected static EnumSet fromByte(final byte value) {
diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/client/SharedAccessBlobPolicy.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/client/SharedAccessBlobPolicy.java
index 937b558ab4c6..8d9c708aa56c 100644
--- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/client/SharedAccessBlobPolicy.java
+++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/client/SharedAccessBlobPolicy.java
@@ -120,52 +120,66 @@ public static String permissionsToString(final EnumSetSharedAccessPolicy class.
+ * Creates an instance of the SharedAccessBlobPolicy class.
* */
public SharedAccessBlobPolicy() {
// Empty Default Ctor
}
/**
- * @return the permissions
+ * Gets the permissions for a shared access signature associated with this shared access policy.
+ *
+ * @return A java.util.EnumSet object that contains {@link SharedAccessBlobPermissions} values that
+ * represents the set of shared access permissions.
*/
public EnumSet getPermissions() {
return this.permissions;
}
/**
- * @return the sharedAccessExpiryTime
+ * Gets the expiry time for a shared access signature associated with this shared access policy.
+ *
+ * @return A Date object that contains the shared access signature expiry time.
*/
public Date getSharedAccessExpiryTime() {
return this.sharedAccessExpiryTime;
}
/**
- * @return the sharedAccessStartTime
+ * Gets the start time for a shared access signature associated with this shared access policy.
+ *
+ * @return A Date object that contains the shared access signature start time.
*/
public Date getSharedAccessStartTime() {
return this.sharedAccessStartTime;
}
/**
+ * Sets the permissions for a shared access signature associated with this shared access policy.
+ *
* @param permissions
- * the permissions to set
+ * The permissions, represented by a java.util.EnumSet object that contains
+ * {@link SharedAccessBlobPermissions} values, to set for the shared access signature.
*/
public void setPermissions(final EnumSet permissions) {
this.permissions = permissions;
}
/**
+ * Sets the expiry time for a shared access signature associated with this shared access policy.
+ *
* @param sharedAccessExpiryTime
- * the sharedAccessExpiryTime to set
+ * The expiry time to set for the shared access signature.
*/
public void setSharedAccessExpiryTime(final Date sharedAccessExpiryTime) {
this.sharedAccessExpiryTime = sharedAccessExpiryTime;
}
/**
+ * Sets the start time for a shared access signature associated with this shared access policy.
+ *
* @param sharedAccessStartTime
- * the sharedAccessStartTime to set
+ * The start time to set for the shared access signature.
*/
public void setSharedAccessStartTime(final Date sharedAccessStartTime) {
this.sharedAccessStartTime = sharedAccessStartTime;
diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/Configuration.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/Configuration.java
index 1664dec98781..e5afff9047a2 100644
--- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/Configuration.java
+++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/Configuration.java
@@ -2,15 +2,15 @@
* Copyright 2011 Microsoft Corporation
*
* Licensed 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
+ * 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.
+ * 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 com.microsoft.windowsazure.services.core;
@@ -23,10 +23,18 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import com.sun.jersey.api.client.config.ClientConfig;
-
public class Configuration {
+ /**
+ * Property name for socket connection timeout used by services created with this configuration.
+ */
+ public static final String PROPERTY_CONNECT_TIMEOUT = "com.microsoft.windowsazure.services.core.Configuration.connectTimeout";
+
+ /**
+ * Property name for socket read timeout used by services created with this configuration.
+ */
+ public static final String PROPERTY_READ_TIMEOUT = "com.microsoft.windowsazure.services.core.Configuration.readTimeout";
+
private static Configuration instance;
Map properties;
Builder builder;
@@ -36,17 +44,11 @@ public class Configuration {
public Configuration() {
this.properties = new HashMap();
this.builder = DefaultBuilder.create();
- init();
}
public Configuration(Builder builder) {
this.properties = new HashMap();
this.builder = builder;
- init();
- }
-
- private void init() {
- setProperty("ClientConfig", builder.build("", ClientConfig.class, properties));
}
public static Configuration getInstance() {
@@ -102,4 +104,7 @@ public void setProperty(String name, Object value) {
properties.put(name, value);
}
+ public Map getProperties() {
+ return properties;
+ }
}
diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/ServiceTimeoutException.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/ServiceTimeoutException.java
new file mode 100644
index 000000000000..9c3c5f7fcd13
--- /dev/null
+++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/ServiceTimeoutException.java
@@ -0,0 +1,63 @@
+/**
+ * Copyright 2012 Microsoft Corporation
+ *
+ * Licensed 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 com.microsoft.windowsazure.services.core;
+
+/**
+ * Exception indicating a service operation has timed out.
+ */
+public class ServiceTimeoutException extends ServiceException {
+
+ private static final long serialVersionUID = 6612846403178749361L;
+
+ /**
+ * Construct a ServiceTimeoutException instance with default parameters.
+ */
+ public ServiceTimeoutException() {
+ }
+
+ /**
+ * Construct a ServiceTimeoutException instance with the specified message.
+ *
+ * @param message
+ * Exception message
+ */
+ public ServiceTimeoutException(String message) {
+ super(message);
+ }
+
+ /**
+ * Construct a ServiceTimeoutException instance with specified
+ * message and cause
+ *
+ * @param message
+ * Exception message
+ * @param cause
+ * Exception that caused this exception to occur
+ */
+ public ServiceTimeoutException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ /**
+ * Construct a ServiceTimeoutException instance with the specified cause.
+ *
+ * @param cause
+ * Exception that caused this exception to occur
+ */
+ public ServiceTimeoutException(Throwable cause) {
+ super(cause);
+ }
+}
diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/LeaseDuration.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/LeaseDuration.java
index 2c807c8dd57f..8e795b831374 100644
--- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/LeaseDuration.java
+++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/LeaseDuration.java
@@ -38,10 +38,10 @@ public enum LeaseDuration {
INFINITE;
/**
- * Parses a lease duration from the given string.
+ * Parses a lease duration from the specified string.
*
* @param typeString
- * A String that represents the string to parse.
+ * The string to parse.
*
* @return A LeaseStatus value that represents the lease status.
*/
diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/LeaseState.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/LeaseState.java
index c2c7f9a79e3f..9bbd28f83ecd 100644
--- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/LeaseState.java
+++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/storage/LeaseState.java
@@ -19,7 +19,7 @@
import com.microsoft.windowsazure.services.core.storage.utils.Utility;
/**
- * he lease state of a resource.
+ * The lease state of a resource.
*/
public enum LeaseState {
/**
@@ -56,7 +56,7 @@ public enum LeaseState {
* Parses a lease status from the given string.
*
* @param typeString
- * A String that represents the string to parse.
+ * The string to parse.
*
* @return A LeaseStatus value that represents the lease status.
*/
diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/utils/DateConverter.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/utils/DateConverter.java
new file mode 100644
index 000000000000..ee00445cf6b6
--- /dev/null
+++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/utils/DateConverter.java
@@ -0,0 +1,72 @@
+/**
+ * Copyright 2012 Microsoft Corporation
+ *
+ * Licensed 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 com.microsoft.windowsazure.services.core.utils;
+
+import java.util.Date;
+import java.util.GregorianCalendar;
+
+import javax.xml.datatype.DatatypeConfigurationException;
+import javax.xml.datatype.DatatypeFactory;
+import javax.xml.datatype.XMLGregorianCalendar;
+
+/**
+ * The Class DateConverter.
+ */
+public class DateConverter {
+
+ /** The datatype factory. */
+ private static DatatypeFactory datatypeFactory = null;
+
+ static {
+ try {
+ datatypeFactory = DatatypeFactory.newInstance();
+ }
+ catch (DatatypeConfigurationException e) {
+ throw new IllegalStateException("Cannot create a new DatatypeFactory instance.", e);
+ }
+ }
+
+ /**
+ * XML gregorian calendar to date.
+ *
+ * @param xmlGregorianCalendar
+ * the xml gregorian calendar
+ * @return the date
+ */
+ public static Date XMLGregorianCalendarToDate(XMLGregorianCalendar xmlGregorianCalendar) {
+ if (xmlGregorianCalendar == null) {
+ return null;
+ }
+
+ return xmlGregorianCalendar.toGregorianCalendar().getTime();
+ }
+
+ /**
+ * Date to xml gregorian calendar.
+ *
+ * @param date
+ * the date
+ * @return the xML gregorian calendar
+ */
+ public static XMLGregorianCalendar DateToXMLGregorianCalendar(Date date) {
+ if (date == null) {
+ return null;
+ }
+
+ GregorianCalendar gregorianCalendar = new GregorianCalendar();
+ gregorianCalendar.setTimeInMillis(date.getTime());
+ return datatypeFactory.newXMLGregorianCalendar(gregorianCalendar);
+ }
+}
diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/utils/ServiceExceptionFactory.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/utils/ServiceExceptionFactory.java
index 90210ac0e625..d11feceb6d20 100644
--- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/utils/ServiceExceptionFactory.java
+++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/utils/ServiceExceptionFactory.java
@@ -2,19 +2,22 @@
* Copyright 2011 Microsoft Corporation
*
* Licensed 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
+ * 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.
+ * 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 com.microsoft.windowsazure.services.core.utils;
+import java.net.SocketTimeoutException;
+
import com.microsoft.windowsazure.services.core.ServiceException;
+import com.microsoft.windowsazure.services.core.ServiceTimeoutException;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.ClientResponse.Status;
import com.sun.jersey.api.client.UniformInterfaceException;
@@ -25,12 +28,16 @@ public static ServiceException process(String serviceName, ServiceException exce
Throwable cause = exception.getCause();
for (Throwable scan = cause; scan != null; scan = scan.getCause()) {
- if (ServiceException.class.isAssignableFrom(scan.getClass())) {
+ Class scanClass = scan.getClass();
+ if (ServiceException.class.isAssignableFrom(scanClass)) {
return populate(exception, serviceName, (ServiceException) scan);
}
- else if (UniformInterfaceException.class.isAssignableFrom(scan.getClass())) {
+ else if (UniformInterfaceException.class.isAssignableFrom(scanClass)) {
return populate(exception, serviceName, (UniformInterfaceException) scan);
}
+ else if (SocketTimeoutException.class.isAssignableFrom(scanClass)) {
+ return populate(exception, serviceName, (SocketTimeoutException) scan);
+ }
}
exception.setServiceName(serviceName);
@@ -83,4 +90,9 @@ static ServiceException populate(ServiceException exception, String serviceName,
return exception;
}
+ static ServiceException populate(ServiceException exception, String serviceName, SocketTimeoutException cause) {
+ ServiceTimeoutException newException = new ServiceTimeoutException(cause.getMessage(), cause);
+ newException.setServiceName(serviceName);
+ return newException;
+ }
}
diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/utils/pipeline/Exports.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/utils/pipeline/Exports.java
index 234581b023fb..d5b9ddc05ce9 100644
--- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/utils/pipeline/Exports.java
+++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/utils/pipeline/Exports.java
@@ -19,6 +19,7 @@
import com.microsoft.windowsazure.services.core.Builder;
import com.microsoft.windowsazure.services.core.Builder.Registry;
+import com.microsoft.windowsazure.services.core.Configuration;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.config.ClientConfig;
import com.sun.jersey.api.client.config.DefaultClientConfig;
@@ -31,8 +32,37 @@ public void register(Registry registry) {
@Override
public ClientConfig create(String profile, Builder builder, Map properties) {
ClientConfig clientConfig = new DefaultClientConfig();
+ profile = normalizeProfile(profile);
+
+ // Lower levels of the stack assume timeouts are set.
+ // Set default timeout on clientConfig in case user
+ // hasn't set it yet in their configuration
+
+ clientConfig.getProperties().put(ClientConfig.PROPERTY_CONNECT_TIMEOUT, new Integer(90 * 1000));
+ clientConfig.getProperties().put(ClientConfig.PROPERTY_READ_TIMEOUT, new Integer(90 * 1000));
+
for (Entry entry : properties.entrySet()) {
- clientConfig.getProperties().put(entry.getKey(), entry.getValue());
+ Object propertyValue = entry.getValue();
+ String propertyKey = entry.getKey();
+
+ if (propertyKey.equals(profile + Configuration.PROPERTY_CONNECT_TIMEOUT)) {
+ propertyKey = ClientConfig.PROPERTY_CONNECT_TIMEOUT;
+ }
+ if (propertyKey.equals(profile + Configuration.PROPERTY_READ_TIMEOUT)) {
+ propertyKey = ClientConfig.PROPERTY_READ_TIMEOUT;
+ }
+
+ // ClientConfig requires instance of Integer to properly set
+ // timeouts, but config file will deliver strings. Special
+ // case these timeout properties and convert them to Integer
+ // if necessary.
+ if (propertyKey.equals(ClientConfig.PROPERTY_CONNECT_TIMEOUT)
+ || propertyKey.equals(ClientConfig.PROPERTY_READ_TIMEOUT)) {
+ if (propertyValue instanceof String) {
+ propertyValue = Integer.valueOf((String) propertyValue);
+ }
+ }
+ clientConfig.getProperties().put(propertyKey, propertyValue);
}
return clientConfig;
}
@@ -41,7 +71,7 @@ public ClientConfig create(String profile, Builder builder, Map
registry.add(new Builder.Factory() {
@Override
public Client create(String profile, Builder builder, Map properties) {
- ClientConfig clientConfig = (ClientConfig) properties.get("ClientConfig");
+ ClientConfig clientConfig = builder.build(profile, ClientConfig.class, properties);
Client client = Client.create(clientConfig);
return client;
}
@@ -50,11 +80,23 @@ public Client create(String profile, Builder builder, Map proper
registry.add(new Builder.Factory() {
@Override
public HttpURLConnectionClient create(String profile, Builder builder, Map properties) {
- ClientConfig clientConfig = (ClientConfig) properties.get("ClientConfig");
+ ClientConfig clientConfig = builder.build(profile, ClientConfig.class, properties);
HttpURLConnectionClient client = HttpURLConnectionClient.create(clientConfig);
//client.addFilter(new LoggingFilter());
return client;
}
});
}
+
+ private static String normalizeProfile(String profile) {
+ if (profile == null) {
+ return "";
+ }
+
+ if (profile.endsWith(".")) {
+ return profile;
+ }
+
+ return profile + ".";
+ }
}
diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/utils/pipeline/HttpURLConnectionClient.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/utils/pipeline/HttpURLConnectionClient.java
index 9b7ca1dd3248..f996e5edc642 100644
--- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/utils/pipeline/HttpURLConnectionClient.java
+++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/utils/pipeline/HttpURLConnectionClient.java
@@ -2,15 +2,15 @@
* Copyright 2011 Microsoft Corporation
*
* Licensed 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
+ * 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.
+ * 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 com.microsoft.windowsazure.services.core.utils.pipeline;
@@ -26,7 +26,7 @@ public HttpURLConnectionClient(HttpURLConnectionClientHandler handler, ClientCon
}
public static HttpURLConnectionClient create(ClientConfig config) {
- return new HttpURLConnectionClient(new HttpURLConnectionClientHandler(), config);
+ return new HttpURLConnectionClient(new HttpURLConnectionClientHandler(config), config);
}
public HttpURLConnectionClientHandler getRootHandler() {
diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/utils/pipeline/HttpURLConnectionClientHandler.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/utils/pipeline/HttpURLConnectionClientHandler.java
index 20d9046c5358..83e0822264e4 100644
--- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/utils/pipeline/HttpURLConnectionClientHandler.java
+++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/utils/pipeline/HttpURLConnectionClientHandler.java
@@ -2,15 +2,15 @@
* Copyright 2011 Microsoft Corporation
*
* Licensed 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
+ * 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.
+ * 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 com.microsoft.windowsazure.services.core.utils.pipeline;
@@ -37,10 +37,28 @@
import com.sun.jersey.core.header.InBoundHeaders;
public class HttpURLConnectionClientHandler extends TerminatingClientHandler {
+
+ private final int connectionTimeoutMillis;
+ private final int readTimeoutMillis;
+
+ public HttpURLConnectionClientHandler(ClientConfig clientConfig) {
+ connectionTimeoutMillis = readTimeoutFromConfig(clientConfig, ClientConfig.PROPERTY_CONNECT_TIMEOUT);
+ readTimeoutMillis = readTimeoutFromConfig(clientConfig, ClientConfig.PROPERTY_READ_TIMEOUT);
+ }
+
+ private static int readTimeoutFromConfig(ClientConfig config, String propertyName) {
+ Integer property = (Integer) config.getProperty(propertyName);
+ if (property != null) {
+ return property.intValue();
+ }
+ throw new IllegalArgumentException(propertyName);
+ }
+
/**
* Empty "no-op" listener if none registered
*/
private static final EntityStreamingListener EMPTY_STREAMING_LISTENER = new EntityStreamingListener() {
+ @Override
public void onBeforeStreamingEntity(ClientRequest clientRequest) {
}
};
@@ -164,6 +182,7 @@ public String toString() {
}
}
+ @Override
public ClientResponse handle(final ClientRequest ro) throws ClientHandlerException {
try {
return doHandle(ro);
@@ -176,6 +195,9 @@ public ClientResponse handle(final ClientRequest ro) throws ClientHandlerExcepti
private ClientResponse doHandle(final ClientRequest clientRequest) throws IOException, MalformedURLException,
ProtocolException {
final HttpURLConnection urlConnection = (HttpURLConnection) clientRequest.getURI().toURL().openConnection();
+ urlConnection.setReadTimeout(readTimeoutMillis);
+ urlConnection.setConnectTimeout(connectionTimeoutMillis);
+
final EntityStreamingListener entityStreamingListener = getEntityStreamingListener(clientRequest);
urlConnection.setRequestMethod(clientRequest.getMethod());
@@ -202,6 +224,7 @@ private ClientResponse doHandle(final ClientRequest clientRequest) throws IOExce
writeRequestEntity(clientRequest, new RequestEntityWriterListener() {
private boolean inStreamingMode;
+ @Override
public void onRequestEntitySize(long size) {
if (size != -1 && size < Integer.MAX_VALUE) {
inStreamingMode = true;
@@ -222,6 +245,7 @@ public void onRequestEntitySize(long size) {
}
}
+ @Override
public OutputStream onGetOutputStream() throws IOException {
if (inStreamingMode)
return new StreamingOutputStream(urlConnection, clientRequest);
diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/Exports.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/Exports.java
index 791ed56f8755..2487fd162e08 100644
--- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/Exports.java
+++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/Exports.java
@@ -1,5 +1,5 @@
/**
- * Copyright 2011 Microsoft Corporation
+ * Copyright 2012 Microsoft Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,20 +14,31 @@
*/
package com.microsoft.windowsazure.services.media;
+import java.util.Map;
+
+import javax.xml.bind.JAXBException;
+import javax.xml.parsers.ParserConfigurationException;
+
import com.microsoft.windowsazure.services.core.Builder;
+import com.microsoft.windowsazure.services.media.implementation.MediaContentProvider;
import com.microsoft.windowsazure.services.media.implementation.MediaExceptionProcessor;
import com.microsoft.windowsazure.services.media.implementation.MediaRestProxy;
import com.microsoft.windowsazure.services.media.implementation.OAuthContract;
import com.microsoft.windowsazure.services.media.implementation.OAuthFilter;
import com.microsoft.windowsazure.services.media.implementation.OAuthRestProxy;
import com.microsoft.windowsazure.services.media.implementation.OAuthTokenManager;
+import com.microsoft.windowsazure.services.media.implementation.ODataEntityCollectionProvider;
+import com.microsoft.windowsazure.services.media.implementation.ODataEntityProvider;
import com.microsoft.windowsazure.services.media.implementation.RedirectFilter;
import com.microsoft.windowsazure.services.media.implementation.ResourceLocationManager;
+import com.microsoft.windowsazure.services.media.implementation.VersionHeadersFilter;
+import com.sun.jersey.api.client.config.ClientConfig;
+import com.sun.jersey.api.json.JSONConfiguration;
public class Exports implements Builder.Exports {
/**
- * register the OAUTH service.
+ * register the Media services.
*/
@Override
public void register(Builder.Registry registry) {
@@ -39,6 +50,31 @@ public void register(Builder.Registry registry) {
registry.add(OAuthFilter.class);
registry.add(ResourceLocationManager.class);
registry.add(RedirectFilter.class);
- }
+ registry.add(VersionHeadersFilter.class);
+
+ registry.alter(ClientConfig.class, new Builder.Alteration() {
+ @Override
+ public ClientConfig alter(ClientConfig instance, Builder builder, Map properties) {
+ instance.getProperties().put(JSONConfiguration.FEATURE_POJO_MAPPING, true);
+
+ // Turn off auto-follow redirects, because Media Services rest calls break if it's on
+ instance.getProperties().put(ClientConfig.PROPERTY_FOLLOW_REDIRECTS, false);
+
+ try {
+ instance.getSingletons().add(new ODataEntityProvider());
+ instance.getSingletons().add(new ODataEntityCollectionProvider());
+ instance.getSingletons().add(new MediaContentProvider());
+ }
+ catch (JAXBException e) {
+ throw new RuntimeException(e);
+ }
+ catch (ParserConfigurationException e) {
+ throw new RuntimeException(e);
+ }
+
+ return instance;
+ }
+ });
+ }
}
diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/MediaConfiguration.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/MediaConfiguration.java
index ac7464c57001..6821f7b10faf 100644
--- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/MediaConfiguration.java
+++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/MediaConfiguration.java
@@ -1,5 +1,5 @@
/**
- * Copyright 2011 Microsoft Corporation
+ * Copyright 2012 Microsoft Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/MediaContract.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/MediaContract.java
index 3e92ac300dae..aac6354b6947 100644
--- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/MediaContract.java
+++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/MediaContract.java
@@ -1,5 +1,5 @@
/**
- * Copyright 2011 Microsoft Corporation
+ * Copyright 2012 Microsoft Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,15 +14,155 @@
*/
package com.microsoft.windowsazure.services.media;
+import java.util.List;
+
import com.microsoft.windowsazure.services.core.FilterableService;
+import com.microsoft.windowsazure.services.core.ServiceException;
+import com.microsoft.windowsazure.services.media.models.AccessPolicyInfo;
+import com.microsoft.windowsazure.services.media.models.AssetInfo;
+import com.microsoft.windowsazure.services.media.models.CreateAccessPolicyOptions;
+import com.microsoft.windowsazure.services.media.models.CreateAssetOptions;
+import com.microsoft.windowsazure.services.media.models.ListAccessPolicyOptions;
+import com.microsoft.windowsazure.services.media.models.ListAssetsOptions;
+import com.microsoft.windowsazure.services.media.models.UpdateAssetOptions;
/**
- *
- * Defines the methods available for Windows Azure Media Services
- *
+ * Defines the methods available for Windows Azure Media Services.
*/
public interface MediaContract extends FilterableService {
- // Will fill in as we implement the various Media Services entities
+ /**
+ * Creates the asset.
+ *
+ * @param assetName
+ * the asset name
+ * @return the asset info
+ * @throws ServiceException
+ */
+ public AssetInfo createAsset(String assetName) throws ServiceException;
+
+ /**
+ * Creates the asset.
+ *
+ * @param assetName
+ * the asset name
+ * @param createAssetOptions
+ * the create asset options
+ * @return the asset info
+ * @throws ServiceException
+ */
+ public AssetInfo createAsset(String assetName, CreateAssetOptions createAssetOptions) throws ServiceException;
+
+ /**
+ * Delete asset.
+ *
+ * @param assetId
+ * the asset id
+ * @throws ServiceException
+ */
+ public void deleteAsset(String assetId) throws ServiceException;
+
+ /**
+ * Gets the asset.
+ *
+ * @param assetId
+ * the asset id
+ * @return the asset
+ * @throws ServiceException
+ */
+ public AssetInfo getAsset(String assetId) throws ServiceException;
+
+ /**
+ * List assets.
+ *
+ * @return the list
+ * @throws ServiceException
+ */
+ public List listAssets() throws ServiceException;
+
+ /**
+ * List assets.
+ *
+ * @param listAssetsOptions
+ * the list assets options
+ * @return the list
+ * @throws ServiceException
+ */
+ public List listAssets(ListAssetsOptions listAssetsOptions) throws ServiceException;
+
+ /**
+ * Update asset.
+ *
+ * @param assetId
+ * the asset id
+ * @param updateAssetOptions
+ * the update asset options
+ * @throws ServiceException
+ * the service exception
+ */
+ public void updateAsset(String assetId, UpdateAssetOptions updateAssetOptions) throws ServiceException;
+
+ /**
+ * Create the access policy
+ *
+ * @param name
+ * name of access policy
+ * @param durationInMinutes
+ * Duration in minutes that blob access will be granted when using this access policy
+ * @return Created access policy
+ * @throws ServiceException
+ */
+ AccessPolicyInfo createAccessPolicy(String name, double durationInMinutes) throws ServiceException;
+
+ /**
+ * Create the access policy with the given options
+ *
+ * @param name
+ * name of access policy
+ * @param durationInMinutes
+ * Duration in minutes that blob access will be granted when using this access policy
+ * @param options
+ * options for creation
+ * @return the created access policy
+ * @throws ServiceException
+ */
+ AccessPolicyInfo createAccessPolicy(String name, double durationInMinutes, CreateAccessPolicyOptions options)
+ throws ServiceException;
+
+ /**
+ * Delete the access policy with the given id
+ *
+ * @param id
+ * of access policy to delete
+ * @throws ServiceException
+ */
+ void deleteAccessPolicy(String id) throws ServiceException;
+
+ /**
+ * Get a single access policy
+ *
+ * @param id
+ * the id of the asset to retrieve
+ * @return the asset
+ * @throws ServiceException
+ */
+ AccessPolicyInfo getAccessPolicy(String id) throws ServiceException;
+
+ /**
+ * List access policies
+ *
+ * @return the list
+ * @throws ServiceException
+ */
+ List listAccessPolicies() throws ServiceException;
+ /**
+ * List access policies
+ *
+ * @param options
+ * the list access policy options
+ * @return the list
+ * @throws ServiceException
+ */
+ List listAccessPolicies(ListAccessPolicyOptions options) throws ServiceException;
}
diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/MediaService.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/MediaService.java
index 413dae44c8d4..9cf13258bab8 100644
--- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/MediaService.java
+++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/MediaService.java
@@ -1,5 +1,5 @@
/**
- * Copyright 2011 Microsoft Corporation
+ * Copyright 2012 Microsoft Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ActiveToken.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ActiveToken.java
index e3c5561f7b77..b38ee7087185 100644
--- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ActiveToken.java
+++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ActiveToken.java
@@ -1,5 +1,5 @@
/**
- * Copyright 2011 Microsoft Corporation
+ * Copyright 2012 Microsoft Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/MediaContentProvider.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/MediaContentProvider.java
new file mode 100644
index 000000000000..4ad8c880c6d4
--- /dev/null
+++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/MediaContentProvider.java
@@ -0,0 +1,80 @@
+/**
+ * Copyright 2012 Microsoft Corporation
+ *
+ * Licensed 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 com.microsoft.windowsazure.services.media.implementation;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.xml.bind.JAXBException;
+import javax.xml.parsers.ParserConfigurationException;
+
+import com.microsoft.windowsazure.services.media.implementation.content.MediaServiceDTO;
+import com.sun.jersey.core.provider.AbstractMessageReaderWriterProvider;
+
+/**
+ * Class to plug into Jersey to properly serialize
+ * raw Media Services DTO types.
+ *
+ */
+public class MediaContentProvider extends AbstractMessageReaderWriterProvider {
+ private final ODataAtomMarshaller marshaller;
+
+ /**
+ * Creates the instance
+ *
+ * @throws JAXBException
+ * @throws ParserConfigurationException
+ */
+ public MediaContentProvider() throws JAXBException, ParserConfigurationException {
+ marshaller = new ODataAtomMarshaller();
+ }
+
+ @Override
+ public boolean isReadable(Class> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
+ // This class only does marshalling, not unmarshalling.
+ return false;
+ }
+
+ @Override
+ public T readFrom(Class type, Type genericType, Annotation[] annotations, MediaType mediaType,
+ MultivaluedMap httpHeaders, InputStream entityStream) throws IOException,
+ WebApplicationException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public boolean isWriteable(Class> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
+ return MediaServiceDTO.class.isAssignableFrom(type);
+ }
+
+ @Override
+ public void writeTo(T t, Class> type, Type genericType, Annotation[] annotations, MediaType mediaType,
+ MultivaluedMap httpHeaders, OutputStream entityStream) throws IOException,
+ WebApplicationException {
+ try {
+ marshaller.marshalEntry(t, entityStream);
+ }
+ catch (JAXBException e) {
+ throw new RuntimeException(e);
+ }
+ }
+}
diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/MediaExceptionProcessor.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/MediaExceptionProcessor.java
index d9c3141d5206..314111bc50b3 100644
--- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/MediaExceptionProcessor.java
+++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/MediaExceptionProcessor.java
@@ -1,5 +1,5 @@
/**
- * Copyright 2011 Microsoft Corporation
+ * Copyright 2012 Microsoft Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,6 +15,8 @@
package com.microsoft.windowsazure.services.media.implementation;
+import java.util.List;
+
import javax.inject.Inject;
import org.apache.commons.logging.Log;
@@ -24,6 +26,15 @@
import com.microsoft.windowsazure.services.core.ServiceFilter;
import com.microsoft.windowsazure.services.core.utils.ServiceExceptionFactory;
import com.microsoft.windowsazure.services.media.MediaContract;
+import com.microsoft.windowsazure.services.media.models.AccessPolicyInfo;
+import com.microsoft.windowsazure.services.media.models.AssetInfo;
+import com.microsoft.windowsazure.services.media.models.CreateAccessPolicyOptions;
+import com.microsoft.windowsazure.services.media.models.CreateAssetOptions;
+import com.microsoft.windowsazure.services.media.models.ListAccessPolicyOptions;
+import com.microsoft.windowsazure.services.media.models.ListAssetsOptions;
+import com.microsoft.windowsazure.services.media.models.UpdateAssetOptions;
+import com.sun.jersey.api.client.ClientHandlerException;
+import com.sun.jersey.api.client.UniformInterfaceException;
/**
* Wrapper implementation of MediaServicesContract that
@@ -32,26 +43,258 @@
*/
public class MediaExceptionProcessor implements MediaContract {
- private final MediaContract next;
+ /** The service. */
+ private final MediaContract service;
+
+ /** The log. */
static Log log = LogFactory.getLog(MediaContract.class);
- public MediaExceptionProcessor(MediaContract next) {
- this.next = next;
+ /**
+ * Instantiates a new media exception processor.
+ *
+ * @param service
+ * the service
+ */
+ public MediaExceptionProcessor(MediaContract service) {
+ this.service = service;
}
+ /**
+ * Instantiates a new media exception processor.
+ *
+ * @param service
+ * the service
+ */
@Inject
- public MediaExceptionProcessor(MediaRestProxy next) {
- this.next = next;
+ public MediaExceptionProcessor(MediaRestProxy service) {
+ this.service = service;
}
+ /* (non-Javadoc)
+ * @see com.microsoft.windowsazure.services.core.FilterableService#withFilter(com.microsoft.windowsazure.services.core.ServiceFilter)
+ */
@Override
public MediaContract withFilter(ServiceFilter filter) {
- return new MediaExceptionProcessor(next.withFilter(filter));
+ return new MediaExceptionProcessor(service.withFilter(filter));
}
+ /**
+ * Process a catch.
+ *
+ * @param e
+ * the e
+ * @return the service exception
+ */
private ServiceException processCatch(ServiceException e) {
log.warn(e.getMessage(), e.getCause());
return ServiceExceptionFactory.process("MediaServices", e);
}
+ /* (non-Javadoc)
+ * @see com.microsoft.windowsazure.services.media.MediaContract#createAsset(java.lang.String)
+ */
+ @Override
+ public AssetInfo createAsset(String assetName) throws ServiceException {
+ try {
+ return service.createAsset(assetName);
+ }
+ catch (UniformInterfaceException e) {
+ throw processCatch(new ServiceException(e));
+ }
+ catch (ClientHandlerException e) {
+ throw processCatch(new ServiceException(e));
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see com.microsoft.windowsazure.services.media.MediaContract#createAsset(java.lang.String, com.microsoft.windowsazure.services.media.models.CreateAssetOptions)
+ */
+ @Override
+ public AssetInfo createAsset(String assetName, CreateAssetOptions createAssetOptions) throws ServiceException {
+ try {
+ return service.createAsset(assetName, createAssetOptions);
+ }
+ catch (UniformInterfaceException e) {
+ throw processCatch(new ServiceException(e));
+ }
+ catch (ClientHandlerException e) {
+ throw processCatch(new ServiceException(e));
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see com.microsoft.windowsazure.services.media.MediaContract#deleteAsset(java.lang.String)
+ */
+ @Override
+ public void deleteAsset(String assetId) throws ServiceException {
+ try {
+ service.deleteAsset(assetId);
+ }
+ catch (UniformInterfaceException e) {
+ throw processCatch(new ServiceException(e));
+ }
+ catch (ClientHandlerException e) {
+ throw processCatch(new ServiceException(e));
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see com.microsoft.windowsazure.services.media.MediaContract#getAsset(java.lang.String)
+ */
+ @Override
+ public AssetInfo getAsset(String assetId) throws ServiceException {
+ try {
+ return service.getAsset(assetId);
+ }
+ catch (UniformInterfaceException e) {
+ throw processCatch(new ServiceException(e));
+ }
+ catch (ClientHandlerException e) {
+ throw processCatch(new ServiceException(e));
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see com.microsoft.windowsazure.services.media.MediaContract#listAssets()
+ */
+ @Override
+ public List listAssets() throws ServiceException {
+ try {
+ return service.listAssets();
+ }
+ catch (UniformInterfaceException e) {
+ throw processCatch(new ServiceException(e));
+ }
+ catch (ClientHandlerException e) {
+ throw processCatch(new ServiceException(e));
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see com.microsoft.windowsazure.services.media.MediaContract#listAssets(com.microsoft.windowsazure.services.media.models.ListAssetsOptions)
+ */
+ @Override
+ public List listAssets(ListAssetsOptions listAssetsOptions) throws ServiceException {
+ try {
+ return service.listAssets(listAssetsOptions);
+ }
+ catch (UniformInterfaceException e) {
+ throw processCatch(new ServiceException(e));
+ }
+ catch (ClientHandlerException e) {
+ throw processCatch(new ServiceException(e));
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see com.microsoft.windowsazure.services.media.MediaContract#updateAsset(com.microsoft.windowsazure.services.media.models.AssetInfo)
+ */
+ @Override
+ public void updateAsset(String assetId, UpdateAssetOptions updateAssetOptions) throws ServiceException {
+ try {
+ service.updateAsset(assetId, updateAssetOptions);
+ }
+ catch (UniformInterfaceException e) {
+ throw processCatch(new ServiceException(e));
+ }
+ catch (ClientHandlerException e) {
+ throw processCatch(new ServiceException(e));
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see com.microsoft.windowsazure.services.media.MediaContract#createAccessPolicy(double)
+ */
+ @Override
+ public AccessPolicyInfo createAccessPolicy(String name, double durationInMinutes) throws ServiceException {
+ try {
+ return service.createAccessPolicy(name, durationInMinutes);
+ }
+ catch (UniformInterfaceException e) {
+ throw processCatch(new ServiceException(e));
+ }
+ catch (ClientHandlerException e) {
+ throw processCatch(new ServiceException(e));
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see com.microsoft.windowsazure.services.media.MediaContract#createAccessPolicy(double, com.microsoft.windowsazure.services.media.models.CreateAccessPolicyOptions)
+ */
+ @Override
+ public AccessPolicyInfo createAccessPolicy(String name, double durationInMinutes, CreateAccessPolicyOptions options)
+ throws ServiceException {
+ try {
+ return service.createAccessPolicy(name, durationInMinutes, options);
+ }
+ catch (UniformInterfaceException e) {
+ throw processCatch(new ServiceException(e));
+ }
+ catch (ClientHandlerException e) {
+ throw processCatch(new ServiceException(e));
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see com.microsoft.windowsazure.services.media.MediaContract#getAccessPolicies()
+ */
+ @Override
+ public List listAccessPolicies() throws ServiceException {
+ try {
+ return service.listAccessPolicies();
+ }
+ catch (UniformInterfaceException e) {
+ throw processCatch(new ServiceException(e));
+ }
+ catch (ClientHandlerException e) {
+ throw processCatch(new ServiceException(e));
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see com.microsoft.windowsazure.services.media.MediaContract#deleteAccessPolicy(java.lang.String)
+ */
+ @Override
+ public void deleteAccessPolicy(String id) throws ServiceException {
+ try {
+ service.deleteAccessPolicy(id);
+ }
+ catch (UniformInterfaceException e) {
+ throw processCatch(new ServiceException(e));
+ }
+ catch (ClientHandlerException e) {
+ throw processCatch(new ServiceException(e));
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see com.microsoft.windowsazure.services.media.MediaContract#getAccessPolicy(java.lang.String)
+ */
+ @Override
+ public AccessPolicyInfo getAccessPolicy(String id) throws ServiceException {
+ try {
+ return service.getAccessPolicy(id);
+ }
+ catch (UniformInterfaceException e) {
+ throw processCatch(new ServiceException(e));
+ }
+ catch (ClientHandlerException e) {
+ throw processCatch(new ServiceException(e));
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see com.microsoft.windowsazure.services.media.MediaContract#listAccessPolicies(com.microsoft.windowsazure.services.media.models.ListAccessPolicyOptions)
+ */@Override
+ public List listAccessPolicies(ListAccessPolicyOptions options) throws ServiceException {
+ try {
+ return service.listAccessPolicies();
+ }
+ catch (UniformInterfaceException e) {
+ throw processCatch(new ServiceException(e));
+ }
+ catch (ClientHandlerException e) {
+ throw processCatch(new ServiceException(e));
+ }
+ }
}
diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/MediaRestProxy.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/MediaRestProxy.java
index 9b1dfc25e5a6..c27f83ff48ff 100644
--- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/MediaRestProxy.java
+++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/MediaRestProxy.java
@@ -1,5 +1,5 @@
/**
- * Copyright 2011 Microsoft Corporation
+ * Copyright 2012 Microsoft Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,39 +15,90 @@
package com.microsoft.windowsazure.services.media.implementation;
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
import java.util.Arrays;
+import java.util.EnumSet;
+import java.util.List;
import javax.inject.Inject;
+import javax.ws.rs.core.MediaType;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import com.microsoft.windowsazure.services.core.ServiceException;
import com.microsoft.windowsazure.services.core.ServiceFilter;
import com.microsoft.windowsazure.services.core.utils.pipeline.ClientFilterAdapter;
+import com.microsoft.windowsazure.services.core.utils.pipeline.PipelineHelpers;
import com.microsoft.windowsazure.services.media.MediaContract;
+import com.microsoft.windowsazure.services.media.implementation.content.AccessPolicyType;
+import com.microsoft.windowsazure.services.media.implementation.content.AssetType;
+import com.microsoft.windowsazure.services.media.models.AccessPolicyInfo;
+import com.microsoft.windowsazure.services.media.models.AccessPolicyPermission;
+import com.microsoft.windowsazure.services.media.models.AssetInfo;
+import com.microsoft.windowsazure.services.media.models.CreateAccessPolicyOptions;
+import com.microsoft.windowsazure.services.media.models.CreateAssetOptions;
+import com.microsoft.windowsazure.services.media.models.ListAccessPolicyOptions;
+import com.microsoft.windowsazure.services.media.models.ListAssetsOptions;
+import com.microsoft.windowsazure.services.media.models.UpdateAssetOptions;
import com.sun.jersey.api.client.Client;
+import com.sun.jersey.api.client.ClientResponse;
+import com.sun.jersey.api.client.GenericType;
import com.sun.jersey.api.client.WebResource;
+/**
+ * The Class MediaRestProxy.
+ */
public class MediaRestProxy implements MediaContract {
+ /** The channel. */
private Client channel;
- static Log log = LogFactory.getLog(MediaContract.class);
+ /** The log. */
+ static Log log = LogFactory.getLog(MediaContract.class);
+ /** The filters. */
ServiceFilter[] filters;
+ /**
+ * Instantiates a new media rest proxy.
+ *
+ * @param channel
+ * the channel
+ * @param authFilter
+ * the auth filter
+ * @param redirectFilter
+ * the redirect filter
+ * @param versionHeadersFilter
+ * the version headers filter
+ */
@Inject
- public MediaRestProxy(Client channel, OAuthFilter authFilter, RedirectFilter redirectFilter) {
+ public MediaRestProxy(Client channel, OAuthFilter authFilter, RedirectFilter redirectFilter,
+ VersionHeadersFilter versionHeadersFilter) {
this.channel = channel;
this.filters = new ServiceFilter[0];
+
channel.addFilter(redirectFilter);
channel.addFilter(authFilter);
+ channel.addFilter(versionHeadersFilter);
}
+ /**
+ * Instantiates a new media rest proxy.
+ *
+ * @param channel
+ * the channel
+ * @param filters
+ * the filters
+ */
public MediaRestProxy(Client channel, ServiceFilter[] filters) {
this.channel = channel;
this.filters = filters;
}
+ /* (non-Javadoc)
+ * @see com.microsoft.windowsazure.services.core.FilterableService#withFilter(com.microsoft.windowsazure.services.core.ServiceFilter)
+ */
@Override
public MediaContract withFilter(ServiceFilter filter) {
ServiceFilter[] newFilters = Arrays.copyOf(filters, filters.length + 1);
@@ -55,14 +106,32 @@ public MediaContract withFilter(ServiceFilter filter) {
return new MediaRestProxy(channel, newFilters);
}
+ /**
+ * Gets the channel.
+ *
+ * @return the channel
+ */
public Client getChannel() {
return channel;
}
+ /**
+ * Sets the channel.
+ *
+ * @param channel
+ * the new channel
+ */
public void setChannel(Client channel) {
this.channel = channel;
}
+ /**
+ * Gets the resource.
+ *
+ * @param entityName
+ * the entity name
+ * @return the resource
+ */
private WebResource getResource(String entityName) {
WebResource resource = getChannel().resource(entityName);
for (ServiceFilter filter : filters) {
@@ -71,4 +140,185 @@ private WebResource getResource(String entityName) {
return resource;
}
+ private WebResource getResource(String entityType, String entityId) throws ServiceException {
+ String escapedEntityId = null;
+ try {
+ escapedEntityId = URLEncoder.encode(entityId, "UTF-8");
+ }
+ catch (UnsupportedEncodingException e) {
+ throw new ServiceException(e);
+ }
+ String entityPath = String.format("%s(\'%s\')", entityType, escapedEntityId);
+
+ return getResource(entityPath);
+ }
+
+ private T mergeRequest(String path, java.lang.Class c, java.lang.Object requestEntity) {
+ WebResource resource = getResource(path);
+ WebResource.Builder builder = resource.getRequestBuilder();
+ builder = builder.type(MediaType.APPLICATION_ATOM_XML).accept(MediaType.APPLICATION_ATOM_XML)
+ .header("X-HTTP-Method", "MERGE");
+ return builder.post(c, requestEntity);
+ }
+
+ /* (non-Javadoc)
+ * @see com.microsoft.windowsazure.services.media.MediaContract#createAsset(java.lang.String)
+ */
+ @Override
+ public AssetInfo createAsset(String assetName) throws ServiceException {
+ return this.createAsset(assetName, null);
+ }
+
+ /* (non-Javadoc)
+ * @see com.microsoft.windowsazure.services.media.MediaContract#createAsset(java.lang.String, com.microsoft.windowsazure.services.media.models.CreateAssetOptions)
+ */
+ @Override
+ public AssetInfo createAsset(String assetName, CreateAssetOptions createAssetOptions) {
+ WebResource resource = getResource("Assets");
+ AssetType assetTypeForSubmission = new AssetType();
+ assetTypeForSubmission.setName(assetName);
+ if (createAssetOptions != null) {
+ assetTypeForSubmission.setAlternateId(createAssetOptions.getAlternateId());
+ if (createAssetOptions.getOptions() != null) {
+ assetTypeForSubmission.setOptions(createAssetOptions.getOptions().getCode());
+ }
+ if (createAssetOptions.getState() != null) {
+ assetTypeForSubmission.setState(createAssetOptions.getState().getCode());
+ }
+ }
+ return resource.type(MediaType.APPLICATION_ATOM_XML).accept(MediaType.APPLICATION_ATOM_XML)
+ .post(AssetInfo.class, assetTypeForSubmission);
+ }
+
+ /* (non-Javadoc)
+ * @see com.microsoft.windowsazure.services.media.MediaContract#getAsset(java.lang.String)
+ */
+ @Override
+ public AssetInfo getAsset(String assetId) throws ServiceException {
+ WebResource resource = getResource("Assets", assetId);
+ return resource.type(MediaType.APPLICATION_ATOM_XML).accept(MediaType.APPLICATION_ATOM_XML)
+ .get(AssetInfo.class);
+ }
+
+ /* (non-Javadoc)
+ * @see com.microsoft.windowsazure.services.media.MediaContract#listAssets(com.microsoft.windowsazure.services.media.models.ListAssetsOptions)
+ */
+ @Override
+ public List listAssets(ListAssetsOptions listAssetsOptions) {
+ WebResource resource = getResource("Assets");
+ return resource.type(MediaType.APPLICATION_ATOM_XML).accept(MediaType.APPLICATION_ATOM_XML)
+ .get(new GenericType>() {
+ });
+ }
+
+ /* (non-Javadoc)
+ * @see com.microsoft.windowsazure.services.media.MediaContract#listAssets()
+ */
+ @Override
+ public List listAssets() {
+ ListAssetsOptions listAssetsOptions = new ListAssetsOptions();
+ return listAssets(listAssetsOptions);
+ }
+
+ /* (non-Javadoc)
+ * @see com.microsoft.windowsazure.services.media.MediaContract#updateAsset(com.microsoft.windowsazure.services.media.models.AssetInfo)
+ */
+ @Override
+ public void updateAsset(String assetId, UpdateAssetOptions updateAssetOptions) throws ServiceException {
+ String escapedAssetId = null;
+ try {
+ escapedAssetId = URLEncoder.encode(assetId, "UTF-8");
+ }
+ catch (UnsupportedEncodingException e) {
+ throw new ServiceException(e);
+ }
+ String assetPath = String.format("Assets(\'%s\')", escapedAssetId);
+ AssetType updatedAssetType = new AssetType();
+ updatedAssetType.setAlternateId(updateAssetOptions.getAlternateId());
+ updatedAssetType.setName(updateAssetOptions.getName());
+ if (updateAssetOptions.getOptions() != null) {
+ updatedAssetType.setOptions(updateAssetOptions.getOptions().getCode());
+ }
+
+ if (updateAssetOptions.getState() != null) {
+ updatedAssetType.setState(updateAssetOptions.getState().getCode());
+ }
+
+ ClientResponse clientResponse = mergeRequest(assetPath, ClientResponse.class, updatedAssetType);
+ PipelineHelpers.ThrowIfNotSuccess(clientResponse);
+ }
+
+ /* (non-Javadoc)
+ * @see com.microsoft.windowsazure.services.media.MediaContract#deleteAsset(java.lang.String)
+ */
+ @Override
+ public void deleteAsset(String assetId) throws ServiceException {
+ getResource("Assets", assetId).delete();
+ }
+
+ /* (non-Javadoc)
+ * @see com.microsoft.windowsazure.services.media.MediaContract#createAccessPolicy(double)
+ */
+ @Override
+ public AccessPolicyInfo createAccessPolicy(String name, double durationInMinutes) throws ServiceException {
+ return createAccessPolicy(name, durationInMinutes, null);
+ }
+
+ /* (non-Javadoc)
+ * @see com.microsoft.windowsazure.services.media.MediaContract#createAccessPolicy(double, com.microsoft.windowsazure.services.media.models.CreateAccessPolicyOptions)
+ */
+ @Override
+ public AccessPolicyInfo createAccessPolicy(String name, double durationInMinutes, CreateAccessPolicyOptions options)
+ throws ServiceException {
+
+ if (options == null) {
+ options = new CreateAccessPolicyOptions().addPermissions(EnumSet.of(AccessPolicyPermission.WRITE));
+ }
+
+ AccessPolicyType requestData = new AccessPolicyType().setDurationInMinutes(durationInMinutes).setName(name)
+ .setPermissions(AccessPolicyPermission.bitsFromPermissions(options.getPermissions()));
+
+ WebResource resource = getResource("AccessPolicies");
+
+ return resource.type(MediaType.APPLICATION_ATOM_XML).accept(MediaType.APPLICATION_ATOM_XML)
+ .post(AccessPolicyInfo.class, requestData);
+ }
+
+ /* (non-Javadoc)
+ * @see com.microsoft.windowsazure.services.media.MediaContract#getAccessPolicy(java.lang.String)
+ */
+ @Override
+ public AccessPolicyInfo getAccessPolicy(String id) throws ServiceException {
+ WebResource resource = getResource("AccessPolicies", id);
+ return resource.type(MediaType.APPLICATION_ATOM_XML).accept(MediaType.APPLICATION_ATOM_XML)
+ .get(AccessPolicyInfo.class);
+ }
+
+ /* (non-Javadoc)
+ * @see com.microsoft.windowsazure.services.media.MediaContract#deleteAccessPolicy(java.lang.String)
+ */
+ @Override
+ public void deleteAccessPolicy(String id) throws ServiceException {
+ getResource("AccessPolicies", id).delete();
+ }
+
+ /* (non-Javadoc)
+ * @see com.microsoft.windowsazure.services.media.MediaContract#listAccessPolicies()
+ */
+ @Override
+ public List listAccessPolicies() throws ServiceException {
+ return listAccessPolicies(null);
+ }
+
+ /* (non-Javadoc)
+ * @see com.microsoft.windowsazure.services.media.MediaContract#listAccessPolicies()
+ */
+ @Override
+ public List listAccessPolicies(ListAccessPolicyOptions options) throws ServiceException {
+ WebResource resource = getResource("AccessPolicies");
+
+ return resource.type(MediaType.APPLICATION_ATOM_XML).accept(MediaType.APPLICATION_ATOM_XML)
+ .get(new GenericType>() {
+ });
+ }
}
diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/OAuthContract.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/OAuthContract.java
index 7e81549642f7..54091fff0586 100644
--- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/OAuthContract.java
+++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/OAuthContract.java
@@ -1,5 +1,5 @@
/**
- * Copyright 2011 Microsoft Corporation
+ * Copyright 2012 Microsoft Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/OAuthFilter.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/OAuthFilter.java
index 3b2e45a363b6..326db58a005f 100644
--- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/OAuthFilter.java
+++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/OAuthFilter.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2011 Microsoft Corporation
+ * Copyright 2012 Microsoft Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/OAuthRestProxy.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/OAuthRestProxy.java
index a51eae7e82c3..6645d55eecdc 100644
--- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/OAuthRestProxy.java
+++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/OAuthRestProxy.java
@@ -1,5 +1,5 @@
/**
- * Copyright 2011 Microsoft Corporation
+ * Copyright 2012 Microsoft Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/OAuthTokenManager.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/OAuthTokenManager.java
index 473bd9d60bb6..7e5df57b529c 100644
--- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/OAuthTokenManager.java
+++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/OAuthTokenManager.java
@@ -1,5 +1,5 @@
/**
- * Copyright 2011 Microsoft Corporation
+ * Copyright 2012 Microsoft Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -51,24 +51,25 @@ public class OAuthTokenManager {
* @param dateFactory
* A DateFactory object instance that represents the date factory.
*
- * @param acsBaseUri
- * A URI object instance that represents the ACS base URI.
+ * @param oAuthUri
+ * A String object instance that represents the ACS base URI.
*
* @param clientId
* A String object instance that represents the client ID.
*
* @param clientSecret
* A String object instance that represents the client secret.
+ * @throws URISyntaxException
*
*/
public OAuthTokenManager(OAuthContract contract, DateFactory dateFactory,
- @Named(MediaConfiguration.OAUTH_URI) URI acsBaseUri,
+ @Named(MediaConfiguration.OAUTH_URI) String oAuthUri,
@Named(MediaConfiguration.OAUTH_CLIENT_ID) String clientId,
@Named(MediaConfiguration.OAUTH_CLIENT_SECRET) String clientSecret,
- @Named(MediaConfiguration.OAUTH_SCOPE) String scope) {
+ @Named(MediaConfiguration.OAUTH_SCOPE) String scope) throws URISyntaxException {
this.contract = contract;
this.dateFactory = dateFactory;
- this.acsBaseUri = acsBaseUri;
+ this.acsBaseUri = new URI(oAuthUri);
this.clientId = clientId;
this.clientSecret = clientSecret;
this.scope = scope;
diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/OAuthTokenResponse.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/OAuthTokenResponse.java
index 42974fb52e3f..b8a357d739f9 100644
--- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/OAuthTokenResponse.java
+++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/OAuthTokenResponse.java
@@ -1,5 +1,5 @@
/**
- * Copyright 2011 Microsoft Corporation
+ * Copyright 2012 Microsoft Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ODataAtomMarshaller.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ODataAtomMarshaller.java
new file mode 100644
index 000000000000..13edb3b00de5
--- /dev/null
+++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ODataAtomMarshaller.java
@@ -0,0 +1,121 @@
+/**
+ * Copyright 2012 Microsoft Corporation
+ *
+ * Licensed 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 com.microsoft.windowsazure.services.media.implementation;
+
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBElement;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Marshaller;
+import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.w3c.dom.Document;
+
+import com.microsoft.windowsazure.services.media.implementation.atom.ContentType;
+import com.microsoft.windowsazure.services.media.implementation.atom.EntryType;
+import com.microsoft.windowsazure.services.media.implementation.atom.FeedType;
+import com.microsoft.windowsazure.services.media.implementation.content.AccessPolicyType;
+import com.microsoft.windowsazure.services.media.implementation.content.AssetType;
+import com.microsoft.windowsazure.services.media.implementation.content.Constants;
+
+/**
+ * A class to manage marshalling of request parameters into
+ * ATOM entry elements for sending to the Media Services REST
+ * endpoints.
+ *
+ */
+public class ODataAtomMarshaller {
+ private final Marshaller marshaller;
+ private final DocumentBuilder documentBuilder;
+
+ public ODataAtomMarshaller() throws JAXBException, ParserConfigurationException {
+ JAXBContext context = JAXBContext.newInstance(getMarshalledClasses(), null);
+ marshaller = context.createMarshaller();
+
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ dbf.setNamespaceAware(true);
+ documentBuilder = dbf.newDocumentBuilder();
+ }
+
+ /**
+ * Convert the given content object into an ATOM entry
+ * (represented as a DOM document) suitable for sending
+ * up to the Media Services service.
+ *
+ * @param content
+ * The content object to send
+ * @return The generated DOM
+ * @throws JAXBException
+ * if content is malformed/not marshallable
+ */
+ public Document marshalEntry(Object content) throws JAXBException {
+ JAXBElement entryElement = createEntry(content);
+
+ Document doc = documentBuilder.newDocument();
+ doc.setXmlStandalone(true);
+
+ marshaller.marshal(entryElement, doc);
+
+ return doc;
+
+ }
+
+ /**
+ * Convert the given content into an ATOM entry
+ * and write it to the given stream.
+ *
+ * @param content
+ * Content object to send
+ * @param stream
+ * Stream to write to
+ * @throws JAXBException
+ * if content is malformed/not marshallable
+ */
+ public void marshalEntry(Object content, OutputStream stream) throws JAXBException {
+ marshaller.marshal(createEntry(content), stream);
+ }
+
+ private JAXBElement createEntry(Object content) {
+ ContentType atomContent = new ContentType();
+ atomContent.setType("application/xml");
+ atomContent.getContent().add(
+ new JAXBElement(new QName(Constants.ODATA_METADATA_NS, "properties"), content.getClass(), content));
+
+ EntryType atomEntry = new EntryType();
+ atomEntry.getEntryChildren().add(
+ new JAXBElement(new QName(Constants.ATOM_NS, "content"), ContentType.class, atomContent));
+
+ JAXBElement entryElement = new JAXBElement(new QName(Constants.ATOM_NS, "entry"),
+ EntryType.class, atomEntry);
+
+ return entryElement;
+ }
+
+ private static Class>[] getMarshalledClasses() {
+ List> classes = new ArrayList>();
+ classes.add(FeedType.class);
+ classes.add(EntryType.class);
+ classes.add(AssetType.class);
+ classes.add(AccessPolicyType.class);
+ return classes.toArray(new Class>[0]);
+ }
+}
diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ODataAtomUnmarshaller.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ODataAtomUnmarshaller.java
new file mode 100644
index 000000000000..66cecfd0a542
--- /dev/null
+++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ODataAtomUnmarshaller.java
@@ -0,0 +1,235 @@
+/**
+ * Copyright 2012 Microsoft Corporation
+ *
+ * Licensed 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 com.microsoft.windowsazure.services.media.implementation;
+
+import java.io.InputStream;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.ParameterizedType;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBElement;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Unmarshaller;
+import javax.xml.namespace.QName;
+import javax.xml.transform.stream.StreamSource;
+
+import org.w3c.dom.Element;
+
+import com.microsoft.windowsazure.services.core.ServiceException;
+import com.microsoft.windowsazure.services.media.implementation.atom.ContentType;
+import com.microsoft.windowsazure.services.media.implementation.atom.EntryType;
+import com.microsoft.windowsazure.services.media.implementation.atom.FeedType;
+import com.microsoft.windowsazure.services.media.implementation.content.AssetType;
+import com.microsoft.windowsazure.services.media.implementation.content.Constants;
+import com.microsoft.windowsazure.services.media.implementation.content.ODataActionType;
+
+/**
+ * This class implements unmarshalling from OData over Atom into Java
+ * classes.
+ *
+ */
+public class ODataAtomUnmarshaller {
+ private final JAXBContext atomContext;
+ private final JAXBContext mediaContentContext;
+ private final Unmarshaller atomUnmarshaller;
+ private final Unmarshaller mediaContentUnmarshaller;
+
+ /**
+ * @throws JAXBException
+ */
+ public ODataAtomUnmarshaller() throws JAXBException {
+ atomContext = JAXBContext.newInstance(FeedType.class.getPackage().getName());
+ atomUnmarshaller = atomContext.createUnmarshaller();
+ mediaContentContext = JAXBContext.newInstance(AssetType.class.getPackage().getName());
+ mediaContentUnmarshaller = mediaContentContext.createUnmarshaller();
+ }
+
+ /**
+ * Given a stream that contains XML with an atom Feed element at the root,
+ * unmarshal it into Java objects with the given content type in the entries.
+ *
+ * @param
+ *
+ * @param stream
+ * - stream containing the XML data
+ * @param contentType
+ * - Java type to unmarshal the entry contents into
+ * @return an instance of contentType that contains the unmarshalled data.
+ * @throws JAXBException
+ * @throws ServiceException
+ */
+ public List unmarshalFeed(InputStream stream, Class contentType)
+ throws JAXBException, ServiceException {
+ validateNotNull(stream, "stream");
+ validateNotNull(contentType, "contentType");
+
+ List entries = new ArrayList();
+ FeedType feed = unmarshalFeed(stream);
+ Class> marshallingContentType = getMarshallingContentType(contentType);
+
+ for (Object feedChild : feed.getFeedChildren()) {
+ EntryType entry = asEntry(feedChild);
+ if (entry != null) {
+ entries.add(contentFromEntry(contentType, marshallingContentType, entry));
+ }
+ }
+ return entries;
+ }
+
+ /**
+ * Given a stream containing XML with an Atom entry element at the root,
+ * unmarshal it into an instance of contentType
+ *
+ * @param stream
+ * - stream containing XML data
+ * @param contentType
+ * - type of object to return
+ * @return An instance of contentType
+ * @throws JAXBException
+ * @throws ServiceException
+ */
+ public T unmarshalEntry(InputStream stream, Class contentType) throws JAXBException,
+ ServiceException {
+ validateNotNull(stream, "stream");
+ validateNotNull(contentType, "contentType");
+
+ Class> marshallingContentType = getMarshallingContentType(contentType);
+
+ EntryType entry = unmarshalEntry(stream);
+ return contentFromEntry(contentType, marshallingContentType, entry);
+ }
+
+ private T contentFromEntry(Class contentType, Class> marshallingContentType,
+ EntryType entry) throws JAXBException, ServiceException {
+ unmarshalODataContent(entry, contentType);
+ ContentType contentElement = getFirstOfType(ContentType.class, entry.getEntryChildren());
+ Object contentObject = getFirstOfType(marshallingContentType, contentElement.getContent());
+ return constructResultObject(contentType, entry, contentObject);
+ }
+
+ private EntryType asEntry(Object o) {
+ if (o instanceof JAXBElement) {
+ JAXBElement e = (JAXBElement) o;
+ if (e.getDeclaredType() == EntryType.class) {
+ return (EntryType) e.getValue();
+ }
+ }
+ return null;
+ }
+
+ private void unmarshalODataContent(EntryType entry, Class> contentType) throws JAXBException {
+ unmarshalEntryActions(entry);
+ unmarshalEntryContent(entry, contentType);
+ }
+
+ private void unmarshalEntryActions(EntryType entry) throws JAXBException {
+ List