Permalink
Browse files

Merge pull request #57 from WindowsAzure/dev

Dev
  • Loading branch information...
2 parents 81070bf + 26b12f8 commit 57dba1e63a4ad8c82cb88fa4f2e4d9084948dea8 Albert Cheng committed Dec 13, 2012
Showing with 1,078 additions and 1,509 deletions.
  1. +6 −0 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/Configuration.java
  2. +99 −0 ...i/src/main/java/com/microsoft/windowsazure/services/core/utils/pipeline/ClientConfigSettings.java
  3. +26 −34 ...soft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/utils/pipeline/Exports.java
  4. +4 −4 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/MediaConfiguration.java
  5. +10 −0 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/MediaContract.java
  6. +0 −57 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/MediaService.java
  7. +10 −0 ...c/main/java/com/microsoft/windowsazure/services/media/implementation/MediaExceptionProcessor.java
  8. +69 −4 ...re-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/MediaRestProxy.java
  9. +9 −15 ...api/src/main/java/com/microsoft/windowsazure/services/media/implementation/OAuthTokenManager.java
  10. +65 −0 ...azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ODataEntity.java
  11. +5 −5 .../main/java/com/microsoft/windowsazure/services/media/implementation/content/AccessPolicyType.java
  12. +16 −9 ...api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/AssetType.java
  13. +3 −3 ...c/main/java/com/microsoft/windowsazure/services/media/implementation/content/LocatorRestType.java
  14. +12 −6 ...ain/java/com/microsoft/windowsazure/services/media/implementation/content/MediaProcessorType.java
  15. +1 −1 ...-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/TaskType.java
  16. +43 −34 ...ft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AccessPolicyInfo.java
  17. +2 −2 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/Asset.java
  18. +2 −94 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AssetInfo.java
  19. +8 −8 .../java/com/microsoft/windowsazure/services/media/models/{EncryptionOption.java → AssetOption.java}
  20. +0 −120 ...soft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/ContentKeyInfo.java
  21. +0 −163 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/JobInfo.java
  22. +69 −0 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/LinkInfo.java
  23. +0 −48 ...oft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/ListTasksResult.java
  24. +0 −116 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/LocatorInfo.java
  25. +0 −79 ...-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/MediaProcessorInfo.java
  26. +0 −223 microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/TaskInfo.java
  27. +40 −36 ...t-azure-api/src/test/java/com/microsoft/windowsazure/services/media/AssetFileIntegrationTest.java
  28. +9 −9 ...osoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/AssetIntegrationTest.java
  29. +31 −1 microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/IntegrationTestBase.java
  30. +124 −100 microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/JobIntegrationTest.java
  31. +0 −3 ...ft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/LocatorIntegrationTests.java
  32. +10 −10 ...oft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/MediaConfigurationTest.java
  33. +2 −10 ...t-azure-api/src/test/java/com/microsoft/windowsazure/services/media/UploadingIntegrationTest.java
  34. +114 −0 ...api/src/test/java/com/microsoft/windowsazure/services/media/implementation/LinkRetrievalTest.java
  35. +1 −4 ...re-api/src/test/java/com/microsoft/windowsazure/services/media/models/AccessPolicyEntityTest.java
  36. +16 −12 ...zure-api/src/test/java/com/microsoft/windowsazure/services/media/models/AccessPolicyInfoTest.java
  37. +2 −2 ...oft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/AssetEntityTest.java
  38. +18 −15 ...osoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/AssetInfoTest.java
  39. +25 −21 ...-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/ContentKeyInfoTest.java
  40. +2 −2 ...t-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/LocatorEntityTest.java
  41. +22 −21 ...oft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/LocatorInfoTest.java
  42. +19 −12 ...re-api/src/test/java/com/microsoft/windowsazure/services/media/models/MediaProcessorInfoTest.java
  43. +0 −113 ...soft-azure-api/src/test/java/com/microsoft/windowsazure/services/scenarios/MediaServiceMocks.java
  44. +22 −20 ...ure-api/src/test/java/com/microsoft/windowsazure/services/scenarios/MediaServiceScenarioTest.java
  45. +50 −28 ...azure-api/src/test/java/com/microsoft/windowsazure/services/scenarios/MediaServiceValidation.java
  46. +105 −60 ...ft-azure-api/src/test/java/com/microsoft/windowsazure/services/scenarios/MediaServiceWrapper.java
  47. +2 −1 ...osoft-azure-api/src/test/java/com/microsoft/windowsazure/services/scenarios/ScenarioTestBase.java
  48. +5 −4 microsoft-azure-api/src/test/resources/META-INF/com.microsoft.windowsazure.properties
@@ -35,6 +35,12 @@
*/
public static final String PROPERTY_READ_TIMEOUT = "com.microsoft.windowsazure.services.core.Configuration.readTimeout";
+ /**
+ * Property name to control if HTTP logging to console is on or off. If property is set, logging is on, regardless
+ * of value.
+ */
+ public static final String PROPERTY_LOG_HTTP_REQUESTS = "com.microsoft.windowsazure.services.core.Configuration.logHttpRequests";
+
private static Configuration instance;
Map<String, Object> properties;
Builder builder;
@@ -0,0 +1,99 @@
+/**
+ * Copyright 2012 Microsoft Corporation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.microsoft.windowsazure.services.core.utils.pipeline;
+
+import com.sun.jersey.api.client.Client;
+import com.sun.jersey.api.client.config.ClientConfig;
+import com.sun.jersey.api.client.filter.LoggingFilter;
+
+/**
+ * Class used for injecting timeout settings into the various places that need it.
+ *
+ */
+public class ClientConfigSettings {
+ private static final int DEFAULT_TIMEOUT_MS = 90 * 1000;
+
+ private final Integer connectTimeout;
+ private final Integer readTimeout;
+ private final boolean shouldLog;
+
+ /**
+ * Construct a {@link ClientConfigSettings} object with the default
+ * settings.
+ */
+ public ClientConfigSettings() {
+ connectTimeout = Integer.valueOf(null);
+ readTimeout = Integer.valueOf(null);
+ shouldLog = false;
+ }
+
+ /**
+ * Construct a {@link ClientConfigSettings} object wit the given
+ * settings.
+ *
+ * @param connectTimeout
+ * Connection timeout in milliseconds
+ * @param readTimeout
+ * read timeout in milliseconds
+ * @param shouldLog
+ * if true, add logging filter to clients.
+ */
+ public ClientConfigSettings(Object connectTimeout, Object readTimeout, boolean shouldLog) {
+ this.connectTimeout = getTimeout(connectTimeout);
+ this.readTimeout = getTimeout(readTimeout);
+ this.shouldLog = shouldLog;
+ }
+
+ /**
+ * Update the given {@link ClientConfig} object with the appropriate
+ * settings from configuration.
+ *
+ * @param clientConfig
+ * object to update.
+ */
+ public void applyConfig(ClientConfig clientConfig) {
+ clientConfig.getProperties().put(ClientConfig.PROPERTY_CONNECT_TIMEOUT, connectTimeout);
+ clientConfig.getProperties().put(ClientConfig.PROPERTY_READ_TIMEOUT, readTimeout);
+ }
+
+ /**
+ * Update the given {@link client} object with the appropriate settings
+ * from configuration.
+ *
+ * @param client
+ */
+ public void applyConfig(Client client) {
+ if (shouldLog) {
+ client.addFilter(new LoggingFilter());
+ }
+ }
+
+ private Integer getTimeout(Object timeoutValue) {
+ if (timeoutValue == null) {
+ return new Integer(DEFAULT_TIMEOUT_MS);
+ }
+
+ if (timeoutValue instanceof Integer) {
+ return (Integer) timeoutValue;
+ }
+
+ if (timeoutValue instanceof String) {
+ return Integer.valueOf((String) timeoutValue);
+ }
+
+ throw new IllegalArgumentException("timeoutValue");
+ }
+}
@@ -15,7 +15,6 @@
package com.microsoft.windowsazure.services.core.utils.pipeline;
import java.util.Map;
-import java.util.Map.Entry;
import com.microsoft.windowsazure.services.core.Builder;
import com.microsoft.windowsazure.services.core.Builder.Registry;
@@ -32,48 +31,31 @@ 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
-
- clientConfig.getProperties().put(ClientConfig.PROPERTY_CONNECT_TIMEOUT, new Integer(90 * 1000));
- clientConfig.getProperties().put(ClientConfig.PROPERTY_READ_TIMEOUT, new Integer(90 * 1000));
+ ClientConfigSettings settings = builder.build(profile, ClientConfigSettings.class, properties);
+ settings.applyConfig(clientConfig);
+ return clientConfig;
+ }
+ });
- for (Entry<String, Object> entry : properties.entrySet()) {
- Object propertyValue = entry.getValue();
- String propertyKey = entry.getKey();
+ registry.add(new Builder.Factory<ClientConfigSettings>() {
- 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;
- }
+ @Override
+ public ClientConfigSettings create(String profile, Builder builder, Map<String, Object> properties) {
+ Object connectTimeout = getPropertyIfExists(profile, properties, Configuration.PROPERTY_CONNECT_TIMEOUT);
+ Object readTimeout = getPropertyIfExists(profile, properties, Configuration.PROPERTY_READ_TIMEOUT);
- // ClientConfig requires instance of Integer to properly set
- // timeouts, but config file will deliver strings. Special
- // case these timeout properties and convert them to Integer
- // if necessary.
- if (propertyKey.equals(ClientConfig.PROPERTY_CONNECT_TIMEOUT)
- || propertyKey.equals(ClientConfig.PROPERTY_READ_TIMEOUT)) {
- if (propertyValue instanceof String) {
- propertyValue = Integer.valueOf((String) propertyValue);
- }
- }
- clientConfig.getProperties().put(propertyKey, propertyValue);
- }
- return clientConfig;
+ return new ClientConfigSettings(connectTimeout, readTimeout, getPropertyIfExists(profile, properties,
+ Configuration.PROPERTY_LOG_HTTP_REQUESTS) != null);
}
});
registry.add(new Builder.Factory<Client>() {
@Override
public Client create(String profile, Builder builder, Map<String, Object> properties) {
ClientConfig clientConfig = builder.build(profile, ClientConfig.class, properties);
+ ClientConfigSettings settings = builder.build(profile, ClientConfigSettings.class, properties);
Client client = Client.create(clientConfig);
- // client.addFilter(new LoggingFilter());
+ settings.applyConfig(client);
return client;
}
});
@@ -82,15 +64,16 @@ public Client create(String profile, Builder builder, Map<String, Object> proper
@Override
public HttpURLConnectionClient create(String profile, Builder builder, Map<String, Object> properties) {
ClientConfig clientConfig = builder.build(profile, ClientConfig.class, properties);
+ ClientConfigSettings settings = builder.build(profile, ClientConfigSettings.class, properties);
HttpURLConnectionClient client = HttpURLConnectionClient.create(clientConfig);
- // client.addFilter(new LoggingFilter());
+ settings.applyConfig(client);
return client;
}
});
}
private static String normalizeProfile(String profile) {
- if (profile == null) {
+ if (profile == null || profile.equals("")) {
return "";
}
@@ -100,4 +83,13 @@ private static String normalizeProfile(String profile) {
return profile + ".";
}
+
+ private static Object getPropertyIfExists(String profile, Map<String, Object> properties, String propertyName) {
+ String fullPropertyName = normalizeProfile(profile) + propertyName;
+
+ if (properties.containsKey(fullPropertyName)) {
+ return properties.get(fullPropertyName);
+ }
+ return null;
+ }
}
@@ -32,24 +32,24 @@
* Defines the OAUTH configuration URI constant.
*
*/
- public static final String OAUTH_URI = "oauth.uri";
+ public static final String OAUTH_URI = "media.oauth.uri";
/**
* Defines the OAUTH configuration client ID constant.
*
*/
- public static final String OAUTH_CLIENT_ID = "oauth.client.id";
+ public static final String OAUTH_CLIENT_ID = "media.oauth.client.id";
/**
* Defines the OAUTH configuration client secret constant.
*
*/
- public static final String OAUTH_CLIENT_SECRET = "oauth.client.secret";
+ public static final String OAUTH_CLIENT_SECRET = "media.oauth.client.secret";
/**
* Defines the SCOPE of the media service sent to OAUTH.
*/
- public static final String OAUTH_SCOPE = "oauth.scope";
+ public static final String OAUTH_SCOPE = "media.oauth.scope";
/**
* Creates a media service configuration using the specified media service base URI, OAUTH URI,
@@ -19,6 +19,7 @@
import com.microsoft.windowsazure.services.core.FilterableService;
import com.microsoft.windowsazure.services.media.implementation.entities.EntityContract;
+import com.microsoft.windowsazure.services.media.models.LocatorInfo;
/**
* Contract for interacting with the back end of Media Services
@@ -28,4 +29,13 @@
URI getRestServiceUri();
+ /**
+ * Creates an instance of the <code>WritableBlobContainerContract</code> API that will
+ * write to the blob container given by the provided locator.
+ *
+ * @param locator
+ * locator specifying where to upload to
+ * @return the implementation of <code>WritableBlobContainerContract</code>
+ */
+ WritableBlobContainerContract createBlobWriter(LocatorInfo locator);
}
@@ -14,13 +14,7 @@
*/
package com.microsoft.windowsazure.services.media;
-import java.net.URI;
-
import com.microsoft.windowsazure.services.core.Configuration;
-import com.microsoft.windowsazure.services.media.implementation.MediaBlobContainerWriter;
-import com.microsoft.windowsazure.services.media.models.LocatorInfo;
-import com.microsoft.windowsazure.services.media.models.LocatorType;
-import com.sun.jersey.api.client.Client;
/**
*
@@ -70,55 +64,4 @@ public static MediaContract create(String profile) {
public static MediaContract create(String profile, Configuration config) {
return config.create(profile, MediaContract.class);
}
-
- /**
- * Creates an instance of the <code>WritableBlobContainerContract</code> API that will
- * write to the blob container given by the provided locator.
- *
- * @param locator
- * locator specifying where to upload to
- * @return the implementation of <code>WritableBlobContainerContract</code>
- */
- public static WritableBlobContainerContract createBlobWriter(LocatorInfo locator) {
- if (locator.getLocatorType() != LocatorType.SAS) {
- throw new IllegalArgumentException("Can only write to SAS locators");
- }
-
- LocatorParser p = new LocatorParser(locator);
-
- return new MediaBlobContainerWriter(createUploaderClient(), p.getAccountName(), p.getStorageUri(),
- p.getContainer(), p.getSASToken());
- }
-
- /**
- * Helper class to encapsulate pulling information out of the locator.
- */
- private static class LocatorParser {
- URI locatorPath;
-
- LocatorParser(LocatorInfo locator) {
- locatorPath = URI.create(locator.getPath());
- }
-
- String getAccountName() {
- return locatorPath.getHost().split("\\.")[0];
- }
-
- String getStorageUri() {
- return locatorPath.getScheme() + "://" + locatorPath.getAuthority();
- }
-
- String getContainer() {
- return locatorPath.getPath().substring(1);
- }
-
- String getSASToken() {
- return locatorPath.getRawQuery();
- }
- }
-
- private static Client createUploaderClient() {
- Client client = Client.create();
- return client;
- }
}
@@ -26,13 +26,15 @@
import com.microsoft.windowsazure.services.core.ServiceFilter;
import com.microsoft.windowsazure.services.core.utils.ServiceExceptionFactory;
import com.microsoft.windowsazure.services.media.MediaContract;
+import com.microsoft.windowsazure.services.media.WritableBlobContainerContract;
import com.microsoft.windowsazure.services.media.implementation.entities.EntityActionOperation;
import com.microsoft.windowsazure.services.media.implementation.entities.EntityCreationOperation;
import com.microsoft.windowsazure.services.media.implementation.entities.EntityDeleteOperation;
import com.microsoft.windowsazure.services.media.implementation.entities.EntityGetOperation;
import com.microsoft.windowsazure.services.media.implementation.entities.EntityListOperation;
import com.microsoft.windowsazure.services.media.implementation.entities.EntityUpdateOperation;
import com.microsoft.windowsazure.services.media.models.ListResult;
+import com.microsoft.windowsazure.services.media.models.LocatorInfo;
import com.sun.jersey.api.client.ClientHandlerException;
import com.sun.jersey.api.client.UniformInterfaceException;
@@ -196,4 +198,12 @@ public URI getRestServiceUri() {
return service.getRestServiceUri();
}
+ /* (non-Javadoc)
+ * @see com.microsoft.windowsazure.services.media.MediaContract#createBlobWriter(com.microsoft.windowsazure.services.media.models.LocatorInfo)
+ */
+ @Override
+ public WritableBlobContainerContract createBlobWriter(LocatorInfo locator) {
+ return service.createBlobWriter(locator);
+ }
+
}
Oops, something went wrong.

0 comments on commit 57dba1e

Please sign in to comment.