Home > Cloud Computing, Software Development > Azure Service Management APIs: The Old APIs That Works

Azure Service Management APIs: The Old APIs That Works

March 14th, 2016 Leave a comment Go to comments

After the initial bad experience with the new Azure Resource Management APIs, I took a different approach – try the old Service Management APIs. While transitioning from old system to new system, the old one may still be the best for an unexpected long period of time. Like VMware vSphere Client, VMware has declared end of life many times, but it’s still the favorite for most customers, while the future Web Client remains “future” since 2011.

There are actually some good documentation on using the old APIs. One of them is this “Getting Started With the Azure Java Management Libraries”. Following the tutorial is mostly straight forward, even though I don’t use the recommended Eclipse IDE with Maven. I had been using Eclipse for many years but found it could not kept up the pace after IBM slowed its involvements there, thus switched to NetBeans.

Time to learn how to "Google" and manage your VMware and clouds in a fast and secure


To run the first sample is not very hard, but I did get into glitches that were mostly caused by the dependencies. Somehow there are many different packages in the com.microsoft.azure namespace, and both the old and new management APIs are there. Even worse, some Java class names are exactly the same. That could end up to cases in which you think you got the right classes but you could not find the methods as shown in the sample. Unless you know exact package name, you know it’s a different class. But for newcomers, they all look the same. :)

So a simple way to avoid the problem is to simply copy what I have as the pom.xml for your Maven project.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

Here is the sample to list regions. Please change the subscription id to yours and upload a certificate as described following the code.

package org.doublecloud.azuredemo;
import com.microsoft.windowsazure.core.utils.KeyStoreType;
import com.microsoft.windowsazure.management.configuration.ManagementConfiguration;
import java.net.URI;
import java.util.ArrayList;
import com.microsoft.windowsazure.Configuration;
import com.microsoft.windowsazure.management.ManagementClient;
import com.microsoft.windowsazure.management.ManagementService;
import com.microsoft.windowsazure.management.models.LocationsListResponse;
public class ClassicAzureListRegion
  public static void main(String[] args) throws Exception
    Configuration config = ManagementConfiguration.configure(
      new URI("https://management.core.windows.net/"), // management api endpoint 
      "800d452f-5fcb-4151-97ec-bf748fb12ea0", // subscriptionId
      "keystore.jks", // path to the JKS file
      "password", // password for the JKS
    ManagementClient client = ManagementService.create(config);
    LocationsListResponse response = client.getLocationsOperations().list();
    ArrayList<LocationsListResponse.Location> locations = response.getLocations();
    // print out each region name
    for(LocationsListResponse.Location location : locations)

Before you run the code, you want to create certificate and upload it to your Azure account. Working with the class GUI for upload the certificate is quite simple. Just click on the Settings, and you won’t miss it.

Here are a few commands for you to create keystore and certificate, assuming you have JDK installed already. You should change the path to the JDK per your installation.

"c:\Program Files\Java\jdk1.8.0_31\bin\keytool.exe" -genkey -keyalg RSA -alias selfsigned -keystore keystore.jks -storepass password -validity 360 -keysize 2048
"c:\Program Files\Java\jdk1.8.0_31\bin\keytool.exe" -exportcert -alias selfsigned -file certForAzure.cer -keystore keystore.jks

BTW, if you want to change your password after creating the keystore, you can use the following command. If you use the same keystore, don’t forget to change the password in the source code accordingly.

"c:\Program Files\Java\jdk1.8.0_31\bin\keytool.exe" -storepasswd -keystore keystore.jks

You can place the keystore.jks file in the project home of the above program. For the certForAzure.cer file, you can delete it after you uploading it to Azure.

After you running the program, you should see the same as I did here:

East US
Central US
North Europe
West Europe
Southeast Asia
Japan West
Japan East
  1. Elsa
    September 19th, 2016 at 16:18 | #1

    Hi Steve! Thanks for the informative articles. I have a simple question for which I cannot somehow find answer – how do I list Virtual Machines?

  2. September 19th, 2016 at 17:56 | #2

    Hi Elsa,

    Good to hear from you. You mean how to list the virtual machines from Azure?


  3. Elsa
    September 20th, 2016 at 14:38 | #3

    yes! What APis do I need to run in the old set (or new for that matter). I thought this was goign to take me no more than 15 mins to figure out :-/

  1. No trackbacks yet.