This commit is contained in:
ZhijunZhao 2017-07-19 15:01:41 +08:00 коммит произвёл GitHub
Родитель 414371f759
Коммит 9f2261c668
16 изменённых файлов: 76 добавлений и 104 удалений

Просмотреть файл

@ -7,15 +7,14 @@
package com.microsoft.azure.autoconfigure.documentdb;
import com.microsoft.azure.documentdb.ConsistencyLevel;
import org.hibernate.validator.constraints.NotEmpty;
import org.springframework.boot.context.properties.ConfigurationProperties;
import javax.validation.constraints.NotNull;
@ConfigurationProperties("azure.documentdb")
public class DocumentDBProperties {
@NotNull
@NotEmpty
private String uri;
@NotNull
@NotEmpty
private String key;
private ConsistencyLevel consistencyLevel;

Просмотреть файл

@ -6,6 +6,9 @@
package com.microsoft.azure.autoconfigure.mediaservices;
import com.microsoft.windowsazure.services.media.MediaConfiguration;
import com.microsoft.windowsazure.services.media.MediaContract;
import com.microsoft.windowsazure.services.media.MediaService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
@ -14,14 +17,6 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;
import com.microsoft.windowsazure.services.media.MediaConfiguration;
import com.microsoft.windowsazure.services.media.MediaContract;
import com.microsoft.windowsazure.services.media.MediaService;
/**
* @author rajakolli
*
*/
@Configuration
@ConditionalOnMissingBean(MediaContract.class)
@EnableConfigurationProperties(MediaServicesProperties.class)

Просмотреть файл

@ -11,70 +11,78 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
@ConfigurationProperties("azure.mediaservices")
public class MediaServicesProperties {
private String mediaServiceUri = "https://media.windows.net/API/";
private String oAuthUri = "https://wamsprodglobal001acs.accesscontrol.windows.net/v2/OAuth2-13";
private String scope = "urn:WindowsAzureMediaServices";
@NotEmpty
private String accountName;
@NotEmpty
private String accountKey;
private String mediaServiceUri = "https://media.windows.net/API/";
private String oAuthUri = "https://wamsprodglobal001acs.accesscontrol.windows.net/v2/OAuth2-13";
private String scope = "urn:WindowsAzureMediaServices";
/**
* @return the mediaServiceUri
*/
public String getMediaServiceUri() {
return mediaServiceUri;
}
/**
* @param mediaServiceUri the mediaServiceUri to set
*/
public void setMediaServiceUri(String mediaServiceUri) {
this.mediaServiceUri = mediaServiceUri;
}
/**
* @return the oAuthUri
*/
public String getoAuthUri() {
return oAuthUri;
}
/**
* @param oAuthUri the oAuthUri to set
*/
public void setoAuthUri(String oAuthUri) {
this.oAuthUri = oAuthUri;
}
/**
* @return the accountName
*/
public String getAccountName() {
return accountName;
}
/**
* @param accountName the accountName to set
*/
public void setAccountName(String accountName) {
this.accountName = accountName;
}
/**
* @return the accountKey
*/
public String getAccountKey() {
return accountKey;
}
/**
* @param accountKey the accountKey to set
*/
public void setAccountKey(String accountKey) {
this.accountKey = accountKey;
}
/**
* @return the scope
*/
public String getScope() {
return scope;
}
/**
* @param scope the scope to set
*/

Просмотреть файл

@ -0,0 +1,8 @@
package com.microsoft.azure.autoconfigure.mediaservices;
public class Constants {
public static final String ACCOUNT_NAME = "some accountname";
public static final String ACCOUNT_NAME_PROPERTY = "azure.mediaservices.account-name";
public static final String ACCOUNT_KEY = "some accountKey";
public static final String ACCOUNT_KEY_PROPERTY = "azure.mediaservices.account-key";
}

Просмотреть файл

@ -1,43 +1,27 @@
package com.microsoft.azure.autoconfigure.mediaservices;
import com.microsoft.windowsazure.services.media.MediaContract;
import org.junit.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import com.microsoft.windowsazure.services.media.MediaContract;
import com.microsoft.windowsazure.services.media.implementation.MediaExceptionProcessor;
public class MediaServicesAutoConfigurationTest {
private static final String CONNECTION_ACCOUNTKEY_PROPERTY = "azure.mediaservices.account-key";
private static final String CONNECTION_ACCOUNTNAME_PROPERTY = "azure.mediaservices.account-name";
private static final String ACCOUNT_KEY = "someKey";
private static final String ACCOUNT_NAME = "someName";
@Test
public void createMediaServiceAccount() {
System.setProperty(CONNECTION_ACCOUNTKEY_PROPERTY, ACCOUNT_KEY);
System.setProperty(CONNECTION_ACCOUNTNAME_PROPERTY, ACCOUNT_NAME);
System.setProperty(Constants.ACCOUNT_KEY_PROPERTY, Constants.ACCOUNT_KEY);
System.setProperty(Constants.ACCOUNT_NAME_PROPERTY, Constants.ACCOUNT_NAME);
try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext()) {
context.register(MediaServicesAutoConfiguration.class);
context.refresh();
MediaContract mediaContract = null;
try {
mediaContract = context.getBean(MediaContract.class);
} catch (Exception e) {
assertThat(e).isExactlyInstanceOf(BeanCreationException.class);
}
final MediaContract mediaContract = context.getBean(MediaContract.class);
assertThat(mediaContract).isNotNull();
assertThat(mediaContract).isExactlyInstanceOf(MediaExceptionProcessor.class);
}
System.clearProperty(CONNECTION_ACCOUNTKEY_PROPERTY);
System.clearProperty(CONNECTION_ACCOUNTNAME_PROPERTY);
System.clearProperty(Constants.ACCOUNT_KEY_PROPERTY);
System.clearProperty(Constants.ACCOUNT_NAME_PROPERTY);
}
}

Просмотреть файл

@ -1,41 +1,31 @@
package com.microsoft.azure.autoconfigure.mediaservices;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Configuration;
public class MediaServicesPropertiesTest {
import static org.assertj.core.api.Assertions.assertThat;
private static final String ACCOUNT_NAME = "some accountname";
private static final String ACCOUNT_NAME_PROPERTY = "azure.mediaservices.account-name";
private static final String ACCOUNT_KEY = "some accountKey";
private static final String ACCOUNT_KEY_PROPERTY = "azure.mediaservices.account-key";
public class MediaServicesPropertiesTest {
@Test
public void canSetProperties() {
System.setProperty(ACCOUNT_NAME_PROPERTY, ACCOUNT_NAME);
System.setProperty(ACCOUNT_KEY_PROPERTY, ACCOUNT_KEY);
System.setProperty(Constants.ACCOUNT_NAME_PROPERTY, Constants.ACCOUNT_NAME);
System.setProperty(Constants.ACCOUNT_KEY_PROPERTY, Constants.ACCOUNT_KEY);
try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext()) {
context.register(Config.class);
context.refresh();
final MediaServicesProperties properties = context
.getBean(MediaServicesProperties.class);
assertThat(properties.getMediaServiceUri())
.isEqualTo("https://media.windows.net/API/");
assertThat(properties.getoAuthUri()).isEqualTo(
"https://wamsprodglobal001acs.accesscontrol.windows.net/v2/OAuth2-13");
assertThat(properties.getAccountName()).isEqualTo(ACCOUNT_NAME);
assertThat(properties.getAccountKey()).isEqualTo(ACCOUNT_KEY);
assertThat(properties.getScope()).isEqualTo("urn:WindowsAzureMediaServices");
final MediaServicesProperties properties = context.getBean(MediaServicesProperties.class);
assertThat(properties.getAccountName()).isEqualTo(Constants.ACCOUNT_NAME);
assertThat(properties.getAccountKey()).isEqualTo(Constants.ACCOUNT_KEY);
}
System.clearProperty(ACCOUNT_NAME_PROPERTY);
System.clearProperty(ACCOUNT_KEY_PROPERTY);
System.clearProperty(Constants.ACCOUNT_NAME_PROPERTY);
System.clearProperty(Constants.ACCOUNT_KEY_PROPERTY);
}
@Test

Просмотреть файл

@ -6,30 +6,22 @@
package com.microsoft.azure.mediaservices;
import com.microsoft.windowsazure.exception.ServiceException;
import com.microsoft.windowsazure.services.media.MediaContract;
import com.microsoft.windowsazure.services.media.WritableBlobContainerContract;
import com.microsoft.windowsazure.services.media.models.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.core.io.ClassPathResource;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.EnumSet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import com.microsoft.windowsazure.exception.ServiceException;
import com.microsoft.windowsazure.services.media.MediaContract;
import com.microsoft.windowsazure.services.media.WritableBlobContainerContract;
import com.microsoft.windowsazure.services.media.models.AccessPolicy;
import com.microsoft.windowsazure.services.media.models.AccessPolicyInfo;
import com.microsoft.windowsazure.services.media.models.AccessPolicyPermission;
import com.microsoft.windowsazure.services.media.models.Asset;
import com.microsoft.windowsazure.services.media.models.AssetFile;
import com.microsoft.windowsazure.services.media.models.AssetInfo;
import com.microsoft.windowsazure.services.media.models.Locator;
import com.microsoft.windowsazure.services.media.models.LocatorInfo;
import com.microsoft.windowsazure.services.media.models.LocatorType;
@SpringBootApplication
public class MediaServicesSampleApplication implements CommandLineRunner {
@ -47,7 +39,7 @@ public class MediaServicesSampleApplication implements CommandLineRunner {
@Override
public void run(String... args) throws Exception {
// Upload a local file to an Asset
final AssetInfo uploadAsset = uploadFileAndCreateAsset("BigBuckBunny.mp4");
final AssetInfo uploadAsset = uploadFileAndCreateAsset("video.mp4");
System.out.println("Uploaded Asset Id: " + uploadAsset.getId());
System.out.println("Sample completed!");
}
@ -75,7 +67,7 @@ public class MediaServicesSampleApplication implements CommandLineRunner {
// Create the Blob Writer using the Locator
uploader = mediaService.createBlobWriter(uploadLocator);
final File file = new File("BigBuckBunny.mp4");
final File file = new ClassPathResource(fileName).getFile();
// The local file that will be uploaded to your Media Services account
try (final InputStream input = new FileInputStream(file)) {

Просмотреть файл

@ -1,2 +1,3 @@
azure.mediaservices.account-key=put-your-azure-media-clientid-here
azure.mediaservices.account-name=put-your-azure-media-secret-here
azure.mediaservices.account-name=put-your-media-services-account-name-here
azure.mediaservices.account-key=put-your-media-services-account-key-here

Двоичный файл не отображается.

Просмотреть файл

@ -2,27 +2,24 @@
### Add the dependency
"azure-media-spring-boot-starter" is published on Maven Central Repository.
"azure-mediaservices-spring-boot-starter" is published on Maven Central Repository.
If you are using Maven, add the following dependency.
```xml
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-media-spring-boot-starter</artifactId>
<artifactId>azure-mediaservices-spring-boot-starter</artifactId>
<version>0.1.3</version>
</dependency>
```
### Add the property setting
Open `application.properties` file and add below property with your Azure Storage connection string.
Open `application.properties` file and add below properties with your Azure Media Services credentials.
```
azure.media.mediaServiceUri=https://media.windows.net/API/
azure.media.oAuthUri=https://wamsprodglobal001acs.accesscontrol.windows.net/v2/OAuth2-13
azure.media.clientId=put-your-azure-media-clientId-here
azure.media.clientSecret=put-your-azure-media-secret-here
azure.media.scope=urn:WindowsAzureMediaServices
azure.mediaservices.account-name=put-your-media-services-account-name-here
azure.mediaservices.account-key=put-your-media-services-account-key-here
```
### Add auto-wiring code

Просмотреть файл

@ -7,13 +7,12 @@
package com.microsoft.azure.autoconfigure.servicebus;
import com.microsoft.azure.servicebus.ReceiveMode;
import org.hibernate.validator.constraints.NotEmpty;
import org.springframework.boot.context.properties.ConfigurationProperties;
import javax.validation.constraints.NotNull;
@ConfigurationProperties("azure.servicebus")
public class ServiceBusProperties {
@NotNull
@NotEmpty
private String connectionString;
private String queueName;
private ReceiveMode queueReceiveMode;

Просмотреть файл

@ -4,7 +4,7 @@
* license information.
*/
package com.microsoft.azure.autoconfigure.azurestorage;
package com.microsoft.azure.autoconfigure.storage;
import com.microsoft.azure.storage.CloudStorageAccount;
import org.slf4j.Logger;

Просмотреть файл

@ -4,16 +4,15 @@
* license information.
*/
package com.microsoft.azure.autoconfigure.azurestorage;
package com.microsoft.azure.autoconfigure.storage;
import org.hibernate.validator.constraints.NotEmpty;
import org.springframework.boot.context.properties.ConfigurationProperties;
import javax.validation.constraints.NotNull;
@ConfigurationProperties("azure.storage")
public class StorageProperties {
@NotNull
@NotEmpty
private String connectionString;
/**

Просмотреть файл

@ -1 +1 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.microsoft.azure.autoconfigure.azurestorage.StorageAutoConfiguration
org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.microsoft.azure.autoconfigure.storage.StorageAutoConfiguration

Просмотреть файл

@ -3,7 +3,7 @@
* Licensed under the MIT License. See LICENSE in the project root for
* license information.
*/
package com.microsoft.azure.autoconfigure.azurestorage;
package com.microsoft.azure.autoconfigure.storage;
import com.microsoft.azure.storage.CloudStorageAccount;
import org.junit.Test;

Просмотреть файл

@ -3,7 +3,7 @@
* Licensed under the MIT License. See LICENSE in the project root for
* license information.
*/
package com.microsoft.azure.autoconfigure.azurestorage;
package com.microsoft.azure.autoconfigure.storage;
import org.junit.Test;
import org.springframework.beans.factory.BeanCreationException;