2.5

API Programming Guide
24 VMware, Inc.
<Property name="enabled" value="true" />
<Property name="granularity" value="DAILY" />
</Settings>
</Computation>
</Configuration>
</Report>
</Reports>
</Request>
vCenterChargebackManagerqueuesthisreportrequestasataskandreturnsanXMLthatindicatesthe
statusofthetask.YoucanusetheGetQueuedTaskStatusAPItotracktheprogressofthetask.Formore
informationontheGetQueuedTaskStatusAPI,seethevCenterChargeback
ManagerAPIReference.
ThefollowingisanexampleprogramthatcallstheAPI.
/**
* This method is to generate report for a vCenter-ChargeBack hierarchy
* entity in vCenter-ChargeBack
*
* @param requestFilePath
* @param baseURL
* @throws IOException
* @throws JDOMException
* @throws NoSuchAlgorithmException
* @throws KeyManagementException
* @throws HttpException
*/
public static void sampleGenerateReportMethod(String requestFilePath, String baseURL)
throws IOException, JDOMException, NoSuchAlgorithmException,
KeyManagementException, HttpException {
PostMethod post = null;
Document requestDocument = CommonUtil.getXMLDocument(requestFilePath);
String bodyString = CommonUtil.xmlAsString(requestDocument);
Protocol.registerProtocol("https", new Protocol("https", (ProtocolSocketFactory) new
FakeSSLCertificateSocketFactory(), 443));
String uri = "https://" + baseURL + "/vCenter-CB/api/report";
HttpClient client = new HttpClient();
System.out.println(uri);
System.out.println(bodyString);
try {
post = new PostMethod(uri);
post.setRequestBody(bodyString);
client.executeMethod(post);
System.out.println(post.getResponseBodyAsString());
} finally {
if (post != null) {
post.releaseConnection();
}
}
}