![]() |
Consumption Analytics Documentation |
To invoke the REST API from a Java client program, you must include the file
<install_dir>/sdk/cc-apiclient-<cc_version>.jar
in your Java client's classpath.
The documentation for individual API methods includes example Java code. For syntax and prototypes of each method, see the Javadoc information at <install_dir>/docs/rest/apidocs/index.html
.
The following example Java code demonstrates using the API with the Apache CXF JAX-RS client.
import org.apache.cxf.jaxrs.client.Client; import org.apache.cxf.jaxrs.client.JAXRSClientFactory; import org.apache.cxf.jaxrs.client.WebClient; import org.apache.cxf.common.util.Base64Utility; import com.cloudcruiser.server.webservices.v1.dto.resource.*; import com.cloudcruiser.server.webservices.v1.services.IResourceWebService; ... // The base URI final String baseUri = "http://localhost:8080/rest/"; // The HTTP Basic authentication header value String basicAuthValue = "Basic " + Base64Utility.encode("username:password".getBytes()); // Create the client and proxy IResourceWebService resourceProxy = JAXRSClientFactory.create(baseUri, IResourceWebService.class); Client client = WebClient.client(resourceProxy); // First make the login request with the HTTP Basic authentication client.header("Authorization", basicAuthValue); // Invoke the CC REST API calls via proxy Resources resources = resourceProxy.getAllResources(); // Invoke the CC REST API calls via proxy to fetch the Resource information with the headerId 10041. client.reset(); client.header("Authorization", basicAuthValue); ResourceInfo resourceInfo = resourceProxy.getResource(10041); // Modify the resource. resourceInfo.setHidden(true); resourceInfo.setUnitDesc("GB"); resourceInfo.setRateDecimals(3); // Invoke the CC REST API calls via proxy to update the existing resource with the headerId 10041. client.reset(); client.header("Authorization", basicAuthValue); ResourceInfo updatedResourceInfo = resourceProxy.updateResource(10041, resourceInfo); ...
(c) Copyright 2017-2020 Hewlett Packard Enterprise Development LP