1.5

vCenter Chargeback API Programming Guide
34 VMware, Inc.
ThefollowingisanexamplerequestXML.
<?xml version="1.0" encoding="UTF-8"?>
<Request>
<SearchQueries>
<SearchQuery id="reportSchedule">
<Criteria type="AND">
<Filter name="name" type="LIKE" value="%reportSchedule1%" />
<Filter name="desc" type="LIKE" value="%reportScheduleDesc1%" />
<Filter name="costModelName" type="EQUAL" value="costModel1"/>
</Criteria>
<SortBy>
<Params>
<Param index="1" order="DESC">name</Param>
</Params>
</SortBy>
<Pagination>
<FirstResultCount>0</FirstResultCount>
<MaxResultCount>100</MaxResultCount>
</Pagination>
</SearchQuery>
</SearchQueries>
</Request>
ThefollowingisanexampleprogramthatcallstheAPI.ThisprogramassumesthattherequestXMLis
populatedwiththerequiredinformation.
/**
* This method get schedule by hierarchy name from vCenter-ChargeBack
*
* @param requestFilePath
* @param baseURL
* @throws IOException
* @throws HttpException
* @throws NoSuchAlgorithmException
* @throws KeyManagementException
* @throws JDOMException
*/
public static void sampleGetScheduleByHierarchyName(String requestFilePath, String
baseURL) throws HttpException, IOException, KeyManagementException,
NoSuchAlgorithmException, JDOMException {
PostMethod post = null;
Document requestDocument = CommonUtil.getXMLDocument(requestFilePath);
String bodyString = CommonUtil.xmlAsString(requestDocument);
HttpClient client = new HttpClient();
Protocol.registerProtocol("https", new Protocol("https", (ProtocolSocketFactory) new
FakeSSLCertificateSocketFactory(), 443));
String uri = "https://" + baseURL + "/vCenter-CB/api/search";
try {
post = new PostMethod(uri);
post.setRequestBody(bodyString);
client.executeMethod(post);
System.out.println(post.getResponseBodyAsString());
} finally {
if (post != null) {
post.releaseConnection();
}
}
}