I am building a Java app to automate some typical infrastructure tasks in my application. I successfully calling the Azure API, but I get a (400) Bad Request return code/message. I'm debugging this in eclipse, but can't find any more meaningful data in the connection object.
The initial simple task I'm trying to do is to add a new Data Disk to my IaaS VM, 'gildev01'. I'm following the guidance in this documentation: http://msdn.microsoft.com/en-us/library/jj157199.aspx
The HTTPS URL is correct, starting with management.core.windows.net followed by my Subscription ID, then the following:
/services/hostedservices/gildev01/deployments/gildev01/roles/gildev01/DataDisks
The payload is as follows:
<DataVirtualHardDisk xmlns="http://schemas.microsoft.com/windowsazure" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<HostCaching>ReadWrite</HostCaching>
<DiskLabel>java-disklabel-1</DiskLabel>
<DiskName>javadisk1</DiskName>
<LogicalDiskSizeInGB>1000</LogicalDiskSizeInGB>
<MediaLink>http://<myacct>.blob.core.windows.net/vhds/javadisk1.vhd</MediaLink>
</DataVirtualHardDisk>
So - two questions:
1) any ideas on what I'm doing wrong with the URL or the payload?
2) any suggestions on how to get more info out of the response object?
Adding Java Code:
private String addDataDisk (URL url, String keyStore, String keyStorePassword) throws UnrecoverableKeyException, KeyManagementException, KeyStoreException, NoSuchAlgorithmException, IOException {
SSLSocketFactory sslFactory = getSSLSocketFactory(keyStore, keyStorePassword);
String requestBody = "<DataVirtualHardDisk xmlns=\"http://schemas.microsoft.com/windowsazure\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\"><HostCaching>ReadWrite</HostCaching><DiskLabel>java-disklabel-1</DiskLabel><DiskName>javadisk1</DiskName><LogicalDiskSizeInGB>1000</LogicalDiskSizeInGB><MediaLink>http://myacct.blob.core.windows.net/vhds/javadisk1.vhd</MediaLink></DataVirtualHardDisk>");
HttpsURLConnection con = null;
con = (HttpsURLConnection) url.openConnection();
con.setSSLSocketFactory(sslFactory);
con.setDoOutput(true);
con.setRequestMethod("POST");
con.addRequestProperty("x-ms-version", "2013-08-01");
con.setRequestProperty("Content-Length", String.valueOf(requestBody.length()));
con.setRequestProperty("Content-Type", "application/xml");
DataOutputStream requestStream = new DataOutputStream (con.getOutputStream());
requestStream.write(requestBody.getBytes());
requestStream.flush();
requestStream.close();
String responseMessage = con.getResponseMessage()+" - "+Integer.toString(con.getResponseCode());