This commit is contained in:
Cam Soper 2017-05-04 13:25:54 -05:00
Родитель 933b0cece0
Коммит b40eb456de
8 изменённых файлов: 214 добавлений и 214 удалений

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

@ -19,40 +19,40 @@ ms.assetid: 10f457e3-578b-4655-8cd1-51339226ee7d
## Connect to services with connection strings
Most Azure service libraries use a connection string or keys to connect to the service from your app. For example, SQL Database uses a JDBC connection string:
Most Azure service libraries use a connection string or secure key to authenticate to the service. For example, SQL Database uses a JDBC connection string:
```java
String url = "jdbc:sqlserver://myazuredb.database.windows.net:1433;" +
"database=testjavadb;" +
"user=myazdbuser;" +
"password=myazdbpass;" +
"encrypt=true;hostNameInCertificate=*.database.windows.net;loginTimeout=30;";
Connection conn = DriverManager.getConnection(url);
"database=testjavadb;" +
"user=myazdbuser;" +
"password=myazdbpass;" +
"encrypt=true;hostNameInCertificate=*.database.windows.net;loginTimeout=30;";
Connection conn = DriverManager.getConnection(url);
```
Azure Storage uses a storage key:
```java
final String storageConnection = "DefaultEndpointsProtocol=https;"
+ "AccountName=" + storageName
+ ";AccountKey=" + storageKey
+ ";EndpointSuffix=core.windows.net";
+ "AccountName=" + storageName
+ ";AccountKey=" + storageKey
+ ";EndpointSuffix=core.windows.net";
```
Service connection strings are used to authenticate to other Azure services like [DocumentDB](https://docs.microsoft.com/azure/documentdb/documentdb-java-application#a-iduseserviceastep-4-using-the-documentdb-service-in-a-java-application), [Redis Cache](https://docs.microsoft.com/azure/redis-cache/cache-java-get-started), and [Service Bus](https://docs.microsoft.com/azure/service-bus-messaging/service-bus-java-how-to-use-queues) and you can get those strings using the Azure portal or the CLI. You can also use the Azure management libraries for Java to query resources to build connection strings in your code.
Service connection strings are used to authenticate to other Azure services like [DocumentDB](https://docs.microsoft.com/azure/documentdb/documentdb-java-application#a-iduseserviceastep-4-using-the-documentdb-service-in-a-java-application), [Redis Cache](https://docs.microsoft.com/azure/redis-cache/cache-java-get-started), and [Service Bus](https://docs.microsoft.com/azure/service-bus-messaging/service-bus-java-how-to-use-queues). You can get the connection strings using the Azure portal or the CLI. You can also use the Azure management libraries for Java to query resources to build connection strings in your code.
This snippet uses the management libraries to create a storage account connection string:
```java
// create a new storage account
StorageAccount stor2 = azure.storageAccounts().getByResourceGroup("myResourceGroup","myStorageAccount");
// create a new storage account
StorageAccount stor2 = azure.storageAccounts().getByResourceGroup("myResourceGroup","myStorageAccount");
// create a storage container to hold the file
List<StorageAccountKey> keys = storage.getKeys();
final String storageConnection = "DefaultEndpointsProtocol=https;"
+ "AccountName=" + storage.name()
+ ";AccountKey=" + keys.get(0).value()
+ ";EndpointSuffix=core.windows.net";
// create a storage container to hold the file
List<StorageAccountKey> keys = storage.getKeys();
final String storageConnection = "DefaultEndpointsProtocol=https;"
+ "AccountName=" + storage.name()
+ ";AccountKey=" + keys.get(0).value()
+ ";EndpointSuffix=core.windows.net";
```
Other libraries require your application to run with a [service prinicpal](https://docs.microsoft.com/azure/active-directory/develop/active-directory-application-objects) authorizing the application to run with granted credentials. This configuration is similar to the object-based authentication steps for the management library listed below.
@ -67,11 +67,11 @@ Two options are available to authenticate your application with Azure when using
Create an instance of `ApplicationTokenCredentials` to supply the service principal credentials to the top-level `Azure` object from inside your code.
```
```java
import com.microsoft.azure.credentials.ApplicationTokenCredentials;
import com.microsoft.azure.AzureEnvironment;
...
// ...
ApplicationTokenCredentials credentials = new ApplicationTokenCredentials(client, tenant,
key, AzureEnvironment.AZURE);
@ -82,7 +82,7 @@ Azure azure = Azure
.withDefaultSubscription();
```
The `client`, `tenant` and `key` are the same service principal values used with file-based authentication. The `AzureEnvironment.AZURE` value creates credentials against the Azure public cloud. Change this to a different `AzureEnvironment` enum value if you need to access another cloud (for example, `AzureEnvironment.AZURE_GERMANY`). Read the service principal values from environment variables or a secret management store like [Key Vault](/azure/key-vault/key-vault-whatis.md). Avoid setting these values as cleartext strings in your code to prevent a leak of the credentials through your version control history.
The `client`, `tenant` and `key` are the same service principal values used with [file-based authentication](#mgmt-file). The `AzureEnvironment.AZURE` value creates credentials against the Azure public cloud. Change this to a different `AzureEnvironment` enum value if you need to access another cloud (for example, `AzureEnvironment.AZURE_GERMANY`). Read the service principal values from environment variables or a secret management store like [Key Vault](/azure/key-vault/key-vault-whatis.md). Avoid setting these values as cleartext strings in your code to prevent a leak of the credentials through your version control history.
<a name="mgmt-file"></a>

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

@ -22,9 +22,9 @@ A fluent interface is a specific form of the builder pattern that creates object
```java
StorageAccount storage = azure.storageAccounts().define(storageAccountName)
.withRegion(region)
.withNewResourceGroup(resourceGroup)
.create();
.withRegion(region)
.withNewResourceGroup(resourceGroup)
.create();
```
As you go through the method chain, your IDE suggests the next method to call in the fluent conversation.
@ -39,11 +39,11 @@ The management library has a single point of entry through the top-level `com.mi
```java
SqlServer sqlServer = azure.sqlServers().define(sqlServerName)
.withRegion(Region.US_EAST)
.withNewResourceGroup(rgName)
.withAdministratorLogin(administratorLogin)
.withAdministratorPassword(administratorPassword)
.create();
.withRegion(Region.US_EAST)
.withNewResourceGroup(rgName)
.withAdministratorLogin(administratorLogin)
.withAdministratorPassword(administratorPassword)
.create();
```
## Lists and iterations
@ -65,8 +65,8 @@ for (VirtualMachine vm : vms) {
The management libraries follows a convention for returned collections from queries:
- Lists: Unordered data that is easy to search and interate over.
- Maps: Maps are key/value pairs with unique keys, but not necessarily unique values. An example of a Map would be app settings for a App Service webapp.
- Lists: Unordered data that is easy to search and iterate over.
- Maps: Maps are key/value pairs with unique keys, but not necessarily unique values. An example of a Map would be app settings for an App Service Web App.
- Sets: Sets have unique keys and values. An example of a Set would be networks attached to a virtual machine, which would have both an unique identifier (the key) and a unique network configuration (the value).
## Actionable verbs
@ -84,7 +84,7 @@ Methods with verbs in their names take immediate action in Azure. These methods
>[!NOTE]
> `define()` and `update()` are verbs but do not block unless followed by a `create()` or `apply()`.
Asynchronous versions of these methods exist with a `Async` suffix use [Reactive extensions](https://github.com/ReactiveX/RxJava).
Asynchronous versions of these methods exist with the `Async` suffix using [Reactive extensions](https://github.com/ReactiveX/RxJava).
Some objects have methods with that change the state of the resource in Azure. For example, `restart()` on a `VirtualMachine`:
@ -106,15 +106,15 @@ Generate `Creatable<T>` objects through the resource collections' `define()` ver
```java
Creatable<PublicIPAddress> publicIPAddressCreatable = azure.publicIPAddresses().define(publicIPAddressName)
.withRegion(Region.US_EAST)
.withNewResourceGroup(rgName);
.withRegion(Region.US_EAST)
.withNewResourceGroup(rgName);
```
The Azure resource defined by the `Creatable<PublicIPAddress>` in this example does not yet exist in your subscription when you run this code. The `Creatable<PublicIPAddress>` is a local representation of a resource that the management library will create when its needed. Use this `Creatable<PublicIPAddress>` to define other Azure resources with this IP address.
```java
Creatable<VirtualMachine> vmCreatable = azure.virtualMachines().define("creatableVM")
.withNewPrimaryPublicIPAddress(publicIPAddressCreatable)
.withNewPrimaryPublicIPAddress(publicIPAddressCreatable)
```
Create the resources in your Azure subscription using the `create()` method for the resource collection.
@ -131,7 +131,7 @@ PublicIPAddress pip = (PublicIPAddress) virtualMachine.createdRelatedResource(pu
## Exception handling
The management libraries currently defines Exception classes that extend `com.microsoft.rest.RestException`. Catch exceptions generated by management libraries, with a `catch (RestException exception)` block after the relevant `try` statement.
The management libraries defines Exception classes that extend `com.microsoft.rest.RestException`. Catch exceptions generated by management libraries with a `catch (RestException exception)` block after the relevant `try` statement.
## Logs and trace

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

@ -20,16 +20,16 @@ This guide walks you through setting up your development environment to authenti
## Prerequisites
- An Azure account. If you don't have one , [get a free trial](https://azure.microsoft.com/free/)
- An Azure account. If you don't have one, [get a free trial](https://azure.microsoft.com/free/)
- [Java 8](http://www.oracle.com/technetwork/java/javase/downloads/index.html)
- [Maven 3](http://maven.apache.org/download.cgi)
- [Azure CLI 2.0](https://docs.microsoft.com/cli/azure/install-az-cli2)
This get started guide uses the Maven build tool to build and run Java source code, but other build tools such as Gradle work fine with the Azure libraries for Java.
This get started guide uses the Maven build tool to build and run Java source code, but other build tools such as Gradle also work with the Azure libraries for Java.
## Set up authentication
Your Java application needs permissions to read and create resources your Azure subscription in order to run the sample code in this guide. Create a service principal and configure your application use its credentials. Service principals provide a way to create a non-interactive account associated with your identity to which you grant only the privileges your app needs to run.
Your Java application needs permissions to read and create resources your Azure subscription in order to run the sample code in this guide. Create a service principal and configure your application to run with its credentials. Service principals provide a way to create a non-interactive account associated with your identity to which you grant only the privileges your app needs to run.
[Create a service principal using the Azure CLI 2.0](/cli/azure/create-an-azure-service-principal-azure-cli) and capture the output. You'll need to provide a [secure password](https://docs.microsoft.com/azure/active-directory/active-directory-passwords-policy) in the password argument instead of `MY_SECURE_PASSWORD`.
@ -155,52 +155,51 @@ public class AzureApp {
Paste in the following `main` method in the class. This code creates an [Azure storage account](https://docs.microsoft.com/azure/storage/storage-introduction) and then uses the Azure Storage libraries for Java to upload a text file to the blob storage in a new container.
```java
public static void main(String[] args) {
public static void main(String[] args) {
try {
try {
// use the properties file with the service principal information to authenticate
// change the name of the environment variable if you used a different name in the previous step
final File credFile = new File(System.getenv("AZURE_AUTH_LOCATION"));
Azure azure = Azure.configure()
.withLogLevel(LogLevel.BASIC)
.authenticate(credFile)
.withDefaultSubscription();
// use the properties file with the service principal information to authenticate
// change the name of the environment variable if you used a different name in the previous step
final File credFile = new File(System.getenv("AZURE_AUTH_LOCATION"));
Azure azure = Azure.configure()
.withLogLevel(LogLevel.BASIC)
.authenticate(credFile)
.withDefaultSubscription();
// create a new storage account
String storageAccountName = SdkContext.randomResourceName("st",8);
StorageAccount storage = azure.storageAccounts().define(storageAccountName)
.withRegion(Region.US_WEST2)
.withNewResourceGroup("sampleStorageResourceGroup")
.create();
// create a new storage account
String storageAccountName = SdkContext.randomResourceName("st",8);
StorageAccount storage = azure.storageAccounts().define(storageAccountName)
.withRegion(Region.US_WEST2)
.withNewResourceGroup("sampleStorageResourceGroup")
.create();
// create a storage container to hold the file
List<StorageAccountKey> keys = storage.getKeys();
final String storageConnection = "DefaultEndpointsProtocol=https;"
+ "AccountName=" + storage.name()
+ ";AccountKey=" + keys.get(0).value()
+ ";EndpointSuffix=core.windows.net";
// create a storage container to hold the file
List<StorageAccountKey> keys = storage.getKeys();
final String storageConnection = "DefaultEndpointsProtocol=https;"
+ "AccountName=" + storage.name()
+ ";AccountKey=" + keys.get(0).value()
+ ";EndpointSuffix=core.windows.net";
CloudStorageAccount account = CloudStorageAccount.parse(storageConnection);
CloudBlobClient serviceClient = account.createCloudBlobClient();
CloudStorageAccount account = CloudStorageAccount.parse(storageConnection);
CloudBlobClient serviceClient = account.createCloudBlobClient();
// Container name must be lower case.
CloudBlobContainer container = serviceClient.getContainerReference("helloazure");
container.createIfNotExists();
// Container name must be lower case.
CloudBlobContainer container = serviceClient.getContainerReference("helloazure");
container.createIfNotExists();
// Make the container public
BlobContainerPermissions containerPermissions = new BlobContainerPermissions();
containerPermissions.setPublicAccess(BlobContainerPublicAccessType.CONTAINER);
container.uploadPermissions(containerPermissions);
// Make the container public
BlobContainerPermissions containerPermissions = new BlobContainerPermissions();
containerPermissions.setPublicAccess(BlobContainerPublicAccessType.CONTAINER);
container.uploadPermissions(containerPermissions);
// write a blob to the container
CloudBlockBlob blob = container.getBlockBlobReference("helloazure.txt");
blob.uploadText("hello Azure");
// write a blob to the container
CloudBlockBlob blob = container.getBlockBlobReference("helloazure.txt");
blob.uploadText("hello Azure");
} catch (Exception e) {
System.out.println(e.getMessage());
e.printStackTrace();
}
} catch (Exception e) {
System.out.println(e.getMessage());
e.printStackTrace();
}
}
```
@ -210,6 +209,7 @@ Run the sample from the command line:
```
mvn compile exec:java
```
You'll see some REST requests and responses in the console as the SDK makes the underlying calls to the Azure REST API to configure the storage account.
You can browse for the `helloazure.txt` file in your storage account through the Azure portal or with [Azure Storage Explorer](https://docs.microsoft.com/azure/vs-azure-tools-storage-explorer-blobs).
@ -228,64 +228,64 @@ Replace the current main method in `AzureApp.java` with the code below, setting
```java
public static void main(String args[])
{
// create the db using the management libraries
try {
final File credFile = new File(System.getenv("AZURE_AUTH_LOCATION"));
Azure azure = Azure.configure()
.withLogLevel(LogLevel.BASIC)
.authenticate(credFile)
.withDefaultSubscription();
public static void main(String args[])
{
// create the db using the management libraries
try {
final File credFile = new File(System.getenv("AZURE_AUTH_LOCATION"));
Azure azure = Azure.configure()
.withLogLevel(LogLevel.BASIC)
.authenticate(credFile)
.withDefaultSubscription();
final String adminUser = SdkContext.randomResourceName("db",8);
final String sqlServerName = SdkContext.randomResourceName("sql",10);
final String sqlDbName = SdkContext.randomResourceName("dbname",8);
final String dbPassword = "YOUR_PASSWORD_HERE";
final String adminUser = SdkContext.randomResourceName("db",8);
final String sqlServerName = SdkContext.randomResourceName("sql",10);
final String sqlDbName = SdkContext.randomResourceName("dbname",8);
final String dbPassword = "YOUR_PASSWORD_HERE";
SqlServer sampleSQLServer = azure.sqlServers().define(sqlServerName)
.withRegion(Region.US_EAST)
.withNewResourceGroup("sampleSqlResourceGroup")
.withAdministratorLogin(adminUser)
.withAdministratorPassword(dbPassword)
.withNewFirewallRule("0.0.0.0","255.255.255.255")
.create();
SqlServer sampleSQLServer = azure.sqlServers().define(sqlServerName)
.withRegion(Region.US_EAST)
.withNewResourceGroup("sampleSqlResourceGroup")
.withAdministratorLogin(adminUser)
.withAdministratorPassword(dbPassword)
.withNewFirewallRule("0.0.0.0","255.255.255.255")
.create();
SqlDatabase sampleSQLDb = sampleSQLServer.databases().define(sqlDbName).create();
SqlDatabase sampleSQLDb = sampleSQLServer.databases().define(sqlDbName).create();
// assemble the connection string to the database
final String domain = sampleSQLServer.fullyQualifiedDomainName();
String url = "jdbc:sqlserver://"+ domain + ":1433;" +
"database=" + sqlDbName +";" +
"user=" + adminUser+ "@" + sqlServerName + ";" +
"password=" + dbPassword + ";" +
"encrypt=true;trustServerCertificate=false;hostNameInCertificate=*.database.windows.net;loginTimeout=30;";
// assemble the connection string to the database
final String domain = sampleSQLServer.fullyQualifiedDomainName();
String url = "jdbc:sqlserver://"+ domain + ":1433;" +
"database=" + sqlDbName +";" +
"user=" + adminUser+ "@" + sqlServerName + ";" +
"password=" + dbPassword + ";" +
"encrypt=true;trustServerCertificate=false;hostNameInCertificate=*.database.windows.net;loginTimeout=30;";
// connect to the database, create a table and insert a entry into it
Connection conn = DriverManager.getConnection(url);
// connect to the database, create a table and insert a entry into it
Connection conn = DriverManager.getConnection(url);
String createTable = "CREATE TABLE CLOUD ( name varchar(255), code int);";
String insertValues = "INSERT INTO CLOUD (name, code ) VALUES ('Azure', 1);";
String selectValues = "SELECT * FROM CLOUD";
Statement createStatement = conn.createStatement();
createStatement.execute(createTable);
Statement insertStatement = conn.createStatement();
insertStatement.execute(insertValues);
Statement selectStatement = conn.createStatement();
ResultSet rst = selectStatement.executeQuery(selectValues);
String createTable = "CREATE TABLE CLOUD ( name varchar(255), code int);";
String insertValues = "INSERT INTO CLOUD (name, code ) VALUES ('Azure', 1);";
String selectValues = "SELECT * FROM CLOUD";
Statement createStatement = conn.createStatement();
createStatement.execute(createTable);
Statement insertStatement = conn.createStatement();
insertStatement.execute(insertValues);
Statement selectStatement = conn.createStatement();
ResultSet rst = selectStatement.executeQuery(selectValues);
while (rst.next()) {
System.out.println(rst.getString(1) + " "
+ rst.getString(2));
}
} catch (Exception e) {
System.out.println(e.getMessage());
System.out.println(e.getStackTrace().toString());
while (rst.next()) {
System.out.println(rst.getString(1) + " "
+ rst.getString(2));
}
} catch (Exception e) {
System.out.println(e.getMessage());
System.out.println(e.getStackTrace().toString());
}
}
```
Run the sample from the command line:
@ -301,45 +301,45 @@ az group delete --name sampleSqlResourceGroup
## Create a Linux virtual machine
Next replace the `main` method, setting real values for `userName` and `password`.
This example creates a new Ubuntu Linux VM in Azure with name `testLinuxVM` in a new Azure resource group `sampleResourceGroup` running in the US East region.
This main method creates a new Ubuntu Linux VM in Azure with name `testLinuxVM` in a new Azure resource group `sampleResourceGroup` running in the US East region.
Replace the `main` method, setting real values for `userName` and `password`.
```java
public static void main(String[] args) {
public static void main(String[] args) {
final String userName = "YOUR_VM_USERNAME";
final String password = "YOUR_VM_PASSWORD";
final String userName = "YOUR_VM_USERNAME";
final String password = "YOUR_VM_PASSWORD";
try {
try {
// use the properties file with the service principal information to authenticate
// change the name of the environment variable if you used a different name in the previous step
final File credFile = new File(System.getenv("AZURE_AUTH_LOCATION"));
Azure azure = Azure.configure()
.withLogLevel(LogLevel.BASIC)
.authenticate(credFile)
.withDefaultSubscription();
// create a Ubuntu virtual machine in a new resource group
VirtualMachine linuxVM = azure.virtualMachines().define("testLinuxVM")
.withRegion(Region.US_EAST)
.withNewResourceGroup("sampleVmResourceGroup")
.withNewPrimaryNetwork("10.0.0.0/24")
.withPrimaryPrivateIpAddressDynamic()
.withoutPrimaryPublicIpAddress()
.withPopularLinuxImage(KnownLinuxVirtualMachineImage.UBUNTU_SERVER_16_04_LTS)
.withRootUsername(userName)
.withRootPassword(password)
.withUnmanagedDisks()
.withSize(VirtualMachineSizeTypes.STANDARD_D3_V2)
.create();
// use the properties file with the service principal information to authenticate
// change the name of the environment variable if you used a different name in the previous step
final File credFile = new File(System.getenv("AZURE_AUTH_LOCATION"));
Azure azure = Azure.configure()
.withLogLevel(LogLevel.BASIC)
.authenticate(credFile)
.withDefaultSubscription();
// create a Ubuntu virtual machine in a new resource group
VirtualMachine linuxVM = azure.virtualMachines().define("testLinuxVM")
.withRegion(Region.US_EAST)
.withNewResourceGroup("sampleVmResourceGroup")
.withNewPrimaryNetwork("10.0.0.0/24")
.withPrimaryPrivateIpAddressDynamic()
.withoutPrimaryPublicIpAddress()
.withPopularLinuxImage(KnownLinuxVirtualMachineImage.UBUNTU_SERVER_16_04_LTS)
.withRootUsername(userName)
.withRootPassword(password)
.withUnmanagedDisks()
.withSize(VirtualMachineSizeTypes.STANDARD_D3_V2)
.create();
} catch (Exception e) {
System.out.println(e.getMessage());
e.printStackTrace();
}
} catch (Exception e) {
System.out.println(e.getMessage());
e.printStackTrace();
}
}
```
Run the sample from the command line:
@ -348,7 +348,7 @@ Run the sample from the command line:
mvn clean compile exec:java
```
You'll see some REST requests and responses in the console as the SDK makes the underlying calls to the Azure REST API to configure the virtual machine and its resources. When the program finishes, verify the virtual machine in your subscription with the Azure CLI 2.0:
When the program finishes, verify the virtual machine in your subscription with the Azure CLI 2.0:
```azurecli
az vm list --resource-group sampleVmResourceGroup
@ -362,36 +362,36 @@ az group delete --name sampleVmResourceGroup
## Deploy a web app from a GitHub repo
This code deploys an code from the `master` branch in a GitHub repo into a new [Azure App Service webapp](https://docs.microsoft.com/azure/app-service-web/app-service-web-overview) running in a free pricing tier plan. Replace the main method in `AzureApp.java` with the one below, updating the `appName` variable to a unique value before running the code.
This code deploys a web application from the `master` branch in a GitHub repo into a new [Azure App Service Web App](https://docs.microsoft.com/azure/app-service-web/app-service-web-overview) running in the free pricing tier. Replace the main method in `AzureApp.java` with the one below, updating the `appName` variable to a unique value before running the code.
```java
public static void main(String[] args) {
try {
public static void main(String[] args) {
try {
final File credFile = new File(System.getenv("AZURE_AUTH_LOCATION"));
final String appName = "YOUR_APP_NAME";
final File credFile = new File(System.getenv("AZURE_AUTH_LOCATION"));
final String appName = "YOUR_APP_NAME";
Azure azure = Azure.configure()
.withLogLevel(LogLevel.BASIC)
.authenticate(credFile)
.withDefaultSubscription();
Azure azure = Azure.configure()
.withLogLevel(LogLevel.BASIC)
.authenticate(credFile)
.withDefaultSubscription();
WebApp app = azure.webApps().define(appName)
.withRegion(Region.US_WEST2)
.withNewResourceGroup("sampleWebResourceGroup")
.withNewWindowsPlan(PricingTier.FREE_F1)
.defineSourceControl()
.withPublicGitRepository(
"https://github.com/Azure-Samples/app-service-web-java-get-started")
.withBranch("master")
.attach()
.create();
WebApp app = azure.webApps().define(appName)
.withRegion(Region.US_WEST2)
.withNewResourceGroup("sampleWebResourceGroup")
.withNewWindowsPlan(PricingTier.FREE_F1)
.defineSourceControl()
.withPublicGitRepository(
"https://github.com/Azure-Samples/app-service-web-java-get-started")
.withBranch("master")
.attach()
.create();
} catch (Exception e) {
System.out.println(e.getMessage());
e.printStackTrace();
}
} catch (Exception e) {
System.out.println(e.getMessage());
e.printStackTrace();
}
}
```
Run the code as before using Maven:
@ -400,13 +400,13 @@ Run the code as before using Maven:
mvn clean compile exec:java
```
Open up a browser to the application using the CLI:
Open a browser pointed to the application using the CLI:
```azurecli
az appservice web browse --resource-group sampleWebResourceGroup --name YOUR_APP_NAME
```
Remove the web app and plan from your subscription once you've proven you can reach it
Remove the web app and plan from your subscription once you've verified the deployment.
```azurecli
az group delete --name sampleWebResourceGroup

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

@ -41,7 +41,7 @@ Other Java build tools like Gradle are supported but the install steps are not p
## Azure service libraries
Integrate Azure services to add functionality to your apps using these libraries. Learn more about building apps with Azure services at [Java developer center](https://azure.microsoft.com/develop/java).
Integrate Azure services to add functionality to your apps using these libraries. Learn more about building apps with Azure services at the [Java developer center](https://azure.microsoft.com/develop/java).
<a name="azure-storage"></a>
@ -161,7 +161,7 @@ Safely access keys and secrets from your applications.
### [Event Hub](https://docs.microsoft.com/azure/event-hubs/event-hubs-what-is-event-hubs)
High throughput event and telemetry handling for your instrumentation or IoT scenarios.
High-throughput event and telemetry handling for your instrumentation or IoT scenarios.
```XML
<dependency>

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

@ -21,9 +21,9 @@ ms.assetid: e4537f38-a60d-4218-a9ba-3cba7af61b8b
|---|---|
| [Create and manage SQL databases][1] | Create SQL databases, set performance levels, and configure firewalls. |
| **Scale databases** ||
| [Manage SQL databases across multiple regions][2] | Create a master SQL databases and read-only databases from the master in multiple regions. Connect VMs to their nearest SQL database instance with a virtual network and firewall rules. |
| [Manage SQL databases across multiple regions][2] | Create a master SQL database and read-only databases from the master in multiple regions. Connect VMs to their nearest SQL database instance with a virtual network and firewall rules. |
| **Elastic Pools** ||
| [Manage SQL Databases in elastic pools][3] | Create, delete, and move SQL databases in and out of elastic pools. |
| [Manage SQL databases in elastic pools][3] | Create, delete, and move SQL databases in and out of elastic pools. |
[1]: https://azure.microsoft.com/resources/samples/sql-database-java-manage-db/
[2]: https://azure.microsoft.com/resources/samples/sql-database-java-manage-sql-databases-across-regions/

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

@ -22,11 +22,11 @@ The following table links to Java source you can use to create and configure Azu
|---|---|
| [Manage virtual machines][1] | Create, modify, start, stop, and delete virtual machines. |
| [Create a virtual machine from a custom image][2] | Create a custom virtual machine image and use it to create new virtual machines. |
| [Create a virtual machine using specialized VHD from a snapshot][3] | Create snapshot from the virtual machine's OS and data disks, create managed disks from the snapshots, then create a virtual machine by attaching the managed disks. |
| [Create a virtual machine using specialized VHD from a snapshot][3] | Create snapshot from the virtual machine's OS and data disks, create managed disks from the snapshots, and then create a virtual machine by attaching the managed disks. |
| [Create virtual machines in parallel in the same network][4] | Create virtual machines in the same region on the same virtual network with two subnets in parallel. |
| [Create virtual machines across regions in parallel][5] | Create and load balance a set of virtual machines across multiple Azure regions. |
| [Create virtual machines across regions in parallel][5] | Create and load-balance a set of virtual machines across multiple Azure regions. |
| **Network virtual machines** ||
| [Manage virtual networks][6] | Set up a virtual network with two subnets and restrict Internet access to the subnets. |
| [Manage virtual networks][6] | Set up a virtual network with two subnets and restrict Internet access to them. |
| **Create scale sets** ||
| [Create a virtual machine scale set with a load balancer][7] | Create a VM scale set, set up a load balancer, and get SSH connection strings to the scale set VMs. |

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

@ -18,15 +18,15 @@ ms.assetid: 43633e5c-9fb1-4807-ba63-e24c126754e2
| **Create an app** ||
|---|---|
| [Create a web app and deploy from FTP or GitHub][1] | Deploy web apps through local Git, FTP, and continuous integration from GitHub. |
| [Create a web app and manage deployment slots][2] | Create a web app and deploy to staging slots, then swap between slots. |
| [Create a web app and deploy from FTP or GitHub][1] | Deploy web apps from local Git, FTP, and continuous integration from GitHub. |
| [Create a web app and manage deployment slots][2] | Create a web app and deploy to staging slots, and then swap deployments between slots. |
| **Configure app** ||
| [Create a web app and configure a custom domain][3] | Create a web app with a custom domain and self-signed SSL certificate. |
| **Scale apps** ||
| [Scale a web app with high availability across multiple regions][4] | Scale a web app in three different geographical regions and make them available through a single endpoint using Azure Traffic Manager. |
| **Connect app to resources** ||
| [Connect a web app to a storage account][5] | Create an Azure storage account and add the storage account connection string to the app settings. |
| [Connect a web app to a SQL database][6] | Create a web app and SQL database, then add the SQL database connection string to the app settings. |
| [Connect a web app to a SQL database][6] | Create a web app and SQL database, and then add the SQL database connection string to the app settings. |
[1]: java-sdk-configure-webapp-sources.md
[2]: https://azure.microsoft.com/resources/samples/app-service-java-manage-staging-and-production-slots-for-web-apps/

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

@ -20,23 +20,23 @@ The Azure libraries for Java let you use Azure services and manage Azure resourc
## Consume Azure services
Use services such as SQL Database, Azure Storage, Active Directory, and DocumentDB in your Java applications with native interfaces. Import the libraries for the services you want to use from [the complete list](java-sdk-azure-install.md) and check out [Java developer center](https://azure.microsoft.com/develop/java/) to learn more about adding features to your apps with Azure services.
Use services such as SQL Database, Azure Storage, Active Directory, and DocumentDB in your Java applications with native interfaces. Import the libraries for the services you want to use from [the complete list](java-sdk-azure-install.md) and check out the [Java developer center](https://azure.microsoft.com/develop/java/) to learn more about adding features to your apps with Azure services.
For example, to print out the contents of all blobs in an Azure storage container:
```java
// get the container from the blob client
CloudBlobContainer container = blobClient.getContainerReference("blobcontainer");
// get the container from the blob client
CloudBlobContainer container = blobClient.getContainerReference("blobcontainer");
// For each item in the container
for (ListBlobItem blobItem : container.listBlobs()) {
// If the item is a blob, not a virtual directory
if (blobItem instanceof CloudBlockBlob) {
// Download the text
CloudBlockBlob retrievedBlob = (CloudBlockBlob) blobItem;
System.out.println(retrievedBlob.downloadText());
}
}
// For each item in the container
for (ListBlobItem blobItem : container.listBlobs()) {
// If the item is a blob, not a virtual directory
if (blobItem instanceof CloudBlockBlob) {
// Download the text
CloudBlockBlob retrievedBlob = (CloudBlockBlob) blobItem;
System.out.println(retrievedBlob.downloadText());
}
}
```
## Manage Azure resources
@ -47,17 +47,17 @@ For example, to create a Linux VM in an existing Azure resource group:
```java
VirtualMachine linuxVM = azure.virtualMachines().define("myAzureVM")
.withRegion(region)
.withExistingResourceGroup("sampleResourceGroup")
.withNewPrimaryNetwork("10.0.0.0/28")
.withPrimaryPrivateIpAddressDynamic()
.withoutPrimaryPublicIpAddress()
.withPopularLinuxImage(KnownLinuxVirtualMachineImage.UBUNTU_SERVER_16_04_LTS)
.withRootUsername(userName)
.withRootPassword(password)
.withUnmanagedStorage()
.withSize(VirtualMachineSizeTypes.STANDARD_D3_V2)
.create();
.withRegion(region)
.withExistingResourceGroup("sampleResourceGroup")
.withNewPrimaryNetwork("10.0.0.0/28")
.withPrimaryPrivateIpAddressDynamic()
.withoutPrimaryPublicIpAddress()
.withPopularLinuxImage(KnownLinuxVirtualMachineImage.UBUNTU_SERVER_16_04_LTS)
.withRootUsername(userName)
.withRootPassword(password)
.withUnmanagedStorage()
.withSize(VirtualMachineSizeTypes.STANDARD_D3_V2)
.create();
```
Review the [install instructions](java-sdk-azure-install.md) for a full list of the libraries and how to import them into your projects and the [get started article](java-sdk-azure-get-started.md) to set up your environment and run some example code in your own subscription.