From 6f5b9305a8a3dbd26e3579c22e5bf6666d83eaaa Mon Sep 17 00:00:00 2001 From: Jeff Wilcox Date: Wed, 11 Jul 2012 13:49:11 -0700 Subject: [PATCH 01/70] Updating README to syntax highlight with Java on GitHub --- README.md | 98 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 50 insertions(+), 48 deletions(-) diff --git a/README.md b/README.md index 07c59ee7dee66..b7a28d26212ff 100644 --- a/README.md +++ b/README.md @@ -62,61 +62,63 @@ 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.*; +```java +import com.microsoft.windowsazure.services.core.storage.*; +import com.microsoft.windowsazure.services.blob.client.*; - public class BlobSample { +public class BlobSample { - public static final String storageConnectionString = - "DefaultEndpointsProtocol=http;" + - "AccountName=your_account_name;" + - "AccountKey= your_account_name"; + public static final String storageConnectionString = + "DefaultEndpointsProtocol=http;" + + "AccountName=your_account_name;" + + "AccountKey= your_account_name"; - public static void main(String[] args) + public static void main(String[] args) + { + try { - 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); - } + 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? From 327b9255c722df52f5343488521f33912e4a4a07 Mon Sep 17 00:00:00 2001 From: "Jeff Wilcox @ Microsoft" Date: Wed, 11 Jul 2012 14:00:39 -0700 Subject: [PATCH 02/70] Highlighting the XML --- README.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index b7a28d26212ff..e4db4978d7ef7 100644 --- a/README.md +++ b/README.md @@ -38,11 +38,13 @@ To get the source code of the SDK via git just type: To get the binaries of this library as distributed by Microsoft, ready for use within your project you can also have them installed by the Java package manager Maven. - - com.microsoft.windowsazure - microsoft-windowsazure-api - 0.3.0 - +```xml + + com.microsoft.windowsazure + microsoft-windowsazure-api + 0.3.0 + +``` ##Minimum Requirements From e2ebe0cab470b41b462f5192e5be2c07ee9a3e8c Mon Sep 17 00:00:00 2001 From: Ryan Wike Date: Thu, 19 Jul 2012 09:59:56 -0700 Subject: [PATCH 03/70] test comment --- .../microsoft/windowsazure/services/table/client/CloudTable.java | 1 + 1 file changed, 1 insertion(+) diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/client/CloudTable.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/client/CloudTable.java index 2ec64eceaf53a..457747a1b5e7d 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/client/CloudTable.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/client/CloudTable.java @@ -641,3 +641,4 @@ private String getSharedAccessCanonicalName() { } } } +// test From 22dbebebeb427e8915111fe3255994de2ade5ace Mon Sep 17 00:00:00 2001 From: Ryan Wike Date: Thu, 19 Jul 2012 10:49:48 -0700 Subject: [PATCH 04/70] removed test comment --- .../microsoft/windowsazure/services/table/client/CloudTable.java | 1 - 1 file changed, 1 deletion(-) diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/client/CloudTable.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/client/CloudTable.java index 457747a1b5e7d..2ec64eceaf53a 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/client/CloudTable.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/client/CloudTable.java @@ -641,4 +641,3 @@ private String getSharedAccessCanonicalName() { } } } -// test From 3c48f1c9a5bfdd1fbdd2cca7b530f3901735597e Mon Sep 17 00:00:00 2001 From: Ryan Wike Date: Thu, 19 Jul 2012 14:31:17 -0700 Subject: [PATCH 05/70] Updated docs in CloudTable.java --- .../services/table/client/CloudTable.java | 33 ++++++++++--------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/client/CloudTable.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/client/CloudTable.java index 2ec64eceaf53a..1d75f8c85ba09 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/client/CloudTable.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/client/CloudTable.java @@ -41,24 +41,24 @@ public final class CloudTable { /** - * Holds the name of the table. + * The name of the table. */ String name; /** - * Holds the URI of the table. + * The URI of the table. */ URI uri; /** - * Holds a reference to the associated service client. + * A reference to the associated service client. */ private final CloudTableClient tableServiceClient; /** - * Gets the name of the queue. + * Gets the name of the table. * - * @return A String object that represents the name of the queue. + * @return A String object that represents the name of the table. */ public String getName() { return this.name; @@ -74,9 +74,9 @@ public CloudTableClient getServiceClient() { } /** - * Gets the absolute URI for this queue. + * Gets the absolute URI for this table. * - * @return A java.net.URI object that represents the URI for this queue. + * @return A java.net.URI object that represents the URI for this table. */ public URI getUri() { return this.uri; @@ -85,7 +85,7 @@ public URI getUri() { /** * Creates an instance of the CloudTable class using the specified address and client. * - * @param tableAddress + * @param tableName * A String that represents the table name. * @param client * A {@link CloudTableClient} object that represents the associated service client, and that specifies @@ -148,7 +148,7 @@ public void create() throws StorageException { * safely ignore operation context. * * @throws StorageException - * if an error occurs accessing the storage service, or because the table cannot be + * If an error occurs accessing the storage service, or because the table cannot be * created, or already exists. */ @DoesServiceRequest @@ -188,7 +188,7 @@ public boolean createIfNotExist() throws StorageException { } /** - * Creates the table in the storage service with the specified request options and operation context if it does not + * Creates the table in the storage service with the specified request options and operation context, if it does not * already exist. * * @param options @@ -300,7 +300,7 @@ public void delete(TableRequestOptions options, OperationContext opContext) thro } /** - * Deletes the table from the storage service if it exists. + * Deletes the table from the storage service, if it exists. * * @return A value of true if the table existed in the storage service and has been deleted, otherwise * false. @@ -445,7 +445,7 @@ public void uploadPermissions(final TablePermissions permissions) throws Storage } /** - * Uploads the container's permissions using the specified request options and operation context. + * Uploads the table's permissions using the specified request options and operation context. * * @param permissions * A {@link TablePermissions} object that represents the permissions to upload. @@ -533,7 +533,7 @@ public TablePermissions downloadPermissions() throws StorageException { * is used to track requests to the storage service, and to provide additional runtime information about * the operation. * - * @return A {@link BlobContainerPermissions} object that represents the container's permissions. + * @return A {@link TablePermissions} object that represents the table's permissions. * * @throws StorageException * If a storage service error occurred. @@ -592,10 +592,13 @@ public TablePermissions execute(final CloudTableClient client, final CloudTable * The access policy for the shared access signature. * @param accessPolicyIdentifier * A table-level access policy. - * @return a shared access signature for the container. + * @return A String containing the shared access signature for the container. * @throws InvalidKeyException + * If an invalid key was passed. * @throws StorageException + * If a storage service error occurred. * @throws IllegalArgumentException + * If an unexpected value is passed. */ public String generateSharedAccessSignature(final SharedAccessTablePolicy policy, final String accessPolicyIdentifier, final String startPartitionKey, final String startRowKey, @@ -629,7 +632,7 @@ public String generateSharedAccessSignature(final SharedAccessTablePolicy policy /** * Returns the canonical name for shared access. * - * @return the canonical name for shared access. + * @return A String containing the canonical name for shared access. */ private String getSharedAccessCanonicalName() { if (this.tableServiceClient.isUsePathStyleUris()) { From bdbf460550da0917c4729595749df9598c6b086d Mon Sep 17 00:00:00 2001 From: Ryan Wike Date: Wed, 1 Aug 2012 15:46:07 -0700 Subject: [PATCH 06/70] Updated API docs --- .../services/queue/client/QueuePermissions.java | 15 +++++++++------ .../services/table/client/TablePermissions.java | 7 +++++-- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/queue/client/QueuePermissions.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/queue/client/QueuePermissions.java index 6454f1b86fe8f..b55d30e820c70 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/queue/client/QueuePermissions.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/queue/client/QueuePermissions.java @@ -26,30 +26,33 @@ public final class QueuePermissions { /** - * Gets the set of shared access policies for the table. + * Gets the set of shared access policies for the queue. */ private HashMap sharedAccessPolicies; /** - * Creates an instance of the TablePermissions class. + * Creates an instance of the QueuePermissions class. */ public QueuePermissions() { this.sharedAccessPolicies = new HashMap(); } /** - * Returns the set of shared access policies for the table. + * Returns the set of shared access policies for the queue. * - * @return A HashMap object of {@link SharedAccessTablePolicy} objects that represent the set of shared - * access policies for the table. + * @return A HashMap object of {@link SharedAccessQueuePolicy} objects that represent the set of shared + * access policies for the queue. */ public HashMap getSharedAccessPolicies() { return this.sharedAccessPolicies; } /** + * Sets the set of shared access policies for the queue. + * * @param sharedAccessPolicies - * the sharedAccessPolicies to set + * A HashMap object of {@link SharedAccessQueuePolicy} objects that represent the set of shared + * access policies for the table. */ public void setSharedAccessPolicies(final HashMap sharedAccessPolicies) { this.sharedAccessPolicies = sharedAccessPolicies; diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/client/TablePermissions.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/client/TablePermissions.java index 4ba7bd8bdfa1c..3ad5d4dbb18b9 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/client/TablePermissions.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/client/TablePermissions.java @@ -18,7 +18,7 @@ import java.util.HashMap; /** - * Represents the permissions for a container. + * Represents the permissions for a table. */ public final class TablePermissions { @@ -46,8 +46,11 @@ public HashMap getSharedAccessPolicies() { } /** + * Sets the set of shared access policies for the table. + * * @param sharedAccessPolicies - * the sharedAccessPolicies to set + * A HashMap object of {@link SharedAccessTablePolicy} objects that represent the set of shared + * access policies for the table. */ public void setSharedAccessPolicies(final HashMap sharedAccessPolicies) { this.sharedAccessPolicies = sharedAccessPolicies; From fe2c15ecfe1d03df0fde15e7750bf47b9da1516c Mon Sep 17 00:00:00 2001 From: Ryan Wike Date: Wed, 1 Aug 2012 16:02:27 -0700 Subject: [PATCH 07/70] Updated API docs --- .../services/queue/client/QueuePermissions.java | 4 ++-- .../services/table/client/TablePermissions.java | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/queue/client/QueuePermissions.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/queue/client/QueuePermissions.java index b55d30e820c70..c502533633f14 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/queue/client/QueuePermissions.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/queue/client/QueuePermissions.java @@ -51,8 +51,8 @@ public HashMap getSharedAccessPolicies() { * Sets the set of shared access policies for the queue. * * @param sharedAccessPolicies - * A HashMap object of {@link SharedAccessQueuePolicy} objects that represent the set of shared - * access policies for the table. + * The set of shared access policies to set for the queue, represented by a HashMap object of + * {@link SharedAccessQueuePolicy} objects. */ public void setSharedAccessPolicies(final HashMap sharedAccessPolicies) { this.sharedAccessPolicies = sharedAccessPolicies; diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/client/TablePermissions.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/client/TablePermissions.java index 3ad5d4dbb18b9..9236b99ced86e 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/client/TablePermissions.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/client/TablePermissions.java @@ -17,6 +17,8 @@ import java.util.HashMap; +import com.microsoft.windowsazure.services.queue.client.SharedAccessQueuePolicy; + /** * Represents the permissions for a table. */ @@ -49,8 +51,8 @@ public HashMap getSharedAccessPolicies() { * Sets the set of shared access policies for the table. * * @param sharedAccessPolicies - * A HashMap object of {@link SharedAccessTablePolicy} objects that represent the set of shared - * access policies for the table. + * The set of shared access policies to set for the table, represented by a HashMap object of + * {@link SharedAccessTablePolicy} objects. */ public void setSharedAccessPolicies(final HashMap sharedAccessPolicies) { this.sharedAccessPolicies = sharedAccessPolicies; From 77c9e0323dac9b0aaf3c3dcec43761bb2c732c9f Mon Sep 17 00:00:00 2001 From: Ryan Wike Date: Wed, 1 Aug 2012 16:30:43 -0700 Subject: [PATCH 08/70] Updated API docs --- .../services/queue/client/SharedAccessQueuePermissions.java | 2 +- .../services/table/client/SharedAccessTablePermissions.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/queue/client/SharedAccessQueuePermissions.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/queue/client/SharedAccessQueuePermissions.java index bec37d8d33d12..10daa8af1f721 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/queue/client/SharedAccessQueuePermissions.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/queue/client/SharedAccessQueuePermissions.java @@ -51,7 +51,7 @@ public enum SharedAccessQueuePermissions { * * @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 SharedAccessQueuePermissions 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/table/client/SharedAccessTablePermissions.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/client/SharedAccessTablePermissions.java index 3e75ac8e196c3..649f4208e6f19 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/client/SharedAccessTablePermissions.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/client/SharedAccessTablePermissions.java @@ -51,7 +51,7 @@ public enum SharedAccessTablePermissions { * * @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 SharedAccessTablePermissions values * corresponding to the specified byte value. */ protected static EnumSet fromByte(final byte value) { From cbc5a38f5f6819e79e8a5423ae88e2bed62afec0 Mon Sep 17 00:00:00 2001 From: Ryan Wike Date: Thu, 2 Aug 2012 11:04:08 -0700 Subject: [PATCH 09/70] Updated API docs --- .../blob/client/SharedAccessBlobPolicy.java | 2 +- .../queue/client/SharedAccessQueuePolicy.java | 32 +++++++++++++------ .../table/client/SharedAccessTablePolicy.java | 30 ++++++++++++----- 3 files changed, 46 insertions(+), 18 deletions(-) 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 937b558ab4c6b..ed8e58c69df7b 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,7 +120,7 @@ public static String permissionsToString(final EnumSetSharedAccessPolicy class. + * Creates an instance of the SharedAccessBlobPolicy class. * */ public SharedAccessBlobPolicy() { // Empty Default Ctor diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/queue/client/SharedAccessQueuePolicy.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/queue/client/SharedAccessQueuePolicy.java index 54bdf677ad44f..033e8d5056456 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/queue/client/SharedAccessQueuePolicy.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/queue/client/SharedAccessQueuePolicy.java @@ -31,7 +31,7 @@ public final class SharedAccessQueuePolicy { * * @param value * A String that represents the shared access permissions. The string must contain one or - * more of the following values. Note they must be lowercase, and the order that they are specified must + * more of the following values. Note that they must be lower case, and the order that they are specified must * be in the order of "rwdl". *
    *
  • d: Delete access.
  • @@ -40,7 +40,7 @@ public final class SharedAccessQueuePolicy { *
  • w: Write access.
  • *
* - * @return A java.util.EnumSet object that contains {@link SharedAccessTablePermissions} values that + * @return A java.util.EnumSet object that contains {@link SharedAccessQueuePermissions} values that * represents the set of shared access permissions. */ public static EnumSet permissionsFromString(final String value) { @@ -121,52 +121,66 @@ public static String permissionsToString(final EnumSetSharedAccessTablePolicy class. + * Creates an instance of the SharedAccessQueuePolicy class. * */ public SharedAccessQueuePolicy() { // 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 SharedAccessQueuePermissions} 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 SharedAccessQueuePermissions} 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/table/client/SharedAccessTablePolicy.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/client/SharedAccessTablePolicy.java index adfaffb35385a..d5fc4c780104a 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/client/SharedAccessTablePolicy.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/client/SharedAccessTablePolicy.java @@ -30,7 +30,7 @@ public final class SharedAccessTablePolicy { * * @param value * A String that represents the shared access permissions. The string must contain one or - * more of the following values. Note they must be lowercase, and the order that they are specified must + * more of the following values. Note that they must be lower case, and the order that they are specified must * be in the order of "rwdl". *
    *
  • d: Delete access.
  • @@ -72,7 +72,7 @@ public static EnumSet permissionsFromString(final * Converts the permissions specified for the shared access policy to a string. * * @param permissions - * A {@link SharedAccessTablePermissions} object that represents the shared access permissions. + * A set of {@link SharedAccessTablePermissions} objects that represent the shared access permissions. * * @return A String that represents the shared access permissions in the "rwdl" format, which is * described at {@link SharedAccessTablePermissions#permissionsFromString}. @@ -127,45 +127,59 @@ public SharedAccessTablePolicy() { } /** - * @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 SharedAccessTablePermissions} 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 SharedAccessTablePermissions} 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; From d7bb6c7438cd7a7f9a0a25a0932f792eed7a5f86 Mon Sep 17 00:00:00 2001 From: Ryan Wike Date: Thu, 2 Aug 2012 11:56:07 -0700 Subject: [PATCH 10/70] Updated API docs --- .../windowsazure/services/queue/client/CloudQueue.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/queue/client/CloudQueue.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/queue/client/CloudQueue.java index f77e7931062e0..769a3794407a8 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/queue/client/CloudQueue.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/queue/client/CloudQueue.java @@ -1540,10 +1540,13 @@ public QueuePermissions execute(final CloudQueueClient client, final CloudQueue * The access policy for the shared access signature. * @param groupPolicyIdentifier * A queue-level access policy. - * @return a shared access signature for the container. + * @return A shared access signature for the container. * @throws InvalidKeyException + * If an invalid key was passed. * @throws StorageException + * If a storage service error occurred. * @throws IllegalArgumentException + * If an unexpected value is passed. */ public String generateSharedAccessSignature(final SharedAccessQueuePolicy policy, final String groupPolicyIdentifier) throws InvalidKeyException, StorageException { From f8c9ffeac354a8d651de6c920d13f9a2867ad5b1 Mon Sep 17 00:00:00 2001 From: Ryan Wike Date: Thu, 2 Aug 2012 15:35:23 -0700 Subject: [PATCH 11/70] Updated API docs --- .../blob/client/SharedAccessBlobPolicy.java | 27 ++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) 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 ed8e58c69df7b..943034dac6ab5 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 @@ -18,6 +18,7 @@ import java.util.EnumSet; import com.microsoft.windowsazure.services.core.storage.Constants; +import com.microsoft.windowsazure.services.table.client.SharedAccessTablePermissions; /** * Represents a shared access policy, which specifies the start time, expiry time, and permissions for a shared access @@ -127,45 +128,59 @@ public SharedAccessBlobPolicy() { } /** - * @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; From a9f00e08272745f7ade15ccefd1542eade8694a5 Mon Sep 17 00:00:00 2001 From: Ryan Wike Date: Thu, 2 Aug 2012 15:41:10 -0700 Subject: [PATCH 12/70] Updated API docs --- .../services/blob/client/SharedAccessBlobPermissions.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 c8dc1c17dff8e..5475705a29fd6 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) { From 591c8e870cf7d73212e743c2221d67ff65551f53 Mon Sep 17 00:00:00 2001 From: Ryan Wike Date: Fri, 3 Aug 2012 16:17:02 -0700 Subject: [PATCH 13/70] Updated API docs --- .../services/blob/client/CloudBlob.java | 53 ++++++++++--------- 1 file changed, 28 insertions(+), 25 deletions(-) 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 a434b75f3de7b..c4cac77d23c49 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 @@ -220,8 +220,9 @@ protected CloudBlob(final CloudBlob otherBlob) { * Acquires a new lease on the blob. * * @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. + * 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, @@ -242,8 +243,9 @@ public final String acquireLease(final Integer leaseTimeInSeconds, final String * Acquires a new lease on the blob using the specified 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. + * 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, @@ -253,10 +255,10 @@ public final String acquireLease(final Integer leaseTimeInSeconds, final String * 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,14 +340,14 @@ 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 + * Breaks the existing lease by rejecting future requests to renew the 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 expires. * 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. + * @return The time, in seconds, remaining in the current lease period. * * @throws StorageException * If a storage service error occurred. @@ -356,21 +358,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, by rejecting future requests + * to renew the 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 expires. * 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 +2002,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 +2022,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 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. * From 4273cc8f30e3295950077ae8ad09d4089319704c Mon Sep 17 00:00:00 2001 From: Ryan Wike Date: Fri, 3 Aug 2012 16:50:21 -0700 Subject: [PATCH 14/70] Updated API docs --- .../microsoft/windowsazure/services/blob/client/CloudBlob.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 c4cac77d23c49..a49953593e621 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 @@ -219,7 +219,7 @@ protected CloudBlob(final CloudBlob otherBlob) { /** * Acquires a new lease on the blob. * - * @param visibilityTimeoutInSeconds + * @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. From 896cd9b31749cdce8d23f187debd725cf42d482c Mon Sep 17 00:00:00 2001 From: Ryan Wike Date: Fri, 3 Aug 2012 16:51:02 -0700 Subject: [PATCH 15/70] Updated API docs --- .../microsoft/windowsazure/services/blob/client/CloudBlob.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 a49953593e621..fc3bfd9ab1b96 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 @@ -242,7 +242,7 @@ public final String acquireLease(final Integer leaseTimeInSeconds, final String /** * Acquires a new lease on the blob using the specified request options and operation context. * - * @param visibilityTimeoutInSeconds + * @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. From eeb920d4a04ad935d4d6c3e5cbe01e71543eaed4 Mon Sep 17 00:00:00 2001 From: Ryan Wike Date: Sat, 4 Aug 2012 11:08:06 -0700 Subject: [PATCH 16/70] Updated API docs --- .../services/blob/client/CloudBlob.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) 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 fc3bfd9ab1b96..41e76bd11b862 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,7 +217,7 @@ 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 leaseTimeInSeconds * Specifies the span of time for which to acquire the lease, in seconds. @@ -240,7 +240,8 @@ 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 leaseTimeInSeconds * Specifies the span of time for which to acquire the lease, in seconds. @@ -253,10 +254,12 @@ 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}). + * * @param opContext * 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 @@ -347,7 +350,7 @@ protected final void assertCorrectBlobType() throws StorageException { * Specifies the time to wait, in seconds, until the current lease expires. * 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 current lease period. + * @return The time, in seconds, remaining in the lease period. * * @throws StorageException * If a storage service error occurred. @@ -2022,8 +2025,8 @@ public final void changeLease(final String proposedLeaseId, final AccessConditio } /** - * Changes the existing lease ID to the proposed lease Id with the specified 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, From a9cd96e1e456d252dc2fa45438f7b2efa5645fe4 Mon Sep 17 00:00:00 2001 From: Ryan Wike Date: Sat, 4 Aug 2012 11:08:22 -0700 Subject: [PATCH 17/70] Updated API docs --- .../blob/client/CloudBlobContainer.java | 105 ++++++++++-------- 1 file changed, 58 insertions(+), 47 deletions(-) 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 ab8bd64df564b..3d2c08ce381ed 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 + * Breaks the existing lease by rejecting future requests to renew the 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 expires. * 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, by rejecting future requests + * to renew the 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 expires. * 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. * From a946e3ab450a24572d356bd4e3ddb7bffa1f83f2 Mon Sep 17 00:00:00 2001 From: Ryan Wike Date: Sat, 4 Aug 2012 11:18:33 -0700 Subject: [PATCH 18/70] Updated API docs --- .../windowsazure/services/core/storage/LeaseDuration.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 2c807c8dd57ff..8e795b831374f 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. */ From 04cad2e7cc845d2410f0c92ccfe096d1b464e524 Mon Sep 17 00:00:00 2001 From: Ryan Wike Date: Sat, 4 Aug 2012 11:27:37 -0700 Subject: [PATCH 19/70] Updated API docs --- .../windowsazure/services/core/storage/LeaseState.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 c2c7f9a79e3ff..9bbd28f83ecd3 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. */ From 8c4afe294ff36f5fefee1f85ae1a2d014c000839 Mon Sep 17 00:00:00 2001 From: Ryan Wike Date: Sat, 4 Aug 2012 13:18:36 -0700 Subject: [PATCH 20/70] Updated API docs --- .../blob/client/BlobContainerProperties.java | 32 ++++++++++++------- 1 file changed, 21 insertions(+), 11 deletions(-) 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 4b34574466fd8..599687b285d76 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; From 8b80a9fe90588c8736a07168a8fc9d235bab7a85 Mon Sep 17 00:00:00 2001 From: Ryan Wike Date: Mon, 6 Aug 2012 15:28:51 -0700 Subject: [PATCH 21/70] Updated API docs --- .../services/blob/client/BlobProperties.java | 94 +++++++++++++------ 1 file changed, 63 insertions(+), 31 deletions(-) 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 81c3faae35c57..9bb09d0b23f64 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; From b8f2f886cc9304ac2dcbe80881957068a96267ec Mon Sep 17 00:00:00 2001 From: Ryan Wike Date: Tue, 7 Aug 2012 10:00:17 -0700 Subject: [PATCH 22/70] Updated API docs --- .../services/blob/client/CopyState.java | 77 ++++++++++++++++++- 1 file changed, 75 insertions(+), 2 deletions(-) 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 6c1a9e921afe0..c6bb3f2829ff3 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 name of the container. + * + * @return A string containing the name 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 name of the container. + * + * @param copyId + * The name 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; } From da443e222723db20ec45bbee9404d2f9c307b14f Mon Sep 17 00:00:00 2001 From: Ryan Wike Date: Tue, 7 Aug 2012 10:01:22 -0700 Subject: [PATCH 23/70] Updated API docs --- .../microsoft/windowsazure/services/blob/client/CopyStatus.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 9e4d13c91dab5..33809c15c10c8 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, From 74c2b82f8f1e38ba82bdb72f62ee06be8f740734 Mon Sep 17 00:00:00 2001 From: Ryan Wike Date: Tue, 7 Aug 2012 10:08:33 -0700 Subject: [PATCH 24/70] Updated API docs --- .../services/blob/client/BlobAttributes.java | 42 +++++++++++++++++-- 1 file changed, 39 insertions(+), 3 deletions(-) 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 f0f782200ab70..64f83ee08e53a 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; } From 6ba7d12a55d2c610184b0f101c3d1449371104b4 Mon Sep 17 00:00:00 2001 From: Chris Tavares Date: Tue, 7 Aug 2012 13:44:26 -0700 Subject: [PATCH 25/70] Fixing client tests so they pull credentials from env vars --- .../windowsazure/services/blob/client/BlobTestBase.java | 6 +++++- .../windowsazure/services/queue/client/QueueTestBase.java | 6 +++++- .../windowsazure/services/table/client/TableTestBase.java | 6 +++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/blob/client/BlobTestBase.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/blob/client/BlobTestBase.java index bd0671e3ece19..938db64c06d4a 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/blob/client/BlobTestBase.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/blob/client/BlobTestBase.java @@ -51,7 +51,11 @@ public static void setup() throws URISyntaxException, StorageException, InvalidK httpAcc = CloudStorageAccount.getDevelopmentStorageAccount(); } else { - httpAcc = CloudStorageAccount.parse(CLOUD_ACCOUNT_HTTP); + String cloudAccount = CLOUD_ACCOUNT_HTTP; + cloudAccount = cloudAccount.replace("[ACCOUNT NAME]", System.getenv("blob.accountName")); + cloudAccount = cloudAccount.replace("[ACCOUNT KEY]", System.getenv("blob.accountKey")); + + httpAcc = CloudStorageAccount.parse(cloudAccount); } bClient = httpAcc.createCloudBlobClient(); diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/queue/client/QueueTestBase.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/queue/client/QueueTestBase.java index feb5b1ceb4a10..8144378d8577b 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/queue/client/QueueTestBase.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/queue/client/QueueTestBase.java @@ -52,7 +52,11 @@ public static void setup() throws URISyntaxException, StorageException, InvalidK httpAcc = CloudStorageAccount.getDevelopmentStorageAccount(); } else { - httpAcc = CloudStorageAccount.parse(CLOUD_ACCOUNT_HTTP); + String cloudAccount = CLOUD_ACCOUNT_HTTP; + cloudAccount = cloudAccount.replace("[ACCOUNT NAME]", System.getenv("queue.accountName")); + cloudAccount = cloudAccount.replace("[ACCOUNT KEY]", System.getenv("queue.accountKey")); + + httpAcc = CloudStorageAccount.parse(cloudAccount); } qClient = httpAcc.createCloudQueueClient(); diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/table/client/TableTestBase.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/table/client/TableTestBase.java index d235ed326cc69..7ba57b75322c8 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/table/client/TableTestBase.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/table/client/TableTestBase.java @@ -577,7 +577,11 @@ public static void setup() throws URISyntaxException, StorageException, InvalidK httpAcc = CloudStorageAccount.getDevelopmentStorageAccount(); } else { - httpAcc = CloudStorageAccount.parse(CLOUD_ACCOUNT_HTTP); + String cloudAccount = CLOUD_ACCOUNT_HTTP; + cloudAccount = cloudAccount.replace("[ACCOUNT NAME]", System.getenv("table.accountName")); + cloudAccount = cloudAccount.replace("[ACCOUNT KEY]", System.getenv("table.accountKey")); + + httpAcc = CloudStorageAccount.parse(cloudAccount); } bClient = httpAcc.createCloudBlobClient(); From 811d1e1080f1b021cc9f19578a280ede099a38eb Mon Sep 17 00:00:00 2001 From: Ryan Wike Date: Wed, 8 Aug 2012 09:29:56 -0700 Subject: [PATCH 26/70] Removed import statement that was accidentally added. --- .../services/blob/client/SharedAccessBlobPolicy.java | 1 - .../windowsazure/services/table/client/TablePermissions.java | 1 - 2 files changed, 2 deletions(-) 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 943034dac6ab5..8d9c708aa56c9 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 @@ -18,7 +18,6 @@ import java.util.EnumSet; import com.microsoft.windowsazure.services.core.storage.Constants; -import com.microsoft.windowsazure.services.table.client.SharedAccessTablePermissions; /** * Represents a shared access policy, which specifies the start time, expiry time, and permissions for a shared access diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/client/TablePermissions.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/client/TablePermissions.java index 9236b99ced86e..d981a820d6b42 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/client/TablePermissions.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/client/TablePermissions.java @@ -17,7 +17,6 @@ import java.util.HashMap; -import com.microsoft.windowsazure.services.queue.client.SharedAccessQueuePolicy; /** * Represents the permissions for a table. From 74d474c3b87bfebe2cb9f42d6d8782275f5c776a Mon Sep 17 00:00:00 2001 From: Ryan Wike Date: Fri, 17 Aug 2012 15:45:16 -0700 Subject: [PATCH 27/70] Tech review fixes --- .../windowsazure/services/blob/client/CopyState.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 c6bb3f2829ff3..a8d60323e9fe6 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 @@ -65,9 +65,9 @@ public CopyState() { } /** - * Gets the name of the container. + * Gets the copy ID of the container. * - * @return A string containing the name of the container. + * @return A string containing the copy ID of the container. */ public String getCopyId() { return this.copyId; @@ -123,10 +123,10 @@ public String getStatusDescription() { } /** - * Sets the name of the container. + * Sets the copy ID of the container. * * @param copyId - * The name of the container to set. + * The copy ID of the container to set. * */ public void setCopyId(final String copyId) { From 6fe29bebee19ae4594c03e66824eb2d45da030f4 Mon Sep 17 00:00:00 2001 From: Ryan Wike Date: Fri, 17 Aug 2012 16:06:53 -0700 Subject: [PATCH 28/70] Tech review fixes --- .../windowsazure/services/queue/client/CloudQueue.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/queue/client/CloudQueue.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/queue/client/CloudQueue.java index 769a3794407a8..1dbfd191a8e16 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/queue/client/CloudQueue.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/queue/client/CloudQueue.java @@ -1540,7 +1540,7 @@ public QueuePermissions execute(final CloudQueueClient client, final CloudQueue * The access policy for the shared access signature. * @param groupPolicyIdentifier * A queue-level access policy. - * @return A shared access signature for the container. + * @return A shared access signature for the queue. * @throws InvalidKeyException * If an invalid key was passed. * @throws StorageException From ef7c5f2f95d5564bf32f5f0ef95b84062005cc17 Mon Sep 17 00:00:00 2001 From: Ryan Wike Date: Fri, 17 Aug 2012 16:10:33 -0700 Subject: [PATCH 29/70] Tech review fixes --- .../windowsazure/services/table/client/CloudTable.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/client/CloudTable.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/client/CloudTable.java index 1d75f8c85ba09..81f75835ae737 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/client/CloudTable.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/table/client/CloudTable.java @@ -592,7 +592,7 @@ public TablePermissions execute(final CloudTableClient client, final CloudTable * The access policy for the shared access signature. * @param accessPolicyIdentifier * A table-level access policy. - * @return A String containing the shared access signature for the container. + * @return A String containing the shared access signature for the table. * @throws InvalidKeyException * If an invalid key was passed. * @throws StorageException From a26c6efc10d51732a543d56c6d803287b3237e4f Mon Sep 17 00:00:00 2001 From: Ryan Wike Date: Thu, 23 Aug 2012 13:33:44 -0700 Subject: [PATCH 30/70] Tech review fixes --- .../windowsazure/services/blob/client/CloudBlob.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) 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 41e76bd11b862..bc87cebfa32cb 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 @@ -343,11 +343,11 @@ protected final void assertCorrectBlobType() throws StorageException { } /** - * Breaks the existing lease by rejecting future requests to renew the 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 time to wait, in seconds, until the current lease expires. + * 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. @@ -361,11 +361,11 @@ public final long breakLease(final Integer breakPeriodInSeconds) throws StorageE } /** - * Breaks the existing lease, using the specified request options and operation context, by rejecting future requests - * to renew the 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 time to wait, in seconds, until the current lease expires. + * 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 From ab51ef6eb7356e573654ccdbd1437589a189f49f Mon Sep 17 00:00:00 2001 From: Ryan Wike Date: Thu, 23 Aug 2012 13:41:08 -0700 Subject: [PATCH 31/70] Tech review fixes --- .../services/blob/client/CloudBlobContainer.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) 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 3d2c08ce381ed..6cd9752c046e7 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 @@ -1890,11 +1890,11 @@ public Void execute(final CloudBlobClient client, final CloudBlobContainer conta } /** - * Breaks the existing lease by rejecting future requests to renew the 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 time to wait, in seconds, until the current lease expires. + * 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. @@ -1908,11 +1908,11 @@ public final long breakLease(final Integer breakPeriodInSeconds) throws StorageE } /** - * Breaks the existing lease, using the specified request options and operation context, by rejecting future requests - * to renew the 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 time to wait, in seconds, until the current lease expires. + * 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 From eed17baab25e39e9d87ba9d9615dc3835406d0ae Mon Sep 17 00:00:00 2001 From: Joost de Nijs Date: Tue, 11 Sep 2012 15:36:53 -0700 Subject: [PATCH 32/70] correctly spelling special --- ChangeLog.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 52bccf4da0b13..17345e70ce1af 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -7,7 +7,7 @@ * 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 speical characters when serializing entity to XML in Table Service Layer + * 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 From 1c798bac713451273847a664e31e80db36a2f18e Mon Sep 17 00:00:00 2001 From: Chris Tavares Date: Mon, 17 Sep 2012 14:41:33 -0700 Subject: [PATCH 33/70] Added xjc generated classes from Atom schema --- .../implementation/atom/CategoryType.java | 208 +++++++ .../implementation/atom/ContentType.java | 225 +++++++ .../implementation/atom/DateTimeType.java | 153 +++++ .../media/implementation/atom/EntryType.java | 206 +++++++ .../media/implementation/atom/FeedType.java | 209 +++++++ .../implementation/atom/GeneratorType.java | 210 +++++++ .../media/implementation/atom/IconType.java | 156 +++++ .../media/implementation/atom/IdType.java | 156 +++++ .../media/implementation/atom/LinkType.java | 324 ++++++++++ .../media/implementation/atom/LogoType.java | 156 +++++ .../implementation/atom/ObjectFactory.java | 556 ++++++++++++++++++ .../media/implementation/atom/PersonType.java | 179 ++++++ .../media/implementation/atom/SourceType.java | 206 +++++++ .../media/implementation/atom/TextType.java | 206 +++++++ .../media/implementation/atom/UriType.java | 152 +++++ .../implementation/atom/package-info.java | 9 + 16 files changed, 3311 insertions(+) create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/atom/CategoryType.java create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/atom/ContentType.java create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/atom/DateTimeType.java create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/atom/EntryType.java create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/atom/FeedType.java create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/atom/GeneratorType.java create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/atom/IconType.java create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/atom/IdType.java create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/atom/LinkType.java create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/atom/LogoType.java create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/atom/ObjectFactory.java create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/atom/PersonType.java create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/atom/SourceType.java create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/atom/TextType.java create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/atom/UriType.java create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/atom/package-info.java diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/atom/CategoryType.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/atom/CategoryType.java new file mode 100644 index 0000000000000..3e0138fef82c8 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/atom/CategoryType.java @@ -0,0 +1,208 @@ +// +// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.1.10 in JDK 6 +// See http://java.sun.com/xml/jaxb +// Any modifications to this file will be lost upon recompilation of the source schema. +// Generated on: 2012.09.17 at 02:31:28 PM PDT +// + + +package com.microsoft.windowsazure.services.media.implementation.atom; + +import java.util.HashMap; +import java.util.Map; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAnyAttribute; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlSchemaType; +import javax.xml.bind.annotation.XmlType; +import javax.xml.bind.annotation.adapters.CollapsedStringAdapter; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; +import javax.xml.namespace.QName; + + +/** + * + * The Atom cagegory construct is defined in section 4.2.2 of the format spec. + * + * + *

    Java class for categoryType complex type. + * + *

    The following schema fragment specifies the expected content contained within this class. + * + *

    + * <complexType name="categoryType">
    + *   <complexContent>
    + *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
    + *       <attGroup ref="{http://www.w3.org/2005/Atom}commonAttributes"/>
    + *       <attribute name="term" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
    + *       <attribute name="scheme" type="{http://www.w3.org/2001/XMLSchema}anyURI" />
    + *       <attribute name="label" type="{http://www.w3.org/2001/XMLSchema}string" />
    + *       <anyAttribute namespace='##other'/>
    + *     </restriction>
    + *   </complexContent>
    + * </complexType>
    + * 
    + * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "categoryType") +public class CategoryType { + + @XmlAttribute(required = true) + protected String term; + @XmlAttribute + @XmlSchemaType(name = "anyURI") + protected String scheme; + @XmlAttribute + protected String label; + @XmlAttribute(namespace = "http://www.w3.org/XML/1998/namespace") + @XmlSchemaType(name = "anyURI") + protected String base; + @XmlAttribute(namespace = "http://www.w3.org/XML/1998/namespace") + @XmlJavaTypeAdapter(CollapsedStringAdapter.class) + @XmlSchemaType(name = "language") + protected String lang; + @XmlAnyAttribute + private Map otherAttributes = new HashMap(); + + /** + * Gets the value of the term property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getTerm() { + return term; + } + + /** + * Sets the value of the term property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setTerm(String value) { + this.term = value; + } + + /** + * Gets the value of the scheme property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getScheme() { + return scheme; + } + + /** + * Sets the value of the scheme property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setScheme(String value) { + this.scheme = value; + } + + /** + * Gets the value of the label property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getLabel() { + return label; + } + + /** + * Sets the value of the label property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setLabel(String value) { + this.label = value; + } + + /** + * Gets the value of the base property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getBase() { + return base; + } + + /** + * Sets the value of the base property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setBase(String value) { + this.base = value; + } + + /** + * Gets the value of the lang property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getLang() { + return lang; + } + + /** + * Sets the value of the lang property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setLang(String value) { + this.lang = value; + } + + /** + * Gets a map that contains attributes that aren't bound to any typed property on this class. + * + *

    + * the map is keyed by the name of the attribute and + * the value is the string value of the attribute. + * + * the map returned by this method is live, and you can add new attribute + * by updating the map directly. Because of this design, there's no setter. + * + * + * @return + * always non-null + */ + public Map getOtherAttributes() { + return otherAttributes; + } + +} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/atom/ContentType.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/atom/ContentType.java new file mode 100644 index 0000000000000..8e03e7cb2b4a8 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/atom/ContentType.java @@ -0,0 +1,225 @@ +// +// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.1.10 in JDK 6 +// See http://java.sun.com/xml/jaxb +// Any modifications to this file will be lost upon recompilation of the source schema. +// Generated on: 2012.09.17 at 02:31:28 PM PDT +// + + +package com.microsoft.windowsazure.services.media.implementation.atom; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAnyAttribute; +import javax.xml.bind.annotation.XmlAnyElement; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlMixed; +import javax.xml.bind.annotation.XmlSchemaType; +import javax.xml.bind.annotation.XmlType; +import javax.xml.bind.annotation.adapters.CollapsedStringAdapter; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; +import javax.xml.namespace.QName; + + +/** + * + * The Atom content construct is defined in section 4.1.3 of the format spec. + * + * + *

    Java class for contentType complex type. + * + *

    The following schema fragment specifies the expected content contained within this class. + * + *

    + * <complexType name="contentType">
    + *   <complexContent>
    + *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
    + *       <sequence>
    + *         <any namespace='##other' maxOccurs="unbounded" minOccurs="0"/>
    + *       </sequence>
    + *       <attGroup ref="{http://www.w3.org/2005/Atom}commonAttributes"/>
    + *       <attribute name="type" type="{http://www.w3.org/2001/XMLSchema}string" />
    + *       <attribute name="src" type="{http://www.w3.org/2001/XMLSchema}anyURI" />
    + *       <anyAttribute namespace='##other'/>
    + *     </restriction>
    + *   </complexContent>
    + * </complexType>
    + * 
    + * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "contentType", propOrder = { + "content" +}) +public class ContentType { + + @XmlMixed + @XmlAnyElement(lax = true) + protected List content; + @XmlAttribute + protected String type; + @XmlAttribute + @XmlSchemaType(name = "anyURI") + protected String src; + @XmlAttribute(namespace = "http://www.w3.org/XML/1998/namespace") + @XmlSchemaType(name = "anyURI") + protected String base; + @XmlAttribute(namespace = "http://www.w3.org/XML/1998/namespace") + @XmlJavaTypeAdapter(CollapsedStringAdapter.class) + @XmlSchemaType(name = "language") + protected String lang; + @XmlAnyAttribute + private Map otherAttributes = new HashMap(); + + /** + * + * The Atom content construct is defined in section 4.1.3 of the format spec. + * Gets the value of the content property. + * + *

    + * This accessor method returns a reference to the live list, + * not a snapshot. Therefore any modification you make to the + * returned list will be present inside the JAXB object. + * This is why there is not a set method for the content property. + * + *

    + * For example, to add a new item, do as follows: + *

    +     *    getContent().add(newItem);
    +     * 
    + * + * + *

    + * Objects of the following type(s) are allowed in the list + * {@link Object } + * {@link String } + * + * + */ + public List getContent() { + if (content == null) { + content = new ArrayList(); + } + return this.content; + } + + /** + * Gets the value of the type property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getType() { + return type; + } + + /** + * Sets the value of the type property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setType(String value) { + this.type = value; + } + + /** + * Gets the value of the src property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getSrc() { + return src; + } + + /** + * Sets the value of the src property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setSrc(String value) { + this.src = value; + } + + /** + * Gets the value of the base property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getBase() { + return base; + } + + /** + * Sets the value of the base property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setBase(String value) { + this.base = value; + } + + /** + * Gets the value of the lang property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getLang() { + return lang; + } + + /** + * Sets the value of the lang property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setLang(String value) { + this.lang = value; + } + + /** + * Gets a map that contains attributes that aren't bound to any typed property on this class. + * + *

    + * the map is keyed by the name of the attribute and + * the value is the string value of the attribute. + * + * the map returned by this method is live, and you can add new attribute + * by updating the map directly. Because of this design, there's no setter. + * + * + * @return + * always non-null + */ + public Map getOtherAttributes() { + return otherAttributes; + } + +} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/atom/DateTimeType.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/atom/DateTimeType.java new file mode 100644 index 0000000000000..4232aee1748e1 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/atom/DateTimeType.java @@ -0,0 +1,153 @@ +// +// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.1.10 in JDK 6 +// See http://java.sun.com/xml/jaxb +// Any modifications to this file will be lost upon recompilation of the source schema. +// Generated on: 2012.09.17 at 02:31:28 PM PDT +// + + +package com.microsoft.windowsazure.services.media.implementation.atom; + +import java.util.HashMap; +import java.util.Map; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAnyAttribute; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlSchemaType; +import javax.xml.bind.annotation.XmlType; +import javax.xml.bind.annotation.XmlValue; +import javax.xml.bind.annotation.adapters.CollapsedStringAdapter; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; +import javax.xml.datatype.XMLGregorianCalendar; +import javax.xml.namespace.QName; + + +/** + *

    Java class for dateTimeType complex type. + * + *

    The following schema fragment specifies the expected content contained within this class. + * + *

    + * <complexType name="dateTimeType">
    + *   <simpleContent>
    + *     <extension base="<http://www.w3.org/2001/XMLSchema>dateTime">
    + *       <attGroup ref="{http://www.w3.org/2005/Atom}commonAttributes"/>
    + *       <anyAttribute namespace='##other'/>
    + *     </extension>
    + *   </simpleContent>
    + * </complexType>
    + * 
    + * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "dateTimeType", propOrder = { + "value" +}) +public class DateTimeType { + + @XmlValue + @XmlSchemaType(name = "dateTime") + protected XMLGregorianCalendar value; + @XmlAttribute(namespace = "http://www.w3.org/XML/1998/namespace") + @XmlSchemaType(name = "anyURI") + protected String base; + @XmlAttribute(namespace = "http://www.w3.org/XML/1998/namespace") + @XmlJavaTypeAdapter(CollapsedStringAdapter.class) + @XmlSchemaType(name = "language") + protected String lang; + @XmlAnyAttribute + private Map otherAttributes = new HashMap(); + + /** + * Gets the value of the value property. + * + * @return + * possible object is + * {@link XMLGregorianCalendar } + * + */ + public XMLGregorianCalendar getValue() { + return value; + } + + /** + * Sets the value of the value property. + * + * @param value + * allowed object is + * {@link XMLGregorianCalendar } + * + */ + public void setValue(XMLGregorianCalendar value) { + this.value = value; + } + + /** + * Gets the value of the base property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getBase() { + return base; + } + + /** + * Sets the value of the base property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setBase(String value) { + this.base = value; + } + + /** + * Gets the value of the lang property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getLang() { + return lang; + } + + /** + * Sets the value of the lang property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setLang(String value) { + this.lang = value; + } + + /** + * Gets a map that contains attributes that aren't bound to any typed property on this class. + * + *

    + * the map is keyed by the name of the attribute and + * the value is the string value of the attribute. + * + * the map returned by this method is live, and you can add new attribute + * by updating the map directly. Because of this design, there's no setter. + * + * + * @return + * always non-null + */ + public Map getOtherAttributes() { + return otherAttributes; + } + +} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/atom/EntryType.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/atom/EntryType.java new file mode 100644 index 0000000000000..d3244af70517d --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/atom/EntryType.java @@ -0,0 +1,206 @@ +// +// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.1.10 in JDK 6 +// See http://java.sun.com/xml/jaxb +// Any modifications to this file will be lost upon recompilation of the source schema. +// Generated on: 2012.09.17 at 02:31:28 PM PDT +// + + +package com.microsoft.windowsazure.services.media.implementation.atom; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import javax.xml.bind.JAXBElement; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAnyAttribute; +import javax.xml.bind.annotation.XmlAnyElement; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlElementRef; +import javax.xml.bind.annotation.XmlElementRefs; +import javax.xml.bind.annotation.XmlSchemaType; +import javax.xml.bind.annotation.XmlType; +import javax.xml.bind.annotation.adapters.CollapsedStringAdapter; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; +import javax.xml.namespace.QName; + + +/** + * + * The Atom entry construct is defined in section 4.1.2 of the format spec. + * + * + *

    Java class for entryType complex type. + * + *

    The following schema fragment specifies the expected content contained within this class. + * + *

    + * <complexType name="entryType">
    + *   <complexContent>
    + *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
    + *       <choice maxOccurs="unbounded">
    + *         <element name="author" type="{http://www.w3.org/2005/Atom}personType" maxOccurs="unbounded" minOccurs="0"/>
    + *         <element name="category" type="{http://www.w3.org/2005/Atom}categoryType" maxOccurs="unbounded" minOccurs="0"/>
    + *         <element name="content" type="{http://www.w3.org/2005/Atom}contentType" minOccurs="0"/>
    + *         <element name="contributor" type="{http://www.w3.org/2005/Atom}personType" maxOccurs="unbounded" minOccurs="0"/>
    + *         <element name="id" type="{http://www.w3.org/2005/Atom}idType"/>
    + *         <element name="link" type="{http://www.w3.org/2005/Atom}linkType" maxOccurs="unbounded" minOccurs="0"/>
    + *         <element name="published" type="{http://www.w3.org/2005/Atom}dateTimeType" minOccurs="0"/>
    + *         <element name="rights" type="{http://www.w3.org/2005/Atom}textType" minOccurs="0"/>
    + *         <element name="source" type="{http://www.w3.org/2005/Atom}textType" minOccurs="0"/>
    + *         <element name="summary" type="{http://www.w3.org/2005/Atom}textType" minOccurs="0"/>
    + *         <element name="title" type="{http://www.w3.org/2005/Atom}textType"/>
    + *         <element name="updated" type="{http://www.w3.org/2005/Atom}dateTimeType"/>
    + *         <any namespace='##other' maxOccurs="unbounded" minOccurs="0"/>
    + *       </choice>
    + *       <attGroup ref="{http://www.w3.org/2005/Atom}commonAttributes"/>
    + *       <anyAttribute namespace='##other'/>
    + *     </restriction>
    + *   </complexContent>
    + * </complexType>
    + * 
    + * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "entryType", propOrder = { + "entryChildren" +}) +public class EntryType { + + @XmlElementRefs({ + @XmlElementRef(name = "category", namespace = "http://www.w3.org/2005/Atom", type = JAXBElement.class), + @XmlElementRef(name = "rights", namespace = "http://www.w3.org/2005/Atom", type = JAXBElement.class), + @XmlElementRef(name = "published", namespace = "http://www.w3.org/2005/Atom", type = JAXBElement.class), + @XmlElementRef(name = "author", namespace = "http://www.w3.org/2005/Atom", type = JAXBElement.class), + @XmlElementRef(name = "link", namespace = "http://www.w3.org/2005/Atom", type = JAXBElement.class), + @XmlElementRef(name = "title", namespace = "http://www.w3.org/2005/Atom", type = JAXBElement.class), + @XmlElementRef(name = "summary", namespace = "http://www.w3.org/2005/Atom", type = JAXBElement.class), + @XmlElementRef(name = "id", namespace = "http://www.w3.org/2005/Atom", type = JAXBElement.class), + @XmlElementRef(name = "source", namespace = "http://www.w3.org/2005/Atom", type = JAXBElement.class), + @XmlElementRef(name = "content", namespace = "http://www.w3.org/2005/Atom", type = JAXBElement.class), + @XmlElementRef(name = "updated", namespace = "http://www.w3.org/2005/Atom", type = JAXBElement.class), + @XmlElementRef(name = "contributor", namespace = "http://www.w3.org/2005/Atom", type = JAXBElement.class) + }) + @XmlAnyElement(lax = true) + protected List entryChildren; + @XmlAttribute(namespace = "http://www.w3.org/XML/1998/namespace") + @XmlSchemaType(name = "anyURI") + protected String base; + @XmlAttribute(namespace = "http://www.w3.org/XML/1998/namespace") + @XmlJavaTypeAdapter(CollapsedStringAdapter.class) + @XmlSchemaType(name = "language") + protected String lang; + @XmlAnyAttribute + private Map otherAttributes = new HashMap(); + + /** + * Gets the value of the entryChildren property. + * + *

    + * This accessor method returns a reference to the live list, + * not a snapshot. Therefore any modification you make to the + * returned list will be present inside the JAXB object. + * This is why there is not a set method for the entryChildren property. + * + *

    + * For example, to add a new item, do as follows: + *

    +     *    getEntryChildren().add(newItem);
    +     * 
    + * + * + *

    + * Objects of the following type(s) are allowed in the list + * {@link JAXBElement }{@code <}{@link CategoryType }{@code >} + * {@link JAXBElement }{@code <}{@link TextType }{@code >} + * {@link JAXBElement }{@code <}{@link DateTimeType }{@code >} + * {@link JAXBElement }{@code <}{@link PersonType }{@code >} + * {@link JAXBElement }{@code <}{@link LinkType }{@code >} + * {@link JAXBElement }{@code <}{@link TextType }{@code >} + * {@link JAXBElement }{@code <}{@link DateTimeType }{@code >} + * {@link JAXBElement }{@code <}{@link PersonType }{@code >} + * {@link JAXBElement }{@code <}{@link TextType }{@code >} + * {@link JAXBElement }{@code <}{@link TextType }{@code >} + * {@link JAXBElement }{@code <}{@link IdType }{@code >} + * {@link JAXBElement }{@code <}{@link ContentType }{@code >} + * {@link Object } + * + * + */ + public List getEntryChildren() { + if (entryChildren == null) { + entryChildren = new ArrayList(); + } + return this.entryChildren; + } + + /** + * Gets the value of the base property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getBase() { + return base; + } + + /** + * Sets the value of the base property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setBase(String value) { + this.base = value; + } + + /** + * Gets the value of the lang property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getLang() { + return lang; + } + + /** + * Sets the value of the lang property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setLang(String value) { + this.lang = value; + } + + /** + * Gets a map that contains attributes that aren't bound to any typed property on this class. + * + *

    + * the map is keyed by the name of the attribute and + * the value is the string value of the attribute. + * + * the map returned by this method is live, and you can add new attribute + * by updating the map directly. Because of this design, there's no setter. + * + * + * @return + * always non-null + */ + public Map getOtherAttributes() { + return otherAttributes; + } + +} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/atom/FeedType.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/atom/FeedType.java new file mode 100644 index 0000000000000..435a81f20f110 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/atom/FeedType.java @@ -0,0 +1,209 @@ +// +// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.1.10 in JDK 6 +// See http://java.sun.com/xml/jaxb +// Any modifications to this file will be lost upon recompilation of the source schema. +// Generated on: 2012.09.17 at 02:31:28 PM PDT +// + + +package com.microsoft.windowsazure.services.media.implementation.atom; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import javax.xml.bind.JAXBElement; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAnyAttribute; +import javax.xml.bind.annotation.XmlAnyElement; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlElementRef; +import javax.xml.bind.annotation.XmlElementRefs; +import javax.xml.bind.annotation.XmlSchemaType; +import javax.xml.bind.annotation.XmlType; +import javax.xml.bind.annotation.adapters.CollapsedStringAdapter; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; +import javax.xml.namespace.QName; + + +/** + * + * The Atom feed construct is defined in section 4.1.1 of the format spec. + * + * + *

    Java class for feedType complex type. + * + *

    The following schema fragment specifies the expected content contained within this class. + * + *

    + * <complexType name="feedType">
    + *   <complexContent>
    + *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
    + *       <choice maxOccurs="unbounded" minOccurs="3">
    + *         <element name="author" type="{http://www.w3.org/2005/Atom}personType" maxOccurs="unbounded" minOccurs="0"/>
    + *         <element name="category" type="{http://www.w3.org/2005/Atom}categoryType" maxOccurs="unbounded" minOccurs="0"/>
    + *         <element name="contributor" type="{http://www.w3.org/2005/Atom}personType" maxOccurs="unbounded" minOccurs="0"/>
    + *         <element name="generator" type="{http://www.w3.org/2005/Atom}generatorType" minOccurs="0"/>
    + *         <element name="icon" type="{http://www.w3.org/2005/Atom}iconType" minOccurs="0"/>
    + *         <element name="id" type="{http://www.w3.org/2005/Atom}idType"/>
    + *         <element name="link" type="{http://www.w3.org/2005/Atom}linkType" maxOccurs="unbounded" minOccurs="0"/>
    + *         <element name="logo" type="{http://www.w3.org/2005/Atom}logoType" minOccurs="0"/>
    + *         <element name="rights" type="{http://www.w3.org/2005/Atom}textType" minOccurs="0"/>
    + *         <element name="subtitle" type="{http://www.w3.org/2005/Atom}textType" minOccurs="0"/>
    + *         <element name="title" type="{http://www.w3.org/2005/Atom}textType"/>
    + *         <element name="updated" type="{http://www.w3.org/2005/Atom}dateTimeType"/>
    + *         <element name="entry" type="{http://www.w3.org/2005/Atom}entryType" maxOccurs="unbounded" minOccurs="0"/>
    + *         <any namespace='##other' maxOccurs="unbounded" minOccurs="0"/>
    + *       </choice>
    + *       <attGroup ref="{http://www.w3.org/2005/Atom}commonAttributes"/>
    + *       <anyAttribute namespace='##other'/>
    + *     </restriction>
    + *   </complexContent>
    + * </complexType>
    + * 
    + * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "feedType", propOrder = { + "authorOrCategoryOrContributor" +}) +public class FeedType { + + @XmlElementRefs({ + @XmlElementRef(name = "logo", namespace = "http://www.w3.org/2005/Atom", type = JAXBElement.class), + @XmlElementRef(name = "rights", namespace = "http://www.w3.org/2005/Atom", type = JAXBElement.class), + @XmlElementRef(name = "icon", namespace = "http://www.w3.org/2005/Atom", type = JAXBElement.class), + @XmlElementRef(name = "subtitle", namespace = "http://www.w3.org/2005/Atom", type = JAXBElement.class), + @XmlElementRef(name = "contributor", namespace = "http://www.w3.org/2005/Atom", type = JAXBElement.class), + @XmlElementRef(name = "title", namespace = "http://www.w3.org/2005/Atom", type = JAXBElement.class), + @XmlElementRef(name = "entry", namespace = "http://www.w3.org/2005/Atom", type = JAXBElement.class), + @XmlElementRef(name = "author", namespace = "http://www.w3.org/2005/Atom", type = JAXBElement.class), + @XmlElementRef(name = "id", namespace = "http://www.w3.org/2005/Atom", type = JAXBElement.class), + @XmlElementRef(name = "updated", namespace = "http://www.w3.org/2005/Atom", type = JAXBElement.class), + @XmlElementRef(name = "link", namespace = "http://www.w3.org/2005/Atom", type = JAXBElement.class), + @XmlElementRef(name = "generator", namespace = "http://www.w3.org/2005/Atom", type = JAXBElement.class), + @XmlElementRef(name = "category", namespace = "http://www.w3.org/2005/Atom", type = JAXBElement.class) + }) + @XmlAnyElement(lax = true) + protected List authorOrCategoryOrContributor; + @XmlAttribute(namespace = "http://www.w3.org/XML/1998/namespace") + @XmlSchemaType(name = "anyURI") + protected String base; + @XmlAttribute(namespace = "http://www.w3.org/XML/1998/namespace") + @XmlJavaTypeAdapter(CollapsedStringAdapter.class) + @XmlSchemaType(name = "language") + protected String lang; + @XmlAnyAttribute + private Map otherAttributes = new HashMap(); + + /** + * Gets the value of the authorOrCategoryOrContributor property. + * + *

    + * This accessor method returns a reference to the live list, + * not a snapshot. Therefore any modification you make to the + * returned list will be present inside the JAXB object. + * This is why there is not a set method for the authorOrCategoryOrContributor property. + * + *

    + * For example, to add a new item, do as follows: + *

    +     *    getAuthorOrCategoryOrContributor().add(newItem);
    +     * 
    + * + * + *

    + * Objects of the following type(s) are allowed in the list + * {@link JAXBElement }{@code <}{@link LogoType }{@code >} + * {@link JAXBElement }{@code <}{@link TextType }{@code >} + * {@link JAXBElement }{@code <}{@link IconType }{@code >} + * {@link JAXBElement }{@code <}{@link TextType }{@code >} + * {@link JAXBElement }{@code <}{@link PersonType }{@code >} + * {@link JAXBElement }{@code <}{@link TextType }{@code >} + * {@link JAXBElement }{@code <}{@link EntryType }{@code >} + * {@link JAXBElement }{@code <}{@link PersonType }{@code >} + * {@link JAXBElement }{@code <}{@link IdType }{@code >} + * {@link JAXBElement }{@code <}{@link DateTimeType }{@code >} + * {@link JAXBElement }{@code <}{@link LinkType }{@code >} + * {@link JAXBElement }{@code <}{@link GeneratorType }{@code >} + * {@link JAXBElement }{@code <}{@link CategoryType }{@code >} + * {@link Object } + * + * + */ + public List getAuthorOrCategoryOrContributor() { + if (authorOrCategoryOrContributor == null) { + authorOrCategoryOrContributor = new ArrayList(); + } + return this.authorOrCategoryOrContributor; + } + + /** + * Gets the value of the base property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getBase() { + return base; + } + + /** + * Sets the value of the base property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setBase(String value) { + this.base = value; + } + + /** + * Gets the value of the lang property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getLang() { + return lang; + } + + /** + * Sets the value of the lang property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setLang(String value) { + this.lang = value; + } + + /** + * Gets a map that contains attributes that aren't bound to any typed property on this class. + * + *

    + * the map is keyed by the name of the attribute and + * the value is the string value of the attribute. + * + * the map returned by this method is live, and you can add new attribute + * by updating the map directly. Because of this design, there's no setter. + * + * + * @return + * always non-null + */ + public Map getOtherAttributes() { + return otherAttributes; + } + +} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/atom/GeneratorType.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/atom/GeneratorType.java new file mode 100644 index 0000000000000..08f56f2f84c75 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/atom/GeneratorType.java @@ -0,0 +1,210 @@ +// +// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.1.10 in JDK 6 +// See http://java.sun.com/xml/jaxb +// Any modifications to this file will be lost upon recompilation of the source schema. +// Generated on: 2012.09.17 at 02:31:28 PM PDT +// + + +package com.microsoft.windowsazure.services.media.implementation.atom; + +import java.util.HashMap; +import java.util.Map; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAnyAttribute; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlSchemaType; +import javax.xml.bind.annotation.XmlType; +import javax.xml.bind.annotation.XmlValue; +import javax.xml.bind.annotation.adapters.CollapsedStringAdapter; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; +import javax.xml.namespace.QName; + + +/** + * + * The Atom generator element is defined in section 4.2.4 of the format spec. + * + * + *

    Java class for generatorType complex type. + * + *

    The following schema fragment specifies the expected content contained within this class. + * + *

    + * <complexType name="generatorType">
    + *   <simpleContent>
    + *     <extension base="<http://www.w3.org/2001/XMLSchema>string">
    + *       <attGroup ref="{http://www.w3.org/2005/Atom}commonAttributes"/>
    + *       <attribute name="uri" type="{http://www.w3.org/2001/XMLSchema}anyURI" />
    + *       <attribute name="version" type="{http://www.w3.org/2001/XMLSchema}string" />
    + *       <anyAttribute namespace='##other'/>
    + *     </extension>
    + *   </simpleContent>
    + * </complexType>
    + * 
    + * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "generatorType", propOrder = { + "value" +}) +public class GeneratorType { + + @XmlValue + protected String value; + @XmlAttribute + @XmlSchemaType(name = "anyURI") + protected String uri; + @XmlAttribute + protected String version; + @XmlAttribute(namespace = "http://www.w3.org/XML/1998/namespace") + @XmlSchemaType(name = "anyURI") + protected String base; + @XmlAttribute(namespace = "http://www.w3.org/XML/1998/namespace") + @XmlJavaTypeAdapter(CollapsedStringAdapter.class) + @XmlSchemaType(name = "language") + protected String lang; + @XmlAnyAttribute + private Map otherAttributes = new HashMap(); + + /** + * Gets the value of the value property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getValue() { + return value; + } + + /** + * Sets the value of the value property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setValue(String value) { + this.value = value; + } + + /** + * Gets the value of the uri property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getUri() { + return uri; + } + + /** + * Sets the value of the uri property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setUri(String value) { + this.uri = value; + } + + /** + * Gets the value of the version property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getVersion() { + return version; + } + + /** + * Sets the value of the version property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setVersion(String value) { + this.version = value; + } + + /** + * Gets the value of the base property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getBase() { + return base; + } + + /** + * Sets the value of the base property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setBase(String value) { + this.base = value; + } + + /** + * Gets the value of the lang property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getLang() { + return lang; + } + + /** + * Sets the value of the lang property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setLang(String value) { + this.lang = value; + } + + /** + * Gets a map that contains attributes that aren't bound to any typed property on this class. + * + *

    + * the map is keyed by the name of the attribute and + * the value is the string value of the attribute. + * + * the map returned by this method is live, and you can add new attribute + * by updating the map directly. Because of this design, there's no setter. + * + * + * @return + * always non-null + */ + public Map getOtherAttributes() { + return otherAttributes; + } + +} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/atom/IconType.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/atom/IconType.java new file mode 100644 index 0000000000000..33675d2d588a5 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/atom/IconType.java @@ -0,0 +1,156 @@ +// +// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.1.10 in JDK 6 +// See http://java.sun.com/xml/jaxb +// Any modifications to this file will be lost upon recompilation of the source schema. +// Generated on: 2012.09.17 at 02:31:28 PM PDT +// + + +package com.microsoft.windowsazure.services.media.implementation.atom; + +import java.util.HashMap; +import java.util.Map; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAnyAttribute; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlSchemaType; +import javax.xml.bind.annotation.XmlType; +import javax.xml.bind.annotation.XmlValue; +import javax.xml.bind.annotation.adapters.CollapsedStringAdapter; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; +import javax.xml.namespace.QName; + + +/** + * + * The Atom icon construct is defined in section 4.2.5 of the format spec. + * + * + *

    Java class for iconType complex type. + * + *

    The following schema fragment specifies the expected content contained within this class. + * + *

    + * <complexType name="iconType">
    + *   <simpleContent>
    + *     <extension base="<http://www.w3.org/2001/XMLSchema>anyURI">
    + *       <attGroup ref="{http://www.w3.org/2005/Atom}commonAttributes"/>
    + *       <anyAttribute namespace='##other'/>
    + *     </extension>
    + *   </simpleContent>
    + * </complexType>
    + * 
    + * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "iconType", propOrder = { + "value" +}) +public class IconType { + + @XmlValue + @XmlSchemaType(name = "anyURI") + protected String value; + @XmlAttribute(namespace = "http://www.w3.org/XML/1998/namespace") + @XmlSchemaType(name = "anyURI") + protected String base; + @XmlAttribute(namespace = "http://www.w3.org/XML/1998/namespace") + @XmlJavaTypeAdapter(CollapsedStringAdapter.class) + @XmlSchemaType(name = "language") + protected String lang; + @XmlAnyAttribute + private Map otherAttributes = new HashMap(); + + /** + * Gets the value of the value property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getValue() { + return value; + } + + /** + * Sets the value of the value property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setValue(String value) { + this.value = value; + } + + /** + * Gets the value of the base property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getBase() { + return base; + } + + /** + * Sets the value of the base property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setBase(String value) { + this.base = value; + } + + /** + * Gets the value of the lang property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getLang() { + return lang; + } + + /** + * Sets the value of the lang property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setLang(String value) { + this.lang = value; + } + + /** + * Gets a map that contains attributes that aren't bound to any typed property on this class. + * + *

    + * the map is keyed by the name of the attribute and + * the value is the string value of the attribute. + * + * the map returned by this method is live, and you can add new attribute + * by updating the map directly. Because of this design, there's no setter. + * + * + * @return + * always non-null + */ + public Map getOtherAttributes() { + return otherAttributes; + } + +} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/atom/IdType.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/atom/IdType.java new file mode 100644 index 0000000000000..0633ac55a4110 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/atom/IdType.java @@ -0,0 +1,156 @@ +// +// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.1.10 in JDK 6 +// See http://java.sun.com/xml/jaxb +// Any modifications to this file will be lost upon recompilation of the source schema. +// Generated on: 2012.09.17 at 02:31:28 PM PDT +// + + +package com.microsoft.windowsazure.services.media.implementation.atom; + +import java.util.HashMap; +import java.util.Map; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAnyAttribute; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlSchemaType; +import javax.xml.bind.annotation.XmlType; +import javax.xml.bind.annotation.XmlValue; +import javax.xml.bind.annotation.adapters.CollapsedStringAdapter; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; +import javax.xml.namespace.QName; + + +/** + * + * The Atom id construct is defined in section 4.2.6 of the format spec. + * + * + *

    Java class for idType complex type. + * + *

    The following schema fragment specifies the expected content contained within this class. + * + *

    + * <complexType name="idType">
    + *   <simpleContent>
    + *     <extension base="<http://www.w3.org/2001/XMLSchema>anyURI">
    + *       <attGroup ref="{http://www.w3.org/2005/Atom}commonAttributes"/>
    + *       <anyAttribute namespace='##other'/>
    + *     </extension>
    + *   </simpleContent>
    + * </complexType>
    + * 
    + * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "idType", propOrder = { + "value" +}) +public class IdType { + + @XmlValue + @XmlSchemaType(name = "anyURI") + protected String value; + @XmlAttribute(namespace = "http://www.w3.org/XML/1998/namespace") + @XmlSchemaType(name = "anyURI") + protected String base; + @XmlAttribute(namespace = "http://www.w3.org/XML/1998/namespace") + @XmlJavaTypeAdapter(CollapsedStringAdapter.class) + @XmlSchemaType(name = "language") + protected String lang; + @XmlAnyAttribute + private Map otherAttributes = new HashMap(); + + /** + * Gets the value of the value property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getValue() { + return value; + } + + /** + * Sets the value of the value property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setValue(String value) { + this.value = value; + } + + /** + * Gets the value of the base property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getBase() { + return base; + } + + /** + * Sets the value of the base property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setBase(String value) { + this.base = value; + } + + /** + * Gets the value of the lang property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getLang() { + return lang; + } + + /** + * Sets the value of the lang property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setLang(String value) { + this.lang = value; + } + + /** + * Gets a map that contains attributes that aren't bound to any typed property on this class. + * + *

    + * the map is keyed by the name of the attribute and + * the value is the string value of the attribute. + * + * the map returned by this method is live, and you can add new attribute + * by updating the map directly. Because of this design, there's no setter. + * + * + * @return + * always non-null + */ + public Map getOtherAttributes() { + return otherAttributes; + } + +} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/atom/LinkType.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/atom/LinkType.java new file mode 100644 index 0000000000000..7ea60224d7f02 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/atom/LinkType.java @@ -0,0 +1,324 @@ +// +// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.1.10 in JDK 6 +// See http://java.sun.com/xml/jaxb +// Any modifications to this file will be lost upon recompilation of the source schema. +// Generated on: 2012.09.17 at 02:31:28 PM PDT +// + + +package com.microsoft.windowsazure.services.media.implementation.atom; + +import java.math.BigInteger; +import java.util.HashMap; +import java.util.Map; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAnyAttribute; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlSchemaType; +import javax.xml.bind.annotation.XmlType; +import javax.xml.bind.annotation.XmlValue; +import javax.xml.bind.annotation.adapters.CollapsedStringAdapter; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; +import javax.xml.namespace.QName; + + +/** + * + * The Atom link construct is defined in section 3.4 of the format spec. + * + * + *

    Java class for linkType complex type. + * + *

    The following schema fragment specifies the expected content contained within this class. + * + *

    + * <complexType name="linkType">
    + *   <complexContent>
    + *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
    + *       <attGroup ref="{http://www.w3.org/2005/Atom}commonAttributes"/>
    + *       <attribute name="href" use="required" type="{http://www.w3.org/2001/XMLSchema}anyURI" />
    + *       <attribute name="rel" type="{http://www.w3.org/2001/XMLSchema}string" />
    + *       <attribute name="type" type="{http://www.w3.org/2001/XMLSchema}string" />
    + *       <attribute name="hreflang" type="{http://www.w3.org/2001/XMLSchema}NMTOKEN" />
    + *       <attribute name="title" type="{http://www.w3.org/2001/XMLSchema}string" />
    + *       <attribute name="length" type="{http://www.w3.org/2001/XMLSchema}positiveInteger" />
    + *       <anyAttribute namespace='##other'/>
    + *     </restriction>
    + *   </complexContent>
    + * </complexType>
    + * 
    + * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "linkType", propOrder = { + "content" +}) +public class LinkType { + + @XmlValue + protected String content; + @XmlAttribute(required = true) + @XmlSchemaType(name = "anyURI") + protected String href; + @XmlAttribute + protected String rel; + @XmlAttribute + protected String type; + @XmlAttribute + @XmlJavaTypeAdapter(CollapsedStringAdapter.class) + @XmlSchemaType(name = "NMTOKEN") + protected String hreflang; + @XmlAttribute + protected String title; + @XmlAttribute + @XmlSchemaType(name = "positiveInteger") + protected BigInteger length; + @XmlAttribute(namespace = "http://www.w3.org/XML/1998/namespace") + @XmlSchemaType(name = "anyURI") + protected String base; + @XmlAttribute(namespace = "http://www.w3.org/XML/1998/namespace") + @XmlJavaTypeAdapter(CollapsedStringAdapter.class) + @XmlSchemaType(name = "language") + protected String lang; + @XmlAnyAttribute + private Map otherAttributes = new HashMap(); + + /** + * + * The Atom link construct is defined in section 3.4 of the format spec. + * + * + * @return + * possible object is + * {@link String } + * + */ + public String getContent() { + return content; + } + + /** + * Sets the value of the content property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setContent(String value) { + this.content = value; + } + + /** + * Gets the value of the href property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getHref() { + return href; + } + + /** + * Sets the value of the href property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setHref(String value) { + this.href = value; + } + + /** + * Gets the value of the rel property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getRel() { + return rel; + } + + /** + * Sets the value of the rel property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setRel(String value) { + this.rel = value; + } + + /** + * Gets the value of the type property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getType() { + return type; + } + + /** + * Sets the value of the type property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setType(String value) { + this.type = value; + } + + /** + * Gets the value of the hreflang property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getHreflang() { + return hreflang; + } + + /** + * Sets the value of the hreflang property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setHreflang(String value) { + this.hreflang = value; + } + + /** + * Gets the value of the title property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getTitle() { + return title; + } + + /** + * Sets the value of the title property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setTitle(String value) { + this.title = value; + } + + /** + * Gets the value of the length property. + * + * @return + * possible object is + * {@link BigInteger } + * + */ + public BigInteger getLength() { + return length; + } + + /** + * Sets the value of the length property. + * + * @param value + * allowed object is + * {@link BigInteger } + * + */ + public void setLength(BigInteger value) { + this.length = value; + } + + /** + * Gets the value of the base property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getBase() { + return base; + } + + /** + * Sets the value of the base property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setBase(String value) { + this.base = value; + } + + /** + * Gets the value of the lang property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getLang() { + return lang; + } + + /** + * Sets the value of the lang property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setLang(String value) { + this.lang = value; + } + + /** + * Gets a map that contains attributes that aren't bound to any typed property on this class. + * + *

    + * the map is keyed by the name of the attribute and + * the value is the string value of the attribute. + * + * the map returned by this method is live, and you can add new attribute + * by updating the map directly. Because of this design, there's no setter. + * + * + * @return + * always non-null + */ + public Map getOtherAttributes() { + return otherAttributes; + } + +} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/atom/LogoType.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/atom/LogoType.java new file mode 100644 index 0000000000000..443f58c771070 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/atom/LogoType.java @@ -0,0 +1,156 @@ +// +// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.1.10 in JDK 6 +// See http://java.sun.com/xml/jaxb +// Any modifications to this file will be lost upon recompilation of the source schema. +// Generated on: 2012.09.17 at 02:31:28 PM PDT +// + + +package com.microsoft.windowsazure.services.media.implementation.atom; + +import java.util.HashMap; +import java.util.Map; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAnyAttribute; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlSchemaType; +import javax.xml.bind.annotation.XmlType; +import javax.xml.bind.annotation.XmlValue; +import javax.xml.bind.annotation.adapters.CollapsedStringAdapter; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; +import javax.xml.namespace.QName; + + +/** + * + * The Atom logo construct is defined in section 4.2.8 of the format spec. + * + * + *

    Java class for logoType complex type. + * + *

    The following schema fragment specifies the expected content contained within this class. + * + *

    + * <complexType name="logoType">
    + *   <simpleContent>
    + *     <extension base="<http://www.w3.org/2001/XMLSchema>anyURI">
    + *       <attGroup ref="{http://www.w3.org/2005/Atom}commonAttributes"/>
    + *       <anyAttribute namespace='##other'/>
    + *     </extension>
    + *   </simpleContent>
    + * </complexType>
    + * 
    + * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "logoType", propOrder = { + "value" +}) +public class LogoType { + + @XmlValue + @XmlSchemaType(name = "anyURI") + protected String value; + @XmlAttribute(namespace = "http://www.w3.org/XML/1998/namespace") + @XmlSchemaType(name = "anyURI") + protected String base; + @XmlAttribute(namespace = "http://www.w3.org/XML/1998/namespace") + @XmlJavaTypeAdapter(CollapsedStringAdapter.class) + @XmlSchemaType(name = "language") + protected String lang; + @XmlAnyAttribute + private Map otherAttributes = new HashMap(); + + /** + * Gets the value of the value property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getValue() { + return value; + } + + /** + * Sets the value of the value property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setValue(String value) { + this.value = value; + } + + /** + * Gets the value of the base property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getBase() { + return base; + } + + /** + * Sets the value of the base property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setBase(String value) { + this.base = value; + } + + /** + * Gets the value of the lang property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getLang() { + return lang; + } + + /** + * Sets the value of the lang property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setLang(String value) { + this.lang = value; + } + + /** + * Gets a map that contains attributes that aren't bound to any typed property on this class. + * + *

    + * the map is keyed by the name of the attribute and + * the value is the string value of the attribute. + * + * the map returned by this method is live, and you can add new attribute + * by updating the map directly. Because of this design, there's no setter. + * + * + * @return + * always non-null + */ + public Map getOtherAttributes() { + return otherAttributes; + } + +} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/atom/ObjectFactory.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/atom/ObjectFactory.java new file mode 100644 index 0000000000000..c620b60d57564 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/atom/ObjectFactory.java @@ -0,0 +1,556 @@ +// +// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.1.10 in JDK 6 +// See http://java.sun.com/xml/jaxb +// Any modifications to this file will be lost upon recompilation of the source schema. +// Generated on: 2012.09.17 at 02:31:28 PM PDT +// + + +package com.microsoft.windowsazure.services.media.implementation.atom; + +import javax.xml.bind.JAXBElement; +import javax.xml.bind.annotation.XmlElementDecl; +import javax.xml.bind.annotation.XmlRegistry; +import javax.xml.bind.annotation.adapters.NormalizedStringAdapter; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; +import javax.xml.namespace.QName; + + +/** + * This object contains factory methods for each + * Java content interface and Java element interface + * generated in the com.microsoft.windowsazure.services.media.implementation.atom package. + *

    An ObjectFactory allows you to programatically + * construct new instances of the Java representation + * for XML content. The Java representation of XML + * content can consist of schema derived interfaces + * and classes representing the binding of schema + * type definitions, element declarations and model + * groups. Factory methods for each of these are + * provided in this class. + * + */ +@XmlRegistry +public class ObjectFactory { + + private final static QName _Entry_QNAME = new QName("http://www.w3.org/2005/Atom", "entry"); + private final static QName _Feed_QNAME = new QName("http://www.w3.org/2005/Atom", "feed"); + private final static QName _PersonTypeName_QNAME = new QName("http://www.w3.org/2005/Atom", "name"); + private final static QName _PersonTypeEmail_QNAME = new QName("http://www.w3.org/2005/Atom", "email"); + private final static QName _PersonTypeUri_QNAME = new QName("http://www.w3.org/2005/Atom", "uri"); + private final static QName _EntryTypeTitle_QNAME = new QName("http://www.w3.org/2005/Atom", "title"); + private final static QName _EntryTypeCategory_QNAME = new QName("http://www.w3.org/2005/Atom", "category"); + private final static QName _EntryTypeAuthor_QNAME = new QName("http://www.w3.org/2005/Atom", "author"); + private final static QName _EntryTypeSummary_QNAME = new QName("http://www.w3.org/2005/Atom", "summary"); + private final static QName _EntryTypeId_QNAME = new QName("http://www.w3.org/2005/Atom", "id"); + private final static QName _EntryTypeContent_QNAME = new QName("http://www.w3.org/2005/Atom", "content"); + private final static QName _EntryTypeLink_QNAME = new QName("http://www.w3.org/2005/Atom", "link"); + private final static QName _EntryTypeContributor_QNAME = new QName("http://www.w3.org/2005/Atom", "contributor"); + private final static QName _EntryTypeUpdated_QNAME = new QName("http://www.w3.org/2005/Atom", "updated"); + private final static QName _EntryTypeSource_QNAME = new QName("http://www.w3.org/2005/Atom", "source"); + private final static QName _EntryTypeRights_QNAME = new QName("http://www.w3.org/2005/Atom", "rights"); + private final static QName _EntryTypePublished_QNAME = new QName("http://www.w3.org/2005/Atom", "published"); + private final static QName _FeedTypeGenerator_QNAME = new QName("http://www.w3.org/2005/Atom", "generator"); + private final static QName _FeedTypeSubtitle_QNAME = new QName("http://www.w3.org/2005/Atom", "subtitle"); + private final static QName _FeedTypeLogo_QNAME = new QName("http://www.w3.org/2005/Atom", "logo"); + private final static QName _FeedTypeIcon_QNAME = new QName("http://www.w3.org/2005/Atom", "icon"); + + /** + * Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: com.microsoft.windowsazure.services.media.implementation.atom + * + */ + public ObjectFactory() { + } + + /** + * Create an instance of {@link PersonType } + * + */ + public PersonType createPersonType() { + return new PersonType(); + } + + /** + * Create an instance of {@link EntryType } + * + */ + public EntryType createEntryType() { + return new EntryType(); + } + + /** + * Create an instance of {@link IconType } + * + */ + public IconType createIconType() { + return new IconType(); + } + + /** + * Create an instance of {@link UriType } + * + */ + public UriType createUriType() { + return new UriType(); + } + + /** + * Create an instance of {@link TextType } + * + */ + public TextType createTextType() { + return new TextType(); + } + + /** + * Create an instance of {@link FeedType } + * + */ + public FeedType createFeedType() { + return new FeedType(); + } + + /** + * Create an instance of {@link DateTimeType } + * + */ + public DateTimeType createDateTimeType() { + return new DateTimeType(); + } + + /** + * Create an instance of {@link IdType } + * + */ + public IdType createIdType() { + return new IdType(); + } + + /** + * Create an instance of {@link SourceType } + * + */ + public SourceType createSourceType() { + return new SourceType(); + } + + /** + * Create an instance of {@link LinkType } + * + */ + public LinkType createLinkType() { + return new LinkType(); + } + + /** + * Create an instance of {@link LogoType } + * + */ + public LogoType createLogoType() { + return new LogoType(); + } + + /** + * Create an instance of {@link GeneratorType } + * + */ + public GeneratorType createGeneratorType() { + return new GeneratorType(); + } + + /** + * Create an instance of {@link ContentType } + * + */ + public ContentType createContentType() { + return new ContentType(); + } + + /** + * Create an instance of {@link CategoryType } + * + */ + public CategoryType createCategoryType() { + return new CategoryType(); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link EntryType }{@code >}} + * + */ + @XmlElementDecl(namespace = "http://www.w3.org/2005/Atom", name = "entry") + public JAXBElement createEntry(EntryType value) { + return new JAXBElement(_Entry_QNAME, EntryType.class, null, value); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link FeedType }{@code >}} + * + */ + @XmlElementDecl(namespace = "http://www.w3.org/2005/Atom", name = "feed") + public JAXBElement createFeed(FeedType value) { + return new JAXBElement(_Feed_QNAME, FeedType.class, null, value); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link String }{@code >}} + * + */ + @XmlElementDecl(namespace = "http://www.w3.org/2005/Atom", name = "name", scope = PersonType.class) + public JAXBElement createPersonTypeName(String value) { + return new JAXBElement(_PersonTypeName_QNAME, String.class, PersonType.class, value); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link String }{@code >}} + * + */ + @XmlElementDecl(namespace = "http://www.w3.org/2005/Atom", name = "email", scope = PersonType.class) + @XmlJavaTypeAdapter(NormalizedStringAdapter.class) + public JAXBElement createPersonTypeEmail(String value) { + return new JAXBElement(_PersonTypeEmail_QNAME, String.class, PersonType.class, value); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link UriType }{@code >}} + * + */ + @XmlElementDecl(namespace = "http://www.w3.org/2005/Atom", name = "uri", scope = PersonType.class) + public JAXBElement createPersonTypeUri(UriType value) { + return new JAXBElement(_PersonTypeUri_QNAME, UriType.class, PersonType.class, value); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link TextType }{@code >}} + * + */ + @XmlElementDecl(namespace = "http://www.w3.org/2005/Atom", name = "title", scope = EntryType.class) + public JAXBElement createEntryTypeTitle(TextType value) { + return new JAXBElement(_EntryTypeTitle_QNAME, TextType.class, EntryType.class, value); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link CategoryType }{@code >}} + * + */ + @XmlElementDecl(namespace = "http://www.w3.org/2005/Atom", name = "category", scope = EntryType.class) + public JAXBElement createEntryTypeCategory(CategoryType value) { + return new JAXBElement(_EntryTypeCategory_QNAME, CategoryType.class, EntryType.class, value); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link PersonType }{@code >}} + * + */ + @XmlElementDecl(namespace = "http://www.w3.org/2005/Atom", name = "author", scope = EntryType.class) + public JAXBElement createEntryTypeAuthor(PersonType value) { + return new JAXBElement(_EntryTypeAuthor_QNAME, PersonType.class, EntryType.class, value); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link TextType }{@code >}} + * + */ + @XmlElementDecl(namespace = "http://www.w3.org/2005/Atom", name = "summary", scope = EntryType.class) + public JAXBElement createEntryTypeSummary(TextType value) { + return new JAXBElement(_EntryTypeSummary_QNAME, TextType.class, EntryType.class, value); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link IdType }{@code >}} + * + */ + @XmlElementDecl(namespace = "http://www.w3.org/2005/Atom", name = "id", scope = EntryType.class) + public JAXBElement createEntryTypeId(IdType value) { + return new JAXBElement(_EntryTypeId_QNAME, IdType.class, EntryType.class, value); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link ContentType }{@code >}} + * + */ + @XmlElementDecl(namespace = "http://www.w3.org/2005/Atom", name = "content", scope = EntryType.class) + public JAXBElement createEntryTypeContent(ContentType value) { + return new JAXBElement(_EntryTypeContent_QNAME, ContentType.class, EntryType.class, value); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link LinkType }{@code >}} + * + */ + @XmlElementDecl(namespace = "http://www.w3.org/2005/Atom", name = "link", scope = EntryType.class) + public JAXBElement createEntryTypeLink(LinkType value) { + return new JAXBElement(_EntryTypeLink_QNAME, LinkType.class, EntryType.class, value); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link PersonType }{@code >}} + * + */ + @XmlElementDecl(namespace = "http://www.w3.org/2005/Atom", name = "contributor", scope = EntryType.class) + public JAXBElement createEntryTypeContributor(PersonType value) { + return new JAXBElement(_EntryTypeContributor_QNAME, PersonType.class, EntryType.class, value); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link DateTimeType }{@code >}} + * + */ + @XmlElementDecl(namespace = "http://www.w3.org/2005/Atom", name = "updated", scope = EntryType.class) + public JAXBElement createEntryTypeUpdated(DateTimeType value) { + return new JAXBElement(_EntryTypeUpdated_QNAME, DateTimeType.class, EntryType.class, value); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link TextType }{@code >}} + * + */ + @XmlElementDecl(namespace = "http://www.w3.org/2005/Atom", name = "source", scope = EntryType.class) + public JAXBElement createEntryTypeSource(TextType value) { + return new JAXBElement(_EntryTypeSource_QNAME, TextType.class, EntryType.class, value); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link TextType }{@code >}} + * + */ + @XmlElementDecl(namespace = "http://www.w3.org/2005/Atom", name = "rights", scope = EntryType.class) + public JAXBElement createEntryTypeRights(TextType value) { + return new JAXBElement(_EntryTypeRights_QNAME, TextType.class, EntryType.class, value); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link DateTimeType }{@code >}} + * + */ + @XmlElementDecl(namespace = "http://www.w3.org/2005/Atom", name = "published", scope = EntryType.class) + public JAXBElement createEntryTypePublished(DateTimeType value) { + return new JAXBElement(_EntryTypePublished_QNAME, DateTimeType.class, EntryType.class, value); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link CategoryType }{@code >}} + * + */ + @XmlElementDecl(namespace = "http://www.w3.org/2005/Atom", name = "category", scope = FeedType.class) + public JAXBElement createFeedTypeCategory(CategoryType value) { + return new JAXBElement(_EntryTypeCategory_QNAME, CategoryType.class, FeedType.class, value); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link TextType }{@code >}} + * + */ + @XmlElementDecl(namespace = "http://www.w3.org/2005/Atom", name = "title", scope = FeedType.class) + public JAXBElement createFeedTypeTitle(TextType value) { + return new JAXBElement(_EntryTypeTitle_QNAME, TextType.class, FeedType.class, value); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link PersonType }{@code >}} + * + */ + @XmlElementDecl(namespace = "http://www.w3.org/2005/Atom", name = "author", scope = FeedType.class) + public JAXBElement createFeedTypeAuthor(PersonType value) { + return new JAXBElement(_EntryTypeAuthor_QNAME, PersonType.class, FeedType.class, value); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link IdType }{@code >}} + * + */ + @XmlElementDecl(namespace = "http://www.w3.org/2005/Atom", name = "id", scope = FeedType.class) + public JAXBElement createFeedTypeId(IdType value) { + return new JAXBElement(_EntryTypeId_QNAME, IdType.class, FeedType.class, value); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link EntryType }{@code >}} + * + */ + @XmlElementDecl(namespace = "http://www.w3.org/2005/Atom", name = "entry", scope = FeedType.class) + public JAXBElement createFeedTypeEntry(EntryType value) { + return new JAXBElement(_Entry_QNAME, EntryType.class, FeedType.class, value); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link PersonType }{@code >}} + * + */ + @XmlElementDecl(namespace = "http://www.w3.org/2005/Atom", name = "contributor", scope = FeedType.class) + public JAXBElement createFeedTypeContributor(PersonType value) { + return new JAXBElement(_EntryTypeContributor_QNAME, PersonType.class, FeedType.class, value); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link DateTimeType }{@code >}} + * + */ + @XmlElementDecl(namespace = "http://www.w3.org/2005/Atom", name = "updated", scope = FeedType.class) + public JAXBElement createFeedTypeUpdated(DateTimeType value) { + return new JAXBElement(_EntryTypeUpdated_QNAME, DateTimeType.class, FeedType.class, value); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link GeneratorType }{@code >}} + * + */ + @XmlElementDecl(namespace = "http://www.w3.org/2005/Atom", name = "generator", scope = FeedType.class) + public JAXBElement createFeedTypeGenerator(GeneratorType value) { + return new JAXBElement(_FeedTypeGenerator_QNAME, GeneratorType.class, FeedType.class, value); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link TextType }{@code >}} + * + */ + @XmlElementDecl(namespace = "http://www.w3.org/2005/Atom", name = "subtitle", scope = FeedType.class) + public JAXBElement createFeedTypeSubtitle(TextType value) { + return new JAXBElement(_FeedTypeSubtitle_QNAME, TextType.class, FeedType.class, value); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link LogoType }{@code >}} + * + */ + @XmlElementDecl(namespace = "http://www.w3.org/2005/Atom", name = "logo", scope = FeedType.class) + public JAXBElement createFeedTypeLogo(LogoType value) { + return new JAXBElement(_FeedTypeLogo_QNAME, LogoType.class, FeedType.class, value); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link IconType }{@code >}} + * + */ + @XmlElementDecl(namespace = "http://www.w3.org/2005/Atom", name = "icon", scope = FeedType.class) + public JAXBElement createFeedTypeIcon(IconType value) { + return new JAXBElement(_FeedTypeIcon_QNAME, IconType.class, FeedType.class, value); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link LinkType }{@code >}} + * + */ + @XmlElementDecl(namespace = "http://www.w3.org/2005/Atom", name = "link", scope = FeedType.class) + public JAXBElement createFeedTypeLink(LinkType value) { + return new JAXBElement(_EntryTypeLink_QNAME, LinkType.class, FeedType.class, value); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link TextType }{@code >}} + * + */ + @XmlElementDecl(namespace = "http://www.w3.org/2005/Atom", name = "rights", scope = FeedType.class) + public JAXBElement createFeedTypeRights(TextType value) { + return new JAXBElement(_EntryTypeRights_QNAME, TextType.class, FeedType.class, value); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link TextType }{@code >}} + * + */ + @XmlElementDecl(namespace = "http://www.w3.org/2005/Atom", name = "title", scope = SourceType.class) + public JAXBElement createSourceTypeTitle(TextType value) { + return new JAXBElement(_EntryTypeTitle_QNAME, TextType.class, SourceType.class, value); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link CategoryType }{@code >}} + * + */ + @XmlElementDecl(namespace = "http://www.w3.org/2005/Atom", name = "category", scope = SourceType.class) + public JAXBElement createSourceTypeCategory(CategoryType value) { + return new JAXBElement(_EntryTypeCategory_QNAME, CategoryType.class, SourceType.class, value); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link IconType }{@code >}} + * + */ + @XmlElementDecl(namespace = "http://www.w3.org/2005/Atom", name = "icon", scope = SourceType.class) + public JAXBElement createSourceTypeIcon(IconType value) { + return new JAXBElement(_FeedTypeIcon_QNAME, IconType.class, SourceType.class, value); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link PersonType }{@code >}} + * + */ + @XmlElementDecl(namespace = "http://www.w3.org/2005/Atom", name = "author", scope = SourceType.class) + public JAXBElement createSourceTypeAuthor(PersonType value) { + return new JAXBElement(_EntryTypeAuthor_QNAME, PersonType.class, SourceType.class, value); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link LogoType }{@code >}} + * + */ + @XmlElementDecl(namespace = "http://www.w3.org/2005/Atom", name = "logo", scope = SourceType.class) + public JAXBElement createSourceTypeLogo(LogoType value) { + return new JAXBElement(_FeedTypeLogo_QNAME, LogoType.class, SourceType.class, value); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link IdType }{@code >}} + * + */ + @XmlElementDecl(namespace = "http://www.w3.org/2005/Atom", name = "id", scope = SourceType.class) + public JAXBElement createSourceTypeId(IdType value) { + return new JAXBElement(_EntryTypeId_QNAME, IdType.class, SourceType.class, value); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link LinkType }{@code >}} + * + */ + @XmlElementDecl(namespace = "http://www.w3.org/2005/Atom", name = "link", scope = SourceType.class) + public JAXBElement createSourceTypeLink(LinkType value) { + return new JAXBElement(_EntryTypeLink_QNAME, LinkType.class, SourceType.class, value); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link PersonType }{@code >}} + * + */ + @XmlElementDecl(namespace = "http://www.w3.org/2005/Atom", name = "contributor", scope = SourceType.class) + public JAXBElement createSourceTypeContributor(PersonType value) { + return new JAXBElement(_EntryTypeContributor_QNAME, PersonType.class, SourceType.class, value); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link DateTimeType }{@code >}} + * + */ + @XmlElementDecl(namespace = "http://www.w3.org/2005/Atom", name = "updated", scope = SourceType.class) + public JAXBElement createSourceTypeUpdated(DateTimeType value) { + return new JAXBElement(_EntryTypeUpdated_QNAME, DateTimeType.class, SourceType.class, value); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link GeneratorType }{@code >}} + * + */ + @XmlElementDecl(namespace = "http://www.w3.org/2005/Atom", name = "generator", scope = SourceType.class) + public JAXBElement createSourceTypeGenerator(GeneratorType value) { + return new JAXBElement(_FeedTypeGenerator_QNAME, GeneratorType.class, SourceType.class, value); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link TextType }{@code >}} + * + */ + @XmlElementDecl(namespace = "http://www.w3.org/2005/Atom", name = "rights", scope = SourceType.class) + public JAXBElement createSourceTypeRights(TextType value) { + return new JAXBElement(_EntryTypeRights_QNAME, TextType.class, SourceType.class, value); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link TextType }{@code >}} + * + */ + @XmlElementDecl(namespace = "http://www.w3.org/2005/Atom", name = "subtitle", scope = SourceType.class) + public JAXBElement createSourceTypeSubtitle(TextType value) { + return new JAXBElement(_FeedTypeSubtitle_QNAME, TextType.class, SourceType.class, value); + } + +} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/atom/PersonType.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/atom/PersonType.java new file mode 100644 index 0000000000000..8bd21a51d5ed6 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/atom/PersonType.java @@ -0,0 +1,179 @@ +// +// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.1.10 in JDK 6 +// See http://java.sun.com/xml/jaxb +// Any modifications to this file will be lost upon recompilation of the source schema. +// Generated on: 2012.09.17 at 02:31:28 PM PDT +// + + +package com.microsoft.windowsazure.services.media.implementation.atom; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import javax.xml.bind.JAXBElement; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAnyAttribute; +import javax.xml.bind.annotation.XmlAnyElement; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlElementRef; +import javax.xml.bind.annotation.XmlElementRefs; +import javax.xml.bind.annotation.XmlSchemaType; +import javax.xml.bind.annotation.XmlType; +import javax.xml.bind.annotation.adapters.CollapsedStringAdapter; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; +import javax.xml.namespace.QName; + + +/** + * + * The Atom person construct is defined in section 3.2 of the format spec. + * + * + *

    Java class for personType complex type. + * + *

    The following schema fragment specifies the expected content contained within this class. + * + *

    + * <complexType name="personType">
    + *   <complexContent>
    + *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
    + *       <choice maxOccurs="unbounded">
    + *         <element name="name" type="{http://www.w3.org/2001/XMLSchema}string"/>
    + *         <element name="uri" type="{http://www.w3.org/2005/Atom}uriType" minOccurs="0"/>
    + *         <element name="email" type="{http://www.w3.org/2005/Atom}emailType" minOccurs="0"/>
    + *         <any namespace='##other'/>
    + *       </choice>
    + *       <attGroup ref="{http://www.w3.org/2005/Atom}commonAttributes"/>
    + *       <anyAttribute namespace='##other'/>
    + *     </restriction>
    + *   </complexContent>
    + * </complexType>
    + * 
    + * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "personType", propOrder = { + "nameOrUriOrEmail" +}) +public class PersonType { + + @XmlElementRefs({ + @XmlElementRef(name = "email", namespace = "http://www.w3.org/2005/Atom", type = JAXBElement.class), + @XmlElementRef(name = "uri", namespace = "http://www.w3.org/2005/Atom", type = JAXBElement.class), + @XmlElementRef(name = "name", namespace = "http://www.w3.org/2005/Atom", type = JAXBElement.class) + }) + @XmlAnyElement(lax = true) + protected List nameOrUriOrEmail; + @XmlAttribute(namespace = "http://www.w3.org/XML/1998/namespace") + @XmlSchemaType(name = "anyURI") + protected String base; + @XmlAttribute(namespace = "http://www.w3.org/XML/1998/namespace") + @XmlJavaTypeAdapter(CollapsedStringAdapter.class) + @XmlSchemaType(name = "language") + protected String lang; + @XmlAnyAttribute + private Map otherAttributes = new HashMap(); + + /** + * Gets the value of the nameOrUriOrEmail property. + * + *

    + * This accessor method returns a reference to the live list, + * not a snapshot. Therefore any modification you make to the + * returned list will be present inside the JAXB object. + * This is why there is not a set method for the nameOrUriOrEmail property. + * + *

    + * For example, to add a new item, do as follows: + *

    +     *    getNameOrUriOrEmail().add(newItem);
    +     * 
    + * + * + *

    + * Objects of the following type(s) are allowed in the list + * {@link JAXBElement }{@code <}{@link String }{@code >} + * {@link Object } + * {@link JAXBElement }{@code <}{@link String }{@code >} + * {@link JAXBElement }{@code <}{@link UriType }{@code >} + * + * + */ + public List getNameOrUriOrEmail() { + if (nameOrUriOrEmail == null) { + nameOrUriOrEmail = new ArrayList(); + } + return this.nameOrUriOrEmail; + } + + /** + * Gets the value of the base property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getBase() { + return base; + } + + /** + * Sets the value of the base property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setBase(String value) { + this.base = value; + } + + /** + * Gets the value of the lang property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getLang() { + return lang; + } + + /** + * Sets the value of the lang property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setLang(String value) { + this.lang = value; + } + + /** + * Gets a map that contains attributes that aren't bound to any typed property on this class. + * + *

    + * the map is keyed by the name of the attribute and + * the value is the string value of the attribute. + * + * the map returned by this method is live, and you can add new attribute + * by updating the map directly. Because of this design, there's no setter. + * + * + * @return + * always non-null + */ + public Map getOtherAttributes() { + return otherAttributes; + } + +} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/atom/SourceType.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/atom/SourceType.java new file mode 100644 index 0000000000000..a5f20de7ae32b --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/atom/SourceType.java @@ -0,0 +1,206 @@ +// +// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.1.10 in JDK 6 +// See http://java.sun.com/xml/jaxb +// Any modifications to this file will be lost upon recompilation of the source schema. +// Generated on: 2012.09.17 at 02:31:28 PM PDT +// + + +package com.microsoft.windowsazure.services.media.implementation.atom; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import javax.xml.bind.JAXBElement; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAnyAttribute; +import javax.xml.bind.annotation.XmlAnyElement; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlElementRef; +import javax.xml.bind.annotation.XmlElementRefs; +import javax.xml.bind.annotation.XmlSchemaType; +import javax.xml.bind.annotation.XmlType; +import javax.xml.bind.annotation.adapters.CollapsedStringAdapter; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; +import javax.xml.namespace.QName; + + +/** + * + * The Atom source construct is defined in section 4.2.11 of the format spec. + * + * + *

    Java class for sourceType complex type. + * + *

    The following schema fragment specifies the expected content contained within this class. + * + *

    + * <complexType name="sourceType">
    + *   <complexContent>
    + *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
    + *       <choice maxOccurs="unbounded">
    + *         <element name="author" type="{http://www.w3.org/2005/Atom}personType" maxOccurs="unbounded" minOccurs="0"/>
    + *         <element name="category" type="{http://www.w3.org/2005/Atom}categoryType" maxOccurs="unbounded" minOccurs="0"/>
    + *         <element name="contributor" type="{http://www.w3.org/2005/Atom}personType" maxOccurs="unbounded" minOccurs="0"/>
    + *         <element name="generator" type="{http://www.w3.org/2005/Atom}generatorType" minOccurs="0"/>
    + *         <element name="icon" type="{http://www.w3.org/2005/Atom}iconType" minOccurs="0"/>
    + *         <element name="id" type="{http://www.w3.org/2005/Atom}idType" minOccurs="0"/>
    + *         <element name="link" type="{http://www.w3.org/2005/Atom}linkType" maxOccurs="unbounded" minOccurs="0"/>
    + *         <element name="logo" type="{http://www.w3.org/2005/Atom}logoType" minOccurs="0"/>
    + *         <element name="rights" type="{http://www.w3.org/2005/Atom}textType" minOccurs="0"/>
    + *         <element name="subtitle" type="{http://www.w3.org/2005/Atom}textType" minOccurs="0"/>
    + *         <element name="title" type="{http://www.w3.org/2005/Atom}textType" minOccurs="0"/>
    + *         <element name="updated" type="{http://www.w3.org/2005/Atom}dateTimeType" minOccurs="0"/>
    + *         <any namespace='##other' maxOccurs="unbounded" minOccurs="0"/>
    + *       </choice>
    + *       <attGroup ref="{http://www.w3.org/2005/Atom}commonAttributes"/>
    + *       <anyAttribute namespace='##other'/>
    + *     </restriction>
    + *   </complexContent>
    + * </complexType>
    + * 
    + * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "sourceType", propOrder = { + "authorOrCategoryOrContributor" +}) +public class SourceType { + + @XmlElementRefs({ + @XmlElementRef(name = "contributor", namespace = "http://www.w3.org/2005/Atom", type = JAXBElement.class), + @XmlElementRef(name = "title", namespace = "http://www.w3.org/2005/Atom", type = JAXBElement.class), + @XmlElementRef(name = "author", namespace = "http://www.w3.org/2005/Atom", type = JAXBElement.class), + @XmlElementRef(name = "category", namespace = "http://www.w3.org/2005/Atom", type = JAXBElement.class), + @XmlElementRef(name = "generator", namespace = "http://www.w3.org/2005/Atom", type = JAXBElement.class), + @XmlElementRef(name = "logo", namespace = "http://www.w3.org/2005/Atom", type = JAXBElement.class), + @XmlElementRef(name = "id", namespace = "http://www.w3.org/2005/Atom", type = JAXBElement.class), + @XmlElementRef(name = "icon", namespace = "http://www.w3.org/2005/Atom", type = JAXBElement.class), + @XmlElementRef(name = "link", namespace = "http://www.w3.org/2005/Atom", type = JAXBElement.class), + @XmlElementRef(name = "rights", namespace = "http://www.w3.org/2005/Atom", type = JAXBElement.class), + @XmlElementRef(name = "subtitle", namespace = "http://www.w3.org/2005/Atom", type = JAXBElement.class), + @XmlElementRef(name = "updated", namespace = "http://www.w3.org/2005/Atom", type = JAXBElement.class) + }) + @XmlAnyElement(lax = true) + protected List authorOrCategoryOrContributor; + @XmlAttribute(namespace = "http://www.w3.org/XML/1998/namespace") + @XmlSchemaType(name = "anyURI") + protected String base; + @XmlAttribute(namespace = "http://www.w3.org/XML/1998/namespace") + @XmlJavaTypeAdapter(CollapsedStringAdapter.class) + @XmlSchemaType(name = "language") + protected String lang; + @XmlAnyAttribute + private Map otherAttributes = new HashMap(); + + /** + * Gets the value of the authorOrCategoryOrContributor property. + * + *

    + * This accessor method returns a reference to the live list, + * not a snapshot. Therefore any modification you make to the + * returned list will be present inside the JAXB object. + * This is why there is not a set method for the authorOrCategoryOrContributor property. + * + *

    + * For example, to add a new item, do as follows: + *

    +     *    getAuthorOrCategoryOrContributor().add(newItem);
    +     * 
    + * + * + *

    + * Objects of the following type(s) are allowed in the list + * {@link JAXBElement }{@code <}{@link PersonType }{@code >} + * {@link JAXBElement }{@code <}{@link TextType }{@code >} + * {@link JAXBElement }{@code <}{@link PersonType }{@code >} + * {@link JAXBElement }{@code <}{@link GeneratorType }{@code >} + * {@link JAXBElement }{@code <}{@link LogoType }{@code >} + * {@link JAXBElement }{@code <}{@link IdType }{@code >} + * {@link JAXBElement }{@code <}{@link TextType }{@code >} + * {@link JAXBElement }{@code <}{@link DateTimeType }{@code >} + * {@link JAXBElement }{@code <}{@link CategoryType }{@code >} + * {@link Object } + * {@link JAXBElement }{@code <}{@link IconType }{@code >} + * {@link JAXBElement }{@code <}{@link LinkType }{@code >} + * {@link JAXBElement }{@code <}{@link TextType }{@code >} + * + * + */ + public List getAuthorOrCategoryOrContributor() { + if (authorOrCategoryOrContributor == null) { + authorOrCategoryOrContributor = new ArrayList(); + } + return this.authorOrCategoryOrContributor; + } + + /** + * Gets the value of the base property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getBase() { + return base; + } + + /** + * Sets the value of the base property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setBase(String value) { + this.base = value; + } + + /** + * Gets the value of the lang property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getLang() { + return lang; + } + + /** + * Sets the value of the lang property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setLang(String value) { + this.lang = value; + } + + /** + * Gets a map that contains attributes that aren't bound to any typed property on this class. + * + *

    + * the map is keyed by the name of the attribute and + * the value is the string value of the attribute. + * + * the map returned by this method is live, and you can add new attribute + * by updating the map directly. Because of this design, there's no setter. + * + * + * @return + * always non-null + */ + public Map getOtherAttributes() { + return otherAttributes; + } + +} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/atom/TextType.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/atom/TextType.java new file mode 100644 index 0000000000000..6421c6ae97c96 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/atom/TextType.java @@ -0,0 +1,206 @@ +// +// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.1.10 in JDK 6 +// See http://java.sun.com/xml/jaxb +// Any modifications to this file will be lost upon recompilation of the source schema. +// Generated on: 2012.09.17 at 02:31:28 PM PDT +// + + +package com.microsoft.windowsazure.services.media.implementation.atom; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAnyAttribute; +import javax.xml.bind.annotation.XmlAnyElement; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlMixed; +import javax.xml.bind.annotation.XmlSchemaType; +import javax.xml.bind.annotation.XmlType; +import javax.xml.bind.annotation.adapters.CollapsedStringAdapter; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; +import javax.xml.namespace.QName; + + +/** + * + * The Atom text construct is defined in section 3.1 of the format spec. + * + * + *

    Java class for textType complex type. + * + *

    The following schema fragment specifies the expected content contained within this class. + * + *

    + * <complexType name="textType">
    + *   <complexContent>
    + *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
    + *       <sequence>
    + *         <any namespace='http://www.w3.org/1999/xhtml' minOccurs="0"/>
    + *       </sequence>
    + *       <attGroup ref="{http://www.w3.org/2005/Atom}commonAttributes"/>
    + *       <attribute name="type">
    + *         <simpleType>
    + *           <restriction base="{http://www.w3.org/2001/XMLSchema}token">
    + *             <enumeration value="text"/>
    + *             <enumeration value="html"/>
    + *             <enumeration value="xhtml"/>
    + *           </restriction>
    + *         </simpleType>
    + *       </attribute>
    + *       <anyAttribute namespace='##other'/>
    + *     </restriction>
    + *   </complexContent>
    + * </complexType>
    + * 
    + * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "textType", propOrder = { + "content" +}) +public class TextType { + + @XmlMixed + @XmlAnyElement(lax = true) + protected List content; + @XmlAttribute + @XmlJavaTypeAdapter(CollapsedStringAdapter.class) + protected String type; + @XmlAttribute(namespace = "http://www.w3.org/XML/1998/namespace") + @XmlSchemaType(name = "anyURI") + protected String base; + @XmlAttribute(namespace = "http://www.w3.org/XML/1998/namespace") + @XmlJavaTypeAdapter(CollapsedStringAdapter.class) + @XmlSchemaType(name = "language") + protected String lang; + @XmlAnyAttribute + private Map otherAttributes = new HashMap(); + + /** + * + * The Atom text construct is defined in section 3.1 of the format spec. + * Gets the value of the content property. + * + *

    + * This accessor method returns a reference to the live list, + * not a snapshot. Therefore any modification you make to the + * returned list will be present inside the JAXB object. + * This is why there is not a set method for the content property. + * + *

    + * For example, to add a new item, do as follows: + *

    +     *    getContent().add(newItem);
    +     * 
    + * + * + *

    + * Objects of the following type(s) are allowed in the list + * {@link Object } + * {@link String } + * + * + */ + public List getContent() { + if (content == null) { + content = new ArrayList(); + } + return this.content; + } + + /** + * Gets the value of the type property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getType() { + return type; + } + + /** + * Sets the value of the type property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setType(String value) { + this.type = value; + } + + /** + * Gets the value of the base property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getBase() { + return base; + } + + /** + * Sets the value of the base property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setBase(String value) { + this.base = value; + } + + /** + * Gets the value of the lang property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getLang() { + return lang; + } + + /** + * Sets the value of the lang property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setLang(String value) { + this.lang = value; + } + + /** + * Gets a map that contains attributes that aren't bound to any typed property on this class. + * + *

    + * the map is keyed by the name of the attribute and + * the value is the string value of the attribute. + * + * the map returned by this method is live, and you can add new attribute + * by updating the map directly. Because of this design, there's no setter. + * + * + * @return + * always non-null + */ + public Map getOtherAttributes() { + return otherAttributes; + } + +} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/atom/UriType.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/atom/UriType.java new file mode 100644 index 0000000000000..07c555c1dd6ee --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/atom/UriType.java @@ -0,0 +1,152 @@ +// +// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.1.10 in JDK 6 +// See http://java.sun.com/xml/jaxb +// Any modifications to this file will be lost upon recompilation of the source schema. +// Generated on: 2012.09.17 at 02:31:28 PM PDT +// + + +package com.microsoft.windowsazure.services.media.implementation.atom; + +import java.util.HashMap; +import java.util.Map; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAnyAttribute; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlSchemaType; +import javax.xml.bind.annotation.XmlType; +import javax.xml.bind.annotation.XmlValue; +import javax.xml.bind.annotation.adapters.CollapsedStringAdapter; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; +import javax.xml.namespace.QName; + + +/** + *

    Java class for uriType complex type. + * + *

    The following schema fragment specifies the expected content contained within this class. + * + *

    + * <complexType name="uriType">
    + *   <simpleContent>
    + *     <extension base="<http://www.w3.org/2001/XMLSchema>anyURI">
    + *       <attGroup ref="{http://www.w3.org/2005/Atom}commonAttributes"/>
    + *       <anyAttribute namespace='##other'/>
    + *     </extension>
    + *   </simpleContent>
    + * </complexType>
    + * 
    + * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "uriType", propOrder = { + "value" +}) +public class UriType { + + @XmlValue + @XmlSchemaType(name = "anyURI") + protected String value; + @XmlAttribute(namespace = "http://www.w3.org/XML/1998/namespace") + @XmlSchemaType(name = "anyURI") + protected String base; + @XmlAttribute(namespace = "http://www.w3.org/XML/1998/namespace") + @XmlJavaTypeAdapter(CollapsedStringAdapter.class) + @XmlSchemaType(name = "language") + protected String lang; + @XmlAnyAttribute + private Map otherAttributes = new HashMap(); + + /** + * Gets the value of the value property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getValue() { + return value; + } + + /** + * Sets the value of the value property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setValue(String value) { + this.value = value; + } + + /** + * Gets the value of the base property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getBase() { + return base; + } + + /** + * Sets the value of the base property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setBase(String value) { + this.base = value; + } + + /** + * Gets the value of the lang property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getLang() { + return lang; + } + + /** + * Sets the value of the lang property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setLang(String value) { + this.lang = value; + } + + /** + * Gets a map that contains attributes that aren't bound to any typed property on this class. + * + *

    + * the map is keyed by the name of the attribute and + * the value is the string value of the attribute. + * + * the map returned by this method is live, and you can add new attribute + * by updating the map directly. Because of this design, there's no setter. + * + * + * @return + * always non-null + */ + public Map getOtherAttributes() { + return otherAttributes; + } + +} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/atom/package-info.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/atom/package-info.java new file mode 100644 index 0000000000000..5fc88fe9c0e0d --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/atom/package-info.java @@ -0,0 +1,9 @@ +// +// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.1.10 in JDK 6 +// See http://java.sun.com/xml/jaxb +// Any modifications to this file will be lost upon recompilation of the source schema. +// Generated on: 2012.09.17 at 02:31:28 PM PDT +// + +@javax.xml.bind.annotation.XmlSchema(namespace = "http://www.w3.org/2005/Atom", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED) +package com.microsoft.windowsazure.services.media.implementation.atom; From 88ab2d77797f12ba442655f84e26986207b18034 Mon Sep 17 00:00:00 2001 From: Chris Tavares Date: Mon, 17 Sep 2012 15:46:44 -0700 Subject: [PATCH 34/70] Added first cut at handrolled serialization wrapper classes along with required infrastructure. --- .../implementation/content/AssetType.java | 156 ++++++++++++++++++ .../implementation/content/Constants.java | 61 +++++++ .../content/ODataActionType.java | 5 + .../implementation/content/ObjectFactory.java | 43 +++++ 4 files changed, 265 insertions(+) create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/AssetType.java create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/Constants.java create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/ODataActionType.java create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/ObjectFactory.java diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/AssetType.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/AssetType.java new file mode 100644 index 0000000000000..9b9cfe57aec7b --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/AssetType.java @@ -0,0 +1,156 @@ +/** + * 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 + * + * 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.content; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.datatype.XMLGregorianCalendar; + +/** + * This type maps the XML returned in the odata ATOM serialization + * for Asset entities. + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +public class AssetType { + + @XmlElement(name = "Id", namespace = Constants.ODATA_DATA_NS) + protected String id; + + @XmlElement(name = "State", namespace = Constants.ODATA_DATA_NS) + protected int state; + + @XmlElement(name = "Created", namespace = Constants.ODATA_DATA_NS) + protected XMLGregorianCalendar created; + + @XmlElement(name = "LastModified", namespace = Constants.ODATA_DATA_NS) + protected XMLGregorianCalendar lastModified; + + @XmlElement(name = "AlternateId", namespace = Constants.ODATA_DATA_NS) + protected String alternateId; + + @XmlElement(name = "Name", namespace = Constants.ODATA_DATA_NS) + protected String name; + + @XmlElement(name = "Options", namespace = Constants.ODATA_DATA_NS) + protected int options; + + /** + * @return the id + */ + public String getId() { + return id; + } + + /** + * @param id + * the id to set + */ + public void setId(String id) { + this.id = id; + } + + /** + * @return the state + */ + public int getState() { + return state; + } + + /** + * @param state + * the state to set + */ + public void setState(int state) { + this.state = state; + } + + /** + * @return the created + */ + public XMLGregorianCalendar getCreated() { + return created; + } + + /** + * @param created + * the created to set + */ + public void setCreated(XMLGregorianCalendar created) { + this.created = created; + } + + /** + * @return the lastModified + */ + public XMLGregorianCalendar getLastModified() { + return lastModified; + } + + /** + * @param lastModified + * the lastModified to set + */ + public void setLastModified(XMLGregorianCalendar lastModified) { + this.lastModified = lastModified; + } + + /** + * @return the alternateId + */ + public String getAlternateId() { + return alternateId; + } + + /** + * @param alternateId + * the alternateId to set + */ + public void setAlternateId(String alternateId) { + this.alternateId = alternateId; + } + + /** + * @return the name + */ + public String getName() { + return name; + } + + /** + * @param name + * the name to set + */ + public void setName(String name) { + this.name = name; + } + + /** + * @return the options + */ + public int getOptions() { + return options; + } + + /** + * @param options + * the options to set + */ + public void setOptions(int options) { + this.options = options; + } +} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/Constants.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/Constants.java new file mode 100644 index 0000000000000..b11c4eadf4409 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/Constants.java @@ -0,0 +1,61 @@ +/** + * 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 + * + * 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.content; + +import javax.xml.namespace.QName; + +/** + * This class provides a set of constants for element names + * and namespaces used throughout the serialization of + * media services entities. + */ + +public class Constants { + /** + * XML Namespace for Atom syndication format, as defined by IETF RFC 4287 + */ + public static final String ATOM_NS = "http://www.w3.org/2005/Atom"; + + /** + * XML Namespace for OData data as serialized inside Atom syndication format. + */ + public static final String ODATA_DATA_NS = "http://schemas.microsoft.com/ado/2007/08/dataservices"; + + /** + * XML Namespace for OData metadata as serialized inside Atom syndication format. + */ + public static final String ODATA_METADATA_NS = "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"; + + /** + * EDM namespace for Azure Media Services entities, as defined in Media Services EDMX file. + */ + public static final String MEDIA_SERVICES_EDM_NAMESPACE = "Microsoft.Cloud.Media.Vod.Rest.Data.Models"; + + /** + * Element name for Atom content element, including namespace + */ + public static final QName ATOM_CONTENT_ELEMENT_NAME = new QName("content", ATOM_NS); + + /** + * Element name for OData action elements, including namespace + */ + public static final QName ODATA_ACTION_ELEMENT_NAME = new QName("action", ODATA_METADATA_NS); + + /** + * Element name for the metadata properties element, including namespace. + */ + public static final QName ODATA_PROPERTIES_ELEMENT_NAME = new QName("properties", ODATA_METADATA_NS); +} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/ODataActionType.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/ODataActionType.java new file mode 100644 index 0000000000000..04126a27ab64b --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/ODataActionType.java @@ -0,0 +1,5 @@ +package com.microsoft.windowsazure.services.media.implementation.content; + +public class ODataActionType { + +} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/ObjectFactory.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/ObjectFactory.java new file mode 100644 index 0000000000000..e38aecbba63e9 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/ObjectFactory.java @@ -0,0 +1,43 @@ +/** + * 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 + * + * 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.content; + +import javax.xml.bind.annotation.XmlRegistry; + +/** + * Class used by JAXB to instantiate the types in this package. + * + */ +@XmlRegistry +public class ObjectFactory { + + /** + * Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: + * com.microsoft.windowsazure.services.media.implementation.atom + * + */ + public ObjectFactory() { + } + + /** + * Create an instance of {@link AssetType } + * + * @return a new AssetType instance. + */ + public AssetType createAssetType() { + return new AssetType(); + } +} From ea38d271a2d57355d184d0bd5c9e156ceb604e81 Mon Sep 17 00:00:00 2001 From: Chris Tavares Date: Mon, 17 Sep 2012 16:14:28 -0700 Subject: [PATCH 35/70] Brought in definiton for odata action element, start of test cases --- .../content/ODataActionType.java | 54 +++++++++++++++++++ .../ODataSerializationTest.java | 14 +++++ 2 files changed, 68 insertions(+) create mode 100644 microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/implementation/ODataSerializationTest.java diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/ODataActionType.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/ODataActionType.java index 04126a27ab64b..c64e4b68178ee 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/ODataActionType.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/ODataActionType.java @@ -1,5 +1,59 @@ +/** + * 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 + * + * 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.content; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; + +// XML Serialization class for odata m:action elements + +@XmlAccessorType(XmlAccessType.FIELD) public class ODataActionType { + @XmlAttribute(required = true) + protected String metadata; + + @XmlAttribute(required = true) + protected String target; + + @XmlAttribute(required = true) + protected String title; + + public String getMetadata() { + return metadata; + } + + public void setMetadata(String metadata) { + this.metadata = metadata; + } + + public String getTarget() { + return target; + } + + public void setTarget(String target) { + this.target = target; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } } diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/implementation/ODataSerializationTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/implementation/ODataSerializationTest.java new file mode 100644 index 0000000000000..f107c1dd1eb5e --- /dev/null +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/implementation/ODataSerializationTest.java @@ -0,0 +1,14 @@ +package com.microsoft.windowsazure.services.media.implementation; + +import static org.junit.Assert.*; + +import org.junit.Test; + +public class ODataSerializationTest { + + @Test + public void test() { + fail("Not yet implemented"); + } + +} From 29c9c476360a70e1cd7b22f209313a6c78fb4508 Mon Sep 17 00:00:00 2001 From: Chris Tavares Date: Tue, 18 Sep 2012 14:07:33 -0700 Subject: [PATCH 36/70] Deserializing sample data from string succeeded. --- .../implementation/ODataAtomUnmarshaller.java | 119 ++++++++++++++++++ .../media/implementation/ODataEntity.java | 48 +++++++ .../media/implementation/atom/FeedType.java | 52 ++++---- .../implementation/content/ObjectFactory.java | 9 ++ .../ODataSerializationTest.java | 44 ++++++- 5 files changed, 242 insertions(+), 30 deletions(-) create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ODataAtomUnmarshaller.java create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ODataEntity.java 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 0000000000000..c5666967ac4e8 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ODataAtomUnmarshaller.java @@ -0,0 +1,119 @@ +/** + * 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 + * + * 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.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.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; + +public class ODataAtomUnmarshaller { + private final JAXBContext atomContext; + private final JAXBContext mediaContentContext; + private final Unmarshaller atomUnmarshaller; + private final Unmarshaller mediaContentUnmarshaller; + + public ODataAtomUnmarshaller() throws JAXBException { + atomContext = JAXBContext.newInstance(FeedType.class.getPackage().getName()); + atomUnmarshaller = atomContext.createUnmarshaller(); + mediaContentContext = JAXBContext.newInstance(AssetType.class.getPackage().getName()); + mediaContentUnmarshaller = mediaContentContext.createUnmarshaller(); + } + + public ODataEntity unmarshal(InputStream stream, Class contentType) throws JAXBException { + JAXBElement feedElement = atomUnmarshaller.unmarshal(new StreamSource(stream), FeedType.class); + FeedType feed = feedElement.getValue(); + EntryType firstEntry = getFirstEntry(feed); + + Object content = getEntryContent(firstEntry, contentType); + + return new ODataEntity(firstEntry, content); + } + + private Object getEntryContent(EntryType entry, Class contentType) throws JAXBException { + List entryChildren = entry.getEntryChildren(); + Object retval = null; + + for (int i = 0; i < entryChildren.size(); ++i) { + Object child = entryChildren.get(i); + if (child instanceof JAXBElement) { + // It's a parsed element, if it's content unmarshal, fixup, and store return value + JAXBElement e = (JAXBElement) child; + if (e.getDeclaredType() == ContentType.class) { + retval = unmarshalEntryContent((ContentType) e.getValue(), contentType); + } + } + else { + // It's an arbitrary XML element. If it's an action, fix up element. + Element e = (Element) child; + if (qnameFromElement(e).equals(Constants.ODATA_ACTION_ELEMENT_NAME)) { + JAXBElement actionElement = mediaContentUnmarshaller.unmarshal(e, + ODataActionType.class); + entryChildren.set(i, actionElement); + } + } + } + return retval; + } + + private EntryType getFirstEntry(FeedType feed) { + for (Object child : feed.getFeedChildren()) { + if (child instanceof JAXBElement) { + JAXBElement e = (JAXBElement) child; + + if (e.getDeclaredType() == EntryType.class) { + return (EntryType) e.getValue(); + } + } + } + return null; + } + + private Object unmarshalEntryContent(ContentType content, Class actualContentType) throws JAXBException { + List contentChildren = content.getContent(); + for (int i = 0; i < contentChildren.size(); ++i) { + Object child = contentChildren.get(i); + if (child instanceof Element) { + Element e = (Element) child; + if (qnameFromElement(e).equals(Constants.ODATA_PROPERTIES_ELEMENT_NAME)) { + JAXBElement actualContentElement = mediaContentUnmarshaller.unmarshal(e, actualContentType); + contentChildren.set(i, actualContentElement); + return actualContentElement.getValue(); + } + } + } + return null; + } + + private QName qnameFromElement(Element e) { + return new QName(e.getLocalName(), e.getNamespaceURI()); + } + +} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ODataEntity.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ODataEntity.java new file mode 100644 index 0000000000000..85a9fae74b1f8 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ODataEntity.java @@ -0,0 +1,48 @@ +/** + * 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 + * + * 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 com.microsoft.windowsazure.services.media.implementation.atom.EntryType; + +/** + * Class wrapping deserialized OData entities. Allows easy + * access to entry and content types. + * + */ +public class ODataEntity { + + private final EntryType entry; + private final T content; + + public ODataEntity(EntryType entry, T content) { + this.entry = entry; + this.content = content; + } + + /** + * @return the entry + */ + public EntryType getEntry() { + return entry; + } + + /** + * @return the content + */ + public T getContent() { + return content; + } +} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/atom/FeedType.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/atom/FeedType.java index 435a81f20f110..9c5ea3df46aef 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/atom/FeedType.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/atom/FeedType.java @@ -2,7 +2,7 @@ // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.1.10 in JDK 6 // See http://java.sun.com/xml/jaxb // Any modifications to this file will be lost upon recompilation of the source schema. -// Generated on: 2012.09.17 at 02:31:28 PM PDT +// Generated on: 2012.09.18 at 11:05:53 AM PDT // @@ -67,27 +67,27 @@ */ @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "feedType", propOrder = { - "authorOrCategoryOrContributor" + "feedChildren" }) public class FeedType { @XmlElementRefs({ - @XmlElementRef(name = "logo", namespace = "http://www.w3.org/2005/Atom", type = JAXBElement.class), + @XmlElementRef(name = "updated", namespace = "http://www.w3.org/2005/Atom", type = JAXBElement.class), + @XmlElementRef(name = "generator", namespace = "http://www.w3.org/2005/Atom", type = JAXBElement.class), @XmlElementRef(name = "rights", namespace = "http://www.w3.org/2005/Atom", type = JAXBElement.class), - @XmlElementRef(name = "icon", namespace = "http://www.w3.org/2005/Atom", type = JAXBElement.class), + @XmlElementRef(name = "id", namespace = "http://www.w3.org/2005/Atom", type = JAXBElement.class), + @XmlElementRef(name = "link", namespace = "http://www.w3.org/2005/Atom", type = JAXBElement.class), @XmlElementRef(name = "subtitle", namespace = "http://www.w3.org/2005/Atom", type = JAXBElement.class), @XmlElementRef(name = "contributor", namespace = "http://www.w3.org/2005/Atom", type = JAXBElement.class), - @XmlElementRef(name = "title", namespace = "http://www.w3.org/2005/Atom", type = JAXBElement.class), @XmlElementRef(name = "entry", namespace = "http://www.w3.org/2005/Atom", type = JAXBElement.class), + @XmlElementRef(name = "logo", namespace = "http://www.w3.org/2005/Atom", type = JAXBElement.class), + @XmlElementRef(name = "icon", namespace = "http://www.w3.org/2005/Atom", type = JAXBElement.class), @XmlElementRef(name = "author", namespace = "http://www.w3.org/2005/Atom", type = JAXBElement.class), - @XmlElementRef(name = "id", namespace = "http://www.w3.org/2005/Atom", type = JAXBElement.class), - @XmlElementRef(name = "updated", namespace = "http://www.w3.org/2005/Atom", type = JAXBElement.class), - @XmlElementRef(name = "link", namespace = "http://www.w3.org/2005/Atom", type = JAXBElement.class), - @XmlElementRef(name = "generator", namespace = "http://www.w3.org/2005/Atom", type = JAXBElement.class), - @XmlElementRef(name = "category", namespace = "http://www.w3.org/2005/Atom", type = JAXBElement.class) + @XmlElementRef(name = "category", namespace = "http://www.w3.org/2005/Atom", type = JAXBElement.class), + @XmlElementRef(name = "title", namespace = "http://www.w3.org/2005/Atom", type = JAXBElement.class) }) @XmlAnyElement(lax = true) - protected List authorOrCategoryOrContributor; + protected List feedChildren; @XmlAttribute(namespace = "http://www.w3.org/XML/1998/namespace") @XmlSchemaType(name = "anyURI") protected String base; @@ -99,45 +99,45 @@ public class FeedType { private Map otherAttributes = new HashMap(); /** - * Gets the value of the authorOrCategoryOrContributor property. + * Gets the value of the feedChildren property. * *

    * This accessor method returns a reference to the live list, * not a snapshot. Therefore any modification you make to the * returned list will be present inside the JAXB object. - * This is why there is not a set method for the authorOrCategoryOrContributor property. + * This is why there is not a set method for the feedChildren property. * *

    * For example, to add a new item, do as follows: *

    -     *    getAuthorOrCategoryOrContributor().add(newItem);
    +     *    getFeedChildren().add(newItem);
          * 
    * * *

    * Objects of the following type(s) are allowed in the list - * {@link JAXBElement }{@code <}{@link LogoType }{@code >} + * {@link JAXBElement }{@code <}{@link DateTimeType }{@code >} + * {@link JAXBElement }{@code <}{@link GeneratorType }{@code >} * {@link JAXBElement }{@code <}{@link TextType }{@code >} - * {@link JAXBElement }{@code <}{@link IconType }{@code >} + * {@link JAXBElement }{@code <}{@link IdType }{@code >} + * {@link JAXBElement }{@code <}{@link LinkType }{@code >} * {@link JAXBElement }{@code <}{@link TextType }{@code >} * {@link JAXBElement }{@code <}{@link PersonType }{@code >} - * {@link JAXBElement }{@code <}{@link TextType }{@code >} + * {@link Object } * {@link JAXBElement }{@code <}{@link EntryType }{@code >} + * {@link JAXBElement }{@code <}{@link LogoType }{@code >} + * {@link JAXBElement }{@code <}{@link IconType }{@code >} * {@link JAXBElement }{@code <}{@link PersonType }{@code >} - * {@link JAXBElement }{@code <}{@link IdType }{@code >} - * {@link JAXBElement }{@code <}{@link DateTimeType }{@code >} - * {@link JAXBElement }{@code <}{@link LinkType }{@code >} - * {@link JAXBElement }{@code <}{@link GeneratorType }{@code >} * {@link JAXBElement }{@code <}{@link CategoryType }{@code >} - * {@link Object } + * {@link JAXBElement }{@code <}{@link TextType }{@code >} * * */ - public List getAuthorOrCategoryOrContributor() { - if (authorOrCategoryOrContributor == null) { - authorOrCategoryOrContributor = new ArrayList(); + public List getFeedChildren() { + if (feedChildren == null) { + feedChildren = new ArrayList(); } - return this.authorOrCategoryOrContributor; + return this.feedChildren; } /** diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/ObjectFactory.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/ObjectFactory.java index e38aecbba63e9..b9fef1eb50b22 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/ObjectFactory.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/ObjectFactory.java @@ -40,4 +40,13 @@ public ObjectFactory() { public AssetType createAssetType() { return new AssetType(); } + + /** + * Create an instance of {@link ODataActionType } + * + * @return a new ODataActionType instance. + */ + public ODataActionType createODataActionType() { + return new ODataActionType(); + } } diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/implementation/ODataSerializationTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/implementation/ODataSerializationTest.java index f107c1dd1eb5e..4d9e908eadd80 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/implementation/ODataSerializationTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/implementation/ODataSerializationTest.java @@ -1,14 +1,50 @@ package com.microsoft.windowsazure.services.media.implementation; -import static org.junit.Assert.*; +import java.io.ByteArrayInputStream; +import java.io.InputStream; + +import junit.framework.Assert; import org.junit.Test; +import com.microsoft.windowsazure.services.media.implementation.content.AssetType; + public class ODataSerializationTest { + private final String sampleFeedOneAsset = "\n" + + "\n" + + " https://wamsbayclus001rest-hs.cloudapp.net/api/Assets\n" + + " Assets\n" + + " 2012-08-28T18:35:15Z\n" + + " \n" + + " \n" + + " https://wamsbayclus001rest-hs.cloudapp.net/api/Assets('nb%3Acid%3AUUID%3A1f6c7bb4-8013-486e-b4c9-2e4a6842b9a6')\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " <updated>2012-08-28T18:35:15Z</updated>\n" + + " <author>\n" + + " <name />\n" + + " </author>\n" + + " <m:action metadata=\"https://wamsbayclus001rest-hs.cloudapp.net/api/$metadata#WindowsAzureMediaServices.Publish\" title=\"Publish\" target=\"https://wamsbayclus001rest-hs.cloudapp.net/api/Assets('nb%3Acid%3AUUID%3A1f6c7bb4-8013-486e-b4c9-2e4a6842b9a6')/Publish\" />\n" + + " <content type=\"application/xml\">\n" + " <m:properties>\n" + + " <d:Id>nb:cid:UUID:1f6c7bb4-8013-486e-b4c9-2e4a6842b9a6</d:Id>\n" + + " <d:State m:type=\"Edm.Int32\">0</d:State>\n" + + " <d:Created m:type=\"Edm.DateTime\">2012-08-28T18:34:06.123</d:Created>\n" + + " <d:LastModified m:type=\"Edm.DateTime\">2012-08-28T18:34:06.123</d:LastModified>\n" + + " <d:AlternateId m:null=\"true\" />\n" + " <d:Name>testAsset</d:Name>\n" + + " <d:Options m:type=\"Edm.Int32\">0</d:Options>\n" + " </m:properties>\n" + + " </content>\n" + " </entry>\n" + "</feed>"; + @Test - public void test() { - fail("Not yet implemented"); + public void canUnmarshallAssetFromFeed() throws Exception { + ODataAtomUnmarshaller um = new ODataAtomUnmarshaller(); + InputStream input = new ByteArrayInputStream(sampleFeedOneAsset.getBytes("UTF-8")); + ODataEntity<AssetType> entry = (ODataEntity<AssetType>) um.unmarshal(input, AssetType.class); + Assert.assertEquals("nb:cid:UUID:1f6c7bb4-8013-486e-b4c9-2e4a6842b9a6", entry.getContent().getId()); } - } From 497ed36917ecb3fbe9179555edc508175edd2f1a Mon Sep 17 00:00:00 2001 From: Albert Cheng <gongchen@microsoft.com> Date: Tue, 18 Sep 2012 23:59:22 -0700 Subject: [PATCH 37/70] Initial commit for Asset CRUD operation unit test and rest proxy. --- .../windowsazure/services/media/Exports.java | 2 +- .../services/media/MediaContract.java | 14 +- .../MediaExceptionProcessor.java | 41 +++- .../media/implementation/MediaRestProxy.java | 34 +++ .../implementation/OAuthTokenManager.java | 11 +- .../media/models/ListAssetsOptions.java | 19 ++ .../services/media/IntegrationTestBase.java | 2 +- .../media/MediaServiceIntegrationTest.java | 198 ++++++++++++++++++ .../implementation/OAuthTokenManagerTest.java | 2 +- 9 files changed, 308 insertions(+), 15 deletions(-) create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/ListAssetsOptions.java create mode 100644 microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/MediaServiceIntegrationTest.java 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 791ed56f87555..cceb8d2377aa9 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 @@ -27,7 +27,7 @@ public class Exports implements Builder.Exports { /** - * register the OAUTH service. + * register the Media services. */ @Override public void register(Builder.Registry registry) { 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 3e92ac300dae0..3fd0e8cee4033 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 @@ -14,7 +14,11 @@ */ package com.microsoft.windowsazure.services.media; +import java.util.List; + import com.microsoft.windowsazure.services.core.FilterableService; +import com.microsoft.windowsazure.services.media.models.Asset; +import com.microsoft.windowsazure.services.media.models.ListAssetsOptions; /** * @@ -23,6 +27,14 @@ */ public interface MediaContract extends FilterableService<MediaContract> { - // Will fill in as we implement the various Media Services entities + public Asset createAsset(Asset asset); + + public Asset getAsset(Asset asset); + + public List<Asset> listAssets(ListAssetsOptions listAssetsOptions); + + public Asset updateAsset(Asset updatedAsset); + + public void deleteAsset(String assetId); } 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 d9c3141d52064..4db539dbde579 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 @@ -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,8 @@ 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.Asset; +import com.microsoft.windowsazure.services.media.models.ListAssetsOptions; /** * Wrapper implementation of <code>MediaServicesContract</code> that @@ -32,21 +36,21 @@ */ public class MediaExceptionProcessor implements MediaContract { - private final MediaContract next; + private final MediaContract service; static Log log = LogFactory.getLog(MediaContract.class); - public MediaExceptionProcessor(MediaContract next) { - this.next = next; + public MediaExceptionProcessor(MediaContract service) { + this.service = service; } @Inject - public MediaExceptionProcessor(MediaRestProxy next) { - this.next = next; + public MediaExceptionProcessor(MediaRestProxy service) { + this.service = service; } @Override public MediaContract withFilter(ServiceFilter filter) { - return new MediaExceptionProcessor(next.withFilter(filter)); + return new MediaExceptionProcessor(service.withFilter(filter)); } private ServiceException processCatch(ServiceException e) { @@ -54,4 +58,29 @@ private ServiceException processCatch(ServiceException e) { return ServiceExceptionFactory.process("MediaServices", e); } + @Override + public Asset createAsset(Asset asset) { + return service.createAsset(asset); + } + + @Override + public Asset getAsset(Asset asset) { + return service.getAsset(asset); + } + + @Override + public List<Asset> listAssets(ListAssetsOptions listAssetsOptions) { + return service.listAssets(listAssetsOptions); + } + + @Override + public Asset updateAsset(Asset updatedAsset) { + return service.updateAsset(updatedAsset); + } + + @Override + public void deleteAsset(String assetId) { + service.deleteAsset(assetId); + } + } 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 9b1dfc25e5a60..b94d8acc240c7 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 @@ -15,7 +15,9 @@ package com.microsoft.windowsazure.services.media.implementation; +import java.util.ArrayList; import java.util.Arrays; +import java.util.List; import javax.inject.Inject; @@ -25,6 +27,8 @@ import com.microsoft.windowsazure.services.core.ServiceFilter; import com.microsoft.windowsazure.services.core.utils.pipeline.ClientFilterAdapter; import com.microsoft.windowsazure.services.media.MediaContract; +import com.microsoft.windowsazure.services.media.models.Asset; +import com.microsoft.windowsazure.services.media.models.ListAssetsOptions; import com.sun.jersey.api.client.Client; import com.sun.jersey.api.client.WebResource; @@ -71,4 +75,34 @@ private WebResource getResource(String entityName) { return resource; } + @Override + public Asset createAsset(Asset asset) { + // TODO Auto-generated method stub + return null; + } + + @Override + public Asset getAsset(Asset asset) { + // TODO Auto-generated method stub + return null; + } + + @Override + public List<Asset> listAssets(ListAssetsOptions listAssetsOptions) { + List<Asset> listAssetsResult = new ArrayList<Asset>(); + return listAssetsResult; + } + + @Override + public Asset updateAsset(Asset updatedAsset) { + // TODO Auto-generated method stub + return null; + } + + @Override + public void deleteAsset(String assetId) { + // TODO Auto-generated method stub + + } + } 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 473bd9d60bb60..f9ad4cfc8550f 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 @@ -51,24 +51,25 @@ public class OAuthTokenManager { * @param dateFactory * A <code>DateFactory</code> object instance that represents the date factory. * - * @param acsBaseUri - * A <code>URI</code> object instance that represents the ACS base URI. + * @param oAuthUri + * A <code>String</code> object instance that represents the ACS base URI. * * @param clientId * A <code>String</code> object instance that represents the client ID. * * @param clientSecret * A <code>String</code> 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/models/ListAssetsOptions.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/ListAssetsOptions.java new file mode 100644 index 0000000000000..fc1ea2d060245 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/ListAssetsOptions.java @@ -0,0 +1,19 @@ +/** + * 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 + * + * 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.models; + +public class ListAssetsOptions { + +} \ No newline at end of file diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/IntegrationTestBase.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/IntegrationTestBase.java index 113d1ff2b2c50..b7e735e55c30e 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/IntegrationTestBase.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/IntegrationTestBase.java @@ -5,7 +5,7 @@ import com.microsoft.windowsazure.services.core.Configuration; public abstract class IntegrationTestBase { - protected Configuration config; + protected static Configuration config; @Before public void beforeEachTest() { diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/MediaServiceIntegrationTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/MediaServiceIntegrationTest.java new file mode 100644 index 0000000000000..a3e5a8ce01058 --- /dev/null +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/MediaServiceIntegrationTest.java @@ -0,0 +1,198 @@ +/** + * 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 + * + * 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; + +import static org.junit.Assert.*; + +import java.util.Collection; +import java.util.List; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +import com.microsoft.windowsazure.services.core.Configuration; +import com.microsoft.windowsazure.services.media.models.Asset; +import com.microsoft.windowsazure.services.media.models.ListAssetsOptions; + +public class MediaServiceIntegrationTest extends IntegrationTestBase { + private static MediaContract service; + + @BeforeClass + public static void setup() throws Exception { + // Create all test containers and their content + config = createConfig(); + service = MediaService.create(config); + List<Asset> listAssetsResult = service.listAssets(null); + for (Asset asset : listAssetsResult) { + service.deleteAsset(asset.getId()); + } + } + + @AfterClass + public static void cleanup() throws Exception { + // Configuration config = createConfiguration(); + // BlobContract service = BlobService.create(config); + + // deleteContainers(service, testContainersPrefix, testContainers); + // deleteContainers(service, createableContainersPrefix, creatableContainers); + } + + private static Configuration createConfig() { + Configuration config = Configuration.getInstance(); + overrideWithEnv(config, MediaConfiguration.URI); + overrideWithEnv(config, MediaConfiguration.OAUTH_URI); + overrideWithEnv(config, MediaConfiguration.OAUTH_CLIENT_ID); + overrideWithEnv(config, MediaConfiguration.OAUTH_CLIENT_SECRET); + overrideWithEnv(config, MediaConfiguration.OAUTH_SCOPE); + return config; + } + + @Test + public void createAssetSuccess() throws Exception { + // Arrange + Asset expectedAsset = new Asset().setName("testAssetName"); + + // Act + Asset actualAsset = service.createAsset(expectedAsset); + + // Assert + assertEquals(expectedAsset, actualAsset); + } + + @Test + public void createAssetMissingNameFailed() { + // Arrange + Asset expectedAsset = new Asset(); + + // Act + Asset actualAsset = service.createAsset(expectedAsset); + + // Assert + assertTrue(false); + } + + @Test + public void getAssetSuccess() throws Exception { + // Arrange + Asset expectedAsset = new Asset(); + service.createAsset(expectedAsset); + + // Act + Asset actualAsset = service.getAsset(expectedAsset); + + // Assert + assertEquals(expectedAsset, actualAsset); + } + + @Test + public void getAssetFailedWithInvalidId() { + // Arrange + Asset expectedAsset = new Asset(); + service.createAsset(expectedAsset); + + // Act + Asset actualAsset = service.getAsset(expectedAsset.setName("IncorrectAssetName")); + + // Assert + assertTrue(false); + + } + + @Test + public void listAssetSuccess() { + // Arrange + Asset assetA = new Asset(); + Asset assetB = new Asset(); + service.createAsset(assetA); + service.createAsset(assetB); + ListAssetsOptions listAssetOptions = new ListAssetsOptions(); + + // Act + Collection<Asset> listAssetResult = service.listAssets(listAssetOptions); + // Assert + + assertEquals(2, listAssetResult.size()); + } + + @Test + public void listAssetFailed() { + // Arrange + ListAssetsOptions listAssetsOptions = new ListAssetsOptions(); + + // Act + Collection<Asset> listAssetResult = service.listAssets(listAssetsOptions); + + // Assert + assertTrue(false); + } + + @Test + public void updateAssetSuccess() throws Exception { + // Arrange + Asset originalAsset = new Asset(); + service.createAsset(originalAsset); + Asset updatedAsset = new Asset(); + + // Act + service.updateAsset(updatedAsset); + Asset actualAsset = service.updateAsset(updatedAsset); + + // Assert + assertEquals(updatedAsset, actualAsset); + + } + + @Test + public void updateAssetFailedWithInvalidId() { + // Arrange + MediaContract service = MediaService.create(config); + Asset updatedAsset = new Asset(); + + // Act + service.updateAsset(updatedAsset); + + // Assert + assertTrue(false); + } + + @Test + public void deleteAssetSuccess() throws Exception { + // Arrange + Asset asset = new Asset(); + service.createAsset(asset); + List<Asset> listAssetsResult = service.listAssets(null); + assertEquals(1, listAssetsResult.size()); + + // Act + service.deleteAsset(asset.getId()); + + // Assert + listAssetsResult = service.listAssets(null); + assertEquals(0, listAssetsResult.size()); + } + + @Test + public void deleteAssetFailedWithInvalidId() { + // Arrange + + // Act + service.deleteAsset("invalidAssetId"); + + // Assert + assertTrue(false); + } + +} \ No newline at end of file diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/implementation/OAuthTokenManagerTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/implementation/OAuthTokenManagerTest.java index 2cbbc85d50854..8d6733e772a93 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/implementation/OAuthTokenManagerTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/implementation/OAuthTokenManagerTest.java @@ -54,7 +54,7 @@ public void init() throws URISyntaxException { String accountPassword = "testpassword"; String scope = "urn:WindowsAzureMediaServices"; - client = new OAuthTokenManager(contract, dateFactory, new URI(acsBaseUri), accountName, accountPassword, scope); + client = new OAuthTokenManager(contract, dateFactory, acsBaseUri, accountName, accountPassword, scope); when(dateFactory.getDate()).thenAnswer(new Answer<Date>() { @Override From 9c146a5c7762e5aac31019e24af9e4ed06ed9243 Mon Sep 17 00:00:00 2001 From: Chris Tavares <ctavares@microsoft.com> Date: Wed, 19 Sep 2012 10:17:07 -0700 Subject: [PATCH 38/70] Successfully creating an asset and deserializing the response --- .../implementation/ODataAtomUnmarshaller.java | 83 +++++++++++++++- .../media/implementation/ODataEntity.java | 4 +- .../implementation/ODataEntityProvider.java | 96 +++++++++++++++++++ .../implementation/VersionHeadersFilter.java | 43 +++++++++ .../services/media/models/AssetInfo.java | 20 ++++ .../ODataSerializationFromJerseyTest.java | 70 ++++++++++++++ .../ODataSerializationTest.java | 2 +- 7 files changed, 313 insertions(+), 5 deletions(-) create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ODataEntityProvider.java create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/VersionHeadersFilter.java create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AssetInfo.java create mode 100644 microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/implementation/ODataSerializationFromJerseyTest.java 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 index c5666967ac4e8..273fb8a13e1f0 100644 --- 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 @@ -16,6 +16,9 @@ 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.List; import javax.xml.bind.JAXBContext; @@ -47,14 +50,84 @@ public ODataAtomUnmarshaller() throws JAXBException { mediaContentUnmarshaller = mediaContentContext.createUnmarshaller(); } - public ODataEntity<?> unmarshal(InputStream stream, Class<?> contentType) throws JAXBException { + public ODataEntity<?> unmarshalFeed(InputStream stream, Class<?> contentType) throws JAXBException { JAXBElement<FeedType> feedElement = atomUnmarshaller.unmarshal(new StreamSource(stream), FeedType.class); FeedType feed = feedElement.getValue(); EntryType firstEntry = getFirstEntry(feed); - Object content = getEntryContent(firstEntry, contentType); + Class<?> serializationType = GetSerializationContentType(contentType); - return new ODataEntity(firstEntry, content); + Object content = getEntryContent(firstEntry, serializationType); + + try { + Constructor<?> resultCtor = contentType.getConstructor(EntryType.class, serializationType); + return (ODataEntity<?>) resultCtor.newInstance(firstEntry, content); + } + catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + catch (SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + catch (InstantiationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + catch (InvocationTargetException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + catch (NoSuchMethodException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return null; + } + + public ODataEntity<?> unmarshalEntry(InputStream stream, Class<?> contentType) throws JAXBException { + JAXBElement<EntryType> entryElement = atomUnmarshaller.unmarshal(new StreamSource(stream), EntryType.class); + + EntryType entry = entryElement.getValue(); + + Class<?> serializationType = GetSerializationContentType(contentType); + + Object content = getEntryContent(entry, serializationType); + + try { + Constructor<?> resultCtor = contentType.getConstructor(EntryType.class, serializationType); + return (ODataEntity<?>) resultCtor.newInstance(entry, content); + } + catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + catch (SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + catch (InstantiationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + catch (InvocationTargetException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + catch (NoSuchMethodException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return null; } private Object getEntryContent(EntryType entry, Class<?> contentType) throws JAXBException { @@ -116,4 +189,8 @@ private QName qnameFromElement(Element e) { return new QName(e.getLocalName(), e.getNamespaceURI()); } + private Class<?> GetSerializationContentType(Class<?> contentType) { + ParameterizedType pt = (ParameterizedType) contentType.getGenericSuperclass(); + return (Class<?>) pt.getActualTypeArguments()[0]; + } } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ODataEntity.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ODataEntity.java index 85a9fae74b1f8..ffea56d970b1e 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ODataEntity.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ODataEntity.java @@ -22,7 +22,7 @@ * access to entry and content types. * */ -public class ODataEntity<T> { +public abstract class ODataEntity<T> { private final EntryType entry; private final T content; @@ -45,4 +45,6 @@ public EntryType getEntry() { public T getContent() { return content; } + + public abstract Class<?> getJAXBContentClass(); } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ODataEntityProvider.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ODataEntityProvider.java new file mode 100644 index 0000000000000..9fd506a764ec5 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ODataEntityProvider.java @@ -0,0 +1,96 @@ +/** + * 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 + * + * 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 com.sun.jersey.core.provider.AbstractMessageReaderWriterProvider; + +/** + * An implementation of {@link AbstractMessageReaderWriterProvider } that + * is used to marshal and unmarshal instances of the ODataEntity<T> type. + * + */ +public class ODataEntityProvider extends AbstractMessageReaderWriterProvider<ODataEntity<?>> { + private final ODataAtomUnmarshaller unmarshaller; + + public ODataEntityProvider() throws JAXBException { + unmarshaller = new ODataAtomUnmarshaller(); + } + + /* (non-Javadoc) + * @see javax.ws.rs.ext.MessageBodyReader#isReadable(java.lang.Class, java.lang.reflect.Type, java.lang.annotation.Annotation[], javax.ws.rs.core.MediaType) + */ + @Override + public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) { + return ODataEntity.class.isAssignableFrom(type); + } + + /* (non-Javadoc) + * @see javax.ws.rs.ext.MessageBodyReader#readFrom(java.lang.Class, java.lang.reflect.Type, java.lang.annotation.Annotation[], javax.ws.rs.core.MediaType, javax.ws.rs.core.MultivaluedMap, java.io.InputStream) + */ + @Override + public ODataEntity<?> readFrom(Class<ODataEntity<?>> type, Type genericType, Annotation[] annotations, + MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) + throws IOException, WebApplicationException { + + ODataEntity entity; + String responseType = mediaType.getParameters().get("type"); + try { + if (responseType.equals("entry")) { + entity = unmarshaller.unmarshalEntry(entityStream, type); + } + else { + entity = unmarshaller.unmarshalFeed(entityStream, type); + } + } + catch (JAXBException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + throw new RuntimeException(e); + } + + return entity; + } + + /* (non-Javadoc) + * @see javax.ws.rs.ext.MessageBodyWriter#isWriteable(java.lang.Class, java.lang.reflect.Type, java.lang.annotation.Annotation[], javax.ws.rs.core.MediaType) + */ + @Override + public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) { + return false; + } + + /* (non-Javadoc) + * @see javax.ws.rs.ext.MessageBodyWriter#writeTo(java.lang.Object, java.lang.Class, java.lang.reflect.Type, java.lang.annotation.Annotation[], javax.ws.rs.core.MediaType, javax.ws.rs.core.MultivaluedMap, java.io.OutputStream) + */ + @Override + public void writeTo(ODataEntity<?> t, Class<?> type, Type genericType, Annotation[] annotations, + MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) + throws IOException, WebApplicationException { + // We do not support writing in this version. + } + +} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/VersionHeadersFilter.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/VersionHeadersFilter.java new file mode 100644 index 0000000000000..3ff3e3e18cec8 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/VersionHeadersFilter.java @@ -0,0 +1,43 @@ +/** + * 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 + * + * 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 javax.ws.rs.core.MultivaluedMap; + +import com.sun.jersey.api.client.ClientHandlerException; +import com.sun.jersey.api.client.ClientRequest; +import com.sun.jersey.api.client.ClientResponse; +import com.sun.jersey.api.client.filter.ClientFilter; + +/** + * A small filter that adds the required Media services/OData 3 + * version headers to the request as it goes through. + * + */ +public class VersionHeadersFilter extends ClientFilter { + + /* (non-Javadoc) + * @see com.sun.jersey.api.client.filter.ClientFilter#handle(com.sun.jersey.api.client.ClientRequest) + */ + @Override + public ClientResponse handle(ClientRequest cr) throws ClientHandlerException { + MultivaluedMap<String, Object> headers = cr.getHeaders(); + headers.add("DataServiceVersion", "3.0"); + headers.add("MaxDataServiceVersion", "3.0"); + headers.add("x-ms-version", "1.0"); + return getNext().handle(cr); + } +} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AssetInfo.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AssetInfo.java new file mode 100644 index 0000000000000..3ce3285957a17 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AssetInfo.java @@ -0,0 +1,20 @@ +package com.microsoft.windowsazure.services.media.models; + +import com.microsoft.windowsazure.services.media.implementation.ODataEntity; +import com.microsoft.windowsazure.services.media.implementation.atom.EntryType; +import com.microsoft.windowsazure.services.media.implementation.content.AssetType; + +public class AssetInfo extends ODataEntity<AssetType> { + + public AssetInfo(EntryType entry, AssetType content) { + super(entry, content); + } + + /* (non-Javadoc) + * @see com.microsoft.windowsazure.services.media.implementation.ODataEntity#getJAXBContentClass() + */ + @Override + public Class<?> getJAXBContentClass() { + return AssetType.class; + } +} diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/implementation/ODataSerializationFromJerseyTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/implementation/ODataSerializationFromJerseyTest.java new file mode 100644 index 0000000000000..195c289d681d4 --- /dev/null +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/implementation/ODataSerializationFromJerseyTest.java @@ -0,0 +1,70 @@ +package com.microsoft.windowsazure.services.media.implementation; + +import java.net.URI; +import java.net.URISyntaxException; +import java.util.HashMap; +import java.util.Map; + +import javax.ws.rs.core.MediaType; + +import org.junit.Assert; +import org.junit.Test; + +import com.microsoft.windowsazure.services.core.utils.DefaultDateFactory; +import com.microsoft.windowsazure.services.media.IntegrationTestBase; +import com.microsoft.windowsazure.services.media.MediaConfiguration; +import com.microsoft.windowsazure.services.media.models.AssetInfo; +import com.sun.jersey.api.client.Client; +import com.sun.jersey.api.client.WebResource; +import com.sun.jersey.api.client.config.ClientConfig; +import com.sun.jersey.api.client.config.DefaultClientConfig; +import com.sun.jersey.api.client.filter.LoggingFilter; + +public class ODataSerializationFromJerseyTest extends IntegrationTestBase { + + @Test + public void canBuildJerseyClientToCreateAnAssetWhichIsProperlyDeserialized() throws Exception { + // Build a jersey client object by hand; this is working up to the + // full integration into the media services rest proxy, but we + // need to go step by step to begin. + + ClientConfig cc = new DefaultClientConfig(); + cc.getProperties().put(ClientConfig.PROPERTY_FOLLOW_REDIRECTS, false); + cc.getSingletons().add(new ODataEntityProvider()); + Client c = Client.create(cc); + + c.addFilter(new LoggingFilter(System.out)); + c.addFilter(new RedirectFilter(createLocationManager())); + c.addFilter(new OAuthFilter(createTokenManager())); + c.addFilter(new VersionHeadersFilter()); + + WebResource assetResource = c.resource("Assets"); + String requestData = "{\"Name\":\"firstTestAsset\"}"; + + Map<String, String> mediaTypeParams = new HashMap<String, String>(); + //mediaTypeParams.put("type", "feed"); + MediaType acceptedType = new MediaType("application", "atom+xml", mediaTypeParams); + + AssetInfo newAsset = assetResource.type("application/json;odata=verbose").accept(acceptedType) + .post(AssetInfo.class, requestData); + + Assert.assertNotNull(newAsset); + Assert.assertEquals("firstTestAsset", newAsset.getContent().getName()); + } + + private OAuthContract createOAuthContract() { + return new OAuthRestProxy(Client.create()); + } + + private OAuthTokenManager createTokenManager() throws URISyntaxException { + return new OAuthTokenManager(createOAuthContract(), new DefaultDateFactory(), new URI( + (String) config.getProperty(MediaConfiguration.OAUTH_URI)), + (String) config.getProperty(MediaConfiguration.OAUTH_CLIENT_ID), + (String) config.getProperty(MediaConfiguration.OAUTH_CLIENT_SECRET), "urn:WindowsAzureMediaServices"); + } + + private ResourceLocationManager createLocationManager() throws URISyntaxException { + return new ResourceLocationManager((String) config.getProperty(MediaConfiguration.URI)); + } + +} diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/implementation/ODataSerializationTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/implementation/ODataSerializationTest.java index 4d9e908eadd80..2da9ece8f3890 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/implementation/ODataSerializationTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/implementation/ODataSerializationTest.java @@ -44,7 +44,7 @@ public class ODataSerializationTest { public void canUnmarshallAssetFromFeed() throws Exception { ODataAtomUnmarshaller um = new ODataAtomUnmarshaller(); InputStream input = new ByteArrayInputStream(sampleFeedOneAsset.getBytes("UTF-8")); - ODataEntity<AssetType> entry = (ODataEntity<AssetType>) um.unmarshal(input, AssetType.class); + ODataEntity<AssetType> entry = (ODataEntity<AssetType>) um.unmarshalFeed(input, AssetType.class); Assert.assertEquals("nb:cid:UUID:1f6c7bb4-8013-486e-b4c9-2e4a6842b9a6", entry.getContent().getId()); } } From 2b096b1956ff2e9f21b56ea715f7f0a4ced1efa3 Mon Sep 17 00:00:00 2001 From: Chris Tavares <ctavares@microsoft.com> Date: Wed, 19 Sep 2012 10:33:20 -0700 Subject: [PATCH 39/70] Serializing request info via JAXB and JSON --- .../media/models/CreateAssetRequest.java | 38 +++++++++++++++++++ .../ODataSerializationFromJerseyTest.java | 12 ++---- 2 files changed, 42 insertions(+), 8 deletions(-) create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/CreateAssetRequest.java diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/CreateAssetRequest.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/CreateAssetRequest.java new file mode 100644 index 0000000000000..d6a7ea845f193 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/CreateAssetRequest.java @@ -0,0 +1,38 @@ +/** + * 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 + * + * 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.models; + +import javax.xml.bind.annotation.XmlRootElement; + +/** + * Serializable class containing the information needed to + * create an asset. + * + */ +@XmlRootElement +public class CreateAssetRequest { + public String Name; + + /** + * Empty constructor required by JaxB. + */ + public CreateAssetRequest() { + } + + public CreateAssetRequest(String name) { + Name = name; + } +} diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/implementation/ODataSerializationFromJerseyTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/implementation/ODataSerializationFromJerseyTest.java index 195c289d681d4..e1b1aa9e860e5 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/implementation/ODataSerializationFromJerseyTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/implementation/ODataSerializationFromJerseyTest.java @@ -2,8 +2,6 @@ import java.net.URI; import java.net.URISyntaxException; -import java.util.HashMap; -import java.util.Map; import javax.ws.rs.core.MediaType; @@ -14,6 +12,7 @@ import com.microsoft.windowsazure.services.media.IntegrationTestBase; import com.microsoft.windowsazure.services.media.MediaConfiguration; import com.microsoft.windowsazure.services.media.models.AssetInfo; +import com.microsoft.windowsazure.services.media.models.CreateAssetRequest; import com.sun.jersey.api.client.Client; import com.sun.jersey.api.client.WebResource; import com.sun.jersey.api.client.config.ClientConfig; @@ -39,14 +38,11 @@ public void canBuildJerseyClientToCreateAnAssetWhichIsProperlyDeserialized() thr c.addFilter(new VersionHeadersFilter()); WebResource assetResource = c.resource("Assets"); - String requestData = "{\"Name\":\"firstTestAsset\"}"; - Map<String, String> mediaTypeParams = new HashMap<String, String>(); - //mediaTypeParams.put("type", "feed"); - MediaType acceptedType = new MediaType("application", "atom+xml", mediaTypeParams); + CreateAssetRequest requestData = new CreateAssetRequest("firstTestAsset"); - AssetInfo newAsset = assetResource.type("application/json;odata=verbose").accept(acceptedType) - .post(AssetInfo.class, requestData); + AssetInfo newAsset = assetResource.type("application/json;odata=verbose") + .accept(MediaType.APPLICATION_ATOM_XML).post(AssetInfo.class, requestData); Assert.assertNotNull(newAsset); Assert.assertEquals("firstTestAsset", newAsset.getContent().getName()); From e3047ccc6a978f464a76fb4fb02303ac3aed4ea6 Mon Sep 17 00:00:00 2001 From: Chris Tavares <ctavares@microsoft.com> Date: Wed, 19 Sep 2012 14:39:31 -0700 Subject: [PATCH 40/70] Hooked up create asset all the way through SDK stack --- .../windowsazure/services/media/Exports.java | 34 ++++- .../services/media/MediaContract.java | 4 +- .../MediaExceptionProcessor.java | 15 ++ .../media/implementation/MediaRestProxy.java | 17 ++- .../implementation/OAuthTokenManager.java | 7 +- .../media/implementation/ODataEntity.java | 2 - .../content}/CreateAssetRequest.java | 2 +- .../services/media/models/AssetInfo.java | 142 +++++++++++++++++- .../implementation/OAuthTokenManagerTest.java | 2 +- .../ODataSerializationFromJerseyTest.java | 20 ++- .../com.microsoft.windowsazure.properties | 7 +- 11 files changed, 231 insertions(+), 21 deletions(-) rename microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/{models => implementation/content}/CreateAssetRequest.java (93%) 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 791ed56f87555..6c24c6acf3c04 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 @@ -14,6 +14,10 @@ */ package com.microsoft.windowsazure.services.media; +import java.util.Map; + +import javax.xml.bind.JAXBException; + import com.microsoft.windowsazure.services.core.Builder; import com.microsoft.windowsazure.services.media.implementation.MediaExceptionProcessor; import com.microsoft.windowsazure.services.media.implementation.MediaRestProxy; @@ -21,8 +25,12 @@ 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.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 { @@ -39,6 +47,30 @@ 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<ClientConfig>() { + @Override + public ClientConfig alter(ClientConfig instance, Builder builder, Map<String, Object> properties) { + // enable this feature for unattributed json object serialization + instance.getProperties().put(JSONConfiguration.FEATURE_POJO_MAPPING, true); + + // Turn off auto-redirect following + instance.getProperties().put(ClientConfig.PROPERTY_FOLLOW_REDIRECTS, false); + + // add body reader/writer for ODataEntity<?> descendant classes + try { + instance.getSingletons().add(new ODataEntityProvider()); + } + catch (JAXBException e) { + // wrap in runtimeexception, we can't change the function signature + e.printStackTrace(); + throw new RuntimeException(e); + } + + return instance; + } + }); + } } 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 3e92ac300dae0..87edc01108989 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 @@ -15,6 +15,8 @@ package com.microsoft.windowsazure.services.media; import com.microsoft.windowsazure.services.core.FilterableService; +import com.microsoft.windowsazure.services.core.ServiceException; +import com.microsoft.windowsazure.services.media.models.AssetInfo; /** * @@ -23,6 +25,6 @@ */ public interface MediaContract extends FilterableService<MediaContract> { - // Will fill in as we implement the various Media Services entities + AssetInfo createAsset(String name) throws ServiceException; } 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 d9c3141d52064..8c311f600f0e1 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 @@ -24,6 +24,9 @@ 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.AssetInfo; +import com.sun.jersey.api.client.ClientHandlerException; +import com.sun.jersey.api.client.UniformInterfaceException; /** * Wrapper implementation of <code>MediaServicesContract</code> that @@ -54,4 +57,16 @@ private ServiceException processCatch(ServiceException e) { return ServiceExceptionFactory.process("MediaServices", e); } + @Override + public AssetInfo createAsset(String name) throws ServiceException { + try { + return next.createAsset(name); + } + 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 9b1dfc25e5a60..ed343220b4501 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 @@ -18,13 +18,17 @@ import java.util.Arrays; 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.media.MediaContract; +import com.microsoft.windowsazure.services.media.implementation.content.CreateAssetRequest; +import com.microsoft.windowsazure.services.media.models.AssetInfo; import com.sun.jersey.api.client.Client; import com.sun.jersey.api.client.WebResource; @@ -32,15 +36,19 @@ public class MediaRestProxy implements MediaContract { private Client channel; static Log log = LogFactory.getLog(MediaContract.class); + private static final String jsonRequestType = "application/json; odata=verbose"; ServiceFilter[] filters; @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); } public MediaRestProxy(Client channel, ServiceFilter[] filters) { @@ -71,4 +79,11 @@ private WebResource getResource(String entityName) { return resource; } + @Override + public AssetInfo createAsset(String name) throws ServiceException { + WebResource resource = getResource("Assets"); + + CreateAssetRequest request = new CreateAssetRequest(name); + return resource.type(jsonRequestType).accept(MediaType.APPLICATION_ATOM_XML).post(AssetInfo.class, request); + } } 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 473bd9d60bb60..a023b4f523dba 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 @@ -59,16 +59,17 @@ public class OAuthTokenManager { * * @param clientSecret * A <code>String</code> 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 acsBaseUri, @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(acsBaseUri); this.clientId = clientId; this.clientSecret = clientSecret; this.scope = scope; diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ODataEntity.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ODataEntity.java index ffea56d970b1e..8b3ce69b03b5d 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ODataEntity.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ODataEntity.java @@ -45,6 +45,4 @@ public EntryType getEntry() { public T getContent() { return content; } - - public abstract Class<?> getJAXBContentClass(); } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/CreateAssetRequest.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/CreateAssetRequest.java similarity index 93% rename from microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/CreateAssetRequest.java rename to microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/CreateAssetRequest.java index d6a7ea845f193..3286c7817ae40 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/CreateAssetRequest.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/CreateAssetRequest.java @@ -13,7 +13,7 @@ * limitations under the License. */ -package com.microsoft.windowsazure.services.media.models; +package com.microsoft.windowsazure.services.media.implementation.content; import javax.xml.bind.annotation.XmlRootElement; diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AssetInfo.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AssetInfo.java index 3ce3285957a17..c62eb7a53d8dd 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AssetInfo.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AssetInfo.java @@ -1,20 +1,152 @@ package com.microsoft.windowsazure.services.media.models; +import javax.xml.datatype.XMLGregorianCalendar; + import com.microsoft.windowsazure.services.media.implementation.ODataEntity; import com.microsoft.windowsazure.services.media.implementation.atom.EntryType; import com.microsoft.windowsazure.services.media.implementation.content.AssetType; +/** + * Data about a Media Services Asset entity. + * + */ public class AssetInfo extends ODataEntity<AssetType> { public AssetInfo(EntryType entry, AssetType content) { super(entry, content); } - /* (non-Javadoc) - * @see com.microsoft.windowsazure.services.media.implementation.ODataEntity#getJAXBContentClass() + /** + * Get the asset id + * + * @return the id + */ + public String getId() { + return getContent().getId(); + } + + /** + * Set the id + * + * @param id + * the id + */ + public void setId(String id) { + getContent().setId(id); + } + + /** + * Get the asset name + * + * @return the name + */ + public String getName() { + return this.getContent().getName(); + } + + /** + * set the name + * + * @param name + * the name + */ + public void setName(String name) { + this.getContent().setName(name); + } + + /** + * Get the asset state + * + * @return the state + */ + public int getState() { + return getContent().getState(); + } + + /** + * Set the state + * + * @param state + * the state + */ + public void setState(int state) { + getContent().setState(state); + } + + /** + * Get the creation date + * + * @return the date + */ + public XMLGregorianCalendar getCreated() { + return this.getContent().getCreated(); + } + + /** + * Set creation date + * + * @param created + * the date + * + */ + public void setCreated(XMLGregorianCalendar created) { + getContent().setCreated(created); + } + + /** + * Get last modified date + * + * @return the date + */ + public XMLGregorianCalendar getLastModified() { + return getContent().getLastModified(); + } + + /** + * Set last modified date + * + * @param lastModified + * the date + */ + public void setLastModified(XMLGregorianCalendar lastModified) { + getContent().setLastModified(lastModified); + } + + /** + * Get the alternate id + * + * @return the id + */ + public String getAlternateId() { + return getContent().getAlternateId(); + } + + /** + * Set the alternate id + * + * @param alternateId + * the id + */ + public void setAlternateId(String alternateId) { + getContent().setAlternateId(alternateId); + } + + /** + * Get the options + * + * @return the options + */ + public int getOptions() { + return getContent().getOptions(); + } + + /** + * Set the options + * + * @param options + * the options */ - @Override - public Class<?> getJAXBContentClass() { - return AssetType.class; + public void setOptions(int options) { + getContent().setOptions(options); } } diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/implementation/OAuthTokenManagerTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/implementation/OAuthTokenManagerTest.java index 2cbbc85d50854..8d6733e772a93 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/implementation/OAuthTokenManagerTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/implementation/OAuthTokenManagerTest.java @@ -54,7 +54,7 @@ public void init() throws URISyntaxException { String accountPassword = "testpassword"; String scope = "urn:WindowsAzureMediaServices"; - client = new OAuthTokenManager(contract, dateFactory, new URI(acsBaseUri), accountName, accountPassword, scope); + client = new OAuthTokenManager(contract, dateFactory, acsBaseUri, accountName, accountPassword, scope); when(dateFactory.getDate()).thenAnswer(new Answer<Date>() { @Override diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/implementation/ODataSerializationFromJerseyTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/implementation/ODataSerializationFromJerseyTest.java index e1b1aa9e860e5..2a2b52225429e 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/implementation/ODataSerializationFromJerseyTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/implementation/ODataSerializationFromJerseyTest.java @@ -1,6 +1,5 @@ package com.microsoft.windowsazure.services.media.implementation; -import java.net.URI; import java.net.URISyntaxException; import javax.ws.rs.core.MediaType; @@ -11,13 +10,16 @@ import com.microsoft.windowsazure.services.core.utils.DefaultDateFactory; import com.microsoft.windowsazure.services.media.IntegrationTestBase; import com.microsoft.windowsazure.services.media.MediaConfiguration; +import com.microsoft.windowsazure.services.media.MediaContract; +import com.microsoft.windowsazure.services.media.MediaService; +import com.microsoft.windowsazure.services.media.implementation.content.CreateAssetRequest; import com.microsoft.windowsazure.services.media.models.AssetInfo; -import com.microsoft.windowsazure.services.media.models.CreateAssetRequest; import com.sun.jersey.api.client.Client; import com.sun.jersey.api.client.WebResource; import com.sun.jersey.api.client.config.ClientConfig; import com.sun.jersey.api.client.config.DefaultClientConfig; import com.sun.jersey.api.client.filter.LoggingFilter; +import com.sun.jersey.api.json.JSONConfiguration; public class ODataSerializationFromJerseyTest extends IntegrationTestBase { @@ -29,6 +31,7 @@ public void canBuildJerseyClientToCreateAnAssetWhichIsProperlyDeserialized() thr ClientConfig cc = new DefaultClientConfig(); cc.getProperties().put(ClientConfig.PROPERTY_FOLLOW_REDIRECTS, false); + cc.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, true); cc.getSingletons().add(new ODataEntityProvider()); Client c = Client.create(cc); @@ -45,7 +48,7 @@ public void canBuildJerseyClientToCreateAnAssetWhichIsProperlyDeserialized() thr .accept(MediaType.APPLICATION_ATOM_XML).post(AssetInfo.class, requestData); Assert.assertNotNull(newAsset); - Assert.assertEquals("firstTestAsset", newAsset.getContent().getName()); + Assert.assertEquals("firstTestAsset", newAsset.getName()); } private OAuthContract createOAuthContract() { @@ -53,8 +56,8 @@ private OAuthContract createOAuthContract() { } private OAuthTokenManager createTokenManager() throws URISyntaxException { - return new OAuthTokenManager(createOAuthContract(), new DefaultDateFactory(), new URI( - (String) config.getProperty(MediaConfiguration.OAUTH_URI)), + return new OAuthTokenManager(createOAuthContract(), new DefaultDateFactory(), + (String) config.getProperty(MediaConfiguration.OAUTH_URI), (String) config.getProperty(MediaConfiguration.OAUTH_CLIENT_ID), (String) config.getProperty(MediaConfiguration.OAUTH_CLIENT_SECRET), "urn:WindowsAzureMediaServices"); } @@ -63,4 +66,11 @@ private ResourceLocationManager createLocationManager() throws URISyntaxExceptio return new ResourceLocationManager((String) config.getProperty(MediaConfiguration.URI)); } + @Test + public void canCreateAssetThroughMediaServiceAPI() throws Exception { + MediaContract client = MediaService.create(config); + AssetInfo newAsset = client.createAsset("secondTestAsset"); + + Assert.assertEquals("secondTestAsset", newAsset.getName()); + } } diff --git a/microsoft-azure-api/src/test/resources/META-INF/com.microsoft.windowsazure.properties b/microsoft-azure-api/src/test/resources/META-INF/com.microsoft.windowsazure.properties index 7739acd3e7333..a06c02e2b8496 100644 --- a/microsoft-azure-api/src/test/resources/META-INF/com.microsoft.windowsazure.properties +++ b/microsoft-azure-api/src/test/resources/META-INF/com.microsoft.windowsazure.properties @@ -10,4 +10,9 @@ queue.accountKey=%QUEUE_ACCOUNTKEY% queue.uri=http://%QUEUE_ACCOUNTNAME%.queue.core.windows.net table.accountName=%TABLE_ACCOUNTNAME% table.accountKey=%TABLE_ACCOUNTKEY% -table.uri=http://%TABLE_ACCOUNTNAME%.table.core.windows.net \ No newline at end of file +table.uri=http://%TABLE_ACCOUNTNAME%.table.core.windows.net +media.uri=%MEDIA.URI% +oauth.uri=%OAUTH.URI% +oauth.client.id=%OAUTH.CLIENT.ID% +oauth.client.secret=%OAUTH.CLIENT.SECRET% +oauth.scope=urn:WindowsAzureMediaServices \ No newline at end of file From 1a41d4e2a06b12bb4dab5b89e33ba5d58541096c Mon Sep 17 00:00:00 2001 From: Chris Tavares <ctavares@microsoft.com> Date: Wed, 19 Sep 2012 17:59:45 -0700 Subject: [PATCH 41/70] Responding to code review feedback --- .../windowsazure/services/media/Exports.java | 7 +- .../services/media/MediaConfiguration.java | 2 +- .../services/media/MediaContract.java | 2 +- .../services/media/MediaService.java | 2 +- .../media/implementation/ActiveToken.java | 2 +- .../MediaExceptionProcessor.java | 2 +- .../media/implementation/MediaRestProxy.java | 2 +- .../media/implementation/OAuthContract.java | 2 +- .../media/implementation/OAuthFilter.java | 2 +- .../media/implementation/OAuthRestProxy.java | 2 +- .../implementation/OAuthTokenManager.java | 6 +- .../implementation/OAuthTokenResponse.java | 2 +- .../implementation/ODataAtomUnmarshaller.java | 85 ++++++++++++++----- .../media/implementation/ODataEntity.java | 8 +- .../implementation/ODataEntityProvider.java | 17 ++-- .../media/implementation/RedirectFilter.java | 2 +- .../ResourceLocationManager.java | 2 +- .../implementation/VersionHeadersFilter.java | 2 +- .../implementation/content/AssetType.java | 2 +- .../implementation/content/Constants.java | 2 +- .../content/CreateAssetRequest.java | 2 +- .../content/ODataActionType.java | 2 +- .../implementation/content/ObjectFactory.java | 2 +- .../media/models/AccessPolicyPermission.java | 2 +- .../ODataSerializationFromJerseyTest.java | 15 ++++ .../ODataSerializationTest.java | 15 ++++ 26 files changed, 135 insertions(+), 56 deletions(-) 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 6c24c6acf3c04..29f4946cc6ea5 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. @@ -53,18 +53,15 @@ public void register(Builder.Registry registry) { @Override public ClientConfig alter(ClientConfig instance, Builder builder, Map<String, Object> properties) { - // enable this feature for unattributed json object serialization instance.getProperties().put(JSONConfiguration.FEATURE_POJO_MAPPING, true); - // Turn off auto-redirect following + // Turn off auto-follow redirects, because Media Services rest calls break if it's on instance.getProperties().put(ClientConfig.PROPERTY_FOLLOW_REDIRECTS, false); - // add body reader/writer for ODataEntity<?> descendant classes try { instance.getSingletons().add(new ODataEntityProvider()); } catch (JAXBException e) { - // wrap in runtimeexception, we can't change the function signature e.printStackTrace(); throw new RuntimeException(e); } 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 ac7464c570018..6821f7b10fafd 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 87edc01108989..8060eceffe028 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. 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 413dae44c8d41..9cf13258bab88 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 e3c5561f7b77f..b38ee70871855 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/MediaExceptionProcessor.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/MediaExceptionProcessor.java index 8c311f600f0e1..b68089352a8d4 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. 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 ed343220b4501..cc33ecab7948d 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. 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 7e81549642f7e..54091fff05864 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 3b2e45a363b67..326db58a005f6 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 a51eae7e82c3b..6645d55eecdc9 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 a023b4f523dba..913fe84830ce4 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. @@ -63,13 +63,13 @@ public class OAuthTokenManager { * */ public OAuthTokenManager(OAuthContract contract, DateFactory dateFactory, - @Named(MediaConfiguration.OAUTH_URI) String 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) throws URISyntaxException { this.contract = contract; this.dateFactory = dateFactory; - this.acsBaseUri = new URI(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 42974fb52e3f5..b8a357d739f95 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/ODataAtomUnmarshaller.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ODataAtomUnmarshaller.java index 273fb8a13e1f0..c9952b7760868 100644 --- 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 @@ -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. @@ -30,6 +30,7 @@ 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; @@ -37,12 +38,20 @@ 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(); @@ -50,7 +59,23 @@ public ODataAtomUnmarshaller() throws JAXBException { mediaContentUnmarshaller = mediaContentContext.createUnmarshaller(); } - public ODataEntity<?> unmarshalFeed(InputStream stream, Class<?> contentType) throws JAXBException { + /** + * 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 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 ODataEntity<?> unmarshalFeed(InputStream stream, Class<?> contentType) throws JAXBException, + ServiceException { + validateNotNull(stream, "stream"); + validateNotNull(contentType, "contentType"); + JAXBElement<FeedType> feedElement = atomUnmarshaller.unmarshal(new StreamSource(stream), FeedType.class); FeedType feed = feedElement.getValue(); EntryType firstEntry = getFirstEntry(feed); @@ -64,33 +89,48 @@ public ODataEntity<?> unmarshalFeed(InputStream stream, Class<?> contentType) th return (ODataEntity<?>) resultCtor.newInstance(firstEntry, content); } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block e.printStackTrace(); + throw new ServiceException(e); } catch (SecurityException e) { - // TODO Auto-generated catch block e.printStackTrace(); + throw new ServiceException(e); } catch (InstantiationException e) { - // TODO Auto-generated catch block e.printStackTrace(); + throw new ServiceException(e); } catch (IllegalAccessException e) { - // TODO Auto-generated catch block e.printStackTrace(); + throw new ServiceException(e); } catch (InvocationTargetException e) { - // TODO Auto-generated catch block e.printStackTrace(); + throw new ServiceException(e); } catch (NoSuchMethodException e) { - // TODO Auto-generated catch block e.printStackTrace(); + throw new ServiceException(e); } - return null; } - public ODataEntity<?> unmarshalEntry(InputStream stream, Class<?> contentType) throws JAXBException { + /** + * 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 ODataEntity<?> unmarshalEntry(InputStream stream, Class<?> contentType) throws JAXBException, + ServiceException { + validateNotNull(stream, "stream"); + validateNotNull(contentType, "contentType"); + JAXBElement<EntryType> entryElement = atomUnmarshaller.unmarshal(new StreamSource(stream), EntryType.class); EntryType entry = entryElement.getValue(); @@ -104,35 +144,34 @@ public ODataEntity<?> unmarshalEntry(InputStream stream, Class<?> contentType) t return (ODataEntity<?>) resultCtor.newInstance(entry, content); } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block e.printStackTrace(); + throw new ServiceException(e); } catch (SecurityException e) { - // TODO Auto-generated catch block e.printStackTrace(); + throw new ServiceException(e); } catch (InstantiationException e) { - // TODO Auto-generated catch block e.printStackTrace(); + throw new ServiceException(e); } catch (IllegalAccessException e) { - // TODO Auto-generated catch block e.printStackTrace(); + throw new ServiceException(e); } catch (InvocationTargetException e) { - // TODO Auto-generated catch block e.printStackTrace(); + throw new ServiceException(e); } catch (NoSuchMethodException e) { - // TODO Auto-generated catch block e.printStackTrace(); + throw new ServiceException(e); } - return null; } private Object getEntryContent(EntryType entry, Class<?> contentType) throws JAXBException { List<Object> entryChildren = entry.getEntryChildren(); - Object retval = null; + Object retVal = null; for (int i = 0; i < entryChildren.size(); ++i) { Object child = entryChildren.get(i); @@ -140,7 +179,7 @@ private Object getEntryContent(EntryType entry, Class<?> contentType) throws JAX // It's a parsed element, if it's content unmarshal, fixup, and store return value JAXBElement e = (JAXBElement) child; if (e.getDeclaredType() == ContentType.class) { - retval = unmarshalEntryContent((ContentType) e.getValue(), contentType); + retVal = unmarshalEntryContent((ContentType) e.getValue(), contentType); } } else { @@ -153,7 +192,7 @@ private Object getEntryContent(EntryType entry, Class<?> contentType) throws JAX } } } - return retval; + return retVal; } private EntryType getFirstEntry(FeedType feed) { @@ -193,4 +232,10 @@ private Class<?> GetSerializationContentType(Class<?> contentType) { ParameterizedType pt = (ParameterizedType) contentType.getGenericSuperclass(); return (Class<?>) pt.getActualTypeArguments()[0]; } + + private static void validateNotNull(Object param, String paramName) { + if (param == null) { + throw new IllegalArgumentException(paramName); + } + } } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ODataEntity.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ODataEntity.java index 8b3ce69b03b5d..f2846162965a7 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ODataEntity.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ODataEntity.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. @@ -27,7 +27,7 @@ public abstract class ODataEntity<T> { private final EntryType entry; private final T content; - public ODataEntity(EntryType entry, T content) { + protected ODataEntity(EntryType entry, T content) { this.entry = entry; this.content = content; } @@ -35,14 +35,14 @@ public ODataEntity(EntryType entry, T content) { /** * @return the entry */ - public EntryType getEntry() { + protected EntryType getEntry() { return entry; } /** * @return the content */ - public T getContent() { + protected T getContent() { return content; } } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ODataEntityProvider.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ODataEntityProvider.java index 9fd506a764ec5..e5f54fbac6113 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ODataEntityProvider.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ODataEntityProvider.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. @@ -26,6 +26,7 @@ import javax.ws.rs.core.MultivaluedMap; import javax.xml.bind.JAXBException; +import com.microsoft.windowsazure.services.core.ServiceException; import com.sun.jersey.core.provider.AbstractMessageReaderWriterProvider; /** @@ -59,15 +60,21 @@ public ODataEntity<?> readFrom(Class<ODataEntity<?>> type, Type genericType, Ann ODataEntity entity; String responseType = mediaType.getParameters().get("type"); try { - if (responseType.equals("entry")) { + if (responseType == null || responseType.equals("feed")) { + entity = unmarshaller.unmarshalFeed(entityStream, type); + } + else if (responseType.equals("entry")) { entity = unmarshaller.unmarshalEntry(entityStream, type); } else { - entity = unmarshaller.unmarshalFeed(entityStream, type); + throw new RuntimeException(); } } catch (JAXBException e) { - // TODO Auto-generated catch block + e.printStackTrace(); + throw new RuntimeException(e); + } + catch (ServiceException e) { e.printStackTrace(); throw new RuntimeException(e); } @@ -90,7 +97,7 @@ public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotat public void writeTo(ODataEntity<?> t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException { - // We do not support writing in this version. + throw new UnsupportedOperationException(); } } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/RedirectFilter.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/RedirectFilter.java index 15b283e78f922..f71ea6381653b 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/RedirectFilter.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/RedirectFilter.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/ResourceLocationManager.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ResourceLocationManager.java index 75b5c12ad6dc6..b030e6454196c 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ResourceLocationManager.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ResourceLocationManager.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/VersionHeadersFilter.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/VersionHeadersFilter.java index 3ff3e3e18cec8..9b69c79942969 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/VersionHeadersFilter.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/VersionHeadersFilter.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/content/AssetType.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/AssetType.java index 9b9cfe57aec7b..160a3088892b5 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/AssetType.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/AssetType.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/content/Constants.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/Constants.java index b11c4eadf4409..0e004668e6ac8 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/Constants.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/Constants.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/content/CreateAssetRequest.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/CreateAssetRequest.java index 3286c7817ae40..e93c2e7f6844d 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/CreateAssetRequest.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/CreateAssetRequest.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/content/ODataActionType.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/ODataActionType.java index c64e4b68178ee..b6cbb23a79b3a 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/ODataActionType.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/ODataActionType.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/content/ObjectFactory.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/ObjectFactory.java index b9fef1eb50b22..d353a7d006964 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/ObjectFactory.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/ObjectFactory.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/models/AccessPolicyPermission.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AccessPolicyPermission.java index a1abc4a25587b..b5f7dd0e88699 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AccessPolicyPermission.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AccessPolicyPermission.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/test/java/com/microsoft/windowsazure/services/media/implementation/ODataSerializationFromJerseyTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/implementation/ODataSerializationFromJerseyTest.java index 2a2b52225429e..960c76828ad51 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/implementation/ODataSerializationFromJerseyTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/implementation/ODataSerializationFromJerseyTest.java @@ -1,3 +1,18 @@ +/** + * 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.net.URISyntaxException; diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/implementation/ODataSerializationTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/implementation/ODataSerializationTest.java index 2da9ece8f3890..215d3c33c31f1 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/implementation/ODataSerializationTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/implementation/ODataSerializationTest.java @@ -1,3 +1,18 @@ +/** + * 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.ByteArrayInputStream; From 656421e4c707f375c58db83a2f692f6a56258c71 Mon Sep 17 00:00:00 2001 From: Chris Tavares <ctavares@microsoft.com> Date: Thu, 20 Sep 2012 15:00:03 -0700 Subject: [PATCH 42/70] Sending request data as XML now --- .../media/implementation/MediaRestProxy.java | 37 +++++++- .../implementation/ODataAtomMarshaller.java | 86 +++++++++++++++++++ .../ODataSerializationFromJerseyTest.java | 12 ++- .../ODataSerializationTest.java | 24 ++++++ 4 files changed, 151 insertions(+), 8 deletions(-) create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ODataAtomMarshaller.java 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 cc33ecab7948d..c22345c361348 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 @@ -19,6 +19,8 @@ import javax.inject.Inject; import javax.ws.rs.core.MediaType; +import javax.xml.bind.JAXBException; +import javax.xml.parsers.ParserConfigurationException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -27,14 +29,17 @@ import com.microsoft.windowsazure.services.core.ServiceFilter; import com.microsoft.windowsazure.services.core.utils.pipeline.ClientFilterAdapter; import com.microsoft.windowsazure.services.media.MediaContract; -import com.microsoft.windowsazure.services.media.implementation.content.CreateAssetRequest; +import com.microsoft.windowsazure.services.media.implementation.content.AssetType; import com.microsoft.windowsazure.services.media.models.AssetInfo; import com.sun.jersey.api.client.Client; +import com.sun.jersey.api.client.UniformInterfaceException; import com.sun.jersey.api.client.WebResource; public class MediaRestProxy implements MediaContract { private Client channel; + private ODataAtomMarshaller marshaller; + static Log log = LogFactory.getLog(MediaContract.class); private static final String jsonRequestType = "application/json; odata=verbose"; @@ -49,11 +54,14 @@ public MediaRestProxy(Client channel, OAuthFilter authFilter, RedirectFilter red channel.addFilter(redirectFilter); channel.addFilter(authFilter); channel.addFilter(versionHeadersFilter); + + createMarshaller(); } public MediaRestProxy(Client channel, ServiceFilter[] filters) { this.channel = channel; this.filters = filters; + createMarshaller(); } @Override @@ -79,11 +87,32 @@ private WebResource getResource(String entityName) { return resource; } + private void createMarshaller() { + try { + this.marshaller = new ODataAtomMarshaller(); + } + catch (JAXBException e) { + e.printStackTrace(); + throw new RuntimeException(e); + } + catch (ParserConfigurationException e) { + e.printStackTrace(); + throw new RuntimeException(e); + } + } + @Override - public AssetInfo createAsset(String name) throws ServiceException { + public AssetInfo createAsset(String name) throws ServiceException, UniformInterfaceException { WebResource resource = getResource("Assets"); - CreateAssetRequest request = new CreateAssetRequest(name); - return resource.type(jsonRequestType).accept(MediaType.APPLICATION_ATOM_XML).post(AssetInfo.class, request); + AssetType request = new AssetType(); + request.setName(name); + try { + return resource.type(MediaType.APPLICATION_ATOM_XML).accept(MediaType.APPLICATION_ATOM_XML) + .post(AssetInfo.class, marshaller.marshalEntry(request)); + } + catch (JAXBException e) { + throw new ServiceException(e); + } } } 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 0000000000000..f636b7b3498e3 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ODataAtomMarshaller.java @@ -0,0 +1,86 @@ +/** + * 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.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.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(); + } + + public Document marshalEntry(Object content) throws JAXBException { + 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<EntryType> entryElement = new JAXBElement<EntryType>(new QName(Constants.ATOM_NS, "entry"), + EntryType.class, atomEntry); + + Document doc = documentBuilder.newDocument(); + doc.setXmlStandalone(true); + + marshaller.marshal(entryElement, doc); + + return doc; + + } + + private static Class<?>[] getMarshalledClasses() { + List<Class<?>> classes = new ArrayList<Class<?>>(); + classes.add(FeedType.class); + classes.add(EntryType.class); + classes.add(AssetType.class); + return classes.toArray(new Class<?>[0]); + } +} diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/implementation/ODataSerializationFromJerseyTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/implementation/ODataSerializationFromJerseyTest.java index 960c76828ad51..7dbb9fdbff3b5 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/implementation/ODataSerializationFromJerseyTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/implementation/ODataSerializationFromJerseyTest.java @@ -27,7 +27,7 @@ import com.microsoft.windowsazure.services.media.MediaConfiguration; import com.microsoft.windowsazure.services.media.MediaContract; import com.microsoft.windowsazure.services.media.MediaService; -import com.microsoft.windowsazure.services.media.implementation.content.CreateAssetRequest; +import com.microsoft.windowsazure.services.media.implementation.content.AssetType; import com.microsoft.windowsazure.services.media.models.AssetInfo; import com.sun.jersey.api.client.Client; import com.sun.jersey.api.client.WebResource; @@ -57,13 +57,17 @@ public void canBuildJerseyClientToCreateAnAssetWhichIsProperlyDeserialized() thr WebResource assetResource = c.resource("Assets"); - CreateAssetRequest requestData = new CreateAssetRequest("firstTestAsset"); + ODataAtomMarshaller m = new ODataAtomMarshaller(); + AssetType requestData = new AssetType(); + requestData.setName("firstTestAsset"); + requestData.setAlternateId("some external id"); - AssetInfo newAsset = assetResource.type("application/json;odata=verbose") - .accept(MediaType.APPLICATION_ATOM_XML).post(AssetInfo.class, requestData); + AssetInfo newAsset = assetResource.type(MediaType.APPLICATION_ATOM_XML).accept(MediaType.APPLICATION_ATOM_XML) + .post(AssetInfo.class, m.marshalEntry(requestData)); Assert.assertNotNull(newAsset); Assert.assertEquals("firstTestAsset", newAsset.getName()); + Assert.assertEquals("some external id", newAsset.getAlternateId()); } private OAuthContract createOAuthContract() { diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/implementation/ODataSerializationTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/implementation/ODataSerializationTest.java index 215d3c33c31f1..51e27d89818b7 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/implementation/ODataSerializationTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/implementation/ODataSerializationTest.java @@ -18,10 +18,15 @@ import java.io.ByteArrayInputStream; import java.io.InputStream; +import javax.xml.bind.JAXBContext; +import javax.xml.bind.Marshaller; + import junit.framework.Assert; import org.junit.Test; +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.content.AssetType; public class ODataSerializationTest { @@ -62,4 +67,23 @@ public void canUnmarshallAssetFromFeed() throws Exception { ODataEntity<AssetType> entry = (ODataEntity<AssetType>) um.unmarshalFeed(input, AssetType.class); Assert.assertEquals("nb:cid:UUID:1f6c7bb4-8013-486e-b4c9-2e4a6842b9a6", entry.getContent().getId()); } + + @Test + public void canMarshalEntryFromJavaObject() throws Exception { + AssetType a = new AssetType(); + a.setName("testNewAsset"); + a.setOptions(0); + a.setAlternateId("some other id"); + + JAXBContext context = JAXBContext.newInstance(EntryType.class, AssetType.class); + Marshaller m = context.createMarshaller(); + + EntryType e = new EntryType(); + ContentType c = new ContentType(); + c.getContent().add(a); + e.getEntryChildren().add(c); + + m.marshal(e, System.out); + + } } From 4f7dd5d71d5fe9d8f4e3ff6f26c3d73d398317a3 Mon Sep 17 00:00:00 2001 From: Chris Tavares <ctavares@microsoft.com> Date: Thu, 20 Sep 2012 15:03:06 -0700 Subject: [PATCH 43/70] Added doc comments --- .../media/implementation/ODataAtomMarshaller.java | 11 +++++++++++ 1 file changed, 11 insertions(+) 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 index f636b7b3498e3..2373660f9f452 100644 --- 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 @@ -54,6 +54,17 @@ public ODataAtomMarshaller() throws JAXBException, ParserConfigurationException 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 serializable + */ public Document marshalEntry(Object content) throws JAXBException { ContentType atomContent = new ContentType(); atomContent.setType("application/xml"); From a97adf5ded972531eb404abdd43702c3392a6f58 Mon Sep 17 00:00:00 2001 From: Albert Cheng <gongchen@microsoft.com> Date: Thu, 20 Sep 2012 16:14:33 -0700 Subject: [PATCH 44/70] address code review feedback. --- .../media/models/AccessPolicyPermission.java | 2 +- .../services/media/models/Asset.java | 132 ------- .../services/media/models/AssetInfo.java | 289 ++++++++++++++ .../services/media/models/AssetState.java | 35 +- .../services/media/models/ContentKey.java | 117 ------ .../services/media/models/ContentKeyInfo.java | 253 ++++++++++++ .../services/media/models/ContentKeyType.java | 22 +- .../media/models/EncryptionOption.java | 22 +- .../services/media/models/File.java | 167 -------- .../services/media/models/FileInfo.java | 373 ++++++++++++++++++ .../services/media/models/Locator.java | 92 ----- .../services/media/models/LocatorInfo.java | 193 +++++++++ .../services/media/models/LocatorType.java | 27 +- .../media/models/ProtectionKeyType.java | 19 +- .../{AssetTest.java => AssetInfoTest.java} | 56 +-- ...ntKeyTest.java => ContentKeyInfoTest.java} | 41 +- .../{FileTest.java => FileInfoTest.java} | 59 +-- ...{LocatorTest.java => LocatorInfoTest.java} | 30 +- 18 files changed, 1320 insertions(+), 609 deletions(-) delete mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/Asset.java create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AssetInfo.java delete mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/ContentKey.java create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/ContentKeyInfo.java delete mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/File.java create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/FileInfo.java delete mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/Locator.java create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/LocatorInfo.java rename microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/{AssetTest.java => AssetInfoTest.java} (60%) rename microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/{ContentKeyTest.java => ContentKeyInfoTest.java} (65%) rename microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/{FileTest.java => FileInfoTest.java} (66%) rename microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/{LocatorTest.java => LocatorInfoTest.java} (70%) diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AccessPolicyPermission.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AccessPolicyPermission.java index a1abc4a25587b..b5f7dd0e88699 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AccessPolicyPermission.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AccessPolicyPermission.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/models/Asset.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/Asset.java deleted file mode 100644 index be3b534bcb3d0..0000000000000 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/Asset.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - * 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 - * - * 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.models; - -import java.util.Date; - -public class Asset { - private String id; - private AssetState state; - private Date created; - private Date lastModified; - private String alternateId; - private String name; - private EncryptionOption options; - private Iterable<Locator> locators; - private Iterable<ContentKey> contentKeys; - private Iterable<File> files; - private Iterable<Asset> parentAssets; - - public String getId() { - return this.id; - } - - public Asset setId(String id) { - this.id = id; - return this; - } - - public AssetState getState() { - return this.state; - } - - public Asset setState(AssetState state) { - this.state = state; - return this; - } - - public Date getCreated() { - return this.created; - } - - public Asset setCreate(Date created) { - this.created = created; - return this; - } - - public Date getLastModified() { - return this.lastModified; - } - - public Asset setLastModified(Date lastModified) { - this.lastModified = lastModified; - return this; - } - - public String getAlternateId() { - return this.alternateId; - } - - public Asset setAlternateId(String alternateId) { - this.alternateId = alternateId; - return this; - } - - public String getName() { - return this.name; - } - - public Asset setName(String name) { - this.name = name; - return this; - } - - public EncryptionOption getOptions() { - return this.options; - } - - public Asset setOptions(EncryptionOption options) { - this.options = options; - return this; - } - - public Iterable<Locator> getLocators() { - return this.locators; - } - - public Asset setLocators(Iterable<Locator> locators) { - this.locators = locators; - return this; - } - - public Iterable<ContentKey> getContentKeys() { - return this.contentKeys; - } - - public Asset setContentKeys(Iterable<ContentKey> expectedContentKeys) { - this.contentKeys = expectedContentKeys; - return this; - } - - public Iterable<File> getFiles() { - return this.files; - } - - public Asset setFiles(Iterable<File> files) { - this.files = files; - return this; - } - - public Iterable<Asset> getParentAssets() { - return this.parentAssets; - } - - public Asset setParentAssets(Iterable<Asset> parentAssets) { - this.parentAssets = parentAssets; - return this; - } - -} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AssetInfo.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AssetInfo.java new file mode 100644 index 0000000000000..420b4a4bf66fb --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AssetInfo.java @@ -0,0 +1,289 @@ +/* + * 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.models; + +import java.util.Date; + +/** + * The Class AssetInfo. + */ +public class AssetInfo { + + /** The id. */ + private String id; + + /** The state. */ + private AssetState state; + + /** The created. */ + private Date created; + + /** The last modified. */ + private Date lastModified; + + /** The alternate id. */ + private String alternateId; + + /** The name. */ + private String name; + + /** The options. */ + private EncryptionOption options; + + /** The locator infos. */ + private Iterable<LocatorInfo> locatorInfos; + + /** The content key infos. */ + private Iterable<ContentKeyInfo> contentKeyInfos; + + /** The file infos. */ + private Iterable<FileInfo> fileInfos; + + /** The parent asset infos. */ + private Iterable<AssetInfo> parentAssetInfos; + + /** + * Gets the id. + * + * @return the id + */ + public String getId() { + return this.id; + } + + /** + * Sets the id. + * + * @param id + * the id + * @return the asset info + */ + public AssetInfo setId(String id) { + this.id = id; + return this; + } + + /** + * Gets the state. + * + * @return the state + */ + public AssetState getState() { + return this.state; + } + + /** + * Sets the state. + * + * @param state + * the state + * @return the asset info + */ + public AssetInfo setState(AssetState state) { + this.state = state; + return this; + } + + /** + * Gets the created. + * + * @return the created + */ + public Date getCreated() { + return this.created; + } + + /** + * Sets the create. + * + * @param created + * the created + * @return the asset info + */ + public AssetInfo setCreate(Date created) { + this.created = created; + return this; + } + + /** + * Gets the last modified. + * + * @return the last modified + */ + public Date getLastModified() { + return this.lastModified; + } + + /** + * Sets the last modified. + * + * @param lastModified + * the last modified + * @return the asset info + */ + public AssetInfo setLastModified(Date lastModified) { + this.lastModified = lastModified; + return this; + } + + /** + * Gets the alternate id. + * + * @return the alternate id + */ + public String getAlternateId() { + return this.alternateId; + } + + /** + * Sets the alternate id. + * + * @param alternateId + * the alternate id + * @return the asset info + */ + public AssetInfo setAlternateId(String alternateId) { + this.alternateId = alternateId; + return this; + } + + /** + * Gets the name. + * + * @return the name + */ + public String getName() { + return this.name; + } + + /** + * Sets the name. + * + * @param name + * the name + * @return the asset info + */ + public AssetInfo setName(String name) { + this.name = name; + return this; + } + + /** + * Gets the options. + * + * @return the options + */ + public EncryptionOption getOptions() { + return this.options; + } + + /** + * Sets the options. + * + * @param options + * the options + * @return the asset info + */ + public AssetInfo setOptions(EncryptionOption options) { + this.options = options; + return this; + } + + /** + * Gets the locators. + * + * @return the locators + */ + public Iterable<LocatorInfo> getLocators() { + return this.locatorInfos; + } + + /** + * Sets the locators. + * + * @param locatorInfos + * the locator infos + * @return the asset info + */ + public AssetInfo setLocators(Iterable<LocatorInfo> locatorInfos) { + this.locatorInfos = locatorInfos; + return this; + } + + /** + * Gets the content keys. + * + * @return the content keys + */ + public Iterable<ContentKeyInfo> getContentKeys() { + return this.contentKeyInfos; + } + + /** + * Sets the content keys. + * + * @param expectedContentKeys + * the expected content keys + * @return the asset info + */ + public AssetInfo setContentKeys(Iterable<ContentKeyInfo> expectedContentKeys) { + this.contentKeyInfos = expectedContentKeys; + return this; + } + + /** + * Gets the files. + * + * @return the files + */ + public Iterable<FileInfo> getFiles() { + return this.fileInfos; + } + + /** + * Sets the files. + * + * @param fileInfos + * the file infos + * @return the asset info + */ + public AssetInfo setFiles(Iterable<FileInfo> fileInfos) { + this.fileInfos = fileInfos; + return this; + } + + /** + * Gets the parent assets. + * + * @return the parent assets + */ + public Iterable<AssetInfo> getParentAssets() { + return this.parentAssetInfos; + } + + /** + * Sets the parent assets. + * + * @param parentAssetInfos + * the parent asset infos + * @return the asset info + */ + public AssetInfo setParentAssets(Iterable<AssetInfo> parentAssetInfos) { + this.parentAssetInfos = parentAssetInfos; + return this; + } + +} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AssetState.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AssetState.java index 35a504b6da720..2e8dd175b7259 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AssetState.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AssetState.java @@ -1,17 +1,50 @@ +/* + * 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.models; /** * Specifies the states of the asset. */ public enum AssetState { - Initialized(0), Published(1), Deleted(2); + /** The Initialized. */ + Initialized(0), + /** The Published. */ + Published(1), + /** The Deleted. */ + Deleted(2); + + /** The asset state code. */ private int assetStateCode; + /** + * Instantiates a new asset state. + * + * @param assetStateCode + * the asset state code + */ private AssetState(int assetStateCode) { this.assetStateCode = assetStateCode; } + /** + * Gets the code. + * + * @return the code + */ public int getCode() { return assetStateCode; } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/ContentKey.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/ContentKey.java deleted file mode 100644 index 8ea9b530b43f6..0000000000000 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/ContentKey.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * 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 - * - * 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.models; - -import java.util.Date; - -public class ContentKey { - private String id; - private Date created; - private Date lastModified; - private ContentKeyType contentKeyType; - private String encryptedContentKey; - private String name; - private String protectionKeyId; - private String checkSum; - private ProtectionKeyType protectionKeyType; - - public String getId() { - return this.id; - } - - public ContentKey setId(String id) { - this.id = id; - return this; - } - - public ContentKey setCreate(Date created) { - this.created = created; - return this; - } - - public Date getLastModified() { - return this.lastModified; - } - - public ContentKey setLastModified(Date lastModified) { - this.lastModified = lastModified; - return this; - } - - public String getName() { - return this.name; - } - - public ContentKey setName(String name) { - this.name = name; - return this; - } - - public ContentKey setCheckSum(String checkSum) { - this.checkSum = checkSum; - return this; - } - - public String getCheckSum() { - return this.checkSum; - } - - public ContentKey setProtectionKeyType(ProtectionKeyType protectionKeyType) { - this.protectionKeyType = protectionKeyType; - return this; - } - - public ProtectionKeyType getProtectionKeyType() { - return this.protectionKeyType; - } - - public ContentKey setProtectionKeyId(String protectionKeyId) { - this.protectionKeyId = protectionKeyId; - return this; - } - - public String getProtectionKeyId() { - return this.protectionKeyId; - } - - public ContentKey setEncryptedContentKey(String encryptedContentKey) { - this.encryptedContentKey = encryptedContentKey; - return this; - } - - public String getEncryptedContentKey() { - return this.encryptedContentKey; - } - - public ContentKey setContentKeyType(ContentKeyType contentKeyType) { - this.contentKeyType = contentKeyType; - return this; - } - - public ContentKeyType getContentKeyType() { - return this.contentKeyType; - } - - public ContentKey setCreated(Date created) { - this.created = created; - return this; - } - - public Date getCreated() { - return this.created; - } - -} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/ContentKeyInfo.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/ContentKeyInfo.java new file mode 100644 index 0000000000000..3fbf2e76c1579 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/ContentKeyInfo.java @@ -0,0 +1,253 @@ +/* + * 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.models; + +import java.util.Date; + +/** + * The Class ContentKeyInfo. + */ +public class ContentKeyInfo { + + /** The id. */ + private String id; + + /** The created. */ + private Date created; + + /** The last modified. */ + private Date lastModified; + + /** The content key type. */ + private ContentKeyType contentKeyType; + + /** The encrypted content key. */ + private String encryptedContentKey; + + /** The name. */ + private String name; + + /** The protection key id. */ + private String protectionKeyId; + + /** The check sum. */ + private String checkSum; + + /** The protection key type. */ + private ProtectionKeyType protectionKeyType; + + /** + * Gets the id. + * + * @return the id + */ + public String getId() { + return this.id; + } + + /** + * Sets the id. + * + * @param id + * the id + * @return the content key info + */ + public ContentKeyInfo setId(String id) { + this.id = id; + return this; + } + + /** + * Sets the create. + * + * @param created + * the created + * @return the content key info + */ + public ContentKeyInfo setCreate(Date created) { + this.created = created; + return this; + } + + /** + * Gets the last modified. + * + * @return the last modified + */ + public Date getLastModified() { + return this.lastModified; + } + + /** + * Sets the last modified. + * + * @param lastModified + * the last modified + * @return the content key info + */ + public ContentKeyInfo setLastModified(Date lastModified) { + this.lastModified = lastModified; + return this; + } + + /** + * Gets the name. + * + * @return the name + */ + public String getName() { + return this.name; + } + + /** + * Sets the name. + * + * @param name + * the name + * @return the content key info + */ + public ContentKeyInfo setName(String name) { + this.name = name; + return this; + } + + /** + * Sets the check sum. + * + * @param checkSum + * the check sum + * @return the content key info + */ + public ContentKeyInfo setCheckSum(String checkSum) { + this.checkSum = checkSum; + return this; + } + + /** + * Gets the check sum. + * + * @return the check sum + */ + public String getCheckSum() { + return this.checkSum; + } + + /** + * Sets the protection key type. + * + * @param protectionKeyType + * the protection key type + * @return the content key info + */ + public ContentKeyInfo setProtectionKeyType(ProtectionKeyType protectionKeyType) { + this.protectionKeyType = protectionKeyType; + return this; + } + + /** + * Gets the protection key type. + * + * @return the protection key type + */ + public ProtectionKeyType getProtectionKeyType() { + return this.protectionKeyType; + } + + /** + * Sets the protection key id. + * + * @param protectionKeyId + * the protection key id + * @return the content key info + */ + public ContentKeyInfo setProtectionKeyId(String protectionKeyId) { + this.protectionKeyId = protectionKeyId; + return this; + } + + /** + * Gets the protection key id. + * + * @return the protection key id + */ + public String getProtectionKeyId() { + return this.protectionKeyId; + } + + /** + * Sets the encrypted content key. + * + * @param encryptedContentKey + * the encrypted content key + * @return the content key info + */ + public ContentKeyInfo setEncryptedContentKey(String encryptedContentKey) { + this.encryptedContentKey = encryptedContentKey; + return this; + } + + /** + * Gets the encrypted content key. + * + * @return the encrypted content key + */ + public String getEncryptedContentKey() { + return this.encryptedContentKey; + } + + /** + * Sets the content key type. + * + * @param contentKeyType + * the content key type + * @return the content key info + */ + public ContentKeyInfo setContentKeyType(ContentKeyType contentKeyType) { + this.contentKeyType = contentKeyType; + return this; + } + + /** + * Gets the content key type. + * + * @return the content key type + */ + public ContentKeyType getContentKeyType() { + return this.contentKeyType; + } + + /** + * Sets the created. + * + * @param created + * the created + * @return the content key info + */ + public ContentKeyInfo setCreated(Date created) { + this.created = created; + return this; + } + + /** + * Gets the created. + * + * @return the created + */ + public Date getCreated() { + return this.created; + } + +} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/ContentKeyType.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/ContentKeyType.java index 1a7bc64e9d565..5bfaf65f9030e 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/ContentKeyType.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/ContentKeyType.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. @@ -21,14 +21,32 @@ * */ public enum ContentKeyType { - CommonEncryption(0), StorageEncryption(1), ConfigurationEncryption(2); + /** The Common encryption. */ + CommonEncryption(0), + /** The Storage encryption. */ + StorageEncryption(1), + /** The Configuration encryption. */ + ConfigurationEncryption(2); + + /** The content key type code. */ private int contentKeyTypeCode; + /** + * Instantiates a new content key type. + * + * @param contentKeyTypeCode + * the content key type code + */ private ContentKeyType(int contentKeyTypeCode) { this.contentKeyTypeCode = contentKeyTypeCode; } + /** + * Gets the code. + * + * @return the code + */ public int getCode() { return contentKeyTypeCode; } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/EncryptionOption.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/EncryptionOption.java index 9e98aecb69aab..7eb929ac60927 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/EncryptionOption.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/EncryptionOption.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. @@ -19,14 +19,32 @@ * Specifies the options for encryption. */ public enum EncryptionOption { - None(0), StorageEncrypted(1), CommonEncryptionProtected(2); + /** The None. */ + None(0), + /** The Storage encrypted. */ + StorageEncrypted(1), + /** The Common encryption protected. */ + CommonEncryptionProtected(2); + + /** The encryption option code. */ private int encryptionOptionCode; + /** + * Instantiates a new encryption option. + * + * @param encryptionOptionCode + * the encryption option code + */ private EncryptionOption(int encryptionOptionCode) { this.encryptionOptionCode = encryptionOptionCode; } + /** + * Gets the code. + * + * @return the code + */ public int getCode() { return encryptionOptionCode; } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/File.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/File.java deleted file mode 100644 index f171d4a1fe576..0000000000000 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/File.java +++ /dev/null @@ -1,167 +0,0 @@ -/* - * 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 - * - * 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.models; - -import java.util.Date; - -public class File { - private String id; - private String name; - private int contentFileSize; - private String parentAssetId; - private String encryptionVersion; - private String encryptionScheme; - private Boolean isEncrypted; - private String encryptionKeyId; - private String initializationVector; - private Boolean isPrimary; - private Date lastModified; - private Date created; - private String mimeType; - private String contentChecksum; - - public String getId() { - return this.id; - } - - public File setId(String id) { - this.id = id; - return this; - } - - public String getName() { - return this.name; - } - - public File setName(String name) { - this.name = name; - return this; - } - - public int getContentFileSize() { - return this.contentFileSize; - } - - public File setContentFileSize(int contentFileSize) { - this.contentFileSize = contentFileSize; - return this; - } - - public String getParentAssetId() { - return this.parentAssetId; - } - - public File setParentAssetId(String parentAssetId) { - this.parentAssetId = parentAssetId; - return this; - } - - public Date getCreated() { - return this.created; - } - - public File setCreate(Date created) { - this.created = created; - return this; - } - - public Date getLastModified() { - return this.lastModified; - } - - public File setLastModified(Date lastModified) { - this.lastModified = lastModified; - return this; - } - - public File setEncryptionVersion(String encryptionVersion) { - this.encryptionVersion = encryptionVersion; - return this; - } - - public String getEncryptionVersion() { - return this.encryptionVersion; - } - - public File setEncryptionScheme(String encryptionScheme) { - this.encryptionScheme = encryptionScheme; - return this; - } - - public String getEncryptionScheme() { - return this.encryptionScheme; - } - - public File setIsEncrypted(Boolean isEncrypted) { - this.isEncrypted = isEncrypted; - return this; - } - - public Boolean getIsEncrypted() { - return this.isEncrypted; - } - - public File setEncryptionKeyId(String encryptionKeyId) { - this.encryptionKeyId = encryptionKeyId; - return this; - } - - public String getEncryptionKeyId() { - return this.encryptionKeyId; - } - - public File setInitializationVector(String expectedInitializationVector) { - this.initializationVector = expectedInitializationVector; - return this; - } - - public String getInitializationVector() { - return this.initializationVector; - } - - public File setIsPrimary(Boolean isPrimary) { - this.isPrimary = isPrimary; - return this; - } - - public Boolean getIsPrimary() { - return this.isPrimary; - } - - public File setCreated(Date created) { - this.created = created; - return this; - } - - public File setMimeType(String mimeType) { - this.mimeType = mimeType; - return this; - } - - public String getMimeType() { - return this.mimeType; - } - - public File setContentChecksum(String contentChecksum) { - this.contentChecksum = contentChecksum; - return this; - } - - public String getContentChecksum() { - return this.contentChecksum; - } - -} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/FileInfo.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/FileInfo.java new file mode 100644 index 0000000000000..9585a76233a67 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/FileInfo.java @@ -0,0 +1,373 @@ +/* + * 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.models; + +import java.util.Date; + +/** + * The Class FileInfo. + */ +public class FileInfo { + + /** The id. */ + private String id; + + /** The name. */ + private String name; + + /** The content file size. */ + private int contentFileSize; + + /** The parent asset id. */ + private String parentAssetId; + + /** The encryption version. */ + private String encryptionVersion; + + /** The encryption scheme. */ + private String encryptionScheme; + + /** The is encrypted. */ + private Boolean isEncrypted; + + /** The encryption key id. */ + private String encryptionKeyId; + + /** The initialization vector. */ + private String initializationVector; + + /** The is primary. */ + private Boolean isPrimary; + + /** The last modified. */ + private Date lastModified; + + /** The created. */ + private Date created; + + /** The mime type. */ + private String mimeType; + + /** The content checksum. */ + private String contentChecksum; + + /** + * Gets the id. + * + * @return the id + */ + public String getId() { + return this.id; + } + + /** + * Sets the id. + * + * @param id + * the id + * @return the file info + */ + public FileInfo setId(String id) { + this.id = id; + return this; + } + + /** + * Gets the name. + * + * @return the name + */ + public String getName() { + return this.name; + } + + /** + * Sets the name. + * + * @param name + * the name + * @return the file info + */ + public FileInfo setName(String name) { + this.name = name; + return this; + } + + /** + * Gets the content file size. + * + * @return the content file size + */ + public int getContentFileSize() { + return this.contentFileSize; + } + + /** + * Sets the content file size. + * + * @param contentFileSize + * the content file size + * @return the file info + */ + public FileInfo setContentFileSize(int contentFileSize) { + this.contentFileSize = contentFileSize; + return this; + } + + /** + * Gets the parent asset id. + * + * @return the parent asset id + */ + public String getParentAssetId() { + return this.parentAssetId; + } + + /** + * Sets the parent asset id. + * + * @param parentAssetId + * the parent asset id + * @return the file info + */ + public FileInfo setParentAssetId(String parentAssetId) { + this.parentAssetId = parentAssetId; + return this; + } + + /** + * Gets the created. + * + * @return the created + */ + public Date getCreated() { + return this.created; + } + + /** + * Sets the create. + * + * @param created + * the created + * @return the file info + */ + public FileInfo setCreate(Date created) { + this.created = created; + return this; + } + + /** + * Gets the last modified. + * + * @return the last modified + */ + public Date getLastModified() { + return this.lastModified; + } + + /** + * Sets the last modified. + * + * @param lastModified + * the last modified + * @return the file info + */ + public FileInfo setLastModified(Date lastModified) { + this.lastModified = lastModified; + return this; + } + + /** + * Sets the encryption version. + * + * @param encryptionVersion + * the encryption version + * @return the file info + */ + public FileInfo setEncryptionVersion(String encryptionVersion) { + this.encryptionVersion = encryptionVersion; + return this; + } + + /** + * Gets the encryption version. + * + * @return the encryption version + */ + public String getEncryptionVersion() { + return this.encryptionVersion; + } + + /** + * Sets the encryption scheme. + * + * @param encryptionScheme + * the encryption scheme + * @return the file info + */ + public FileInfo setEncryptionScheme(String encryptionScheme) { + this.encryptionScheme = encryptionScheme; + return this; + } + + /** + * Gets the encryption scheme. + * + * @return the encryption scheme + */ + public String getEncryptionScheme() { + return this.encryptionScheme; + } + + /** + * Sets the is encrypted. + * + * @param isEncrypted + * the is encrypted + * @return the file info + */ + public FileInfo setIsEncrypted(Boolean isEncrypted) { + this.isEncrypted = isEncrypted; + return this; + } + + /** + * Gets the checks if is encrypted. + * + * @return the checks if is encrypted + */ + public Boolean getIsEncrypted() { + return this.isEncrypted; + } + + /** + * Sets the encryption key id. + * + * @param encryptionKeyId + * the encryption key id + * @return the file info + */ + public FileInfo setEncryptionKeyId(String encryptionKeyId) { + this.encryptionKeyId = encryptionKeyId; + return this; + } + + /** + * Gets the encryption key id. + * + * @return the encryption key id + */ + public String getEncryptionKeyId() { + return this.encryptionKeyId; + } + + /** + * Sets the initialization vector. + * + * @param expectedInitializationVector + * the expected initialization vector + * @return the file info + */ + public FileInfo setInitializationVector(String expectedInitializationVector) { + this.initializationVector = expectedInitializationVector; + return this; + } + + /** + * Gets the initialization vector. + * + * @return the initialization vector + */ + public String getInitializationVector() { + return this.initializationVector; + } + + /** + * Sets the is primary. + * + * @param isPrimary + * the is primary + * @return the file info + */ + public FileInfo setIsPrimary(Boolean isPrimary) { + this.isPrimary = isPrimary; + return this; + } + + /** + * Gets the checks if is primary. + * + * @return the checks if is primary + */ + public Boolean getIsPrimary() { + return this.isPrimary; + } + + /** + * Sets the created. + * + * @param created + * the created + * @return the file info + */ + public FileInfo setCreated(Date created) { + this.created = created; + return this; + } + + /** + * Sets the mime type. + * + * @param mimeType + * the mime type + * @return the file info + */ + public FileInfo setMimeType(String mimeType) { + this.mimeType = mimeType; + return this; + } + + /** + * Gets the mime type. + * + * @return the mime type + */ + public String getMimeType() { + return this.mimeType; + } + + /** + * Sets the content checksum. + * + * @param contentChecksum + * the content checksum + * @return the file info + */ + public FileInfo setContentChecksum(String contentChecksum) { + this.contentChecksum = contentChecksum; + return this; + } + + /** + * Gets the content checksum. + * + * @return the content checksum + */ + public String getContentChecksum() { + return this.contentChecksum; + } + +} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/Locator.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/Locator.java deleted file mode 100644 index 2cfa54e1a429d..0000000000000 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/Locator.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * 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 - * - * 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.models; - -import java.util.Date; - -public class Locator { - private String id; - private Date expirationDatetime; - private String path; - private String accessPolicyId; - private String assetId; - private Date startTime; - private LocatorType locatorType; - - public String getId() { - return this.id; - } - - public Locator setId(String id) { - this.id = id; - return this; - } - - public Locator setExpirationDateTime(Date expirationDateTime) { - this.expirationDatetime = expirationDateTime; - return this; - } - - public Date getExpirationDateTime() { - return this.expirationDatetime; - } - - public Locator setLocatorType(LocatorType locatorType) { - this.locatorType = locatorType; - return this; - } - - public LocatorType getLocatorType() { - return this.locatorType; - } - - public Locator setPath(String path) { - this.path = path; - return this; - } - - public String getPath() { - return this.path; - } - - public Locator setAccessPolicyId(String accessPolicyId) { - this.accessPolicyId = accessPolicyId; - return this; - } - - public String getAccessPolicyId() { - return this.accessPolicyId; - } - - public Locator setAssetId(String assetId) { - this.assetId = assetId; - return this; - } - - public String getAssetId() { - return this.assetId; - } - - public Locator setStartTime(Date startTime) { - this.startTime = startTime; - return this; - } - - public Date getStartTime() { - return this.startTime; - } - -} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/LocatorInfo.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/LocatorInfo.java new file mode 100644 index 0000000000000..c90c38aba3e85 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/LocatorInfo.java @@ -0,0 +1,193 @@ +/* + * 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.models; + +import java.util.Date; + +/** + * The Class LocatorInfo. + */ +public class LocatorInfo { + + /** The id. */ + private String id; + + /** The expiration datetime. */ + private Date expirationDatetime; + + /** The path. */ + private String path; + + /** The access policy id. */ + private String accessPolicyId; + + /** The asset id. */ + private String assetId; + + /** The start time. */ + private Date startTime; + + /** The locator type. */ + private LocatorType locatorType; + + /** + * Gets the id. + * + * @return the id + */ + public String getId() { + return this.id; + } + + /** + * Sets the id. + * + * @param id + * the id + * @return the locator info + */ + public LocatorInfo setId(String id) { + this.id = id; + return this; + } + + /** + * Sets the expiration date time. + * + * @param expirationDateTime + * the expiration date time + * @return the locator info + */ + public LocatorInfo setExpirationDateTime(Date expirationDateTime) { + this.expirationDatetime = expirationDateTime; + return this; + } + + /** + * Gets the expiration date time. + * + * @return the expiration date time + */ + public Date getExpirationDateTime() { + return this.expirationDatetime; + } + + /** + * Sets the locator type. + * + * @param locatorType + * the locator type + * @return the locator info + */ + public LocatorInfo setLocatorType(LocatorType locatorType) { + this.locatorType = locatorType; + return this; + } + + /** + * Gets the locator type. + * + * @return the locator type + */ + public LocatorType getLocatorType() { + return this.locatorType; + } + + /** + * Sets the path. + * + * @param path + * the path + * @return the locator info + */ + public LocatorInfo setPath(String path) { + this.path = path; + return this; + } + + /** + * Gets the path. + * + * @return the path + */ + public String getPath() { + return this.path; + } + + /** + * Sets the access policy id. + * + * @param accessPolicyId + * the access policy id + * @return the locator info + */ + public LocatorInfo setAccessPolicyId(String accessPolicyId) { + this.accessPolicyId = accessPolicyId; + return this; + } + + /** + * Gets the access policy id. + * + * @return the access policy id + */ + public String getAccessPolicyId() { + return this.accessPolicyId; + } + + /** + * Sets the asset id. + * + * @param assetId + * the asset id + * @return the locator info + */ + public LocatorInfo setAssetId(String assetId) { + this.assetId = assetId; + return this; + } + + /** + * Gets the asset id. + * + * @return the asset id + */ + public String getAssetId() { + return this.assetId; + } + + /** + * Sets the start time. + * + * @param startTime + * the start time + * @return the locator info + */ + public LocatorInfo setStartTime(Date startTime) { + this.startTime = startTime; + return this; + } + + /** + * Gets the start time. + * + * @return the start time + */ + public Date getStartTime() { + return this.startTime; + } + +} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/LocatorType.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/LocatorType.java index ef74b364fa655..3cc4a583b151d 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/LocatorType.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/LocatorType.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,15 +15,38 @@ package com.microsoft.windowsazure.services.media.models; +/** + * The Enum LocatorType. + */ public enum LocatorType { - None(0), SAS(1), Origin(2), WindowsAzureCDN(3); + /** The None. */ + None(0), + /** The sas. */ + SAS(1), + /** The Origin. */ + Origin(2), + /** The Windows azure cdn. */ + WindowsAzureCDN(3); + + /** The locator type code. */ private int locatorTypeCode; + /** + * Instantiates a new locator type. + * + * @param locatorTypeCode + * the locator type code + */ private LocatorType(int locatorTypeCode) { this.locatorTypeCode = locatorTypeCode; } + /** + * Gets the code. + * + * @return the code + */ public int getCode() { return this.locatorTypeCode; } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/ProtectionKeyType.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/ProtectionKeyType.java index 88f0099e20bd9..e0ddb7911c4d2 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/ProtectionKeyType.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/ProtectionKeyType.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,15 +15,32 @@ package com.microsoft.windowsazure.services.media.models; +/** + * The Enum ProtectionKeyType. + */ public enum ProtectionKeyType { + + /** The X509 certificate thumbprint. */ X509CertificateThumbprint(0); + /** The protection key type code. */ private int protectionKeyTypeCode; + /** + * Instantiates a new protection key type. + * + * @param protectionKeyTypeCode + * the protection key type code + */ private ProtectionKeyType(int protectionKeyTypeCode) { this.protectionKeyTypeCode = protectionKeyTypeCode; } + /** + * Gets the code. + * + * @return the code + */ public int getCode() { return protectionKeyTypeCode; } diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/AssetTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/AssetInfoTest.java similarity index 60% rename from microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/AssetTest.java rename to microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/AssetInfoTest.java index d622d9473bb04..a1222e83d5234 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/AssetTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/AssetInfoTest.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. @@ -21,16 +21,16 @@ import org.junit.Test; -public class AssetTest { +public class AssetInfoTest { @Test public void testGetSetId() { // Arrange String expectedId = "expectedId"; - Asset asset = new Asset(); + AssetInfo assetInfo = new AssetInfo(); // Act - String actualId = asset.setId(expectedId).getId(); + String actualId = assetInfo.setId(expectedId).getId(); // Assert assertEquals(expectedId, actualId); @@ -41,10 +41,10 @@ public void testGetSetId() { public void testGetSetState() { // Arrange AssetState expectedState = AssetState.Published; - Asset asset = new Asset(); + AssetInfo assetInfo = new AssetInfo(); // Act - AssetState actualState = asset.setState(expectedState).getState(); + AssetState actualState = assetInfo.setState(expectedState).getState(); // Assert assertEquals(expectedState, actualState); @@ -54,10 +54,10 @@ public void testGetSetState() { public void testGetSetCreated() { // Arrange Date expectedCreated = new Date(); - Asset asset = new Asset(); + AssetInfo assetInfo = new AssetInfo(); // Act - Date actualCreated = asset.setCreate(expectedCreated).getCreated(); + Date actualCreated = assetInfo.setCreate(expectedCreated).getCreated(); // Assert assertEquals(expectedCreated, actualCreated); @@ -68,10 +68,10 @@ public void testGetSetCreated() { public void testGetSetLastModified() { // Arrange Date expectedLastModified = new Date(); - Asset asset = new Asset(); + AssetInfo assetInfo = new AssetInfo(); // Act - Date actualLastModified = asset.setLastModified(expectedLastModified).getLastModified(); + Date actualLastModified = assetInfo.setLastModified(expectedLastModified).getLastModified(); // Assert assertEquals(expectedLastModified, actualLastModified); @@ -81,10 +81,10 @@ public void testGetSetLastModified() { public void testGetSetAlternateId() { // Arrange String expectedAlternateId = "testAlternateId"; - Asset asset = new Asset(); + AssetInfo assetInfo = new AssetInfo(); // Act - String actualAlternateId = asset.setAlternateId(expectedAlternateId).getAlternateId(); + String actualAlternateId = assetInfo.setAlternateId(expectedAlternateId).getAlternateId(); // Assert assertEquals(expectedAlternateId, actualAlternateId); @@ -94,10 +94,10 @@ public void testGetSetAlternateId() { public void testGetSetName() { // Arrange String expectedName = "testName"; - Asset asset = new Asset(); + AssetInfo assetInfo = new AssetInfo(); // Act - String actualName = asset.setName(expectedName).getName(); + String actualName = assetInfo.setName(expectedName).getName(); // Assert assertEquals(expectedName, actualName); @@ -107,10 +107,10 @@ public void testGetSetName() { public void testGetSetOptions() { // Arrange EncryptionOption expectedOptions = EncryptionOption.None; - Asset asset = new Asset(); + AssetInfo assetInfo = new AssetInfo(); // Act - EncryptionOption actualOptions = asset.setOptions(expectedOptions).getOptions(); + EncryptionOption actualOptions = assetInfo.setOptions(expectedOptions).getOptions(); // Assert assertEquals(expectedOptions, actualOptions); @@ -119,11 +119,11 @@ public void testGetSetOptions() { @Test public void testGetSetLocators() { // Arrange - Iterable<Locator> expectedLocators = new ArrayList<Locator>(); - Asset asset = new Asset(); + Iterable<LocatorInfo> expectedLocators = new ArrayList<LocatorInfo>(); + AssetInfo assetInfo = new AssetInfo(); // Act - Iterable<Locator> actualLocators = asset.setLocators(expectedLocators).getLocators(); + Iterable<LocatorInfo> actualLocators = assetInfo.setLocators(expectedLocators).getLocators(); // Assert assertEquals(expectedLocators, actualLocators); @@ -132,11 +132,11 @@ public void testGetSetLocators() { @Test public void testGetSetContentKeys() { // Arrange - Iterable<ContentKey> expectedContentKeys = new ArrayList<ContentKey>(); - Asset asset = new Asset(); + Iterable<ContentKeyInfo> expectedContentKeys = new ArrayList<ContentKeyInfo>(); + AssetInfo assetInfo = new AssetInfo(); // Act - Iterable<ContentKey> actualContentKeys = asset.setContentKeys(expectedContentKeys).getContentKeys(); + Iterable<ContentKeyInfo> actualContentKeys = assetInfo.setContentKeys(expectedContentKeys).getContentKeys(); // Assert assertEquals(expectedContentKeys, actualContentKeys); @@ -145,11 +145,11 @@ public void testGetSetContentKeys() { @Test public void testGetSetFiles() { // Arrange - Iterable<File> expectedFiles = new ArrayList<File>(); - Asset asset = new Asset(); + Iterable<FileInfo> expectedFiles = new ArrayList<FileInfo>(); + AssetInfo assetInfo = new AssetInfo(); // Act - Iterable<File> actualFiles = asset.setFiles(expectedFiles).getFiles(); + Iterable<FileInfo> actualFiles = assetInfo.setFiles(expectedFiles).getFiles(); // Assert assertEquals(expectedFiles, actualFiles); @@ -158,11 +158,11 @@ public void testGetSetFiles() { @Test public void testGetSetParentAsset() { // Arrange - Iterable<Asset> expectedParentAssets = new ArrayList<Asset>(); - Asset asset = new Asset(); + Iterable<AssetInfo> expectedParentAssets = new ArrayList<AssetInfo>(); + AssetInfo asset = new AssetInfo(); // Act - Iterable<Asset> actualAssets = asset.setParentAssets(expectedParentAssets).getParentAssets(); + Iterable<AssetInfo> actualAssets = asset.setParentAssets(expectedParentAssets).getParentAssets(); // Assert assertEquals(expectedParentAssets, actualAssets); diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/ContentKeyTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/ContentKeyInfoTest.java similarity index 65% rename from microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/ContentKeyTest.java rename to microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/ContentKeyInfoTest.java index a2cf7644b10db..eddd15aad4e1f 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/ContentKeyTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/ContentKeyInfoTest.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. @@ -20,16 +20,16 @@ import org.junit.Test; -public class ContentKeyTest { +public class ContentKeyInfoTest { @Test public void testGetSetId() { // Arrange String expectedId = "expectedId"; - ContentKey contentKey = new ContentKey(); + ContentKeyInfo contentKeyInfo = new ContentKeyInfo(); // Act - String actualId = contentKey.setId(expectedId).getId(); + String actualId = contentKeyInfo.setId(expectedId).getId(); // Assert assertEquals(expectedId, actualId); @@ -39,10 +39,10 @@ public void testGetSetId() { public void testGetSetCreated() { // Arrange Date expectedCreated = new Date(); - ContentKey contentKey = new ContentKey(); + ContentKeyInfo contentKeyInfo = new ContentKeyInfo(); // Act - Date actualCreated = contentKey.setCreated(expectedCreated).getCreated(); + Date actualCreated = contentKeyInfo.setCreated(expectedCreated).getCreated(); // Assert assertEquals(expectedCreated, actualCreated); @@ -52,10 +52,10 @@ public void testGetSetCreated() { public void testGetSetLastModified() { // Arrange Date expectedLastModified = new Date(); - ContentKey contentKey = new ContentKey(); + ContentKeyInfo contentKeyInfo = new ContentKeyInfo(); // Act - Date actualLastModified = contentKey.setLastModified(expectedLastModified).getLastModified(); + Date actualLastModified = contentKeyInfo.setLastModified(expectedLastModified).getLastModified(); // Assert assertEquals(expectedLastModified, actualLastModified); @@ -65,10 +65,11 @@ public void testGetSetLastModified() { public void testGetSetContentKeyType() { // Arrange ContentKeyType expectedContentKeyType = ContentKeyType.ConfigurationEncryption; - ContentKey contentKey = new ContentKey(); + ContentKeyInfo contentKeyInfo = new ContentKeyInfo(); // Act - ContentKeyType actualContentKeyType = contentKey.setContentKeyType(expectedContentKeyType).getContentKeyType(); + ContentKeyType actualContentKeyType = contentKeyInfo.setContentKeyType(expectedContentKeyType) + .getContentKeyType(); // Assert assertEquals(expectedContentKeyType, actualContentKeyType); @@ -79,10 +80,10 @@ public void testGetSetContentKeyType() { public void testGetSetEncryptedContentKey() { // Arrange String expectedEncryptedContentKey = "testX509Certificate"; - ContentKey contentKey = new ContentKey(); + ContentKeyInfo contentKeyInfo = new ContentKeyInfo(); // Act - String actualEncryptedContentKey = contentKey.setEncryptedContentKey(expectedEncryptedContentKey) + String actualEncryptedContentKey = contentKeyInfo.setEncryptedContentKey(expectedEncryptedContentKey) .getEncryptedContentKey(); // Assert @@ -93,10 +94,10 @@ public void testGetSetEncryptedContentKey() { public void testGetSetName() { // Arrange String expectedName = "expectedName"; - ContentKey contentKey = new ContentKey(); + ContentKeyInfo contentKeyInfo = new ContentKeyInfo(); // Act - String actualName = contentKey.setName(expectedName).getName(); + String actualName = contentKeyInfo.setName(expectedName).getName(); // Assert assertEquals(expectedName, actualName); @@ -106,10 +107,10 @@ public void testGetSetName() { public void testGetSetProtectionKeyId() { // Arrange String expectedProtectionKeyId = "expectedProtectionKeyId"; - ContentKey contentKey = new ContentKey(); + ContentKeyInfo contentKeyInfo = new ContentKeyInfo(); // Act - String actualProtectionKeyId = contentKey.setProtectionKeyId(expectedProtectionKeyId).getProtectionKeyId(); + String actualProtectionKeyId = contentKeyInfo.setProtectionKeyId(expectedProtectionKeyId).getProtectionKeyId(); // Assert assertEquals(expectedProtectionKeyId, actualProtectionKeyId); @@ -120,10 +121,10 @@ public void testGetSetProtectionKeyId() { public void testGetSetProtectionKeyType() { // Arrange ProtectionKeyType expectedProtectionKeyType = ProtectionKeyType.X509CertificateThumbprint; - ContentKey contentKey = new ContentKey(); + ContentKeyInfo contentKeyInfo = new ContentKeyInfo(); // Act - ProtectionKeyType actualProtectionKeyType = contentKey.setProtectionKeyType(expectedProtectionKeyType) + ProtectionKeyType actualProtectionKeyType = contentKeyInfo.setProtectionKeyType(expectedProtectionKeyType) .getProtectionKeyType(); // Assert @@ -134,10 +135,10 @@ public void testGetSetProtectionKeyType() { public void testGetSetCheckSum() { // Arrange String expectedCheckSum = "testCheckSum"; - ContentKey contentKey = new ContentKey(); + ContentKeyInfo contentKeyInfo = new ContentKeyInfo(); // Act - String actualCheckSum = contentKey.setCheckSum(expectedCheckSum).getCheckSum(); + String actualCheckSum = contentKeyInfo.setCheckSum(expectedCheckSum).getCheckSum(); // Assert assertEquals(expectedCheckSum, actualCheckSum); diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/FileTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/FileInfoTest.java similarity index 66% rename from microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/FileTest.java rename to microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/FileInfoTest.java index 3a4a760cdbacd..3e32e0626a7ab 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/FileTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/FileInfoTest.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. @@ -20,13 +20,13 @@ import org.junit.Test; -public class FileTest { +public class FileInfoTest { @Test public void testGetSetId() { // Arrange String expectedId = "testId"; - File file = new File(); + FileInfo file = new FileInfo(); // Act String actualId = file.setId(expectedId).getId(); @@ -39,10 +39,10 @@ public void testGetSetId() { public void testGetSetName() { // Arrange String expectedName = "testName"; - File file = new File(); + FileInfo fileInfo = new FileInfo(); // Act - String actualName = file.setName(expectedName).getName(); + String actualName = fileInfo.setName(expectedName).getName(); // Assert assertEquals(expectedName, actualName); @@ -52,10 +52,10 @@ public void testGetSetName() { public void testGetSetContentFileSize() { // Arrange int expectedContentFileSize = 1234; - File file = new File(); + FileInfo fileInfo = new FileInfo(); // Act - int actualContentFileSize = file.setContentFileSize(expectedContentFileSize).getContentFileSize(); + int actualContentFileSize = fileInfo.setContentFileSize(expectedContentFileSize).getContentFileSize(); // Assert assertEquals(expectedContentFileSize, actualContentFileSize); @@ -66,10 +66,10 @@ public void testGetSetContentFileSize() { public void testGetSetParentAssetId() { // Arrange String expectedParentAssetId = "testParentAssetId"; - File file = new File(); + FileInfo fileInfo = new FileInfo(); // Act - String actualParentAssetId = file.setParentAssetId(expectedParentAssetId).getParentAssetId(); + String actualParentAssetId = fileInfo.setParentAssetId(expectedParentAssetId).getParentAssetId(); // Assert assertEquals(expectedParentAssetId, actualParentAssetId); @@ -79,10 +79,11 @@ public void testGetSetParentAssetId() { public void testGetSetEncryptionVersion() { // Arrange String expectedEncryptionVersion = "testEncryptionVersion"; - File file = new File(); + FileInfo fileInfo = new FileInfo(); // Act - String actualEncryptionVersion = file.setEncryptionVersion(expectedEncryptionVersion).getEncryptionVersion(); + String actualEncryptionVersion = fileInfo.setEncryptionVersion(expectedEncryptionVersion) + .getEncryptionVersion(); // Assert assertEquals(expectedEncryptionVersion, actualEncryptionVersion); @@ -92,10 +93,10 @@ public void testGetSetEncryptionVersion() { public void testGetSetEncryptionScheme() { // Arrange String expectedEncryptionScheme = "testEncryptionScheme"; - File file = new File(); + FileInfo fileInfo = new FileInfo(); // Act - String actualEncryptionScheme = file.setEncryptionScheme(expectedEncryptionScheme).getEncryptionScheme(); + String actualEncryptionScheme = fileInfo.setEncryptionScheme(expectedEncryptionScheme).getEncryptionScheme(); // Assert assertEquals(expectedEncryptionScheme, actualEncryptionScheme); @@ -105,10 +106,10 @@ public void testGetSetEncryptionScheme() { public void testGetSetIsEncrypted() { // Arrange Boolean expectedIsEncrypted = true; - File file = new File(); + FileInfo fileInfo = new FileInfo(); // Act - Boolean actualIsEncrypted = file.setIsEncrypted(expectedIsEncrypted).getIsEncrypted(); + Boolean actualIsEncrypted = fileInfo.setIsEncrypted(expectedIsEncrypted).getIsEncrypted(); // Assert assertEquals(expectedIsEncrypted, actualIsEncrypted); @@ -118,10 +119,10 @@ public void testGetSetIsEncrypted() { public void testGetSetEncryptionKeyId() { // Arrange String expectedEncryptionKeyId = "testEncryptionKeyId"; - File file = new File(); + FileInfo fileInfo = new FileInfo(); // Act - String actualEncryptionKeyId = file.setEncryptionKeyId(expectedEncryptionKeyId).getEncryptionKeyId(); + String actualEncryptionKeyId = fileInfo.setEncryptionKeyId(expectedEncryptionKeyId).getEncryptionKeyId(); // Assert assertEquals(expectedEncryptionKeyId, actualEncryptionKeyId); @@ -131,10 +132,10 @@ public void testGetSetEncryptionKeyId() { public void testGetSetInitializationVector() { // Arrange String expectedInitializationVector = "testInitializationVector"; - File file = new File(); + FileInfo fileInfo = new FileInfo(); // Act - String actualInitializationVector = file.setInitializationVector(expectedInitializationVector) + String actualInitializationVector = fileInfo.setInitializationVector(expectedInitializationVector) .getInitializationVector(); // Assert @@ -146,10 +147,10 @@ public void testGetSetInitializationVector() { public void testGetSetIsPrimary() { // Arrange Boolean expectedIsPrimary = true; - File file = new File(); + FileInfo fileInfo = new FileInfo(); // Act - Boolean actualIsPrimary = file.setIsPrimary(expectedIsPrimary).getIsPrimary(); + Boolean actualIsPrimary = fileInfo.setIsPrimary(expectedIsPrimary).getIsPrimary(); // Assert assertEquals(expectedIsPrimary, actualIsPrimary); @@ -159,10 +160,10 @@ public void testGetSetIsPrimary() { public void testGetSetLastModified() { // Arrange Date expectedLastModified = new Date(); - File file = new File(); + FileInfo fileInfo = new FileInfo(); // Act - Date actualLastModified = file.setLastModified(expectedLastModified).getLastModified(); + Date actualLastModified = fileInfo.setLastModified(expectedLastModified).getLastModified(); // Assert assertEquals(expectedLastModified, actualLastModified); @@ -172,10 +173,10 @@ public void testGetSetLastModified() { public void testGetSetCreated() { // Arrange Date expectedCreated = new Date(); - File file = new File(); + FileInfo fileInfo = new FileInfo(); // Act - Date actualCreated = file.setCreated(expectedCreated).getCreated(); + Date actualCreated = fileInfo.setCreated(expectedCreated).getCreated(); // Assert assertEquals(expectedCreated, actualCreated); @@ -185,10 +186,10 @@ public void testGetSetCreated() { public void testGetSetMimeType() { // Arrange String expectedMimeType = "testMimeType"; - File file = new File(); + FileInfo fileInfo = new FileInfo(); // Act - String actualMimeType = file.setMimeType(expectedMimeType).getMimeType(); + String actualMimeType = fileInfo.setMimeType(expectedMimeType).getMimeType(); // Assert assertEquals(expectedMimeType, actualMimeType); @@ -198,10 +199,10 @@ public void testGetSetMimeType() { public void testGetSetContentChecksum() { // Arrange String expectedContentChecksum = "testContentChecksum"; - File file = new File(); + FileInfo fileInfo = new FileInfo(); // Act - String actualContentChecksum = file.setContentChecksum(expectedContentChecksum).getContentChecksum(); + String actualContentChecksum = fileInfo.setContentChecksum(expectedContentChecksum).getContentChecksum(); // Assert assertEquals(expectedContentChecksum, actualContentChecksum); diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/LocatorTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/LocatorInfoTest.java similarity index 70% rename from microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/LocatorTest.java rename to microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/LocatorInfoTest.java index c4c0da8c02f4e..c749bd1b23cb5 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/LocatorTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/LocatorInfoTest.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. @@ -20,13 +20,13 @@ import org.junit.Test; -public class LocatorTest { +public class LocatorInfoTest { @Test public void testGetSetId() { // Arrange String expectedId = "testId"; - Locator locator = new Locator(); + LocatorInfo locator = new LocatorInfo(); // Act String actualId = locator.setId(expectedId).getId(); @@ -39,10 +39,10 @@ public void testGetSetId() { public void testGetSetExpirationDateTime() { // Arrange Date expectedExpirationDateTime = new Date(); - Locator locator = new Locator(); + LocatorInfo locatorInfo = new LocatorInfo(); // Act - Date actualExpirationDateTime = locator.setExpirationDateTime(expectedExpirationDateTime) + Date actualExpirationDateTime = locatorInfo.setExpirationDateTime(expectedExpirationDateTime) .getExpirationDateTime(); // Assert @@ -53,10 +53,10 @@ public void testGetSetExpirationDateTime() { public void testGetSetType() { // Arrange LocatorType expectedLocatorType = LocatorType.WindowsAzureCDN; - Locator locator = new Locator(); + LocatorInfo locatorInfo = new LocatorInfo(); // Act - LocatorType actualLocatorType = locator.setLocatorType(expectedLocatorType).getLocatorType(); + LocatorType actualLocatorType = locatorInfo.setLocatorType(expectedLocatorType).getLocatorType(); // Assert assertEquals(expectedLocatorType, actualLocatorType); @@ -66,10 +66,10 @@ public void testGetSetType() { public void testGetSetPath() { // Arrange String expectedPath = "testPath"; - Locator locator = new Locator(); + LocatorInfo locatorInfo = new LocatorInfo(); // Act - String actualPath = locator.setPath(expectedPath).getPath(); + String actualPath = locatorInfo.setPath(expectedPath).getPath(); // Assert assertEquals(expectedPath, actualPath); @@ -79,10 +79,10 @@ public void testGetSetPath() { public void testGetSetAccessPolicyId() { // Arrange String expectedAccessPolicyId = "testAccessPolicyId"; - Locator locator = new Locator(); + LocatorInfo locatorInfo = new LocatorInfo(); // Act - String actualAccessPolicyId = locator.setAccessPolicyId(expectedAccessPolicyId).getAccessPolicyId(); + String actualAccessPolicyId = locatorInfo.setAccessPolicyId(expectedAccessPolicyId).getAccessPolicyId(); // Assert assertEquals(expectedAccessPolicyId, actualAccessPolicyId); @@ -92,10 +92,10 @@ public void testGetSetAccessPolicyId() { public void testGetSetAssetId() { // Arrange String expectedAssetId = "testAssetId"; - Locator locator = new Locator(); + LocatorInfo locatorInfo = new LocatorInfo(); // Act - String actualAssetId = locator.setAssetId(expectedAssetId).getAssetId(); + String actualAssetId = locatorInfo.setAssetId(expectedAssetId).getAssetId(); // Assert assertEquals(expectedAssetId, actualAssetId); @@ -105,10 +105,10 @@ public void testGetSetAssetId() { public void testGetSetStartTime() { // Arrange Date expectedStartTime = new Date(); - Locator locator = new Locator(); + LocatorInfo locatorInfo = new LocatorInfo(); // Act - Date actualStartTime = locator.setStartTime(expectedStartTime).getStartTime(); + Date actualStartTime = locatorInfo.setStartTime(expectedStartTime).getStartTime(); // Assert assertEquals(expectedStartTime, actualStartTime); From f3f40b3fcc7bc6bec88e1c60ec7c5de83347e3b5 Mon Sep 17 00:00:00 2001 From: Chris Tavares <ctavares@microsoft.com> Date: Thu, 20 Sep 2012 15:22:44 -0700 Subject: [PATCH 45/70] Tweaked exception specs to match interface --- .../media/implementation/MediaRestProxy.java | 4 +- .../implementation/ODataAtomUnmarshaller.java | 192 +++++++++--------- .../implementation/ODataEntityProvider.java | 4 +- .../ODataSerializationTest.java | 16 +- 4 files changed, 110 insertions(+), 106 deletions(-) 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 c22345c361348..602d46efb7723 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 @@ -32,7 +32,6 @@ import com.microsoft.windowsazure.services.media.implementation.content.AssetType; import com.microsoft.windowsazure.services.media.models.AssetInfo; import com.sun.jersey.api.client.Client; -import com.sun.jersey.api.client.UniformInterfaceException; import com.sun.jersey.api.client.WebResource; public class MediaRestProxy implements MediaContract { @@ -102,11 +101,12 @@ private void createMarshaller() { } @Override - public AssetInfo createAsset(String name) throws ServiceException, UniformInterfaceException { + public AssetInfo createAsset(String name) throws ServiceException { WebResource resource = getResource("Assets"); AssetType request = new AssetType(); request.setName(name); + try { return resource.type(MediaType.APPLICATION_ATOM_XML).accept(MediaType.APPLICATION_ATOM_XML) .post(AssetInfo.class, marshaller.marshalEntry(request)); 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 index c9952b7760868..f9e7f68bce7fc 100644 --- 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 @@ -19,6 +19,7 @@ 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; @@ -63,6 +64,8 @@ public ODataAtomUnmarshaller() throws JAXBException { * 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 <T> + * * @param stream * - stream containing the XML data * @param contentType @@ -71,47 +74,25 @@ public ODataAtomUnmarshaller() throws JAXBException { * @throws JAXBException * @throws ServiceException */ - public ODataEntity<?> unmarshalFeed(InputStream stream, Class<?> contentType) throws JAXBException, - ServiceException { + public <T extends ODataEntity> List<T> unmarshalFeed(InputStream stream, Class<T> contentType) + throws JAXBException, ServiceException { validateNotNull(stream, "stream"); validateNotNull(contentType, "contentType"); - JAXBElement<FeedType> feedElement = atomUnmarshaller.unmarshal(new StreamSource(stream), FeedType.class); - FeedType feed = feedElement.getValue(); - EntryType firstEntry = getFirstEntry(feed); - - Class<?> serializationType = GetSerializationContentType(contentType); - - Object content = getEntryContent(firstEntry, serializationType); - - try { - Constructor<?> resultCtor = contentType.getConstructor(EntryType.class, serializationType); - return (ODataEntity<?>) resultCtor.newInstance(firstEntry, content); - } - catch (IllegalArgumentException e) { - e.printStackTrace(); - throw new ServiceException(e); - } - catch (SecurityException e) { - e.printStackTrace(); - throw new ServiceException(e); - } - catch (InstantiationException e) { - e.printStackTrace(); - throw new ServiceException(e); - } - catch (IllegalAccessException e) { - e.printStackTrace(); - throw new ServiceException(e); - } - catch (InvocationTargetException e) { - e.printStackTrace(); - throw new ServiceException(e); - } - catch (NoSuchMethodException e) { - e.printStackTrace(); - throw new ServiceException(e); + List<T> entries = new ArrayList<T>(); + FeedType feed = unmarshalFeed(stream); + Class<?> marshallingContentType = getMarshallingContentType(contentType); + + for (Object feedChild : feed.getFeedChildren()) { + EntryType entry = asEntry(feedChild); + if (entry != null) { + unmarshalODataContent(entry, contentType); + ContentType contentElement = getFirstOfType(ContentType.class, entry.getEntryChildren()); + Object contentObject = getFirstOfType(marshallingContentType, contentElement.getContent()); + entries.add(constructResultObject(contentType, entry, contentObject)); + } } + return entries; } /** @@ -126,22 +107,84 @@ public ODataEntity<?> unmarshalFeed(InputStream stream, Class<?> contentType) th * @throws JAXBException * @throws ServiceException */ - public ODataEntity<?> unmarshalEntry(InputStream stream, Class<?> contentType) throws JAXBException, + public <T extends ODataEntity> T unmarshalEntry(InputStream stream, Class<T> contentType) throws JAXBException, ServiceException { validateNotNull(stream, "stream"); validateNotNull(contentType, "contentType"); - JAXBElement<EntryType> entryElement = atomUnmarshaller.unmarshal(new StreamSource(stream), EntryType.class); + Class<?> marshallingContentType = getMarshallingContentType(contentType); - EntryType entry = entryElement.getValue(); + EntryType entry = unmarshalEntry(stream); + 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<Object> children = entry.getEntryChildren(); + for (int i = 0; i < children.size(); ++i) { + Object child = children.get(i); + if (child instanceof Element) { + Element e = (Element) child; + if (qnameFromElement(e).equals(Constants.ODATA_ACTION_ELEMENT_NAME)) { + JAXBElement<ODataActionType> actionElement = mediaContentUnmarshaller.unmarshal(e, + ODataActionType.class); + children.set(i, actionElement); + } + } + } + } - Class<?> serializationType = GetSerializationContentType(contentType); + private void unmarshalEntryContent(EntryType entry, Class<?> contentType) throws JAXBException { + Class<?> marshallingContentType = getMarshallingContentType(contentType); + ContentType contentElement = getFirstOfType(ContentType.class, entry.getEntryChildren()); + List<Object> contentChildren = contentElement.getContent(); + for (int i = 0; i < contentChildren.size(); ++i) { + Object child = contentChildren.get(i); + if (child instanceof Element) { + Element e = (Element) child; + if (qnameFromElement(e).equals(Constants.ODATA_PROPERTIES_ELEMENT_NAME)) { + JAXBElement actualContentElement = mediaContentUnmarshaller.unmarshal(e, marshallingContentType); + contentChildren.set(i, actualContentElement); + } + } + } + } - Object content = getEntryContent(entry, serializationType); + private <T> T getFirstOfType(Class<T> targetType, List<Object> collection) { + for (Object c : collection) { + if (c instanceof JAXBElement) { + JAXBElement e = (JAXBElement) c; + if (e.getDeclaredType() == targetType) { + return (T) e.getValue(); + } + } + } + return null; + } + private <T extends ODataEntity> T constructResultObject(Class<T> contentType, EntryType entry, Object contentObject) + throws ServiceException { + Class<?> marshallingType = getMarshallingContentType(contentType); try { - Constructor<?> resultCtor = contentType.getConstructor(EntryType.class, serializationType); - return (ODataEntity<?>) resultCtor.newInstance(entry, content); + Constructor<T> resultCtor = contentType.getConstructor(EntryType.class, marshallingType); + return resultCtor.newInstance(entry, contentObject); } catch (IllegalArgumentException e) { e.printStackTrace(); @@ -169,66 +212,21 @@ public ODataEntity<?> unmarshalEntry(InputStream stream, Class<?> contentType) t } } - private Object getEntryContent(EntryType entry, Class<?> contentType) throws JAXBException { - List<Object> entryChildren = entry.getEntryChildren(); - Object retVal = null; - - for (int i = 0; i < entryChildren.size(); ++i) { - Object child = entryChildren.get(i); - if (child instanceof JAXBElement) { - // It's a parsed element, if it's content unmarshal, fixup, and store return value - JAXBElement e = (JAXBElement) child; - if (e.getDeclaredType() == ContentType.class) { - retVal = unmarshalEntryContent((ContentType) e.getValue(), contentType); - } - } - else { - // It's an arbitrary XML element. If it's an action, fix up element. - Element e = (Element) child; - if (qnameFromElement(e).equals(Constants.ODATA_ACTION_ELEMENT_NAME)) { - JAXBElement<ODataActionType> actionElement = mediaContentUnmarshaller.unmarshal(e, - ODataActionType.class); - entryChildren.set(i, actionElement); - } - } - } - return retVal; - } - - private EntryType getFirstEntry(FeedType feed) { - for (Object child : feed.getFeedChildren()) { - if (child instanceof JAXBElement) { - JAXBElement e = (JAXBElement) child; - - if (e.getDeclaredType() == EntryType.class) { - return (EntryType) e.getValue(); - } - } - } - return null; + private EntryType unmarshalEntry(InputStream stream) throws JAXBException { + JAXBElement<EntryType> entryElement = atomUnmarshaller.unmarshal(new StreamSource(stream), EntryType.class); + return entryElement.getValue(); } - private Object unmarshalEntryContent(ContentType content, Class<?> actualContentType) throws JAXBException { - List<Object> contentChildren = content.getContent(); - for (int i = 0; i < contentChildren.size(); ++i) { - Object child = contentChildren.get(i); - if (child instanceof Element) { - Element e = (Element) child; - if (qnameFromElement(e).equals(Constants.ODATA_PROPERTIES_ELEMENT_NAME)) { - JAXBElement actualContentElement = mediaContentUnmarshaller.unmarshal(e, actualContentType); - contentChildren.set(i, actualContentElement); - return actualContentElement.getValue(); - } - } - } - return null; + private FeedType unmarshalFeed(InputStream stream) throws JAXBException { + JAXBElement<FeedType> feedElement = atomUnmarshaller.unmarshal(new StreamSource(stream), FeedType.class); + return feedElement.getValue(); } - private QName qnameFromElement(Element e) { + private static QName qnameFromElement(Element e) { return new QName(e.getLocalName(), e.getNamespaceURI()); } - private Class<?> GetSerializationContentType(Class<?> contentType) { + private static Class<?> getMarshallingContentType(Class<?> contentType) { ParameterizedType pt = (ParameterizedType) contentType.getGenericSuperclass(); return (Class<?>) pt.getActualTypeArguments()[0]; } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ODataEntityProvider.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ODataEntityProvider.java index e5f54fbac6113..af0d7b0b8de3e 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ODataEntityProvider.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ODataEntityProvider.java @@ -57,11 +57,11 @@ public ODataEntity<?> readFrom(Class<ODataEntity<?>> type, Type genericType, Ann MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException, WebApplicationException { - ODataEntity entity; + ODataEntity entity = null; String responseType = mediaType.getParameters().get("type"); try { if (responseType == null || responseType.equals("feed")) { - entity = unmarshaller.unmarshalFeed(entityStream, type); + //entity = unmarshaller.unmarshalFeed(entityStream, type); } else if (responseType.equals("entry")) { entity = unmarshaller.unmarshalEntry(entityStream, type); diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/implementation/ODataSerializationTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/implementation/ODataSerializationTest.java index 51e27d89818b7..80905eb549c3e 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/implementation/ODataSerializationTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/implementation/ODataSerializationTest.java @@ -17,9 +17,12 @@ import java.io.ByteArrayInputStream; import java.io.InputStream; +import java.util.List; import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBElement; import javax.xml.bind.Marshaller; +import javax.xml.namespace.QName; import junit.framework.Assert; @@ -28,6 +31,8 @@ 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.content.AssetType; +import com.microsoft.windowsazure.services.media.implementation.content.Constants; +import com.microsoft.windowsazure.services.media.models.AssetInfo; public class ODataSerializationTest { @@ -64,8 +69,9 @@ public class ODataSerializationTest { public void canUnmarshallAssetFromFeed() throws Exception { ODataAtomUnmarshaller um = new ODataAtomUnmarshaller(); InputStream input = new ByteArrayInputStream(sampleFeedOneAsset.getBytes("UTF-8")); - ODataEntity<AssetType> entry = (ODataEntity<AssetType>) um.unmarshalFeed(input, AssetType.class); - Assert.assertEquals("nb:cid:UUID:1f6c7bb4-8013-486e-b4c9-2e4a6842b9a6", entry.getContent().getId()); + List<AssetInfo> entries = um.unmarshalFeed(input, AssetInfo.class); + Assert.assertEquals(1, entries.size()); + Assert.assertEquals("nb:cid:UUID:1f6c7bb4-8013-486e-b4c9-2e4a6842b9a6", entries.get(0).getId()); } @Test @@ -80,10 +86,10 @@ public void canMarshalEntryFromJavaObject() throws Exception { EntryType e = new EntryType(); ContentType c = new ContentType(); - c.getContent().add(a); - e.getEntryChildren().add(c); + c.getContent().add(new JAXBElement(Constants.ODATA_PROPERTIES_ELEMENT_NAME, AssetType.class, a)); + e.getEntryChildren().add(new JAXBElement(Constants.ATOM_CONTENT_ELEMENT_NAME, ContentType.class, c)); - m.marshal(e, System.out); + m.marshal(new JAXBElement(new QName(Constants.ATOM_NS, "entry"), EntryType.class, e), System.out); } } From 9d302b31da5648c99a26fc550c2edc437bf10bf9 Mon Sep 17 00:00:00 2001 From: Chris Tavares <ctavares@microsoft.com> Date: Thu, 20 Sep 2012 17:22:17 -0700 Subject: [PATCH 46/70] refactored unmarshaller --- .../media/implementation/ODataAtomUnmarshaller.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) 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 index f9e7f68bce7fc..0844faedfa171 100644 --- 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 @@ -86,10 +86,7 @@ public <T extends ODataEntity> List<T> unmarshalFeed(InputStream stream, Class<T for (Object feedChild : feed.getFeedChildren()) { EntryType entry = asEntry(feedChild); if (entry != null) { - unmarshalODataContent(entry, contentType); - ContentType contentElement = getFirstOfType(ContentType.class, entry.getEntryChildren()); - Object contentObject = getFirstOfType(marshallingContentType, contentElement.getContent()); - entries.add(constructResultObject(contentType, entry, contentObject)); + entries.add(contentFromEntry(contentType, marshallingContentType, entry)); } } return entries; @@ -115,6 +112,11 @@ public <T extends ODataEntity> T unmarshalEntry(InputStream stream, Class<T> con Class<?> marshallingContentType = getMarshallingContentType(contentType); EntryType entry = unmarshalEntry(stream); + return contentFromEntry(contentType, marshallingContentType, entry); + } + + private <T extends ODataEntity> T contentFromEntry(Class<T> contentType, Class<?> marshallingContentType, + EntryType entry) throws JAXBException, ServiceException { unmarshalODataContent(entry, contentType); ContentType contentElement = getFirstOfType(ContentType.class, entry.getEntryChildren()); Object contentObject = getFirstOfType(marshallingContentType, contentElement.getContent()); From 539c3ac00278a2cb618056bc721f9c8e3fd0b6cc Mon Sep 17 00:00:00 2001 From: Chris Tavares <ctavares@microsoft.com> Date: Fri, 21 Sep 2012 10:44:46 -0700 Subject: [PATCH 47/70] Successfully deserializing feeds --- .../windowsazure/services/media/Exports.java | 2 + .../services/media/MediaContract.java | 3 + .../MediaExceptionProcessor.java | 15 ++++ .../media/implementation/MediaRestProxy.java | 15 ++++ .../media/implementation/ODataEntity.java | 48 +++++++++++ .../ODataEntityCollectionProvider.java | 86 +++++++++++++++++++ .../implementation/ODataEntityProvider.java | 13 +-- .../content/ODataActionType.java | 38 +++++++- .../ODataSerializationFromJerseyTest.java | 9 ++ 9 files changed, 221 insertions(+), 8 deletions(-) create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ODataEntityCollectionProvider.java 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 29f4946cc6ea5..0734dfaa933b5 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 @@ -25,6 +25,7 @@ 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; @@ -60,6 +61,7 @@ public ClientConfig alter(ClientConfig instance, Builder builder, Map<String, Ob try { instance.getSingletons().add(new ODataEntityProvider()); + instance.getSingletons().add(new ODataEntityCollectionProvider()); } catch (JAXBException e) { e.printStackTrace(); 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 8060eceffe028..5a5a8f2ba325b 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 @@ -14,6 +14,8 @@ */ 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.AssetInfo; @@ -27,4 +29,5 @@ public interface MediaContract extends FilterableService<MediaContract> { AssetInfo createAsset(String name) throws ServiceException; + List<AssetInfo> getAssets() throws ServiceException; } 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 b68089352a8d4..3cde5ec2029d4 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 @@ -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; @@ -69,4 +71,17 @@ public AssetInfo createAsset(String name) throws ServiceException { throw processCatch(new ServiceException(e)); } } + + @Override + public List<AssetInfo> getAssets() throws ServiceException { + try { + return next.getAssets(); + } + 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 602d46efb7723..c72ccbc53c4c3 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 @@ -16,6 +16,7 @@ package com.microsoft.windowsazure.services.media.implementation; import java.util.Arrays; +import java.util.List; import javax.inject.Inject; import javax.ws.rs.core.MediaType; @@ -32,6 +33,7 @@ import com.microsoft.windowsazure.services.media.implementation.content.AssetType; import com.microsoft.windowsazure.services.media.models.AssetInfo; import com.sun.jersey.api.client.Client; +import com.sun.jersey.api.client.GenericType; import com.sun.jersey.api.client.WebResource; public class MediaRestProxy implements MediaContract { @@ -115,4 +117,17 @@ public AssetInfo createAsset(String name) throws ServiceException { throw new ServiceException(e); } } + + /* (non-Javadoc) + * @see com.microsoft.windowsazure.services.media.MediaContract#getAssets() + */ + @Override + public List<AssetInfo> getAssets() throws ServiceException { + WebResource resource = getResource("Assets"); + + return resource.type(MediaType.APPLICATION_ATOM_XML).accept(MediaType.APPLICATION_ATOM_XML) + .get(new GenericType<List<AssetInfo>>() { + }); + + } } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ODataEntity.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ODataEntity.java index f2846162965a7..516303a1fdf30 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ODataEntity.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ODataEntity.java @@ -15,6 +15,10 @@ package com.microsoft.windowsazure.services.media.implementation; +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; +import java.util.List; + import com.microsoft.windowsazure.services.media.implementation.atom.EntryType; /** @@ -45,4 +49,48 @@ protected EntryType getEntry() { protected T getContent() { return content; } + + /** + * Is the given type inherited from ODataEntity + * + * @param type + * Type to check + * @return true if derived from ODataEntity + */ + public static boolean isODataEntityType(Class<?> type) { + return ODataEntity.class.isAssignableFrom(type); + } + + /** + * Is the given type a collection of ODataEntity + * + * @param type + * Base type + * @param genericType + * Generic type + * @return true if it's List<OEntity> or derive from. + */ + public static boolean isODataEntityCollectionType(Class<?> type, Type genericType) { + if (List.class != type) { + return false; + } + + ParameterizedType pt = (ParameterizedType) genericType; + + if (pt.getActualTypeArguments().length != 1) { + return false; + } + + Class<?> typeClass = getCollectedType(genericType); + + return isODataEntityType(typeClass); + } + + public static Class<?> getCollectedType(Type genericType) { + ParameterizedType pt = (ParameterizedType) genericType; + if (pt.getActualTypeArguments().length != 1) { + throw new IllegalArgumentException("genericType"); + } + return (Class<?>) pt.getActualTypeArguments()[0]; + } } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ODataEntityCollectionProvider.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ODataEntityCollectionProvider.java new file mode 100644 index 0000000000000..ad354b98a8c22 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ODataEntityCollectionProvider.java @@ -0,0 +1,86 @@ +/** + * + */ +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 java.util.List; + +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.MultivaluedMap; +import javax.xml.bind.JAXBException; + +import com.microsoft.windowsazure.services.core.ServiceException; +import com.sun.jersey.core.provider.AbstractMessageReaderWriterProvider; + +/** + * Jersey provider to unmarshal lists of entities from Media Services. + * + */ +public class ODataEntityCollectionProvider extends AbstractMessageReaderWriterProvider<List<ODataEntity<?>>> { + private final ODataAtomUnmarshaller unmarshaller; + + public ODataEntityCollectionProvider() throws JAXBException { + unmarshaller = new ODataAtomUnmarshaller(); + } + + @Override + public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) { + return ODataEntity.isODataEntityCollectionType(type, genericType); + } + + @Override + public List<ODataEntity<?>> readFrom(Class<List<ODataEntity<?>>> type, Type genericType, Annotation[] annotations, + MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) + throws IOException, WebApplicationException { + + String responseType = mediaType.getParameters().get("type"); + try { + if (responseType == null || responseType.equals("feed")) { + return unmarshaller.unmarshalFeed(entityStream, + (Class<ODataEntity<?>>) ODataEntity.getCollectedType(genericType)); + } + else { + throw new RuntimeException(); + } + } + catch (JAXBException e) { + e.printStackTrace(); + throw new RuntimeException(e); + } + catch (ServiceException e) { + e.printStackTrace(); + throw new RuntimeException(e); + } + } + + /** + * Can this type be written by this provider? + * + * @return false - we don't support writing + */ + @Override + public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) { + return false; + } + + /** + * Write the given object to the stream. + * This method implementation throws, we don't support writing. + * + * @throws UnsupportedOperationException + */ + @Override + public void writeTo(List<ODataEntity<?>> t, Class<?> type, Type genericType, Annotation[] annotations, + MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) + throws IOException, WebApplicationException { + + throw new UnsupportedOperationException(); + } + +} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ODataEntityProvider.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ODataEntityProvider.java index af0d7b0b8de3e..03639f5b936e5 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ODataEntityProvider.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ODataEntityProvider.java @@ -20,6 +20,7 @@ import java.io.OutputStream; import java.lang.annotation.Annotation; import java.lang.reflect.Type; +import java.util.List; import javax.ws.rs.WebApplicationException; import javax.ws.rs.core.MediaType; @@ -46,7 +47,7 @@ public ODataEntityProvider() throws JAXBException { */ @Override public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) { - return ODataEntity.class.isAssignableFrom(type); + return ODataEntity.isODataEntityType(type); } /* (non-Javadoc) @@ -57,14 +58,15 @@ public ODataEntity<?> readFrom(Class<ODataEntity<?>> type, Type genericType, Ann MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException, WebApplicationException { - ODataEntity entity = null; + ODataEntity<?> result = null; String responseType = mediaType.getParameters().get("type"); try { if (responseType == null || responseType.equals("feed")) { - //entity = unmarshaller.unmarshalFeed(entityStream, type); + List<ODataEntity<?>> feedContents = unmarshaller.unmarshalFeed(entityStream, type); + return feedContents.get(0); } else if (responseType.equals("entry")) { - entity = unmarshaller.unmarshalEntry(entityStream, type); + result = unmarshaller.unmarshalEntry(entityStream, type); } else { throw new RuntimeException(); @@ -79,7 +81,7 @@ else if (responseType.equals("entry")) { throw new RuntimeException(e); } - return entity; + return result; } /* (non-Javadoc) @@ -99,5 +101,4 @@ public void writeTo(ODataEntity<?> t, Class<?> type, Type genericType, Annotatio throws IOException, WebApplicationException { throw new UnsupportedOperationException(); } - } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/ODataActionType.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/ODataActionType.java index b6cbb23a79b3a..2081027c7420a 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/ODataActionType.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/ODataActionType.java @@ -19,8 +19,12 @@ import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAttribute; -// XML Serialization class for odata m:action elements - +/** + * XML Serialization class for odata m:action elements + * + * @author ctavares + * + */ @XmlAccessorType(XmlAccessType.FIELD) public class ODataActionType { @@ -33,26 +37,56 @@ public class ODataActionType { @XmlAttribute(required = true) protected String title; + /** + * Get metadata + * + * @return the metadata + */ public String getMetadata() { return metadata; } + /** + * Set metadata + * + * @param metadata + */ public void setMetadata(String metadata) { this.metadata = metadata; } + /** + * Get target + * + * @return the target + */ public String getTarget() { return target; } + /** + * set target + * + * @param target + */ public void setTarget(String target) { this.target = target; } + /** + * Get title + * + * @return the title + */ public String getTitle() { return title; } + /** + * set title + * + * @param title + */ public void setTitle(String title) { this.title = title; } diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/implementation/ODataSerializationFromJerseyTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/implementation/ODataSerializationFromJerseyTest.java index 7dbb9fdbff3b5..2c2ac5bf05e52 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/implementation/ODataSerializationFromJerseyTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/implementation/ODataSerializationFromJerseyTest.java @@ -16,6 +16,7 @@ package com.microsoft.windowsazure.services.media.implementation; import java.net.URISyntaxException; +import java.util.List; import javax.ws.rs.core.MediaType; @@ -92,4 +93,12 @@ public void canCreateAssetThroughMediaServiceAPI() throws Exception { Assert.assertEquals("secondTestAsset", newAsset.getName()); } + + @Test + public void canRetrieveListOfAssets() throws Exception { + MediaContract client = MediaService.create(config); + List<AssetInfo> assets = client.getAssets(); + + Assert.assertNotNull(assets); + } } From 0a0a5386ad99762809b51a9d9097c8d403bc83a3 Mon Sep 17 00:00:00 2001 From: Chris Tavares <ctavares@microsoft.com> Date: Fri, 21 Sep 2012 12:09:26 -0700 Subject: [PATCH 48/70] Removed extraneous alias --- .../services/media/implementation/content/ODataActionType.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/ODataActionType.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/ODataActionType.java index 2081027c7420a..569cd17d4f3f9 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/ODataActionType.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/ODataActionType.java @@ -22,8 +22,6 @@ /** * XML Serialization class for odata m:action elements * - * @author ctavares - * */ @XmlAccessorType(XmlAccessType.FIELD) public class ODataActionType { From f52aa2babd7d040535a3695e93de1a99a2836cbd Mon Sep 17 00:00:00 2001 From: Chris Tavares <ctavares@microsoft.com> Date: Fri, 21 Sep 2012 12:10:52 -0700 Subject: [PATCH 49/70] missing copyright header --- .../services/media/models/AssetInfo.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AssetInfo.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AssetInfo.java index c62eb7a53d8dd..86f9d9e03ff9e 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AssetInfo.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AssetInfo.java @@ -1,11 +1,26 @@ -package com.microsoft.windowsazure.services.media.models; +/** + * 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.models; import javax.xml.datatype.XMLGregorianCalendar; import com.microsoft.windowsazure.services.media.implementation.ODataEntity; import com.microsoft.windowsazure.services.media.implementation.atom.EntryType; import com.microsoft.windowsazure.services.media.implementation.content.AssetType; + /** * Data about a Media Services Asset entity. * From 940e557ede5bba524c98cdbd1784bc8221d6ae13 Mon Sep 17 00:00:00 2001 From: Chris Tavares <ctavares@microsoft.com> Date: Fri, 21 Sep 2012 12:16:21 -0700 Subject: [PATCH 50/70] Pulling back in stash of marshalling work --- .../windowsazure/services/media/Exports.java | 5 ++- .../implementation/MediaContentProvider.java | 14 +++++++ .../media/implementation/MediaRestProxy.java | 10 ++--- .../implementation/ODataAtomMarshaller.java | 38 +++++++++++++++---- .../implementation/ODataEntityProvider.java | 16 ++++++-- .../implementation/content/AssetType.java | 1 + .../content/MediaServiceDTO.java | 17 +++++++++ .../services/media/models/AssetInfo.java | 2 +- 8 files changed, 83 insertions(+), 20 deletions(-) create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/MediaContentProvider.java create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/MediaServiceDTO.java 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 0734dfaa933b5..b3dfe6b6bc6c3 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 @@ -17,6 +17,7 @@ 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.MediaExceptionProcessor; @@ -64,7 +65,9 @@ public ClientConfig alter(ClientConfig instance, Builder builder, Map<String, Ob instance.getSingletons().add(new ODataEntityCollectionProvider()); } catch (JAXBException e) { - e.printStackTrace(); + throw new RuntimeException(e); + } + catch (ParserConfigurationException e) { throw new RuntimeException(e); } 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 0000000000000..2af37f9e2603c --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/MediaContentProvider.java @@ -0,0 +1,14 @@ +/** + * + */ +package com.microsoft.windowsazure.services.media.implementation; + +import com.sun.jersey.core.provider.AbstractMessageReaderWriterProvider; + +/** + * @author ctavares + * + */ +public class MediaContentProvider extends AbstractMessageReaderWriterProvider<T> { + +} 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 c72ccbc53c4c3..f252234495d63 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 @@ -109,13 +109,9 @@ public AssetInfo createAsset(String name) throws ServiceException { AssetType request = new AssetType(); request.setName(name); - try { - return resource.type(MediaType.APPLICATION_ATOM_XML).accept(MediaType.APPLICATION_ATOM_XML) - .post(AssetInfo.class, marshaller.marshalEntry(request)); - } - catch (JAXBException e) { - throw new ServiceException(e); - } + return resource.type(MediaType.APPLICATION_ATOM_XML).accept(MediaType.APPLICATION_ATOM_XML) + .post(AssetInfo.class, request); + } /* (non-Javadoc) 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 index 2373660f9f452..2556c510a5ff2 100644 --- 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 @@ -15,6 +15,7 @@ package com.microsoft.windowsazure.services.media.implementation; +import java.io.OutputStream; import java.util.ArrayList; import java.util.List; @@ -63,9 +64,36 @@ public ODataAtomMarshaller() throws JAXBException, ParserConfigurationException * The content object to send * @return The generated DOM * @throws JAXBException - * if content is malformed/not serializable + * if content is malformed/not marshallable */ public Document marshalEntry(Object content) throws JAXBException { + JAXBElement<EntryType> 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<EntryType> createEntry(Object content) { ContentType atomContent = new ContentType(); atomContent.setType("application/xml"); atomContent.getContent().add( @@ -78,13 +106,7 @@ public Document marshalEntry(Object content) throws JAXBException { JAXBElement<EntryType> entryElement = new JAXBElement<EntryType>(new QName(Constants.ATOM_NS, "entry"), EntryType.class, atomEntry); - Document doc = documentBuilder.newDocument(); - doc.setXmlStandalone(true); - - marshaller.marshal(entryElement, doc); - - return doc; - + return entryElement; } private static Class<?>[] getMarshalledClasses() { diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ODataEntityProvider.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ODataEntityProvider.java index 03639f5b936e5..9b432b99236b3 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ODataEntityProvider.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ODataEntityProvider.java @@ -26,8 +26,10 @@ 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.core.ServiceException; +import com.microsoft.windowsazure.services.media.implementation.content.MediaServiceDTO; import com.sun.jersey.core.provider.AbstractMessageReaderWriterProvider; /** @@ -37,9 +39,11 @@ */ public class ODataEntityProvider extends AbstractMessageReaderWriterProvider<ODataEntity<?>> { private final ODataAtomUnmarshaller unmarshaller; + private final ODataAtomMarshaller marshaller; - public ODataEntityProvider() throws JAXBException { + public ODataEntityProvider() throws JAXBException, ParserConfigurationException { unmarshaller = new ODataAtomUnmarshaller(); + marshaller = new ODataAtomMarshaller(); } /* (non-Javadoc) @@ -89,7 +93,8 @@ else if (responseType.equals("entry")) { */ @Override public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) { - return false; + boolean result = type.isAnnotationPresent(MediaServiceDTO.class); + return result; } /* (non-Javadoc) @@ -99,6 +104,11 @@ public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotat public void writeTo(ODataEntity<?> t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException { - throw new UnsupportedOperationException(); + 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/content/AssetType.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/AssetType.java index 160a3088892b5..d5271b9e922e6 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/AssetType.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/AssetType.java @@ -25,6 +25,7 @@ * for Asset entities. * */ +@MediaServiceDTO @XmlAccessorType(XmlAccessType.FIELD) public class AssetType { diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/MediaServiceDTO.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/MediaServiceDTO.java new file mode 100644 index 0000000000000..9c3fdf1fad986 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/MediaServiceDTO.java @@ -0,0 +1,17 @@ +package com.microsoft.windowsazure.services.media.implementation.content; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Annotation marking a type as a data transfer object + * to or from Media Services. + * + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +public @interface MediaServiceDTO { + +} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AssetInfo.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AssetInfo.java index 86f9d9e03ff9e..7fc7a9c28306f 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AssetInfo.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AssetInfo.java @@ -14,13 +14,13 @@ */ package com.microsoft.windowsazure.services.media.models; + import javax.xml.datatype.XMLGregorianCalendar; import com.microsoft.windowsazure.services.media.implementation.ODataEntity; import com.microsoft.windowsazure.services.media.implementation.atom.EntryType; import com.microsoft.windowsazure.services.media.implementation.content.AssetType; - /** * Data about a Media Services Asset entity. * From 644a04c026c040d895a08af682f24e44cfbfe0dc Mon Sep 17 00:00:00 2001 From: Chris Tavares <ctavares@microsoft.com> Date: Fri, 21 Sep 2012 12:44:23 -0700 Subject: [PATCH 51/70] Marshalling through Jersey pipeline instead of manually --- .../windowsazure/services/media/Exports.java | 2 + .../implementation/MediaContentProvider.java | 72 ++++++++++++++++++- .../media/implementation/MediaRestProxy.java | 22 ------ .../implementation/ODataEntityProvider.java | 13 +--- .../implementation/content/AssetType.java | 3 +- .../content/MediaServiceDTO.java | 13 ++-- 6 files changed, 79 insertions(+), 46 deletions(-) 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 b3dfe6b6bc6c3..b0ab8a4f5571c 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 @@ -20,6 +20,7 @@ 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; @@ -63,6 +64,7 @@ public ClientConfig alter(ClientConfig instance, Builder builder, Map<String, Ob try { instance.getSingletons().add(new ODataEntityProvider()); instance.getSingletons().add(new ODataEntityCollectionProvider()); + instance.getSingletons().add(new MediaContentProvider()); } catch (JAXBException e) { throw new RuntimeException(e); 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 index 2af37f9e2603c..4ad8c880c6d4f 100644 --- 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 @@ -1,14 +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; /** - * @author ctavares - * + * Class to plug into Jersey to properly serialize + * raw Media Services DTO types. + * */ -public class MediaContentProvider extends AbstractMessageReaderWriterProvider<T> { +public class MediaContentProvider<T extends MediaServiceDTO> extends AbstractMessageReaderWriterProvider<T> { + 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<T> type, Type genericType, Annotation[] annotations, MediaType mediaType, + MultivaluedMap<String, String> 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<String, Object> 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/MediaRestProxy.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/MediaRestProxy.java index f252234495d63..a42fd68f25a4b 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 @@ -20,8 +20,6 @@ import javax.inject.Inject; import javax.ws.rs.core.MediaType; -import javax.xml.bind.JAXBException; -import javax.xml.parsers.ParserConfigurationException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -39,11 +37,8 @@ public class MediaRestProxy implements MediaContract { private Client channel; - private ODataAtomMarshaller marshaller; static Log log = LogFactory.getLog(MediaContract.class); - private static final String jsonRequestType = "application/json; odata=verbose"; - ServiceFilter[] filters; @Inject @@ -55,14 +50,11 @@ public MediaRestProxy(Client channel, OAuthFilter authFilter, RedirectFilter red channel.addFilter(redirectFilter); channel.addFilter(authFilter); channel.addFilter(versionHeadersFilter); - - createMarshaller(); } public MediaRestProxy(Client channel, ServiceFilter[] filters) { this.channel = channel; this.filters = filters; - createMarshaller(); } @Override @@ -88,20 +80,6 @@ private WebResource getResource(String entityName) { return resource; } - private void createMarshaller() { - try { - this.marshaller = new ODataAtomMarshaller(); - } - catch (JAXBException e) { - e.printStackTrace(); - throw new RuntimeException(e); - } - catch (ParserConfigurationException e) { - e.printStackTrace(); - throw new RuntimeException(e); - } - } - @Override public AssetInfo createAsset(String name) throws ServiceException { WebResource resource = getResource("Assets"); diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ODataEntityProvider.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ODataEntityProvider.java index 9b432b99236b3..a7dca481e6b54 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ODataEntityProvider.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ODataEntityProvider.java @@ -29,7 +29,6 @@ import javax.xml.parsers.ParserConfigurationException; import com.microsoft.windowsazure.services.core.ServiceException; -import com.microsoft.windowsazure.services.media.implementation.content.MediaServiceDTO; import com.sun.jersey.core.provider.AbstractMessageReaderWriterProvider; /** @@ -39,11 +38,9 @@ */ public class ODataEntityProvider extends AbstractMessageReaderWriterProvider<ODataEntity<?>> { private final ODataAtomUnmarshaller unmarshaller; - private final ODataAtomMarshaller marshaller; public ODataEntityProvider() throws JAXBException, ParserConfigurationException { unmarshaller = new ODataAtomUnmarshaller(); - marshaller = new ODataAtomMarshaller(); } /* (non-Javadoc) @@ -93,8 +90,7 @@ else if (responseType.equals("entry")) { */ @Override public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) { - boolean result = type.isAnnotationPresent(MediaServiceDTO.class); - return result; + return false; } /* (non-Javadoc) @@ -104,11 +100,6 @@ public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotat public void writeTo(ODataEntity<?> t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException { - try { - marshaller.marshalEntry(t, entityStream); - } - catch (JAXBException e) { - throw new RuntimeException(e); - } + throw new UnsupportedOperationException(); } } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/AssetType.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/AssetType.java index d5271b9e922e6..391e0c497aaa5 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/AssetType.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/AssetType.java @@ -25,9 +25,8 @@ * for Asset entities. * */ -@MediaServiceDTO @XmlAccessorType(XmlAccessType.FIELD) -public class AssetType { +public class AssetType implements MediaServiceDTO { @XmlElement(name = "Id", namespace = Constants.ODATA_DATA_NS) protected String id; diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/MediaServiceDTO.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/MediaServiceDTO.java index 9c3fdf1fad986..762cae0eed0b7 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/MediaServiceDTO.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/MediaServiceDTO.java @@ -1,17 +1,14 @@ package com.microsoft.windowsazure.services.media.implementation.content; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; /** - * Annotation marking a type as a data transfer object + * Marker interface to mark types as a data transfer object * to or from Media Services. * + * This is a marker interface rather than an annotation so + * that it can be used as a generic type parameter or restriction. + * */ -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.TYPE) -public @interface MediaServiceDTO { +public interface MediaServiceDTO { } From f80e5eff428426b3958fa0d2bb88b4b22d5fd33f Mon Sep 17 00:00:00 2001 From: Chris Tavares <ctavares@microsoft.com> Date: Fri, 21 Sep 2012 12:48:28 -0700 Subject: [PATCH 52/70] Removed extraneous stack trace prints --- .../media/implementation/ODataAtomUnmarshaller.java | 6 ------ .../media/implementation/ODataEntityCollectionProvider.java | 2 -- .../services/media/implementation/ODataEntityProvider.java | 2 -- 3 files changed, 10 deletions(-) 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 index 0844faedfa171..66cecfd0a542d 100644 --- 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 @@ -189,27 +189,21 @@ private <T extends ODataEntity> T constructResultObject(Class<T> contentType, En return resultCtor.newInstance(entry, contentObject); } catch (IllegalArgumentException e) { - e.printStackTrace(); throw new ServiceException(e); } catch (SecurityException e) { - e.printStackTrace(); throw new ServiceException(e); } catch (InstantiationException e) { - e.printStackTrace(); throw new ServiceException(e); } catch (IllegalAccessException e) { - e.printStackTrace(); throw new ServiceException(e); } catch (InvocationTargetException e) { - e.printStackTrace(); throw new ServiceException(e); } catch (NoSuchMethodException e) { - e.printStackTrace(); throw new ServiceException(e); } } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ODataEntityCollectionProvider.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ODataEntityCollectionProvider.java index ad354b98a8c22..b6b6eac581503 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ODataEntityCollectionProvider.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ODataEntityCollectionProvider.java @@ -50,11 +50,9 @@ public List<ODataEntity<?>> readFrom(Class<List<ODataEntity<?>>> type, Type gene } } catch (JAXBException e) { - e.printStackTrace(); throw new RuntimeException(e); } catch (ServiceException e) { - e.printStackTrace(); throw new RuntimeException(e); } } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ODataEntityProvider.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ODataEntityProvider.java index a7dca481e6b54..704e0885db0e2 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ODataEntityProvider.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ODataEntityProvider.java @@ -74,11 +74,9 @@ else if (responseType.equals("entry")) { } } catch (JAXBException e) { - e.printStackTrace(); throw new RuntimeException(e); } catch (ServiceException e) { - e.printStackTrace(); throw new RuntimeException(e); } From b6d1652aac3d51b5c1d13b4e596eba4e3e4395dd Mon Sep 17 00:00:00 2001 From: Albert Cheng <gongchen@microsoft.com> Date: Fri, 21 Sep 2012 14:03:44 -0700 Subject: [PATCH 53/70] code review feedback for the initial commit of AssetCRUD --- .../services/media/MediaContract.java | 89 ++++++++++++-- .../MediaExceptionProcessor.java | 41 +++++-- .../media/implementation/MediaRestProxy.java | 115 ++++++++++++++++-- .../media/models/CreateAssetOptions.java | 19 +++ .../media/MediaServiceIntegrationTest.java | 46 +++---- 5 files changed, 256 insertions(+), 54 deletions(-) create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/CreateAssetOptions.java 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 3fd0e8cee4033..3d653b53d341c 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. @@ -17,24 +17,93 @@ import java.util.List; import com.microsoft.windowsazure.services.core.FilterableService; -import com.microsoft.windowsazure.services.media.models.Asset; +import com.microsoft.windowsazure.services.media.models.AssetInfo; +import com.microsoft.windowsazure.services.media.models.CreateAssetOptions; import com.microsoft.windowsazure.services.media.models.ListAssetsOptions; +// TODO: Auto-generated Javadoc /** - * - * Defines the methods available for Windows Azure Media Services - * + * Defines the methods available for Windows Azure Media Services. */ public interface MediaContract extends FilterableService<MediaContract> { - public Asset createAsset(Asset asset); + /** + * Creates the asset. + * + * @param asset + * the asset + * @return the asset info + */ + public AssetInfo createAsset(AssetInfo asset); - public Asset getAsset(Asset asset); + /** + * List assets. + * + * @param listAssetsOptions + * the list assets options + * @return the list + */ + public List<AssetInfo> listAssets(ListAssetsOptions listAssetsOptions); - public List<Asset> listAssets(ListAssetsOptions listAssetsOptions); - - public Asset updateAsset(Asset updatedAsset); + /** + * Update asset. + * + * @param updatedAsset + * the updated asset + * @return the asset info + */ + public AssetInfo updateAsset(AssetInfo updatedAsset); + /** + * Delete asset. + * + * @param assetId + * the asset id + */ public void deleteAsset(String assetId); + /** + * Creates the asset. + * + * @param assetName + * the asset name + * @return the asset info + */ + public AssetInfo createAsset(String assetName); + + /** + * Creates the asset. + * + * @param assetName + * the asset name + * @param createAssetOptions + * the create asset options + * @return the asset info + */ + public AssetInfo createAsset(String assetName, CreateAssetOptions createAssetOptions); + + /** + * Gets the asset. + * + * @param assetId + * the asset id + * @return the asset + */ + public AssetInfo getAsset(String assetId); + + /** + * List assets. + * + * @return the list + */ + public List<AssetInfo> listAssets(); + + /** + * Delete asset. + * + * @param assetInfo + * the asset info + */ + public void deleteAsset(AssetInfo assetInfo); + } 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 4db539dbde579..54792e65462e6 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 @@ -26,7 +26,8 @@ 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.Asset; +import com.microsoft.windowsazure.services.media.models.AssetInfo; +import com.microsoft.windowsazure.services.media.models.CreateAssetOptions; import com.microsoft.windowsazure.services.media.models.ListAssetsOptions; /** @@ -59,28 +60,48 @@ private ServiceException processCatch(ServiceException e) { } @Override - public Asset createAsset(Asset asset) { + public void deleteAsset(String assetId) { + service.deleteAsset(assetId); + } + + @Override + public AssetInfo createAsset(AssetInfo asset) { return service.createAsset(asset); } @Override - public Asset getAsset(Asset asset) { - return service.getAsset(asset); + public AssetInfo updateAsset(AssetInfo updatedAsset) { + return service.updateAsset(updatedAsset); } @Override - public List<Asset> listAssets(ListAssetsOptions listAssetsOptions) { - return service.listAssets(listAssetsOptions); + public AssetInfo createAsset(String assetName) { + return service.createAsset(assetName); } @Override - public Asset updateAsset(Asset updatedAsset) { - return service.updateAsset(updatedAsset); + public AssetInfo createAsset(String assetName, CreateAssetOptions createAssetOptions) { + return service.createAsset(assetName, createAssetOptions); } @Override - public void deleteAsset(String assetId) { - service.deleteAsset(assetId); + public AssetInfo getAsset(String assetId) { + return service.getAsset(assetId); + } + + @Override + public List<AssetInfo> listAssets() { + return service.listAssets(); + } + + @Override + public void deleteAsset(AssetInfo assetInfo) { + service.deleteAsset(assetInfo); + } + + @Override + public List<AssetInfo> listAssets(ListAssetsOptions listAssetsOptions) { + return service.listAssets(listAssetsOptions); } } 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 b94d8acc240c7..c25eaba9a248b 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. @@ -27,18 +27,37 @@ import com.microsoft.windowsazure.services.core.ServiceFilter; import com.microsoft.windowsazure.services.core.utils.pipeline.ClientFilterAdapter; import com.microsoft.windowsazure.services.media.MediaContract; -import com.microsoft.windowsazure.services.media.models.Asset; +import com.microsoft.windowsazure.services.media.models.AssetInfo; +import com.microsoft.windowsazure.services.media.models.CreateAssetOptions; import com.microsoft.windowsazure.services.media.models.ListAssetsOptions; import com.sun.jersey.api.client.Client; import com.sun.jersey.api.client.WebResource; +// TODO: Auto-generated Javadoc +/** + * The Class MediaRestProxy. + */ public class MediaRestProxy implements MediaContract { + /** The channel. */ private Client channel; + + /** 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 + */ @Inject public MediaRestProxy(Client channel, OAuthFilter authFilter, RedirectFilter redirectFilter) { this.channel = channel; @@ -47,11 +66,22 @@ public MediaRestProxy(Client channel, OAuthFilter authFilter, RedirectFilter red channel.addFilter(authFilter); } + /** + * 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); @@ -59,14 +89,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) { @@ -75,34 +123,79 @@ private WebResource getResource(String entityName) { return resource; } + /* (non-Javadoc) + * @see com.microsoft.windowsazure.services.media.MediaContract#createAsset(java.lang.String) + */ @Override - public Asset createAsset(Asset asset) { - // TODO Auto-generated method stub + public AssetInfo createAsset(String assetName) { + CreateAssetOptions createAssetOptions = new CreateAssetOptions(); + return createAsset(assetName, createAssetOptions); + } + + /* (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) { return null; } + /* (non-Javadoc) + * @see com.microsoft.windowsazure.services.media.MediaContract#getAsset(java.lang.String) + */ @Override - public Asset getAsset(Asset asset) { - // TODO Auto-generated method stub + public AssetInfo getAsset(String assetId) { return null; } + /* (non-Javadoc) + * @see com.microsoft.windowsazure.services.media.MediaContract#listAssets(com.microsoft.windowsazure.services.media.models.ListAssetsOptions) + */ @Override - public List<Asset> listAssets(ListAssetsOptions listAssetsOptions) { - List<Asset> listAssetsResult = new ArrayList<Asset>(); + public List<AssetInfo> listAssets(ListAssetsOptions listAssetsOptions) { + List<AssetInfo> listAssetsResult = new ArrayList<AssetInfo>(); return listAssetsResult; } + /* (non-Javadoc) + * @see com.microsoft.windowsazure.services.media.MediaContract#listAssets() + */ @Override - public Asset updateAsset(Asset updatedAsset) { - // TODO Auto-generated method stub + public List<AssetInfo> 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 AssetInfo updateAsset(AssetInfo updatedAssetInfo) { return null; } + /* (non-Javadoc) + * @see com.microsoft.windowsazure.services.media.MediaContract#deleteAsset(java.lang.String) + */ @Override public void deleteAsset(String assetId) { - // TODO Auto-generated method stub + } + + /* (non-Javadoc) + * @see com.microsoft.windowsazure.services.media.MediaContract#deleteAsset(com.microsoft.windowsazure.services.media.models.AssetInfo) + */ + @Override + public void deleteAsset(AssetInfo assetInfo) { + this.deleteAsset(assetInfo.getId()); + } + /* (non-Javadoc) + * @see com.microsoft.windowsazure.services.media.MediaContract#createAsset(com.microsoft.windowsazure.services.media.models.AssetInfo) + */ + @Override + public AssetInfo createAsset(AssetInfo assetInfo) { + // TODO Auto-generated method stub + return null; } } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/CreateAssetOptions.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/CreateAssetOptions.java new file mode 100644 index 0000000000000..ecf58db9057e1 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/CreateAssetOptions.java @@ -0,0 +1,19 @@ +/** + * 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.models; + +public class CreateAssetOptions { + +} \ No newline at end of file diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/MediaServiceIntegrationTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/MediaServiceIntegrationTest.java index a3e5a8ce01058..a838f8cac87c1 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/MediaServiceIntegrationTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/MediaServiceIntegrationTest.java @@ -24,7 +24,7 @@ import org.junit.Test; import com.microsoft.windowsazure.services.core.Configuration; -import com.microsoft.windowsazure.services.media.models.Asset; +import com.microsoft.windowsazure.services.media.models.AssetInfo; import com.microsoft.windowsazure.services.media.models.ListAssetsOptions; public class MediaServiceIntegrationTest extends IntegrationTestBase { @@ -35,9 +35,9 @@ public static void setup() throws Exception { // Create all test containers and their content config = createConfig(); service = MediaService.create(config); - List<Asset> listAssetsResult = service.listAssets(null); - for (Asset asset : listAssetsResult) { - service.deleteAsset(asset.getId()); + List<AssetInfo> listAssetsResult = service.listAssets(null); + for (AssetInfo assetInfo : listAssetsResult) { + service.deleteAsset(assetInfo.getId()); } } @@ -63,10 +63,10 @@ private static Configuration createConfig() { @Test public void createAssetSuccess() throws Exception { // Arrange - Asset expectedAsset = new Asset().setName("testAssetName"); + AssetInfo expectedAsset = new AssetInfo().setName("testAssetName"); // Act - Asset actualAsset = service.createAsset(expectedAsset); + AssetInfo actualAsset = service.createAsset(expectedAsset); // Assert assertEquals(expectedAsset, actualAsset); @@ -75,10 +75,10 @@ public void createAssetSuccess() throws Exception { @Test public void createAssetMissingNameFailed() { // Arrange - Asset expectedAsset = new Asset(); + AssetInfo expectedAsset = new AssetInfo(); // Act - Asset actualAsset = service.createAsset(expectedAsset); + AssetInfo actualAsset = service.createAsset(expectedAsset); // Assert assertTrue(false); @@ -87,11 +87,11 @@ public void createAssetMissingNameFailed() { @Test public void getAssetSuccess() throws Exception { // Arrange - Asset expectedAsset = new Asset(); - service.createAsset(expectedAsset); + AssetInfo expectedAsset = new AssetInfo(); + AssetInfo assetInfo = service.createAsset(expectedAsset); // Act - Asset actualAsset = service.getAsset(expectedAsset); + AssetInfo actualAsset = service.getAsset(assetInfo.getId()); // Assert assertEquals(expectedAsset, actualAsset); @@ -100,11 +100,11 @@ public void getAssetSuccess() throws Exception { @Test public void getAssetFailedWithInvalidId() { // Arrange - Asset expectedAsset = new Asset(); + AssetInfo expectedAsset = new AssetInfo(); service.createAsset(expectedAsset); // Act - Asset actualAsset = service.getAsset(expectedAsset.setName("IncorrectAssetName")); + AssetInfo actualAsset = service.getAsset(expectedAsset.setId("IncorrectAssetId").getId()); // Assert assertTrue(false); @@ -114,14 +114,14 @@ public void getAssetFailedWithInvalidId() { @Test public void listAssetSuccess() { // Arrange - Asset assetA = new Asset(); - Asset assetB = new Asset(); + AssetInfo assetA = new AssetInfo(); + AssetInfo assetB = new AssetInfo(); service.createAsset(assetA); service.createAsset(assetB); ListAssetsOptions listAssetOptions = new ListAssetsOptions(); // Act - Collection<Asset> listAssetResult = service.listAssets(listAssetOptions); + Collection<AssetInfo> listAssetResult = service.listAssets(listAssetOptions); // Assert assertEquals(2, listAssetResult.size()); @@ -133,7 +133,7 @@ public void listAssetFailed() { ListAssetsOptions listAssetsOptions = new ListAssetsOptions(); // Act - Collection<Asset> listAssetResult = service.listAssets(listAssetsOptions); + Collection<AssetInfo> listAssetResult = service.listAssets(listAssetsOptions); // Assert assertTrue(false); @@ -142,13 +142,13 @@ public void listAssetFailed() { @Test public void updateAssetSuccess() throws Exception { // Arrange - Asset originalAsset = new Asset(); + AssetInfo originalAsset = new AssetInfo(); service.createAsset(originalAsset); - Asset updatedAsset = new Asset(); + AssetInfo updatedAsset = new AssetInfo(); // Act service.updateAsset(updatedAsset); - Asset actualAsset = service.updateAsset(updatedAsset); + AssetInfo actualAsset = service.updateAsset(updatedAsset); // Assert assertEquals(updatedAsset, actualAsset); @@ -159,7 +159,7 @@ public void updateAssetSuccess() throws Exception { public void updateAssetFailedWithInvalidId() { // Arrange MediaContract service = MediaService.create(config); - Asset updatedAsset = new Asset(); + AssetInfo updatedAsset = new AssetInfo(); // Act service.updateAsset(updatedAsset); @@ -171,9 +171,9 @@ public void updateAssetFailedWithInvalidId() { @Test public void deleteAssetSuccess() throws Exception { // Arrange - Asset asset = new Asset(); + AssetInfo asset = new AssetInfo(); service.createAsset(asset); - List<Asset> listAssetsResult = service.listAssets(null); + List<AssetInfo> listAssetsResult = service.listAssets(null); assertEquals(1, listAssetsResult.size()); // Act From 8f6f13537aa6ed7b16f29ec1a038883d3bef5fda Mon Sep 17 00:00:00 2001 From: Albert Cheng <gongchen@microsoft.com> Date: Fri, 21 Sep 2012 16:32:24 -0700 Subject: [PATCH 54/70] Resolve merging conflicts. --- .../services/media/MediaContract.java | 4 +++- .../MediaExceptionProcessor.java | 17 +++++++---------- .../media/implementation/MediaRestProxy.java | 18 +++++++----------- 3 files changed, 17 insertions(+), 22 deletions(-) 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 670cfed89507b..e5efb41eb5e98 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 @@ -17,6 +17,7 @@ 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.AssetInfo; import com.microsoft.windowsazure.services.media.models.CreateAssetOptions; import com.microsoft.windowsazure.services.media.models.ListAssetsOptions; @@ -67,8 +68,9 @@ public interface MediaContract extends FilterableService<MediaContract> { * @param assetName * the asset name * @return the asset info + * @throws ServiceException */ - public AssetInfo createAsset(String assetName); + public AssetInfo createAsset(String assetName) throws ServiceException; /** * Creates the asset. 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 83faae2255d61..8b53f2f9a6f0c 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 @@ -27,10 +27,10 @@ import com.microsoft.windowsazure.services.core.utils.ServiceExceptionFactory; import com.microsoft.windowsazure.services.media.MediaContract; import com.microsoft.windowsazure.services.media.models.AssetInfo; -import com.sun.jersey.api.client.ClientHandlerException; -import com.sun.jersey.api.client.UniformInterfaceException; import com.microsoft.windowsazure.services.media.models.CreateAssetOptions; import com.microsoft.windowsazure.services.media.models.ListAssetsOptions; +import com.sun.jersey.api.client.ClientHandlerException; +import com.sun.jersey.api.client.UniformInterfaceException; /** * Wrapper implementation of <code>MediaServicesContract</code> that @@ -62,9 +62,9 @@ private ServiceException processCatch(ServiceException e) { } @Override - public AssetInfo createAsset(String name) throws ServiceException { + public AssetInfo createAsset(String assetName) throws ServiceException { try { - return next.createAsset(name); + return service.createAsset(assetName); } catch (UniformInterfaceException e) { throw processCatch(new ServiceException(e)); @@ -77,7 +77,7 @@ public AssetInfo createAsset(String name) throws ServiceException { @Override public List<AssetInfo> getAssets() throws ServiceException { try { - return next.getAssets(); + return service.getAssets(); } catch (UniformInterfaceException e) { throw processCatch(new ServiceException(e)); @@ -86,6 +86,8 @@ public List<AssetInfo> getAssets() throws ServiceException { throw processCatch(new ServiceException(e)); } } + + @Override public void deleteAsset(String assetId) { service.deleteAsset(assetId); } @@ -100,11 +102,6 @@ public AssetInfo updateAsset(AssetInfo updatedAsset) { return service.updateAsset(updatedAsset); } - @Override - public AssetInfo createAsset(String assetName) { - return service.createAsset(assetName); - } - @Override public AssetInfo createAsset(String assetName, CreateAssetOptions createAssetOptions) { return service.createAsset(assetName, createAssetOptions); 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 798b73ee562b4..a7c528729e9b0 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 @@ -31,7 +31,6 @@ import com.microsoft.windowsazure.services.media.MediaContract; import com.microsoft.windowsazure.services.media.implementation.content.AssetType; import com.microsoft.windowsazure.services.media.models.AssetInfo; -import com.microsoft.windowsazure.services.media.models.AssetInfo; import com.microsoft.windowsazure.services.media.models.CreateAssetOptions; import com.microsoft.windowsazure.services.media.models.ListAssetsOptions; import com.sun.jersey.api.client.Client; @@ -61,6 +60,8 @@ public class MediaRestProxy implements MediaContract { * the auth filter * @param redirectFilter * the redirect filter + * @param versionHeadersFilter + * the version headers filter */ @Inject public MediaRestProxy(Client channel, OAuthFilter authFilter, RedirectFilter redirectFilter, @@ -130,12 +131,15 @@ private WebResource getResource(String entityName) { return resource; } + /* (non-Javadoc) + * @see com.microsoft.windowsazure.services.media.MediaContract#createAsset(java.lang.String) + */ @Override - public AssetInfo createAsset(String name) throws ServiceException { + public AssetInfo createAsset(String assetName) throws ServiceException { WebResource resource = getResource("Assets"); AssetType request = new AssetType(); - request.setName(name); + request.setName(assetName); return resource.type(MediaType.APPLICATION_ATOM_XML).accept(MediaType.APPLICATION_ATOM_XML) .post(AssetInfo.class, request); @@ -154,14 +158,6 @@ public List<AssetInfo> getAssets() throws ServiceException { }); } - /* (non-Javadoc) - * @see com.microsoft.windowsazure.services.media.MediaContract#createAsset(java.lang.String) - */ - @Override - public AssetInfo createAsset(String assetName) { - CreateAssetOptions createAssetOptions = new CreateAssetOptions(); - return createAsset(assetName, createAssetOptions); - } /* (non-Javadoc) * @see com.microsoft.windowsazure.services.media.MediaContract#createAsset(java.lang.String, com.microsoft.windowsazure.services.media.models.CreateAssetOptions) From 40f629b74e363136537ec1baf1754f2f9c65d2a9 Mon Sep 17 00:00:00 2001 From: Chris Tavares <ctavares@microsoft.com> Date: Mon, 24 Sep 2012 17:34:31 -0700 Subject: [PATCH 55/70] Adding support for setting timeout in configuration --- .../services/core/Configuration.java | 27 +++++----- .../services/core/utils/pipeline/Exports.java | 18 +++++-- .../pipeline/HttpURLConnectionClient.java | 18 +++---- .../HttpURLConnectionClientHandler.java | 40 ++++++++++++--- .../table/TableServiceIntegrationTest.java | 49 +++++++++++++++++++ 5 files changed, 116 insertions(+), 36 deletions(-) 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 1664dec987818..67f30dfe880e4 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,8 +23,6 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import com.sun.jersey.api.client.config.ClientConfig; - public class Configuration { private static Configuration instance; @@ -36,17 +34,11 @@ public class Configuration { public Configuration() { this.properties = new HashMap<String, Object>(); this.builder = DefaultBuilder.create(); - init(); } public Configuration(Builder builder) { this.properties = new HashMap<String, Object>(); this.builder = builder; - init(); - } - - private void init() { - setProperty("ClientConfig", builder.build("", ClientConfig.class, properties)); } public static Configuration getInstance() { @@ -102,4 +94,7 @@ public void setProperty(String name, Object value) { properties.put(name, value); } + public Map<String, Object> getProperties() { + return properties; + } } 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 234581b023fb8..026a4254de70b 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 @@ -32,7 +32,19 @@ public void register(Registry registry) { public ClientConfig create(String profile, Builder builder, Map<String, Object> properties) { ClientConfig clientConfig = new DefaultClientConfig(); for (Entry<String, Object> entry : properties.entrySet()) { - clientConfig.getProperties().put(entry.getKey(), entry.getValue()); + Object propertyValue = entry.getValue(); + + // 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 (entry.getKey().equals(ClientConfig.PROPERTY_CONNECT_TIMEOUT) + || entry.getKey().equals(ClientConfig.PROPERTY_READ_TIMEOUT)) { + if (propertyValue instanceof String) { + propertyValue = Integer.valueOf((String) propertyValue); + } + } + clientConfig.getProperties().put(entry.getKey(), propertyValue); } return clientConfig; } @@ -41,7 +53,7 @@ public ClientConfig create(String profile, Builder builder, Map<String, Object> registry.add(new Builder.Factory<Client>() { @Override public Client create(String profile, Builder builder, Map<String, Object> properties) { - ClientConfig clientConfig = (ClientConfig) properties.get("ClientConfig"); + ClientConfig clientConfig = builder.build(profile, ClientConfig.class, properties); Client client = Client.create(clientConfig); return client; } @@ -50,7 +62,7 @@ public Client create(String profile, Builder builder, Map<String, Object> proper registry.add(new Builder.Factory<HttpURLConnectionClient>() { @Override public HttpURLConnectionClient create(String profile, Builder builder, Map<String, Object> 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; 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 9b7ca1dd32482..f996e5edc6421 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 20d9046c5358c..21b1f3c0b3c3b 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 connectionTimeoutMS; + private final int readTimeoutMS; + + public HttpURLConnectionClientHandler(ClientConfig clientConfig) { + connectionTimeoutMS = readTimeoutFromConfig(clientConfig, ClientConfig.PROPERTY_CONNECT_TIMEOUT); + readTimeoutMS = 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(); + } + return 0; + } + /** * 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(readTimeoutMS); + urlConnection.setConnectTimeout(connectionTimeoutMS); + 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/test/java/com/microsoft/windowsazure/services/table/TableServiceIntegrationTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/table/TableServiceIntegrationTest.java index 4651f71acf0d6..05cc34eafae09 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/table/TableServiceIntegrationTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/table/TableServiceIntegrationTest.java @@ -47,6 +47,7 @@ import com.microsoft.windowsazure.services.table.models.QueryTablesResult; import com.microsoft.windowsazure.services.table.models.ServiceProperties; import com.microsoft.windowsazure.services.table.models.TableEntry; +import com.sun.jersey.api.client.config.ClientConfig; public class TableServiceIntegrationTest extends IntegrationTestBase { private static final String testTablesPrefix = "sdktest"; @@ -1139,4 +1140,52 @@ public void batchNegativeWorks() throws Exception { assertEquals("Second result status code", 412, error.getError().getHttpStatusCode()); assertNull("Third result should be null", result.getEntries().get(2)); } + + @Test + public void settingTimeoutWorks() throws Exception { + Configuration config = createConfiguration(); + + // Set timeout to very short to force failure + config.setProperty(ClientConfig.PROPERTY_CONNECT_TIMEOUT, new Integer(1)); + config.setProperty(ClientConfig.PROPERTY_READ_TIMEOUT, new Integer(1)); + + TableContract service = TableService.create(config); + + try { + service.queryTables(); + fail("Exception should have been thrown"); + } + catch (ServiceException ex) { + assertNotNull(ex.getCause()); + } + finally { + // Clean up timeouts, they interfere with other tests otherwise + config.getProperties().remove(ClientConfig.PROPERTY_CONNECT_TIMEOUT); + config.getProperties().remove(ClientConfig.PROPERTY_READ_TIMEOUT); + } + } + + @Test + public void settingTimeoutFromStringWorks() throws Exception { + Configuration config = createConfiguration(); + + // Set timeout to very short to force failure + config.setProperty(ClientConfig.PROPERTY_CONNECT_TIMEOUT, "1"); + config.setProperty(ClientConfig.PROPERTY_READ_TIMEOUT, "1"); + + TableContract service = TableService.create(config); + + try { + service.queryTables(); + fail("Exception should have been thrown"); + } + catch (ServiceException ex) { + assertNotNull(ex.getCause()); + } + finally { + // Clean up timeouts, they interfere with other tests otherwise + config.getProperties().remove(ClientConfig.PROPERTY_CONNECT_TIMEOUT); + config.getProperties().remove(ClientConfig.PROPERTY_READ_TIMEOUT); + } + } } From e1bafa873026d2f4812d7f48d9a0f78393745123 Mon Sep 17 00:00:00 2001 From: Chris Tavares <ctavares@microsoft.com> Date: Tue, 25 Sep 2012 16:07:54 -0700 Subject: [PATCH 56/70] Setting default timeout at 90 seconds --- .../windowsazure/services/core/Configuration.java | 9 +++++++++ .../pipeline/HttpURLConnectionClientHandler.java | 14 +++++++------- 2 files changed, 16 insertions(+), 7 deletions(-) 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 67f30dfe880e4..a3308a0cf0505 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 @@ -23,6 +23,8 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import com.sun.jersey.api.client.config.ClientConfig; + public class Configuration { private static Configuration instance; @@ -34,11 +36,18 @@ public class Configuration { public Configuration() { this.properties = new HashMap<String, Object>(); this.builder = DefaultBuilder.create(); + init(); } public Configuration(Builder builder) { this.properties = new HashMap<String, Object>(); this.builder = builder; + init(); + } + + private void init() { + setProperty(ClientConfig.PROPERTY_READ_TIMEOUT, new Integer(90 * 1000)); + setProperty(ClientConfig.PROPERTY_CONNECT_TIMEOUT, new Integer(90 * 1000)); } public static Configuration getInstance() { 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 21b1f3c0b3c3b..83e0822264e45 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 @@ -38,12 +38,12 @@ public class HttpURLConnectionClientHandler extends TerminatingClientHandler { - private final int connectionTimeoutMS; - private final int readTimeoutMS; + private final int connectionTimeoutMillis; + private final int readTimeoutMillis; public HttpURLConnectionClientHandler(ClientConfig clientConfig) { - connectionTimeoutMS = readTimeoutFromConfig(clientConfig, ClientConfig.PROPERTY_CONNECT_TIMEOUT); - readTimeoutMS = readTimeoutFromConfig(clientConfig, ClientConfig.PROPERTY_READ_TIMEOUT); + connectionTimeoutMillis = readTimeoutFromConfig(clientConfig, ClientConfig.PROPERTY_CONNECT_TIMEOUT); + readTimeoutMillis = readTimeoutFromConfig(clientConfig, ClientConfig.PROPERTY_READ_TIMEOUT); } private static int readTimeoutFromConfig(ClientConfig config, String propertyName) { @@ -51,7 +51,7 @@ private static int readTimeoutFromConfig(ClientConfig config, String propertyNam if (property != null) { return property.intValue(); } - return 0; + throw new IllegalArgumentException(propertyName); } /** @@ -195,8 +195,8 @@ 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(readTimeoutMS); - urlConnection.setConnectTimeout(connectionTimeoutMS); + urlConnection.setReadTimeout(readTimeoutMillis); + urlConnection.setConnectTimeout(connectionTimeoutMillis); final EntityStreamingListener entityStreamingListener = getEntityStreamingListener(clientRequest); From 38d35ae1ab6302dfcd5ce5a0078a67bb30f36eee Mon Sep 17 00:00:00 2001 From: Albert Cheng <gongchen@microsoft.com> Date: Wed, 26 Sep 2012 01:06:54 -0700 Subject: [PATCH 57/70] Test driven Asset CRUD operation --- .../services/media/MediaContract.java | 50 +++---- .../MediaExceptionProcessor.java | 117 ++++++++++++--- .../media/implementation/MediaRestProxy.java | 133 +++++++++++++----- .../implementation/content/AssetType.java | 14 ++ .../media/models/CreateAssetOptions.java | 75 ++++++++++ .../media/models/UpdateAssetOptions.java | 60 ++++++++ .../media/MediaServiceIntegrationTest.java | 96 ++++++------- .../ODataSerializationFromJerseyTest.java | 2 +- 8 files changed, 407 insertions(+), 140 deletions(-) create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/UpdateAssetOptions.java 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 e5efb41eb5e98..49a8cb4411caa 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 @@ -21,46 +21,31 @@ import com.microsoft.windowsazure.services.media.models.AssetInfo; import com.microsoft.windowsazure.services.media.models.CreateAssetOptions; 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. */ public interface MediaContract extends FilterableService<MediaContract> { - /** - * Creates the asset. - * - * @param asset - * the asset - * @return the asset info - */ - public AssetInfo createAsset(AssetInfo asset); - /** * List assets. * * @param listAssetsOptions * the list assets options * @return the list + * @throws ServiceException */ - public List<AssetInfo> listAssets(ListAssetsOptions listAssetsOptions); - - /** - * Update asset. - * - * @param updatedAsset - * the updated asset - * @return the asset info - */ - public AssetInfo updateAsset(AssetInfo updatedAsset); + public List<AssetInfo> listAssets(ListAssetsOptions listAssetsOptions) throws ServiceException; /** * Delete asset. * * @param assetId * the asset id + * @throws ServiceException */ - public void deleteAsset(String assetId); + public void deleteAsset(String assetId) throws ServiceException; /** * Creates the asset. @@ -80,8 +65,9 @@ public interface MediaContract extends FilterableService<MediaContract> { * @param createAssetOptions * the create asset options * @return the asset info + * @throws ServiceException */ - public AssetInfo createAsset(String assetName, CreateAssetOptions createAssetOptions); + public AssetInfo createAsset(String assetName, CreateAssetOptions createAssetOptions) throws ServiceException; /** * Gets the asset. @@ -89,23 +75,37 @@ public interface MediaContract extends FilterableService<MediaContract> { * @param assetId * the asset id * @return the asset + * @throws ServiceException */ - public AssetInfo getAsset(String assetId); + public AssetInfo getAsset(String assetId) throws ServiceException; /** * List assets. * * @return the list + * @throws ServiceException */ - public List<AssetInfo> listAssets(); + public List<AssetInfo> listAssets() throws ServiceException; /** * Delete asset. * * @param assetInfo * the asset info + * @throws ServiceException + */ + public void deleteAsset(AssetInfo assetInfo) throws ServiceException; + + /** + * Update asset. + * + * @param assetId + * the asset id + * @param updateAssetOptions + * the update asset options + * @throws ServiceException + * the service exception */ - public void deleteAsset(AssetInfo assetInfo); + public void updateAsset(String assetId, UpdateAssetOptions updateAssetOptions) throws ServiceException; - List<AssetInfo> getAssets() throws ServiceException; } 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 8b53f2f9a6f0c..838068976a573 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 @@ -29,6 +29,7 @@ import com.microsoft.windowsazure.services.media.models.AssetInfo; import com.microsoft.windowsazure.services.media.models.CreateAssetOptions; 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; @@ -39,28 +40,56 @@ */ public class MediaExceptionProcessor implements MediaContract { + /** The service. */ private final MediaContract service; + + /** The log. */ static Log log = LogFactory.getLog(MediaContract.class); + /** + * 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 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(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 { @@ -74,10 +103,13 @@ public AssetInfo createAsset(String assetName) throws ServiceException { } } + /* (non-Javadoc) + * @see com.microsoft.windowsazure.services.media.MediaContract#listAssets() + */ @Override - public List<AssetInfo> getAssets() throws ServiceException { + public List<AssetInfo> listAssets() throws ServiceException { try { - return service.getAssets(); + return service.listAssets(); } catch (UniformInterfaceException e) { throw processCatch(new ServiceException(e)); @@ -87,44 +119,83 @@ public List<AssetInfo> getAssets() throws ServiceException { } } + /* (non-Javadoc) + * @see com.microsoft.windowsazure.services.media.MediaContract#updateAsset(com.microsoft.windowsazure.services.media.models.AssetInfo) + */ @Override - public void deleteAsset(String assetId) { - service.deleteAsset(assetId); - } - - @Override - public AssetInfo createAsset(AssetInfo asset) { - return service.createAsset(asset); + public void updateAsset(String assetId, UpdateAssetOptions updateAssetOptions) throws ServiceException { + try { + service.updateAsset(assetId, updateAssetOptions); + } + catch (UniformInterfaceException e) { + throw 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 updateAsset(AssetInfo updatedAsset) { - return service.updateAsset(updatedAsset); + public AssetInfo createAsset(String assetName, CreateAssetOptions createAssetOptions) throws ServiceException { + try { + return service.createAsset(assetName, createAssetOptions); + } + catch (UniformInterfaceException e) { + throw processCatch(new ServiceException(e)); + } } + /* (non-Javadoc) + * @see com.microsoft.windowsazure.services.media.MediaContract#getAsset(java.lang.String) + */ @Override - public AssetInfo createAsset(String assetName, CreateAssetOptions createAssetOptions) { - return service.createAsset(assetName, createAssetOptions); - } + public AssetInfo getAsset(String assetId) throws ServiceException { + try { + return service.getAsset(assetId); + } + catch (UniformInterfaceException e) { + throw processCatch(new ServiceException(e)); + } - @Override - public AssetInfo getAsset(String assetId) { - return service.getAsset(assetId); } + /* (non-Javadoc) + * @see com.microsoft.windowsazure.services.media.MediaContract#deleteAsset(java.lang.String) + */ @Override - public List<AssetInfo> listAssets() { - return service.listAssets(); + public void deleteAsset(String assetId) throws ServiceException { + try { + service.deleteAsset(assetId); + } + catch (UniformInterfaceException e) { + throw processCatch(new ServiceException(e)); + } } + /* (non-Javadoc) + * @see com.microsoft.windowsazure.services.media.MediaContract#deleteAsset(com.microsoft.windowsazure.services.media.models.AssetInfo) + */ @Override - public void deleteAsset(AssetInfo assetInfo) { - service.deleteAsset(assetInfo); + public void deleteAsset(AssetInfo assetInfo) throws ServiceException { + try { + service.deleteAsset(assetInfo); + } + catch (UniformInterfaceException 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<AssetInfo> listAssets(ListAssetsOptions listAssetsOptions) { - return service.listAssets(listAssetsOptions); + public List<AssetInfo> listAssets(ListAssetsOptions listAssetsOptions) throws ServiceException { + try { + return service.listAssets(listAssetsOptions); + } + catch (UniformInterfaceException 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 a7c528729e9b0..fc03acea681f5 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 @@ -15,7 +15,8 @@ package com.microsoft.windowsazure.services.media.implementation; -import java.util.ArrayList; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; import java.util.Arrays; import java.util.List; @@ -28,16 +29,19 @@ 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.AssetType; import com.microsoft.windowsazure.services.media.models.AssetInfo; import com.microsoft.windowsazure.services.media.models.CreateAssetOptions; 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.UniformInterfaceException; import com.sun.jersey.api.client.WebResource; -// TODO: Auto-generated Javadoc /** * The Class MediaRestProxy. */ @@ -136,27 +140,8 @@ private WebResource getResource(String entityName) { */ @Override public AssetInfo createAsset(String assetName) throws ServiceException { - WebResource resource = getResource("Assets"); - - AssetType request = new AssetType(); - request.setName(assetName); - - return resource.type(MediaType.APPLICATION_ATOM_XML).accept(MediaType.APPLICATION_ATOM_XML) - .post(AssetInfo.class, request); - - } - - /* (non-Javadoc) - * @see com.microsoft.windowsazure.services.media.MediaContract#getAssets() - */ - @Override - public List<AssetInfo> getAssets() throws ServiceException { - WebResource resource = getResource("Assets"); - - return resource.type(MediaType.APPLICATION_ATOM_XML).accept(MediaType.APPLICATION_ATOM_XML) - .get(new GenericType<List<AssetInfo>>() { - }); - + CreateAssetOptions createAssetOptions = new CreateAssetOptions(); + return this.createAsset(assetName, createAssetOptions); } /* (non-Javadoc) @@ -164,15 +149,37 @@ public List<AssetInfo> getAssets() throws ServiceException { */ @Override public AssetInfo createAsset(String assetName, CreateAssetOptions createAssetOptions) { - return null; + WebResource resource = getResource("Assets"); + AssetType assetType = new AssetType(); + assetType.setName(assetName); + assetType.setAlternateId(createAssetOptions.getAlternateId()); + if (createAssetOptions.getOptions() != null) { + assetType.setOptions(createAssetOptions.getOptions().getCode()); + } + if (createAssetOptions.getState() != null) { + assetType.setState(createAssetOptions.getState().getCode()); + } + return resource.type(MediaType.APPLICATION_ATOM_XML).accept(MediaType.APPLICATION_ATOM_XML) + .post(AssetInfo.class, assetType); } /* (non-Javadoc) * @see com.microsoft.windowsazure.services.media.MediaContract#getAsset(java.lang.String) */ @Override - public AssetInfo getAsset(String assetId) { - return null; + public AssetInfo getAsset(String assetId) 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); + WebResource resource = getResource(assetPath); + return resource.type(MediaType.APPLICATION_ATOM_XML).accept(MediaType.APPLICATION_ATOM_XML) + .get(new GenericType<AssetInfo>() { + }); } /* (non-Javadoc) @@ -180,8 +187,10 @@ public AssetInfo getAsset(String assetId) { */ @Override public List<AssetInfo> listAssets(ListAssetsOptions listAssetsOptions) { - List<AssetInfo> listAssetsResult = new ArrayList<AssetInfo>(); - return listAssetsResult; + WebResource resource = getResource("Assets"); + return resource.type(MediaType.APPLICATION_ATOM_XML).accept(MediaType.APPLICATION_ATOM_XML) + .get(new GenericType<List<AssetInfo>>() { + }); } /* (non-Javadoc) @@ -197,32 +206,78 @@ public List<AssetInfo> listAssets() { * @see com.microsoft.windowsazure.services.media.MediaContract#updateAsset(com.microsoft.windowsazure.services.media.models.AssetInfo) */ @Override - public AssetInfo updateAsset(AssetInfo updatedAssetInfo) { - return null; + 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); + WebResource resource = getResource(assetPath); + 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) { + public void deleteAsset(String assetId) 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); + WebResource resource = getResource(assetPath); + try { + resource.delete(); + } + catch (UniformInterfaceException e) { + throw new ServiceException(e); + } } /* (non-Javadoc) * @see com.microsoft.windowsazure.services.media.MediaContract#deleteAsset(com.microsoft.windowsazure.services.media.models.AssetInfo) */ @Override - public void deleteAsset(AssetInfo assetInfo) { + public void deleteAsset(AssetInfo assetInfo) throws ServiceException { this.deleteAsset(assetInfo.getId()); } - /* (non-Javadoc) - * @see com.microsoft.windowsazure.services.media.MediaContract#createAsset(com.microsoft.windowsazure.services.media.models.AssetInfo) - */ - @Override - public AssetInfo createAsset(AssetInfo assetInfo) { - // TODO Auto-generated method stub - return null; + private <T> T mergeRequest(String path, GenericType<T> genericClass, java.lang.Object requestEntity) + throws ServiceException { + 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.method("POST", genericClass, requestEntity); + + } + + private <T> T mergeRequest(String path, java.lang.Class<T> 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.method("POST", c, requestEntity); + } } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/AssetType.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/AssetType.java index 391e0c497aaa5..84f5b353785ab 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/AssetType.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/AssetType.java @@ -20,6 +20,8 @@ import javax.xml.bind.annotation.XmlElement; import javax.xml.datatype.XMLGregorianCalendar; +import com.microsoft.windowsazure.services.media.models.AssetInfo; + /** * This type maps the XML returned in the odata ATOM serialization * for Asset entities. @@ -153,4 +155,16 @@ public int getOptions() { public void setOptions(int options) { this.options = options; } + + public static AssetType create(AssetInfo assetInfo) { + AssetType assetType = new AssetType(); + assetType.setAlternateId(assetInfo.getAlternateId()); + assetType.setCreated(assetInfo.getCreated()); + assetType.setId(assetInfo.getId()); + assetType.setLastModified(assetInfo.getLastModified()); + assetType.setName(assetInfo.getName()); + assetType.setOptions(assetInfo.getOptions().getCode()); + assetType.setState(assetInfo.getState().getCode()); + return assetType; + } } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/CreateAssetOptions.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/CreateAssetOptions.java index ecf58db9057e1..9905e36e8ef46 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/CreateAssetOptions.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/CreateAssetOptions.java @@ -14,6 +14,81 @@ */ package com.microsoft.windowsazure.services.media.models; +/** + * The Class CreateAssetOptions. + */ public class CreateAssetOptions { + /** The alternate id. */ + private String alternateId; + + /** The options. */ + private EncryptionOption options; + + /** The state. */ + private AssetState state; + + /** + * Gets the alternate id. + * + * @return the alternate id + */ + public String getAlternateId() { + return alternateId; + } + + /** + * Sets the alternate id. + * + * @param alternateId + * the alternate id + * @return the creates the asset options + */ + public CreateAssetOptions setAlternateId(String alternateId) { + this.alternateId = alternateId; + return this; + } + + /** + * Gets the options. + * + * @return the options + */ + public EncryptionOption getOptions() { + return options; + } + + /** + * Sets the options. + * + * @param encryptionOption + * the encryption option + * @return the creates the asset options + */ + public CreateAssetOptions setOptions(EncryptionOption encryptionOption) { + this.options = encryptionOption; + return this; + } + + /** + * Gets the state. + * + * @return the state + */ + public AssetState getState() { + return state; + } + + /** + * Sets the state. + * + * @param assetState + * the asset state + * @return the creates the asset options + */ + public CreateAssetOptions setState(AssetState assetState) { + this.state = assetState; + return this; + } + } \ No newline at end of file diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/UpdateAssetOptions.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/UpdateAssetOptions.java new file mode 100644 index 0000000000000..07390ecd2dfce --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/UpdateAssetOptions.java @@ -0,0 +1,60 @@ +/** + * 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.models; + +public class UpdateAssetOptions { + + private String alternateId; + private String name; + private EncryptionOption options; + private AssetState state; + + public String getAlternateId() { + return alternateId; + } + + public UpdateAssetOptions setAlternatedId(String alternateId) { + this.alternateId = alternateId; + return this; + } + + public String getName() { + return name; + } + + public UpdateAssetOptions setName(String name) { + this.name = name; + return this; + } + + public EncryptionOption getOptions() { + return options; + } + + public UpdateAssetOptions setOptions(EncryptionOption options) { + this.options = options; + return this; + } + + public AssetState getState() { + return state; + } + + public UpdateAssetOptions setState(AssetState assetState) { + this.state = assetState; + return this; + } + +} diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/MediaServiceIntegrationTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/MediaServiceIntegrationTest.java index a838f8cac87c1..5b941aef9b446 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/MediaServiceIntegrationTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/MediaServiceIntegrationTest.java @@ -24,8 +24,9 @@ import org.junit.Test; import com.microsoft.windowsazure.services.core.Configuration; +import com.microsoft.windowsazure.services.core.ServiceException; import com.microsoft.windowsazure.services.media.models.AssetInfo; -import com.microsoft.windowsazure.services.media.models.ListAssetsOptions; +import com.microsoft.windowsazure.services.media.models.UpdateAssetOptions; public class MediaServiceIntegrationTest extends IntegrationTestBase { private static MediaContract service; @@ -37,7 +38,12 @@ public static void setup() throws Exception { service = MediaService.create(config); List<AssetInfo> listAssetsResult = service.listAssets(null); for (AssetInfo assetInfo : listAssetsResult) { - service.deleteAsset(assetInfo.getId()); + try { + service.deleteAsset(assetInfo.getId()); + } + catch (Exception e) { + e.printStackTrace(); + } } } @@ -66,45 +72,43 @@ public void createAssetSuccess() throws Exception { AssetInfo expectedAsset = new AssetInfo().setName("testAssetName"); // Act - AssetInfo actualAsset = service.createAsset(expectedAsset); + AssetInfo actualAsset = service.createAsset("testAssetName"); // Assert - assertEquals(expectedAsset, actualAsset); + assertEquals(expectedAsset.getName(), actualAsset.getName()); } @Test - public void createAssetMissingNameFailed() { + public void createAssetNullNameSuccess() throws ServiceException { // Arrange - AssetInfo expectedAsset = new AssetInfo(); // Act - AssetInfo actualAsset = service.createAsset(expectedAsset); + AssetInfo actualAsset = service.createAsset(null); // Assert - assertTrue(false); + assertNotNull(actualAsset); } @Test public void getAssetSuccess() throws Exception { // Arrange - AssetInfo expectedAsset = new AssetInfo(); - AssetInfo assetInfo = service.createAsset(expectedAsset); + AssetInfo expectedAsset = new AssetInfo().setName("testGetAssetSuccess"); + AssetInfo assetInfo = service.createAsset("testGetAssetSuccess"); // Act AssetInfo actualAsset = service.getAsset(assetInfo.getId()); // Assert - assertEquals(expectedAsset, actualAsset); + assertEquals(expectedAsset.getName(), actualAsset.getName()); } - @Test - public void getAssetFailedWithInvalidId() { + @Test(expected = ServiceException.class) + public void getAssetFailedWithInvalidId() throws ServiceException { // Arrange - AssetInfo expectedAsset = new AssetInfo(); - service.createAsset(expectedAsset); + AssetInfo expectedAsset = new AssetInfo().setId("IncorrectAssetId"); // Act - AssetInfo actualAsset = service.getAsset(expectedAsset.setId("IncorrectAssetId").getId()); + AssetInfo actualAsset = service.getAsset(expectedAsset.getId()); // Assert assertTrue(false); @@ -112,57 +116,45 @@ public void getAssetFailedWithInvalidId() { } @Test - public void listAssetSuccess() { + public void listAssetSuccess() throws ServiceException { // Arrange + Collection<AssetInfo> listAssetResultBaseLine = service.listAssets(); AssetInfo assetA = new AssetInfo(); AssetInfo assetB = new AssetInfo(); - service.createAsset(assetA); - service.createAsset(assetB); - ListAssetsOptions listAssetOptions = new ListAssetsOptions(); + service.createAsset("assetA"); + service.createAsset("assetB"); // Act - Collection<AssetInfo> listAssetResult = service.listAssets(listAssetOptions); + Collection<AssetInfo> listAssetResult = service.listAssets(); // Assert - assertEquals(2, listAssetResult.size()); - } - - @Test - public void listAssetFailed() { - // Arrange - ListAssetsOptions listAssetsOptions = new ListAssetsOptions(); - - // Act - Collection<AssetInfo> listAssetResult = service.listAssets(listAssetsOptions); - - // Assert - assertTrue(false); + assertEquals(listAssetResultBaseLine.size() + 2, listAssetResult.size()); } @Test public void updateAssetSuccess() throws Exception { // Arrange - AssetInfo originalAsset = new AssetInfo(); - service.createAsset(originalAsset); - AssetInfo updatedAsset = new AssetInfo(); + + AssetInfo updatedAsset = service.createAsset("updateAssetSuccess"); + UpdateAssetOptions updateAssetOptions = new UpdateAssetOptions().setName("updateAssetSuccessResult"); + updatedAsset.setName("updateAssetSuccessResult"); // Act - service.updateAsset(updatedAsset); - AssetInfo actualAsset = service.updateAsset(updatedAsset); + service.updateAsset(updatedAsset.getId(), updateAssetOptions); + AssetInfo actualAsset = service.getAsset(updatedAsset.getId()); // Assert - assertEquals(updatedAsset, actualAsset); + assertEquals(updatedAsset.getName(), actualAsset.getName()); } - @Test - public void updateAssetFailedWithInvalidId() { + @Test(expected = ServiceException.class) + public void updateAssetFailedWithInvalidId() throws ServiceException { // Arrange - MediaContract service = MediaService.create(config); - AssetInfo updatedAsset = new AssetInfo(); + UpdateAssetOptions updateAssetOptions = new UpdateAssetOptions(); // Act - service.updateAsset(updatedAsset); + service.updateAsset("updateAssetFailedWithInvalidId", updateAssetOptions); // Assert assertTrue(false); @@ -171,21 +163,21 @@ public void updateAssetFailedWithInvalidId() { @Test public void deleteAssetSuccess() throws Exception { // Arrange - AssetInfo asset = new AssetInfo(); - service.createAsset(asset); + String assetName = "deleteAssetSuccess"; + AssetInfo assetInfo = service.createAsset(assetName); List<AssetInfo> listAssetsResult = service.listAssets(null); - assertEquals(1, listAssetsResult.size()); + int assetCountBaseline = listAssetsResult.size(); // Act - service.deleteAsset(asset.getId()); + service.deleteAsset(assetInfo.getId()); // Assert listAssetsResult = service.listAssets(null); - assertEquals(0, listAssetsResult.size()); + assertEquals(assetCountBaseline - 1, listAssetsResult.size()); } - @Test - public void deleteAssetFailedWithInvalidId() { + @Test(expected = ServiceException.class) + public void deleteAssetFailedWithInvalidId() throws ServiceException { // Arrange // Act diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/implementation/ODataSerializationFromJerseyTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/implementation/ODataSerializationFromJerseyTest.java index 2c2ac5bf05e52..53c67ba9798bb 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/implementation/ODataSerializationFromJerseyTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/implementation/ODataSerializationFromJerseyTest.java @@ -97,7 +97,7 @@ public void canCreateAssetThroughMediaServiceAPI() throws Exception { @Test public void canRetrieveListOfAssets() throws Exception { MediaContract client = MediaService.create(config); - List<AssetInfo> assets = client.getAssets(); + List<AssetInfo> assets = client.listAssets(); Assert.assertNotNull(assets); } From 0a67369c5d93e00aa7df282cf48a45df7d0d65f4 Mon Sep 17 00:00:00 2001 From: Albert Cheng <gongchen@microsoft.com> Date: Wed, 26 Sep 2012 16:27:37 -0700 Subject: [PATCH 58/70] Code review feedback for Asset CRUD operation. --- .../services/media/MediaContract.java | 37 ++++----- .../MediaExceptionProcessor.java | 57 +++++++------- .../media/implementation/MediaRestProxy.java | 75 ++++++------------- .../services/media/models/AssetInfo.java | 1 - .../media/models/UpdateAssetOptions.java | 2 +- .../media/models/CreateAssetOptionsTest.java | 62 +++++++++++++++ .../media/models/UpdateAssetOptionsTest.java | 75 +++++++++++++++++++ 7 files changed, 204 insertions(+), 105 deletions(-) create mode 100644 microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/CreateAssetOptionsTest.java create mode 100644 microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/UpdateAssetOptionsTest.java 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 49a8cb4411caa..7dfa4844ad837 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 @@ -28,25 +28,6 @@ */ public interface MediaContract extends FilterableService<MediaContract> { - /** - * List assets. - * - * @param listAssetsOptions - * the list assets options - * @return the list - * @throws ServiceException - */ - public List<AssetInfo> listAssets(ListAssetsOptions listAssetsOptions) throws ServiceException; - - /** - * Delete asset. - * - * @param assetId - * the asset id - * @throws ServiceException - */ - public void deleteAsset(String assetId) throws ServiceException; - /** * Creates the asset. * @@ -69,6 +50,15 @@ public interface MediaContract extends FilterableService<MediaContract> { */ 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. * @@ -88,13 +78,14 @@ public interface MediaContract extends FilterableService<MediaContract> { public List<AssetInfo> listAssets() throws ServiceException; /** - * Delete asset. + * List assets. * - * @param assetInfo - * the asset info + * @param listAssetsOptions + * the list assets options + * @return the list * @throws ServiceException */ - public void deleteAsset(AssetInfo assetInfo) throws ServiceException; + public List<AssetInfo> listAssets(ListAssetsOptions listAssetsOptions) throws ServiceException; /** * Update asset. 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 838068976a573..9af373b2ae08d 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 @@ -104,12 +104,12 @@ public AssetInfo createAsset(String assetName) throws ServiceException { } /* (non-Javadoc) - * @see com.microsoft.windowsazure.services.media.MediaContract#listAssets() + * @see com.microsoft.windowsazure.services.media.MediaContract#createAsset(java.lang.String, com.microsoft.windowsazure.services.media.models.CreateAssetOptions) */ @Override - public List<AssetInfo> listAssets() throws ServiceException { + public AssetInfo createAsset(String assetName, CreateAssetOptions createAssetOptions) throws ServiceException { try { - return service.listAssets(); + return service.createAsset(assetName, createAssetOptions); } catch (UniformInterfaceException e) { throw processCatch(new ServiceException(e)); @@ -120,27 +120,17 @@ public List<AssetInfo> listAssets() throws ServiceException { } /* (non-Javadoc) - * @see com.microsoft.windowsazure.services.media.MediaContract#updateAsset(com.microsoft.windowsazure.services.media.models.AssetInfo) + * @see com.microsoft.windowsazure.services.media.MediaContract#deleteAsset(java.lang.String) */ @Override - public void updateAsset(String assetId, UpdateAssetOptions updateAssetOptions) throws ServiceException { + public void deleteAsset(String assetId) throws ServiceException { try { - service.updateAsset(assetId, updateAssetOptions); + service.deleteAsset(assetId); } catch (UniformInterfaceException e) { - throw 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); + throw processCatch(new ServiceException(e)); } - catch (UniformInterfaceException e) { + catch (ClientHandlerException e) { throw processCatch(new ServiceException(e)); } } @@ -156,46 +146,57 @@ public AssetInfo getAsset(String assetId) throws ServiceException { 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) + * @see com.microsoft.windowsazure.services.media.MediaContract#listAssets() */ @Override - public void deleteAsset(String assetId) throws ServiceException { + public List<AssetInfo> listAssets() throws ServiceException { try { - service.deleteAsset(assetId); + 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#deleteAsset(com.microsoft.windowsazure.services.media.models.AssetInfo) + * @see com.microsoft.windowsazure.services.media.MediaContract#listAssets(com.microsoft.windowsazure.services.media.models.ListAssetsOptions) */ @Override - public void deleteAsset(AssetInfo assetInfo) throws ServiceException { + public List<AssetInfo> listAssets(ListAssetsOptions listAssetsOptions) throws ServiceException { try { - service.deleteAsset(assetInfo); + 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#listAssets(com.microsoft.windowsazure.services.media.models.ListAssetsOptions) + * @see com.microsoft.windowsazure.services.media.MediaContract#updateAsset(com.microsoft.windowsazure.services.media.models.AssetInfo) */ @Override - public List<AssetInfo> listAssets(ListAssetsOptions listAssetsOptions) throws ServiceException { + public void updateAsset(String assetId, UpdateAssetOptions updateAssetOptions) throws ServiceException { try { - return service.listAssets(listAssetsOptions); + service.updateAsset(assetId, updateAssetOptions); } 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 fc03acea681f5..eb060a973833f 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 @@ -39,7 +39,6 @@ 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.UniformInterfaceException; import com.sun.jersey.api.client.WebResource; /** @@ -140,8 +139,7 @@ private WebResource getResource(String entityName) { */ @Override public AssetInfo createAsset(String assetName) throws ServiceException { - CreateAssetOptions createAssetOptions = new CreateAssetOptions(); - return this.createAsset(assetName, createAssetOptions); + return this.createAsset(assetName, null); } /* (non-Javadoc) @@ -150,17 +148,19 @@ public AssetInfo createAsset(String assetName) throws ServiceException { @Override public AssetInfo createAsset(String assetName, CreateAssetOptions createAssetOptions) { WebResource resource = getResource("Assets"); - AssetType assetType = new AssetType(); - assetType.setName(assetName); - assetType.setAlternateId(createAssetOptions.getAlternateId()); - if (createAssetOptions.getOptions() != null) { - assetType.setOptions(createAssetOptions.getOptions().getCode()); - } - if (createAssetOptions.getState() != null) { - assetType.setState(createAssetOptions.getState().getCode()); + 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, assetType); + .post(AssetInfo.class, assetTypeForSubmission); } /* (non-Javadoc) @@ -168,18 +168,9 @@ public AssetInfo createAsset(String assetName, CreateAssetOptions createAssetOpt */ @Override public AssetInfo getAsset(String assetId) 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); - WebResource resource = getResource(assetPath); + WebResource resource = getResource("Assets", assetId); return resource.type(MediaType.APPLICATION_ATOM_XML).accept(MediaType.APPLICATION_ATOM_XML) - .get(new GenericType<AssetInfo>() { - }); + .get(AssetInfo.class); } /* (non-Javadoc) @@ -215,7 +206,6 @@ public void updateAsset(String assetId, UpdateAssetOptions updateAssetOptions) t throw new ServiceException(e); } String assetPath = String.format("Assets(\'%s\')", escapedAssetId); - WebResource resource = getResource(assetPath); AssetType updatedAssetType = new AssetType(); updatedAssetType.setAlternateId(updateAssetOptions.getAlternateId()); updatedAssetType.setName(updateAssetOptions.getName()); @@ -236,39 +226,20 @@ public void updateAsset(String assetId, UpdateAssetOptions updateAssetOptions) t */ @Override public void deleteAsset(String assetId) throws ServiceException { - String escapedAssetId = null; + getResource("Assets", assetId).delete(); + } + + private WebResource getResource(String entityType, String entityId) throws ServiceException { + String escapedEntityId = null; try { - escapedAssetId = URLEncoder.encode(assetId, "UTF-8"); + escapedEntityId = URLEncoder.encode(entityId, "UTF-8"); } catch (UnsupportedEncodingException e) { throw new ServiceException(e); } - String assetPath = String.format("Assets(\'%s\')", escapedAssetId); - WebResource resource = getResource(assetPath); - try { - resource.delete(); - } - catch (UniformInterfaceException e) { - throw new ServiceException(e); - } - } - - /* (non-Javadoc) - * @see com.microsoft.windowsazure.services.media.MediaContract#deleteAsset(com.microsoft.windowsazure.services.media.models.AssetInfo) - */ - @Override - public void deleteAsset(AssetInfo assetInfo) throws ServiceException { - this.deleteAsset(assetInfo.getId()); - } - - private <T> T mergeRequest(String path, GenericType<T> genericClass, java.lang.Object requestEntity) - throws ServiceException { - 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.method("POST", genericClass, requestEntity); + String entityPath = String.format("%s(\'%s\')", entityType, escapedEntityId); + return getResource(entityPath); } private <T> T mergeRequest(String path, java.lang.Class<T> c, java.lang.Object requestEntity) { @@ -276,7 +247,7 @@ private <T> T mergeRequest(String path, java.lang.Class<T> c, java.lang.Object r WebResource.Builder builder = resource.getRequestBuilder(); builder = builder.type(MediaType.APPLICATION_ATOM_XML).accept(MediaType.APPLICATION_ATOM_XML) .header("X-HTTP-Method", "MERGE"); - return builder.method("POST", c, requestEntity); + return builder.post(c, requestEntity); } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AssetInfo.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AssetInfo.java index c7e9468f9e0a3..68a1c9058cf81 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AssetInfo.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AssetInfo.java @@ -1,5 +1,4 @@ /** - * >>>>>>> e8cf07bb1f265cdf72add1bd00ac069cb4dbaa33 * Copyright 2012 Microsoft Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/UpdateAssetOptions.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/UpdateAssetOptions.java index 07390ecd2dfce..8e452dddc78f3 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/UpdateAssetOptions.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/UpdateAssetOptions.java @@ -25,7 +25,7 @@ public String getAlternateId() { return alternateId; } - public UpdateAssetOptions setAlternatedId(String alternateId) { + public UpdateAssetOptions setAlternateId(String alternateId) { this.alternateId = alternateId; return this; } diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/CreateAssetOptionsTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/CreateAssetOptionsTest.java new file mode 100644 index 0000000000000..93f09cbde5e18 --- /dev/null +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/CreateAssetOptionsTest.java @@ -0,0 +1,62 @@ +/** + * 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.models; + +import static org.junit.Assert.*; + +import org.junit.Test; + +public class CreateAssetOptionsTest { + + @Test + public void testGetSetState() { + // Arrange + AssetState expectedState = AssetState.Published; + CreateAssetOptions createAssetOptions = new CreateAssetOptions(); + + // Act + AssetState actualState = createAssetOptions.setState(expectedState).getState(); + + // Assert + assertEquals(expectedState, actualState); + } + + @Test + public void testGetSetAlternateId() { + // Arrange + String expectedAlternateId = "testAlternateId"; + CreateAssetOptions createAssetOptions = new CreateAssetOptions(); + + // Act + String actualAlternateId = createAssetOptions.setAlternateId(expectedAlternateId).getAlternateId(); + + // Assert + assertEquals(expectedAlternateId, actualAlternateId); + } + + @Test + public void testGetSetOptions() { + // Arrange + EncryptionOption expectedOptions = EncryptionOption.None; + CreateAssetOptions createAssetOptions = new CreateAssetOptions(); + + // Act + EncryptionOption actualOptions = createAssetOptions.setOptions(expectedOptions).getOptions(); + + // Assert + assertEquals(expectedOptions, actualOptions); + } + +} diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/UpdateAssetOptionsTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/UpdateAssetOptionsTest.java new file mode 100644 index 0000000000000..be47f311119b2 --- /dev/null +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/UpdateAssetOptionsTest.java @@ -0,0 +1,75 @@ +/** + * 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.models; + +import static org.junit.Assert.*; + +import org.junit.Test; + +public class UpdateAssetOptionsTest { + + @Test + public void testGetSetState() { + // Arrange + AssetState expectedState = AssetState.Published; + UpdateAssetOptions updateAssetOptions = new UpdateAssetOptions(); + + // Act + AssetState actualState = updateAssetOptions.setState(expectedState).getState(); + + // Assert + assertEquals(expectedState, actualState); + } + + @Test + public void testGetSetAlternateId() { + // Arrange + String expectedAlternateId = "testAlternateId"; + UpdateAssetOptions updateAssetOptions = new UpdateAssetOptions(); + + // Act + String actualAlternateId = updateAssetOptions.setAlternateId(expectedAlternateId).getAlternateId(); + + // Assert + assertEquals(expectedAlternateId, actualAlternateId); + } + + @Test + public void testGetSetName() { + // Arrange + String expectedName = "testName"; + UpdateAssetOptions updateAssetOptions = new UpdateAssetOptions(); + + // Act + String actualName = updateAssetOptions.setName(expectedName).getName(); + + // Assert + assertEquals(expectedName, actualName); + } + + @Test + public void testGetSetOptions() { + // Arrange + EncryptionOption expectedOptions = EncryptionOption.None; + UpdateAssetOptions updateAssetOptions = new UpdateAssetOptions(); + + // Act + EncryptionOption actualOptions = updateAssetOptions.setOptions(expectedOptions).getOptions(); + + // Assert + assertEquals(expectedOptions, actualOptions); + } + +} From 927e6bb999d56014bf4ee008bf80b57d41168b7e Mon Sep 17 00:00:00 2001 From: Albert Cheng <gongchen@microsoft.com> Date: Wed, 26 Sep 2012 16:30:04 -0700 Subject: [PATCH 59/70] adds missing java doc skeleton for UpdateAssetOptions class. --- .../media/models/UpdateAssetOptions.java | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/UpdateAssetOptions.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/UpdateAssetOptions.java index 8e452dddc78f3..74b4a51e4daf7 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/UpdateAssetOptions.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/UpdateAssetOptions.java @@ -14,44 +14,103 @@ */ package com.microsoft.windowsazure.services.media.models; +// TODO: Auto-generated Javadoc +/** + * The Class UpdateAssetOptions. + */ public class UpdateAssetOptions { + /** The alternate id. */ private String alternateId; + + /** The name. */ private String name; + + /** The options. */ private EncryptionOption options; + + /** The state. */ private AssetState state; + /** + * Gets the alternate id. + * + * @return the alternate id + */ public String getAlternateId() { return alternateId; } + /** + * Sets the alternate id. + * + * @param alternateId + * the alternate id + * @return the update asset options + */ public UpdateAssetOptions setAlternateId(String alternateId) { this.alternateId = alternateId; return this; } + /** + * Gets the name. + * + * @return the name + */ public String getName() { return name; } + /** + * Sets the name. + * + * @param name + * the name + * @return the update asset options + */ public UpdateAssetOptions setName(String name) { this.name = name; return this; } + /** + * Gets the options. + * + * @return the options + */ public EncryptionOption getOptions() { return options; } + /** + * Sets the options. + * + * @param options + * the options + * @return the update asset options + */ public UpdateAssetOptions setOptions(EncryptionOption options) { this.options = options; return this; } + /** + * Gets the state. + * + * @return the state + */ public AssetState getState() { return state; } + /** + * Sets the state. + * + * @param assetState + * the asset state + * @return the update asset options + */ public UpdateAssetOptions setState(AssetState assetState) { this.state = assetState; return this; From 2b5455ca80369b1c3ec464158d45513084d67857 Mon Sep 17 00:00:00 2001 From: Chris Tavares <ctavares@microsoft.com> Date: Wed, 26 Sep 2012 17:57:29 -0700 Subject: [PATCH 60/70] Throwing ServiceTimeoutException on socket timeout. Also fixed bug in default timeout setting --- .../services/core/Configuration.java | 9 -- .../core/ServiceTimeoutException.java | 50 +++++++++++ .../core/utils/ServiceExceptionFactory.java | 90 ++++++++++++++++--- .../services/core/utils/pipeline/Exports.java | 7 ++ .../table/TableServiceIntegrationTest.java | 15 +++- .../utils/ServiceExceptionFactoryTest.java | 46 ++++++---- 6 files changed, 176 insertions(+), 41 deletions(-) create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/ServiceTimeoutException.java 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 a3308a0cf0505..67f30dfe880e4 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 @@ -23,8 +23,6 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import com.sun.jersey.api.client.config.ClientConfig; - public class Configuration { private static Configuration instance; @@ -36,18 +34,11 @@ public class Configuration { public Configuration() { this.properties = new HashMap<String, Object>(); this.builder = DefaultBuilder.create(); - init(); } public Configuration(Builder builder) { this.properties = new HashMap<String, Object>(); this.builder = builder; - init(); - } - - private void init() { - setProperty(ClientConfig.PROPERTY_READ_TIMEOUT, new Integer(90 * 1000)); - setProperty(ClientConfig.PROPERTY_CONNECT_TIMEOUT, new Integer(90 * 1000)); } public static Configuration getInstance() { 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 0000000000000..6de101f3d93d3 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/ServiceTimeoutException.java @@ -0,0 +1,50 @@ +/** + * + */ +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 + */ + public ServiceTimeoutException() { + } + + /** + * Construct a ServiceTimeoutException instance + * + * @param message + * Exception message + */ + public ServiceTimeoutException(String message) { + super(message); + } + + /** + * Construct a ServiceTimeoutException instance + * + * @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 + * + * @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/utils/ServiceExceptionFactory.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/utils/ServiceExceptionFactory.java index 90210ac0e6254..dd593322c2073 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,23 @@ * 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.ClientHandlerException; import com.sun.jersey.api.client.ClientResponse; import com.sun.jersey.api.client.ClientResponse.Status; import com.sun.jersey.api.client.UniformInterfaceException; @@ -22,14 +26,69 @@ public class ServiceExceptionFactory { public static ServiceException process(String serviceName, ServiceException exception) { + // State machine for figuring out what to do with the exception + // + // Input is the type of the current exception cause. + // FSM starts in state 0. + // + // State | Input | New State | Action + //--------------------------------------------------------------------------- + // 0 | ServiceException | None | populate and return + // | | | + // 0 | UniformInterfaceException | None | populate and return + // | | | + // 0 | ClientHandlerException | 1 | None + // | | | + // 0 | Any other | 0 | None + // | | | + // 1 | ServiceException | None | populate and return + // | | | + // 1 | UniformInterfaceException | None | populate and return + // | | | + // 1 | ClientHandlerException | 1 | None + // | | | + // 1 | SocketTimeoutException | None | populate and return + // | | | + // 1 | Any other | 0 | None + + int state = 0; Throwable cause = exception.getCause(); for (Throwable scan = cause; scan != null; scan = scan.getCause()) { - if (ServiceException.class.isAssignableFrom(scan.getClass())) { - return populate(exception, serviceName, (ServiceException) scan); - } - else if (UniformInterfaceException.class.isAssignableFrom(scan.getClass())) { - return populate(exception, serviceName, (UniformInterfaceException) scan); + Class scanClass = scan.getClass(); + + switch (state) { + case 0: + if (ServiceException.class.isAssignableFrom(scanClass)) { + return populate(exception, serviceName, (ServiceException) scan); + } + else if (UniformInterfaceException.class.isAssignableFrom(scanClass)) { + return populate(exception, serviceName, (UniformInterfaceException) scan); + } + else if (ClientHandlerException.class.isAssignableFrom(scanClass)) { + state = 1; + } + else { + state = 0; + } + break; + + case 1: + if (ServiceException.class.isAssignableFrom(scanClass)) { + return populate(exception, serviceName, (ServiceException) scan); + } + else if (UniformInterfaceException.class.isAssignableFrom(scanClass)) { + return populate(exception, serviceName, (UniformInterfaceException) scan); + } + else if (SocketTimeoutException.class.isAssignableFrom(scanClass)) { + return populate(exception, serviceName, (SocketTimeoutException) scan); + } + else if (ClientHandlerException.class.isAssignableFrom(scanClass)) { + state = 1; + } + else { + state = 0; + } } } @@ -83,4 +142,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 026a4254de70b..e8de5bd31606e 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 @@ -31,6 +31,13 @@ public void register(Registry registry) { @Override public ClientConfig create(String profile, Builder builder, Map<String, Object> properties) { ClientConfig clientConfig = new DefaultClientConfig(); + // 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<String, Object> entry : properties.entrySet()) { Object propertyValue = entry.getValue(); diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/table/TableServiceIntegrationTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/table/TableServiceIntegrationTest.java index 05cc34eafae09..0faee5e7603ca 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/table/TableServiceIntegrationTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/table/TableServiceIntegrationTest.java @@ -29,6 +29,7 @@ import com.microsoft.windowsazure.services.core.ExponentialRetryPolicy; import com.microsoft.windowsazure.services.core.RetryPolicyFilter; import com.microsoft.windowsazure.services.core.ServiceException; +import com.microsoft.windowsazure.services.core.ServiceTimeoutException; import com.microsoft.windowsazure.services.table.models.BatchOperations; import com.microsoft.windowsazure.services.table.models.BatchResult; import com.microsoft.windowsazure.services.table.models.BatchResult.DeleteEntity; @@ -1155,8 +1156,11 @@ public void settingTimeoutWorks() throws Exception { service.queryTables(); fail("Exception should have been thrown"); } - catch (ServiceException ex) { - assertNotNull(ex.getCause()); + catch (ServiceTimeoutException ex) { + // No need to assert, test is if correct assertion type is thrown. + } + catch (Exception ex) { + fail("unexpected exception was thrown"); } finally { // Clean up timeouts, they interfere with other tests otherwise @@ -1179,8 +1183,11 @@ public void settingTimeoutFromStringWorks() throws Exception { service.queryTables(); fail("Exception should have been thrown"); } - catch (ServiceException ex) { - assertNotNull(ex.getCause()); + catch (ServiceTimeoutException ex) { + // No need to assert, test is if correct assertion type is thrown. + } + catch (Exception ex) { + fail("unexpected exception was thrown"); } finally { // Clean up timeouts, they interfere with other tests otherwise diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/utils/ServiceExceptionFactoryTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/utils/ServiceExceptionFactoryTest.java index 3cc8639eb849c..54c5b84aab75a 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/utils/ServiceExceptionFactoryTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/utils/ServiceExceptionFactoryTest.java @@ -2,25 +2,27 @@ * 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.utils; import static org.junit.Assert.*; import java.io.ByteArrayInputStream; +import java.net.SocketTimeoutException; import org.junit.Test; import com.microsoft.windowsazure.services.core.ServiceException; +import com.microsoft.windowsazure.services.core.ServiceTimeoutException; import com.microsoft.windowsazure.services.core.utils.ServiceExceptionFactory; import com.sun.jersey.api.client.ClientHandlerException; import com.sun.jersey.api.client.ClientResponse; @@ -31,11 +33,11 @@ public class ServiceExceptionFactoryTest { public void serviceNameAndMessageAndCauseAppearInException() { // Arrange ClientResponse response = new ClientResponse(404, null, new ByteArrayInputStream(new byte[0]), null); - UniformInterfaceException cause = new UniformInterfaceException( - response); + UniformInterfaceException cause = new UniformInterfaceException(response); // Act - ServiceException exception = ServiceExceptionFactory.process("testing", new ServiceException("this is a test", cause)); + ServiceException exception = ServiceExceptionFactory.process("testing", new ServiceException("this is a test", + cause)); // Assert assertNotNull(exception); @@ -48,11 +50,11 @@ public void serviceNameAndMessageAndCauseAppearInException() { public void httpStatusCodeAndReasonPhraseAppearInException() { // Arrange ClientResponse response = new ClientResponse(404, null, new ByteArrayInputStream(new byte[0]), null); - UniformInterfaceException cause = new UniformInterfaceException( - response); + UniformInterfaceException cause = new UniformInterfaceException(response); // Act - ServiceException exception = ServiceExceptionFactory.process("testing", new ServiceException("this is a test", cause)); + ServiceException exception = ServiceExceptionFactory.process("testing", new ServiceException("this is a test", + cause)); // Assert assertNotNull(exception); @@ -65,7 +67,8 @@ public void informationWillPassUpIfServiceExceptionIsRootCauseOfClientHandlerExc // Arrange ClientResponse response = new ClientResponse(503, null, new ByteArrayInputStream(new byte[0]), null); UniformInterfaceException rootCause = new UniformInterfaceException(response); - ServiceException originalDescription = ServiceExceptionFactory.process("underlying", new ServiceException(rootCause)); + ServiceException originalDescription = ServiceExceptionFactory.process("underlying", new ServiceException( + rootCause)); ClientHandlerException wrappingException = new ClientHandlerException(originalDescription); // Act @@ -76,4 +79,17 @@ public void informationWillPassUpIfServiceExceptionIsRootCauseOfClientHandlerExc assertEquals("underlying", exception.getServiceName()); } + @Test + public void socketTimeoutWillPassUpIfInsideClientHandlerException() { + String expectedMessage = "connect timeout"; + SocketTimeoutException rootCause = new SocketTimeoutException(expectedMessage); + ClientHandlerException wrappingException = new ClientHandlerException(rootCause); + + ServiceException exception = ServiceExceptionFactory + .process("testing", new ServiceException(wrappingException)); + + assertSame(ServiceTimeoutException.class, exception.getClass()); + assertEquals(expectedMessage, exception.getMessage()); + assertEquals("testing", exception.getServiceName()); + } } From 43b8223e41819368fff6a90648b5c352d348abfb Mon Sep 17 00:00:00 2001 From: Albert Cheng <gongchen@microsoft.com> Date: Thu, 27 Sep 2012 11:46:52 -0700 Subject: [PATCH 61/70] Expose AssetInfo Date as Date. --- .../implementation/content/AssetType.java | 5 +++-- .../services/media/models/AssetInfo.java | 19 ++++++++++--------- .../services/media/models/AssetInfoTest.java | 17 ++++------------- 3 files changed, 17 insertions(+), 24 deletions(-) diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/AssetType.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/AssetType.java index 84f5b353785ab..9d48dfd71a29a 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/AssetType.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/AssetType.java @@ -20,6 +20,7 @@ import javax.xml.bind.annotation.XmlElement; import javax.xml.datatype.XMLGregorianCalendar; +import com.microsoft.windowsazure.services.core.utils.DateConverter; import com.microsoft.windowsazure.services.media.models.AssetInfo; /** @@ -159,9 +160,9 @@ public void setOptions(int options) { public static AssetType create(AssetInfo assetInfo) { AssetType assetType = new AssetType(); assetType.setAlternateId(assetInfo.getAlternateId()); - assetType.setCreated(assetInfo.getCreated()); + assetType.setCreated(DateConverter.DateToXMLGregorianCalendar(assetInfo.getCreated())); assetType.setId(assetInfo.getId()); - assetType.setLastModified(assetInfo.getLastModified()); + assetType.setLastModified(DateConverter.DateToXMLGregorianCalendar(assetInfo.getLastModified())); assetType.setName(assetInfo.getName()); assetType.setOptions(assetInfo.getOptions().getCode()); assetType.setState(assetInfo.getState().getCode()); diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AssetInfo.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AssetInfo.java index 68a1c9058cf81..736c2366a7d4b 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AssetInfo.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AssetInfo.java @@ -15,8 +15,9 @@ package com.microsoft.windowsazure.services.media.models; -import javax.xml.datatype.XMLGregorianCalendar; +import java.util.Date; +import com.microsoft.windowsazure.services.core.utils.DateConverter; import com.microsoft.windowsazure.services.media.implementation.ODataEntity; import com.microsoft.windowsazure.services.media.implementation.atom.EntryType; import com.microsoft.windowsazure.services.media.implementation.content.AssetType; @@ -103,8 +104,8 @@ public AssetInfo setState(AssetState state) { * * @return the date */ - public XMLGregorianCalendar getCreated() { - return this.getContent().getCreated(); + public Date getCreated() { + return DateConverter.XMLGregorianCalendarToDate(this.getContent().getCreated()); } /** @@ -114,8 +115,8 @@ public XMLGregorianCalendar getCreated() { * the date * @return the asset info */ - public AssetInfo setCreated(XMLGregorianCalendar created) { - getContent().setCreated(created); + public AssetInfo setCreated(Date created) { + getContent().setCreated(DateConverter.DateToXMLGregorianCalendar(created)); return this; } @@ -124,8 +125,8 @@ public AssetInfo setCreated(XMLGregorianCalendar created) { * * @return the date */ - public XMLGregorianCalendar getLastModified() { - return getContent().getLastModified(); + public Date getLastModified() { + return DateConverter.XMLGregorianCalendarToDate(getContent().getLastModified()); } /** @@ -135,8 +136,8 @@ public XMLGregorianCalendar getLastModified() { * the date * @return the asset info */ - public AssetInfo setLastModified(XMLGregorianCalendar lastModified) { - getContent().setLastModified(lastModified); + public AssetInfo setLastModified(Date lastModified) { + getContent().setLastModified(DateConverter.DateToXMLGregorianCalendar(lastModified)); return this; } diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/AssetInfoTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/AssetInfoTest.java index a1b33f825fa46..2e974c81773c9 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/AssetInfoTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/AssetInfoTest.java @@ -17,10 +17,6 @@ import static org.junit.Assert.*; import java.util.Date; -import java.util.GregorianCalendar; - -import javax.xml.datatype.DatatypeFactory; -import javax.xml.datatype.XMLGregorianCalendar; import org.junit.Test; @@ -56,14 +52,12 @@ public void testGetSetState() { @Test public void testGetSetCreated() throws Exception { // Arrange - GregorianCalendar c = new GregorianCalendar(); - c.setTime(new Date()); - XMLGregorianCalendar expectedCreated = DatatypeFactory.newInstance().newXMLGregorianCalendar(c); + Date expectedCreated = new Date(); AssetInfo assetInfo = new AssetInfo(); // Act - XMLGregorianCalendar actualCreated = assetInfo.setCreated(expectedCreated).getCreated(); + Date actualCreated = assetInfo.setCreated(expectedCreated).getCreated(); // Assert assertEquals(expectedCreated, actualCreated); @@ -73,14 +67,11 @@ public void testGetSetCreated() throws Exception { @Test public void testGetSetLastModified() throws Exception { // Arrange - - GregorianCalendar c = new GregorianCalendar(); - c.setTime(new Date()); - XMLGregorianCalendar expectedLastModified = DatatypeFactory.newInstance().newXMLGregorianCalendar(c); + Date expectedLastModified = new Date(); AssetInfo assetInfo = new AssetInfo(); // Act - XMLGregorianCalendar actualLastModified = assetInfo.setLastModified(expectedLastModified).getLastModified(); + Date actualLastModified = assetInfo.setLastModified(expectedLastModified).getLastModified(); // Assert assertEquals(expectedLastModified, actualLastModified); From b93edab6083594e88853e3fa3c5e7d5c136f61bd Mon Sep 17 00:00:00 2001 From: Albert Cheng <gongchen@microsoft.com> Date: Thu, 27 Sep 2012 11:48:09 -0700 Subject: [PATCH 62/70] Add DateConverter to transform XMLGregorianCalendar back and forth. --- .../services/core/utils/DateConverter.java | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/utils/DateConverter.java 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 0000000000000..60c99c6edc810 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/utils/DateConverter.java @@ -0,0 +1,72 @@ +/** + * 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 + * + * 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); + } +} From 22ad696828f282a691df08418ee078fb2c1c93e4 Mon Sep 17 00:00:00 2001 From: Albert Cheng <gongchen@microsoft.com> Date: Thu, 27 Sep 2012 11:51:29 -0700 Subject: [PATCH 63/70] fix the year in the license. --- .../windowsazure/services/core/utils/DateConverter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index 60c99c6edc810..ee00445cf6b61 100644 --- 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 @@ -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. From 45cec57ca38afbb076e9fd04d0306e7bcb3ee911 Mon Sep 17 00:00:00 2001 From: Chris Tavares <ctavares@microsoft.com> Date: Thu, 27 Sep 2012 12:45:29 -0700 Subject: [PATCH 64/70] Code review feedback applied --- .../core/ServiceTimeoutException.java | 21 ++++-- .../core/utils/ServiceExceptionFactory.java | 68 +++---------------- 2 files changed, 25 insertions(+), 64 deletions(-) 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 index 6de101f3d93d3..9c3c5f7fcd134 100644 --- 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 @@ -1,6 +1,18 @@ /** + * 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; /** @@ -11,13 +23,13 @@ public class ServiceTimeoutException extends ServiceException { private static final long serialVersionUID = 6612846403178749361L; /** - * Construct a ServiceTimeoutException instance + * Construct a ServiceTimeoutException instance with default parameters. */ public ServiceTimeoutException() { } /** - * Construct a ServiceTimeoutException instance + * Construct a ServiceTimeoutException instance with the specified message. * * @param message * Exception message @@ -27,7 +39,8 @@ public ServiceTimeoutException(String message) { } /** - * Construct a ServiceTimeoutException instance + * Construct a ServiceTimeoutException instance with specified + * message and cause * * @param message * Exception message @@ -39,7 +52,7 @@ public ServiceTimeoutException(String message, Throwable cause) { } /** - * Construct a ServiceTimeoutException instance + * Construct a ServiceTimeoutException instance with the specified cause. * * @param cause * Exception that caused this exception to occur 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 dd593322c2073..d11feceb6d20b 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 @@ -18,7 +18,6 @@ import com.microsoft.windowsazure.services.core.ServiceException; import com.microsoft.windowsazure.services.core.ServiceTimeoutException; -import com.sun.jersey.api.client.ClientHandlerException; import com.sun.jersey.api.client.ClientResponse; import com.sun.jersey.api.client.ClientResponse.Status; import com.sun.jersey.api.client.UniformInterfaceException; @@ -26,69 +25,18 @@ public class ServiceExceptionFactory { public static ServiceException process(String serviceName, ServiceException exception) { - // State machine for figuring out what to do with the exception - // - // Input is the type of the current exception cause. - // FSM starts in state 0. - // - // State | Input | New State | Action - //--------------------------------------------------------------------------- - // 0 | ServiceException | None | populate and return - // | | | - // 0 | UniformInterfaceException | None | populate and return - // | | | - // 0 | ClientHandlerException | 1 | None - // | | | - // 0 | Any other | 0 | None - // | | | - // 1 | ServiceException | None | populate and return - // | | | - // 1 | UniformInterfaceException | None | populate and return - // | | | - // 1 | ClientHandlerException | 1 | None - // | | | - // 1 | SocketTimeoutException | None | populate and return - // | | | - // 1 | Any other | 0 | None - - int state = 0; Throwable cause = exception.getCause(); for (Throwable scan = cause; scan != null; scan = scan.getCause()) { Class scanClass = scan.getClass(); - - switch (state) { - case 0: - if (ServiceException.class.isAssignableFrom(scanClass)) { - return populate(exception, serviceName, (ServiceException) scan); - } - else if (UniformInterfaceException.class.isAssignableFrom(scanClass)) { - return populate(exception, serviceName, (UniformInterfaceException) scan); - } - else if (ClientHandlerException.class.isAssignableFrom(scanClass)) { - state = 1; - } - else { - state = 0; - } - break; - - case 1: - if (ServiceException.class.isAssignableFrom(scanClass)) { - return populate(exception, serviceName, (ServiceException) scan); - } - else if (UniformInterfaceException.class.isAssignableFrom(scanClass)) { - return populate(exception, serviceName, (UniformInterfaceException) scan); - } - else if (SocketTimeoutException.class.isAssignableFrom(scanClass)) { - return populate(exception, serviceName, (SocketTimeoutException) scan); - } - else if (ClientHandlerException.class.isAssignableFrom(scanClass)) { - state = 1; - } - else { - state = 0; - } + if (ServiceException.class.isAssignableFrom(scanClass)) { + return populate(exception, serviceName, (ServiceException) scan); + } + else if (UniformInterfaceException.class.isAssignableFrom(scanClass)) { + return populate(exception, serviceName, (UniformInterfaceException) scan); + } + else if (SocketTimeoutException.class.isAssignableFrom(scanClass)) { + return populate(exception, serviceName, (SocketTimeoutException) scan); } } From ab94bb7d7771fa374075aad307fa35f66c1472e4 Mon Sep 17 00:00:00 2001 From: Chris Tavares <ctavares@microsoft.com> Date: Thu, 27 Sep 2012 14:07:53 -0700 Subject: [PATCH 65/70] Using sdk specific timeout property string, rather than Jersey's. Fixed issues with prefixed client creates. --- .../services/core/Configuration.java | 10 +++++ .../services/core/utils/pipeline/Exports.java | 29 +++++++++++-- .../table/TableServiceIntegrationTest.java | 43 +++++++++++++++---- .../com.microsoft.windowsazure.properties | 4 +- 4 files changed, 73 insertions(+), 13 deletions(-) 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 67f30dfe880e4..e5afff9047a29 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 @@ -25,6 +25,16 @@ 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<String, Object> properties; Builder builder; 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 e8de5bd31606e..d5b9ddc05ce9f 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,6 +32,8 @@ public void register(Registry registry) { @Override public ClientConfig create(String profile, Builder builder, Map<String, Object> 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 @@ -40,18 +43,26 @@ public ClientConfig create(String profile, Builder builder, Map<String, Object> for (Entry<String, Object> entry : properties.entrySet()) { 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 (entry.getKey().equals(ClientConfig.PROPERTY_CONNECT_TIMEOUT) - || entry.getKey().equals(ClientConfig.PROPERTY_READ_TIMEOUT)) { + 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(entry.getKey(), propertyValue); + clientConfig.getProperties().put(propertyKey, propertyValue); } return clientConfig; } @@ -76,4 +87,16 @@ public HttpURLConnectionClient create(String profile, Builder builder, Map<Strin } }); } + + private static String normalizeProfile(String profile) { + if (profile == null) { + return ""; + } + + if (profile.endsWith(".")) { + return profile; + } + + return profile + "."; + } } diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/table/TableServiceIntegrationTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/table/TableServiceIntegrationTest.java index 0faee5e7603ca..74fdd4d911499 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/table/TableServiceIntegrationTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/table/TableServiceIntegrationTest.java @@ -48,7 +48,6 @@ import com.microsoft.windowsazure.services.table.models.QueryTablesResult; import com.microsoft.windowsazure.services.table.models.ServiceProperties; import com.microsoft.windowsazure.services.table.models.TableEntry; -import com.sun.jersey.api.client.config.ClientConfig; public class TableServiceIntegrationTest extends IntegrationTestBase { private static final String testTablesPrefix = "sdktest"; @@ -1147,8 +1146,8 @@ public void settingTimeoutWorks() throws Exception { Configuration config = createConfiguration(); // Set timeout to very short to force failure - config.setProperty(ClientConfig.PROPERTY_CONNECT_TIMEOUT, new Integer(1)); - config.setProperty(ClientConfig.PROPERTY_READ_TIMEOUT, new Integer(1)); + config.setProperty(Configuration.PROPERTY_CONNECT_TIMEOUT, new Integer(1)); + config.setProperty(Configuration.PROPERTY_READ_TIMEOUT, new Integer(1)); TableContract service = TableService.create(config); @@ -1164,8 +1163,8 @@ public void settingTimeoutWorks() throws Exception { } finally { // Clean up timeouts, they interfere with other tests otherwise - config.getProperties().remove(ClientConfig.PROPERTY_CONNECT_TIMEOUT); - config.getProperties().remove(ClientConfig.PROPERTY_READ_TIMEOUT); + config.getProperties().remove(Configuration.PROPERTY_CONNECT_TIMEOUT); + config.getProperties().remove(Configuration.PROPERTY_READ_TIMEOUT); } } @@ -1174,8 +1173,8 @@ public void settingTimeoutFromStringWorks() throws Exception { Configuration config = createConfiguration(); // Set timeout to very short to force failure - config.setProperty(ClientConfig.PROPERTY_CONNECT_TIMEOUT, "1"); - config.setProperty(ClientConfig.PROPERTY_READ_TIMEOUT, "1"); + config.setProperty(Configuration.PROPERTY_CONNECT_TIMEOUT, "1"); + config.setProperty(Configuration.PROPERTY_READ_TIMEOUT, "1"); TableContract service = TableService.create(config); @@ -1191,8 +1190,34 @@ public void settingTimeoutFromStringWorks() throws Exception { } finally { // Clean up timeouts, they interfere with other tests otherwise - config.getProperties().remove(ClientConfig.PROPERTY_CONNECT_TIMEOUT); - config.getProperties().remove(ClientConfig.PROPERTY_READ_TIMEOUT); + config.getProperties().remove(Configuration.PROPERTY_CONNECT_TIMEOUT); + config.getProperties().remove(Configuration.PROPERTY_READ_TIMEOUT); } } + + @Test + public void settingTimeoutPrefixedFromConfigWorks() throws Exception { + Configuration config = createConfiguration(); + + TableContract service = TableService.create("testprefix", config); + + try { + service.queryTables(); + fail("Exception should have been thrown"); + } + catch (ServiceTimeoutException ex) { + // No need to assert, test is if correct assertion type is thrown. + } + catch (Exception ex) { + fail("unexpected exception was thrown"); + } + } + + @Test + public void prefixedTimeoutsGetLoaded() throws Exception { + Configuration config = createConfiguration(); + + assertEquals("3", config.getProperty("testprefix." + Configuration.PROPERTY_CONNECT_TIMEOUT)); + assertEquals("7", config.getProperty("testprefix." + Configuration.PROPERTY_READ_TIMEOUT)); + } } diff --git a/microsoft-azure-api/src/test/resources/META-INF/com.microsoft.windowsazure.properties b/microsoft-azure-api/src/test/resources/META-INF/com.microsoft.windowsazure.properties index 7739acd3e7333..5685b680eab64 100644 --- a/microsoft-azure-api/src/test/resources/META-INF/com.microsoft.windowsazure.properties +++ b/microsoft-azure-api/src/test/resources/META-INF/com.microsoft.windowsazure.properties @@ -10,4 +10,6 @@ queue.accountKey=%QUEUE_ACCOUNTKEY% queue.uri=http://%QUEUE_ACCOUNTNAME%.queue.core.windows.net table.accountName=%TABLE_ACCOUNTNAME% table.accountKey=%TABLE_ACCOUNTKEY% -table.uri=http://%TABLE_ACCOUNTNAME%.table.core.windows.net \ No newline at end of file +table.uri=http://%TABLE_ACCOUNTNAME%.table.core.windows.net +testprefix.com.microsoft.windowsazure.services.core.Configuration.connectTimeout=3 +testprefix.com.microsoft.windowsazure.services.core.Configuration.readTimeout=7 From 509b321391e675b4e40007cfa2ab424c494ae20e Mon Sep 17 00:00:00 2001 From: Albert Cheng <gongchen@microsoft.com> Date: Thu, 27 Sep 2012 15:43:30 -0700 Subject: [PATCH 66/70] minor clean up of the code. --- .../windowsazure/services/media/models/UpdateAssetOptions.java | 1 - 1 file changed, 1 deletion(-) diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/UpdateAssetOptions.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/UpdateAssetOptions.java index 74b4a51e4daf7..dd0affeac070e 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/UpdateAssetOptions.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/UpdateAssetOptions.java @@ -14,7 +14,6 @@ */ package com.microsoft.windowsazure.services.media.models; -// TODO: Auto-generated Javadoc /** * The Class UpdateAssetOptions. */ From 70a1cdd693b380c97a250ccb553aecccf02cc240 Mon Sep 17 00:00:00 2001 From: Chris Tavares <ctavares@microsoft.com> Date: Tue, 7 Aug 2012 13:44:26 -0700 Subject: [PATCH 67/70] Fixing client tests so they pull credentials from env vars --- .../windowsazure/services/blob/client/BlobTestBase.java | 6 +++++- .../windowsazure/services/queue/client/QueueTestBase.java | 6 +++++- .../windowsazure/services/table/client/TableTestBase.java | 6 +++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/blob/client/BlobTestBase.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/blob/client/BlobTestBase.java index bd0671e3ece19..938db64c06d4a 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/blob/client/BlobTestBase.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/blob/client/BlobTestBase.java @@ -51,7 +51,11 @@ public static void setup() throws URISyntaxException, StorageException, InvalidK httpAcc = CloudStorageAccount.getDevelopmentStorageAccount(); } else { - httpAcc = CloudStorageAccount.parse(CLOUD_ACCOUNT_HTTP); + String cloudAccount = CLOUD_ACCOUNT_HTTP; + cloudAccount = cloudAccount.replace("[ACCOUNT NAME]", System.getenv("blob.accountName")); + cloudAccount = cloudAccount.replace("[ACCOUNT KEY]", System.getenv("blob.accountKey")); + + httpAcc = CloudStorageAccount.parse(cloudAccount); } bClient = httpAcc.createCloudBlobClient(); diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/queue/client/QueueTestBase.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/queue/client/QueueTestBase.java index feb5b1ceb4a10..8144378d8577b 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/queue/client/QueueTestBase.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/queue/client/QueueTestBase.java @@ -52,7 +52,11 @@ public static void setup() throws URISyntaxException, StorageException, InvalidK httpAcc = CloudStorageAccount.getDevelopmentStorageAccount(); } else { - httpAcc = CloudStorageAccount.parse(CLOUD_ACCOUNT_HTTP); + String cloudAccount = CLOUD_ACCOUNT_HTTP; + cloudAccount = cloudAccount.replace("[ACCOUNT NAME]", System.getenv("queue.accountName")); + cloudAccount = cloudAccount.replace("[ACCOUNT KEY]", System.getenv("queue.accountKey")); + + httpAcc = CloudStorageAccount.parse(cloudAccount); } qClient = httpAcc.createCloudQueueClient(); diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/table/client/TableTestBase.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/table/client/TableTestBase.java index d235ed326cc69..7ba57b75322c8 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/table/client/TableTestBase.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/table/client/TableTestBase.java @@ -577,7 +577,11 @@ public static void setup() throws URISyntaxException, StorageException, InvalidK httpAcc = CloudStorageAccount.getDevelopmentStorageAccount(); } else { - httpAcc = CloudStorageAccount.parse(CLOUD_ACCOUNT_HTTP); + String cloudAccount = CLOUD_ACCOUNT_HTTP; + cloudAccount = cloudAccount.replace("[ACCOUNT NAME]", System.getenv("table.accountName")); + cloudAccount = cloudAccount.replace("[ACCOUNT KEY]", System.getenv("table.accountKey")); + + httpAcc = CloudStorageAccount.parse(cloudAccount); } bClient = httpAcc.createCloudBlobClient(); From 9b929240adfe408946c45773940825f32b46a8d2 Mon Sep 17 00:00:00 2001 From: Chris Tavares <ctavares@microsoft.com> Date: Mon, 1 Oct 2012 12:22:40 -0700 Subject: [PATCH 68/70] Access policy crud implementation --- .../services/media/MediaContract.java | 66 ++++++++ .../MediaExceptionProcessor.java | 98 ++++++++++++ .../media/implementation/MediaRestProxy.java | 100 ++++++++++-- .../implementation/ODataAtomMarshaller.java | 2 + .../content/AccessPolicyType.java | 145 ++++++++++++++++++ .../implementation/content/ObjectFactory.java | 9 ++ .../media/models/AccessPolicyInfo.java | 74 +++++++++ .../models/CreateAccessPolicyOptions.java | 41 +++++ .../media/models/ListAccessPolicyOptions.java | 24 +++ .../media/AccessPolicyIntegrationTest.java | 117 ++++++++++++++ .../ODataSerializationFromJerseyTest.java | 1 + .../media/models/AccessPolicyInfoTest.java | 86 +++++++++++ 12 files changed, 747 insertions(+), 16 deletions(-) create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/AccessPolicyType.java create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AccessPolicyInfo.java create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/CreateAccessPolicyOptions.java create mode 100644 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/ListAccessPolicyOptions.java create mode 100644 microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/AccessPolicyIntegrationTest.java create mode 100644 microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/AccessPolicyInfoTest.java 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 7dfa4844ad837..cd0b1c90560b0 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 @@ -18,8 +18,11 @@ 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; @@ -99,4 +102,67 @@ public interface MediaContract extends FilterableService<MediaContract> { */ public void updateAsset(String assetId, UpdateAssetOptions updateAssetOptions) throws ServiceException; + /** + * Create the access policy + * + * @param name + * name of access policy + * @param durationInMinutes + * duration access policy is active + * @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 access policy is active + * @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<AccessPolicyInfo> listAccessPolicies() throws ServiceException; + + /** + * List access policies + * + * @param options + * the list access policy options + * @return the list + * @throws ServiceException + */ + List<AccessPolicyInfo> listAccessPolicies(ListAccessPolicyOptions options) throws ServiceException; } 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 9af373b2ae08d..314111bc50b34 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 @@ -26,8 +26,11 @@ 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; @@ -199,4 +202,99 @@ public void updateAsset(String assetId, UpdateAssetOptions updateAssetOptions) t } } + /* (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<AccessPolicyInfo> 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<AccessPolicyInfo> 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 eb060a973833f..3ba10b301cd79 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 @@ -31,9 +31,14 @@ 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; @@ -134,6 +139,27 @@ 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> T mergeRequest(String path, java.lang.Class<T> 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) */ @@ -229,26 +255,68 @@ public void deleteAsset(String assetId) throws ServiceException { getResource("Assets", assetId).delete(); } - 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); + /* (non-Javadoc) + * @see com.microsoft.windowsazure.services.media.MediaContract#createAccessPolicy(double) + */ + @Override + public AccessPolicyInfo createAccessPolicy(String name, double durationInMinutes) throws ServiceException { + CreateAccessPolicyOptions options = new CreateAccessPolicyOptions(); + options.getPermissions().add(AccessPolicyPermission.WRITE); + return createAccessPolicy(name, durationInMinutes, options); + } - return getResource(entityPath); + /* (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 { + + 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); } - private <T> T mergeRequest(String path, java.lang.Class<T> 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#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<AccessPolicyInfo> listAccessPolicies() throws ServiceException { + WebResource resource = getResource("AccessPolicies"); + + return resource.type(MediaType.APPLICATION_ATOM_XML).accept(MediaType.APPLICATION_ATOM_XML) + .get(new GenericType<List<AccessPolicyInfo>>() { + }); + } + + /* (non-Javadoc) + * @see com.microsoft.windowsazure.services.media.MediaContract#listAccessPolicies() + */ + @Override + public List<AccessPolicyInfo> listAccessPolicies(ListAccessPolicyOptions options) throws ServiceException { + // Currently no options defined so can call zero arg overload instead + return listAccessPolicies(); + } } 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 index 2556c510a5ff2..13edb3b00de50 100644 --- 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 @@ -33,6 +33,7 @@ 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; @@ -114,6 +115,7 @@ private static Class<?>[] getMarshalledClasses() { 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/content/AccessPolicyType.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/AccessPolicyType.java new file mode 100644 index 0000000000000..219a65b668f16 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/AccessPolicyType.java @@ -0,0 +1,145 @@ +/** + * 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.content; + +import java.util.Date; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; + +/** + * Wrapper DTO for Media Services access policies. + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +public class AccessPolicyType implements MediaServiceDTO { + + @XmlElement(name = "Id", namespace = Constants.ODATA_DATA_NS) + protected String id; + + @XmlElement(name = "Created", namespace = Constants.ODATA_DATA_NS) + protected Date created; + + @XmlElement(name = "LastModified", namespace = Constants.ODATA_DATA_NS) + protected Date lastModified; + + @XmlElement(name = "Name", namespace = Constants.ODATA_DATA_NS) + protected String name; + + @XmlElement(name = "DurationInMinutes", namespace = Constants.ODATA_DATA_NS) + protected double durationInMinutes; + + @XmlElement(name = "Permissions", namespace = Constants.ODATA_DATA_NS) + protected int permissions; + + /** + * @return the id + */ + public String getId() { + return id; + } + + /** + * @param id + * the id to set + */ + public AccessPolicyType setId(String id) { + this.id = id; + return this; + } + + /** + * @return the created + */ + public Date getCreated() { + return created; + } + + /** + * @param created + * the created to set + */ + public AccessPolicyType setCreated(Date created) { + this.created = created; + return this; + } + + /** + * @return the lastModified + */ + public Date getLastModified() { + return lastModified; + } + + /** + * @param lastModified + * the lastModified to set + */ + public AccessPolicyType setLastModified(Date lastModified) { + this.lastModified = lastModified; + return this; + } + + /** + * @return the name + */ + public String getName() { + return name; + } + + /** + * @param name + * the name to set + */ + public AccessPolicyType setName(String name) { + this.name = name; + return this; + } + + /** + * @return the durationInMinutes + */ + public double getDurationInMinutes() { + return durationInMinutes; + } + + /** + * @param durationInMinutes + * the durationInMinutes to set + */ + public AccessPolicyType setDurationInMinutes(double durationInMinutes) { + this.durationInMinutes = durationInMinutes; + return this; + } + + /** + * @return the permissions + */ + public int getPermissions() { + return permissions; + } + + /** + * @param permissions + * the permissions to set + */ + public AccessPolicyType setPermissions(int permissions) { + this.permissions = permissions; + return this; + } + +} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/ObjectFactory.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/ObjectFactory.java index d353a7d006964..09cc9f513adba 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/ObjectFactory.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/ObjectFactory.java @@ -49,4 +49,13 @@ public AssetType createAssetType() { public ODataActionType createODataActionType() { return new ODataActionType(); } + + /** + * Create an instance of {@link AccessPolicyType } + * + * @return a new AccessPolicyType instance. + */ + public AccessPolicyType createAccessPolicyType() { + return new AccessPolicyType(); + } } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AccessPolicyInfo.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AccessPolicyInfo.java new file mode 100644 index 0000000000000..50213d4503654 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AccessPolicyInfo.java @@ -0,0 +1,74 @@ +package com.microsoft.windowsazure.services.media.models; + +import java.util.Date; +import java.util.EnumSet; + +import com.microsoft.windowsazure.services.media.implementation.ODataEntity; +import com.microsoft.windowsazure.services.media.implementation.atom.EntryType; +import com.microsoft.windowsazure.services.media.implementation.content.AccessPolicyType; + +public class AccessPolicyInfo extends ODataEntity<AccessPolicyType> { + + public AccessPolicyInfo(EntryType entry, AccessPolicyType content) { + super(entry, content); + // TODO Auto-generated constructor stub + } + + public AccessPolicyInfo() { + super(new AccessPolicyType()); + } + + public String getId() { + return getContent().getId(); + } + + public AccessPolicyInfo setId(String id) { + getContent().setId(id); + return this; + } + + public Date getCreated() { + return getContent().getCreated(); + } + + public AccessPolicyInfo setCreated(Date created) { + getContent().setCreated(created); + return this; + } + + public Date getLastModified() { + return getContent().getLastModified(); + } + + public AccessPolicyInfo setLastModified(Date lastModified) { + getContent().setLastModified(lastModified); + return this; + } + + public String getName() { + return getContent().getName(); + } + + public AccessPolicyInfo setName(String name) { + getContent().setName(name); + return this; + } + + public double getDurationInMinutes() { + return getContent().getDurationInMinutes(); + } + + public AccessPolicyInfo setDurationInMinutes(double durationInMinutes) { + getContent().setDurationInMinutes(durationInMinutes); + return this; + } + + public EnumSet<AccessPolicyPermission> getPermissions() { + return AccessPolicyPermission.permissionsFromBits(getContent().getPermissions()); + } + + public AccessPolicyInfo setPermissions(EnumSet<AccessPolicyPermission> permissions) { + getContent().setPermissions(AccessPolicyPermission.bitsFromPermissions(permissions)); + return this; + } +} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/CreateAccessPolicyOptions.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/CreateAccessPolicyOptions.java new file mode 100644 index 0000000000000..d5e4cb87ee0c6 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/CreateAccessPolicyOptions.java @@ -0,0 +1,41 @@ +package com.microsoft.windowsazure.services.media.models; + +import java.util.EnumSet; + +public class CreateAccessPolicyOptions { + private final EnumSet<AccessPolicyPermission> permissions = EnumSet.noneOf(AccessPolicyPermission.class); + + public CreateAccessPolicyOptions() { + } + + /** + * Returns a live pointer to the underlying permissions set. + * + * @return the permissions + */ + public EnumSet<AccessPolicyPermission> getPermissions() { + return permissions; + } + + /** + * Add the given permissions to this creation request + * + * @param permissionsToAdd + * @return the CreateAccessPolicyOptions object + */ + public CreateAccessPolicyOptions addPermissions(EnumSet<AccessPolicyPermission> permissionsToAdd) { + permissions.addAll(permissionsToAdd); + return this; + } + + /** + * Remove the given permissions from this creation request + * + * @param permissionsToRemove + * @return the CreateAccessPolicyOptions object + */ + public CreateAccessPolicyOptions removePermissions(EnumSet<AccessPolicyPermission> permissionsToRemove) { + permissions.removeAll(permissionsToRemove); + return this; + } +} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/ListAccessPolicyOptions.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/ListAccessPolicyOptions.java new file mode 100644 index 0000000000000..2327574c985bc --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/ListAccessPolicyOptions.java @@ -0,0 +1,24 @@ +/** + * 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.models; + +/** + * Options class for listing access policies + * No options available at this time. + */ +public class ListAccessPolicyOptions { + +} diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/AccessPolicyIntegrationTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/AccessPolicyIntegrationTest.java new file mode 100644 index 0000000000000..2dea4f4e4d86b --- /dev/null +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/AccessPolicyIntegrationTest.java @@ -0,0 +1,117 @@ +/** + * 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 + * + * 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; + +import static org.junit.Assert.*; + +import java.util.EnumSet; +import java.util.List; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +import com.microsoft.windowsazure.services.core.Configuration; +import com.microsoft.windowsazure.services.media.models.AccessPolicyInfo; +import com.microsoft.windowsazure.services.media.models.AccessPolicyPermission; +import com.microsoft.windowsazure.services.media.models.CreateAccessPolicyOptions; + +public class AccessPolicyIntegrationTest extends IntegrationTestBase { + private static MediaContract service; + + @BeforeClass + public static void setup() throws Exception { + service = MediaService.create(createConfig()); + } + + private static Configuration createConfig() { + Configuration config = Configuration.getInstance(); + overrideWithEnv(config, MediaConfiguration.URI); + overrideWithEnv(config, MediaConfiguration.OAUTH_URI); + overrideWithEnv(config, MediaConfiguration.OAUTH_CLIENT_ID); + overrideWithEnv(config, MediaConfiguration.OAUTH_CLIENT_SECRET); + overrideWithEnv(config, MediaConfiguration.OAUTH_SCOPE); + return config; + } + + @AfterClass + public static void cleanup() throws Exception { + for (AccessPolicyInfo policy : service.listAccessPolicies()) { + if (policy.getName().startsWith("testPolicy")) { + service.deleteAccessPolicy(policy.getId()); + } + } + } + + @Test + public void canCreateAccessPolicy() throws Exception { + AccessPolicyInfo policy = service.createAccessPolicy("testPolicy", 5, + new CreateAccessPolicyOptions().addPermissions(EnumSet.of(AccessPolicyPermission.WRITE))); + + assertTrue(policy.getPermissions().contains(AccessPolicyPermission.WRITE)); + } + + @Test + public void canGetSinglePolicyById() throws Exception { + String expectedName = "testPolicyGetOne"; + AccessPolicyInfo policyToGet = service.createAccessPolicy(expectedName, 1); + + AccessPolicyInfo retrievedPolicy = service.getAccessPolicy(policyToGet.getId()); + + assertEquals(expectedName, retrievedPolicy.getName()); + assertEquals(policyToGet.getId(), retrievedPolicy.getId()); + } + + @Test + public void canRetrieveListOfAccessPolicies() throws Exception { + String[] policyNames = new String[] { "testPolicy1", "testPolicy2" }; + for (String name : policyNames) { + service.createAccessPolicy(name, 3, new CreateAccessPolicyOptions().addPermissions(EnumSet.of( + AccessPolicyPermission.WRITE, AccessPolicyPermission.LIST))); + } + + List<AccessPolicyInfo> policies = service.listAccessPolicies(); + + assertNotNull(policies); + assertTrue(policies.size() >= 2); + + AccessPolicyInfo policy1 = null; + AccessPolicyInfo policy2 = null; + + for (AccessPolicyInfo policy : policies) { + if (policy.getName().equals("testPolicy1")) { + policy1 = policy; + } + if (policy.getName().equals("testPolicy2")) { + policy2 = policy; + } + } + + assertNotNull(policy1); + assertNotNull(policy2); + } + + @Test + public void canDeleteAccessPolicyById() throws Exception { + AccessPolicyInfo policyToDelete = service.createAccessPolicy("testPolicyToDelete", 1); + + service.deleteAccessPolicy(policyToDelete.getId()); + + for (AccessPolicyInfo policy : service.listAccessPolicies()) { + assertFalse(policyToDelete.getId().equals(policy.getId())); + } + } +} diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/implementation/ODataSerializationFromJerseyTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/implementation/ODataSerializationFromJerseyTest.java index 53c67ba9798bb..84a8d66b47d20 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/implementation/ODataSerializationFromJerseyTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/implementation/ODataSerializationFromJerseyTest.java @@ -101,4 +101,5 @@ public void canRetrieveListOfAssets() throws Exception { Assert.assertNotNull(assets); } + } diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/AccessPolicyInfoTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/AccessPolicyInfoTest.java new file mode 100644 index 0000000000000..c18e9a5297c56 --- /dev/null +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/AccessPolicyInfoTest.java @@ -0,0 +1,86 @@ +/** + * 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.models; + +import java.util.Date; +import java.util.EnumSet; + +import org.junit.Assert; +import org.junit.Test; + +public class AccessPolicyInfoTest { + + @Test + public void getSetId() { + AccessPolicyInfo policy = new AccessPolicyInfo(); + String expected = "expectedId"; + + String actual = policy.setId(expected).getId(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void getSetCreated() { + AccessPolicyInfo policy = new AccessPolicyInfo(); + Date expected = new Date(); + + Date actual = policy.setCreated(expected).getCreated(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void getSetLastModified() { + AccessPolicyInfo policy = new AccessPolicyInfo(); + Date expected = new Date(); + + Date actual = policy.setLastModified(expected).getLastModified(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void getSetName() { + AccessPolicyInfo policy = new AccessPolicyInfo(); + String expected = "policy name goes here"; + + String actual = policy.setName(expected).getName(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void getSetDurationInMinutes() { + AccessPolicyInfo policy = new AccessPolicyInfo(); + double expected = 60; // arbitrary value + + double actual = policy.setDurationInMinutes(expected).getDurationInMinutes(); + + Assert.assertEquals(expected, actual, 0.0); + } + + @Test + public void getSetPermissions() { + AccessPolicyInfo policy = new AccessPolicyInfo(); + EnumSet<AccessPolicyPermission> expected = EnumSet + .of(AccessPolicyPermission.LIST, AccessPolicyPermission.WRITE); + + EnumSet<AccessPolicyPermission> actual = policy.setPermissions(expected).getPermissions(); + + Assert.assertEquals(expected, actual); + } +} From fc42caf090e754e9e5f5642a1f45e57ac2392af1 Mon Sep 17 00:00:00 2001 From: Chris Tavares <ctavares@microsoft.com> Date: Mon, 1 Oct 2012 14:31:14 -0700 Subject: [PATCH 69/70] Updated for code review feedback --- .../services/media/MediaContract.java | 4 +- .../media/implementation/MediaRestProxy.java | 22 +++---- .../media/models/AccessPolicyInfo.java | 16 ++++- .../media/AccessPolicyIntegrationTest.java | 60 ++++++++++++++++--- 4 files changed, 81 insertions(+), 21 deletions(-) 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 cd0b1c90560b0..aac6354b6947c 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 @@ -108,7 +108,7 @@ public interface MediaContract extends FilterableService<MediaContract> { * @param name * name of access policy * @param durationInMinutes - * duration access policy is active + * Duration in minutes that blob access will be granted when using this access policy * @return Created access policy * @throws ServiceException */ @@ -120,7 +120,7 @@ public interface MediaContract extends FilterableService<MediaContract> { * @param name * name of access policy * @param durationInMinutes - * duration access policy is active + * Duration in minutes that blob access will be granted when using this access policy * @param options * options for creation * @return the created access policy 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 3ba10b301cd79..c27f83ff48ff0 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 @@ -18,6 +18,7 @@ import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.util.Arrays; +import java.util.EnumSet; import java.util.List; import javax.inject.Inject; @@ -260,9 +261,7 @@ public void deleteAsset(String assetId) throws ServiceException { */ @Override public AccessPolicyInfo createAccessPolicy(String name, double durationInMinutes) throws ServiceException { - CreateAccessPolicyOptions options = new CreateAccessPolicyOptions(); - options.getPermissions().add(AccessPolicyPermission.WRITE); - return createAccessPolicy(name, durationInMinutes, options); + return createAccessPolicy(name, durationInMinutes, null); } /* (non-Javadoc) @@ -272,6 +271,10 @@ public AccessPolicyInfo createAccessPolicy(String name, double durationInMinutes 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())); @@ -304,11 +307,7 @@ public void deleteAccessPolicy(String id) throws ServiceException { */ @Override public List<AccessPolicyInfo> listAccessPolicies() throws ServiceException { - WebResource resource = getResource("AccessPolicies"); - - return resource.type(MediaType.APPLICATION_ATOM_XML).accept(MediaType.APPLICATION_ATOM_XML) - .get(new GenericType<List<AccessPolicyInfo>>() { - }); + return listAccessPolicies(null); } /* (non-Javadoc) @@ -316,7 +315,10 @@ public List<AccessPolicyInfo> listAccessPolicies() throws ServiceException { */ @Override public List<AccessPolicyInfo> listAccessPolicies(ListAccessPolicyOptions options) throws ServiceException { - // Currently no options defined so can call zero arg overload instead - return listAccessPolicies(); + WebResource resource = getResource("AccessPolicies"); + + return resource.type(MediaType.APPLICATION_ATOM_XML).accept(MediaType.APPLICATION_ATOM_XML) + .get(new GenericType<List<AccessPolicyInfo>>() { + }); } } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AccessPolicyInfo.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AccessPolicyInfo.java index 50213d4503654..f4d608dd712a5 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AccessPolicyInfo.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AccessPolicyInfo.java @@ -1,3 +1,18 @@ +/** + * 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.models; import java.util.Date; @@ -11,7 +26,6 @@ public class AccessPolicyInfo extends ODataEntity<AccessPolicyType> { public AccessPolicyInfo(EntryType entry, AccessPolicyType content) { super(entry, content); - // TODO Auto-generated constructor stub } public AccessPolicyInfo() { diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/AccessPolicyIntegrationTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/AccessPolicyIntegrationTest.java index 2dea4f4e4d86b..f91f09eb06b0a 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/AccessPolicyIntegrationTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/AccessPolicyIntegrationTest.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. @@ -20,11 +20,16 @@ import java.util.EnumSet; import java.util.List; +import org.hamcrest.BaseMatcher; +import org.hamcrest.Description; import org.junit.AfterClass; import org.junit.BeforeClass; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; import com.microsoft.windowsazure.services.core.Configuration; +import com.microsoft.windowsazure.services.core.ServiceException; import com.microsoft.windowsazure.services.media.models.AccessPolicyInfo; import com.microsoft.windowsazure.services.media.models.AccessPolicyPermission; import com.microsoft.windowsazure.services.media.models.CreateAccessPolicyOptions; @@ -32,6 +37,8 @@ public class AccessPolicyIntegrationTest extends IntegrationTestBase { private static MediaContract service; + private static final String testPrefix = "testPolicy"; + @BeforeClass public static void setup() throws Exception { service = MediaService.create(createConfig()); @@ -50,7 +57,7 @@ private static Configuration createConfig() { @AfterClass public static void cleanup() throws Exception { for (AccessPolicyInfo policy : service.listAccessPolicies()) { - if (policy.getName().startsWith("testPolicy")) { + if (policy.getName().startsWith(testPrefix)) { service.deleteAccessPolicy(policy.getId()); } } @@ -58,7 +65,7 @@ public static void cleanup() throws Exception { @Test public void canCreateAccessPolicy() throws Exception { - AccessPolicyInfo policy = service.createAccessPolicy("testPolicy", 5, + AccessPolicyInfo policy = service.createAccessPolicy(testPrefix + "CanCreate", 5, new CreateAccessPolicyOptions().addPermissions(EnumSet.of(AccessPolicyPermission.WRITE))); assertTrue(policy.getPermissions().contains(AccessPolicyPermission.WRITE)); @@ -66,7 +73,7 @@ public void canCreateAccessPolicy() throws Exception { @Test public void canGetSinglePolicyById() throws Exception { - String expectedName = "testPolicyGetOne"; + String expectedName = testPrefix + "GetOne"; AccessPolicyInfo policyToGet = service.createAccessPolicy(expectedName, 1); AccessPolicyInfo retrievedPolicy = service.getAccessPolicy(policyToGet.getId()); @@ -77,7 +84,7 @@ public void canGetSinglePolicyById() throws Exception { @Test public void canRetrieveListOfAccessPolicies() throws Exception { - String[] policyNames = new String[] { "testPolicy1", "testPolicy2" }; + String[] policyNames = new String[] { testPrefix + "ListOne", testPrefix + "ListTwo" }; for (String name : policyNames) { service.createAccessPolicy(name, 3, new CreateAccessPolicyOptions().addPermissions(EnumSet.of( AccessPolicyPermission.WRITE, AccessPolicyPermission.LIST))); @@ -92,21 +99,58 @@ public void canRetrieveListOfAccessPolicies() throws Exception { AccessPolicyInfo policy2 = null; for (AccessPolicyInfo policy : policies) { - if (policy.getName().equals("testPolicy1")) { + if (policy.getName().equals(policyNames[0])) { policy1 = policy; } - if (policy.getName().equals("testPolicy2")) { + if (policy.getName().equals(policyNames[1])) { policy2 = policy; } } assertNotNull(policy1); assertNotNull(policy2); + + assertTrue(policy1.getPermissions().containsAll( + EnumSet.of(AccessPolicyPermission.WRITE, AccessPolicyPermission.LIST))); + } + + @Rule + public ExpectedException expected = ExpectedException.none(); + + @Test + public void getWithBadIdThrowsServiceException() throws Exception { + expected.expect(ServiceException.class); + AccessPolicyInfo policy = service.getAccessPolicy("notAValidId"); + } + + @Test + public void getWithValidButNonExistentPolicyIdThrows404ServiceException() throws Exception { + expected.expect(new BaseMatcher<ServiceException>() { + + @Override + public boolean matches(Object item) { + if (item.getClass() != ServiceException.class) { + return false; + } + + if (((ServiceException) item).getHttpStatusCode() != 404) { + return false; + } + + return true; + } + + @Override + public void describeTo(Description description) { + description.appendText("Must be ServiceException with a 404 status code"); + } + }); + service.getAccessPolicy("nb:pid:UUID:bce3863e-830b-49f5-9199-7cfaff52935f"); } @Test public void canDeleteAccessPolicyById() throws Exception { - AccessPolicyInfo policyToDelete = service.createAccessPolicy("testPolicyToDelete", 1); + AccessPolicyInfo policyToDelete = service.createAccessPolicy(testPrefix + "ToDelete", 1); service.deleteAccessPolicy(policyToDelete.getId()); From 384a73583f375a8368a6090a555ad3612a68f7e2 Mon Sep 17 00:00:00 2001 From: Chris Tavares <ctavares@microsoft.com> Date: Wed, 3 Oct 2012 14:22:58 -0700 Subject: [PATCH 70/70] Added more convenient overloads for getting / setting permissions, issue #340 --- .../models/CreateAccessPolicyOptions.java | 43 ++++++++ .../models/CreateAccessPolicyOptionsTest.java | 97 +++++++++++++++++++ 2 files changed, 140 insertions(+) create mode 100644 microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/CreateAccessPolicyOptionsTest.java diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/CreateAccessPolicyOptions.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/CreateAccessPolicyOptions.java index d5e4cb87ee0c6..7c003d2e0cd02 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/CreateAccessPolicyOptions.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/CreateAccessPolicyOptions.java @@ -1,3 +1,18 @@ +/** + * 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.models; import java.util.EnumSet; @@ -28,6 +43,20 @@ public CreateAccessPolicyOptions addPermissions(EnumSet<AccessPolicyPermission> return this; } + /** + * Add the given permissions to this creation request + * + * @param permissionsToAdd + * varargs - permissions to add + * @return the CreateAccessPolicyOptions object + */ + public CreateAccessPolicyOptions addPermissions(AccessPolicyPermission... permissionsToAdd) { + for (AccessPolicyPermission permission : permissionsToAdd) { + permissions.add(permission); + } + return this; + } + /** * Remove the given permissions from this creation request * @@ -38,4 +67,18 @@ public CreateAccessPolicyOptions removePermissions(EnumSet<AccessPolicyPermissio permissions.removeAll(permissionsToRemove); return this; } + + /** + * Remove the given permissions from this creation request + * + * @param permissionsToRemove + * vararg - permissions to remove + * @return the CreateAccessPolicyOptions object + */ + public CreateAccessPolicyOptions removePermissions(AccessPolicyPermission... permissionsToRemove) { + for (AccessPolicyPermission permission : permissionsToRemove) { + permissions.remove(permission); + } + return this; + } } diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/CreateAccessPolicyOptionsTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/CreateAccessPolicyOptionsTest.java new file mode 100644 index 0000000000000..f5b578d40e789 --- /dev/null +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/CreateAccessPolicyOptionsTest.java @@ -0,0 +1,97 @@ +/** + * 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.models; + +import static org.junit.Assert.*; + +import java.util.EnumSet; + +import org.junit.Test; + +public class CreateAccessPolicyOptionsTest { + + private static void assertPermissions(EnumSet<AccessPolicyPermission> expected, + EnumSet<AccessPolicyPermission> actual) { + assertTrue(actual.containsAll(expected)); + assertTrue(EnumSet.complementOf(actual).containsAll(EnumSet.complementOf(expected))); + } + + @Test + public void optionsCreatedWithNoPermissions() throws Exception { + CreateAccessPolicyOptions options = new CreateAccessPolicyOptions(); + + assertPermissions(EnumSet.noneOf(AccessPolicyPermission.class), options.getPermissions()); + } + + @Test + public void canGetSetPermissionsAsEnumSet() throws Exception { + EnumSet<AccessPolicyPermission> expectedPermissions = EnumSet.of(AccessPolicyPermission.LIST, + AccessPolicyPermission.DELETE); + + CreateAccessPolicyOptions options = new CreateAccessPolicyOptions(); + + options.addPermissions(expectedPermissions); + + EnumSet<AccessPolicyPermission> permissions = options.getPermissions(); + + assertPermissions(expectedPermissions, permissions); + } + + @Test + public void canGetSetPermissionsAsVarargs() throws Exception { + EnumSet<AccessPolicyPermission> expectedPermissions = EnumSet.of(AccessPolicyPermission.READ, + AccessPolicyPermission.WRITE); + + CreateAccessPolicyOptions options = new CreateAccessPolicyOptions().addPermissions(AccessPolicyPermission.READ, + AccessPolicyPermission.WRITE); + + EnumSet<AccessPolicyPermission> permissions = options.getPermissions(); + + assertPermissions(expectedPermissions, permissions); + } + + @Test + public void canRemovePermissionsAsEnumSet() throws Exception { + EnumSet<AccessPolicyPermission> originalPermissions = EnumSet.of(AccessPolicyPermission.READ, + AccessPolicyPermission.WRITE, AccessPolicyPermission.DELETE); + EnumSet<AccessPolicyPermission> permissionsToRemove = EnumSet.of(AccessPolicyPermission.READ, + AccessPolicyPermission.DELETE); + EnumSet<AccessPolicyPermission> expectedPermissions = EnumSet.of(AccessPolicyPermission.WRITE); + + CreateAccessPolicyOptions options = new CreateAccessPolicyOptions().addPermissions(originalPermissions); + + options.removePermissions(permissionsToRemove); + + EnumSet<AccessPolicyPermission> actualPermissions = options.getPermissions(); + + assertPermissions(expectedPermissions, actualPermissions); + } + + @Test + public void canRemovePermissionsAsVarargs() throws Exception { + EnumSet<AccessPolicyPermission> originalPermissions = EnumSet.of(AccessPolicyPermission.READ, + AccessPolicyPermission.WRITE, AccessPolicyPermission.DELETE); + EnumSet<AccessPolicyPermission> expectedPermissions = EnumSet.of(AccessPolicyPermission.WRITE); + + CreateAccessPolicyOptions options = new CreateAccessPolicyOptions().addPermissions(originalPermissions); + + options.removePermissions(AccessPolicyPermission.READ, AccessPolicyPermission.DELETE); + + EnumSet<AccessPolicyPermission> actualPermissions = options.getPermissions(); + + assertPermissions(expectedPermissions, actualPermissions); + } +}