The entry point of the SBLIM CIM Client for Java is the WBEMClient
class. An instance of this class encapsulates a client connection to a CIMOM. The API represents the WBEM operations.
WBEMClient is just an interface, for instantiation call
WBEMClientFactory.getClient().
Other quite important classes are found in the javax.cim
package that contains the Java representations of all CIM objects.
The following code snippet opens a connection and enumerates all CIM_RegisteredProfile instances in the
root/cimv2 namespace.
URL cimomUrl = new URL("https://127.0.0.1:5989");
String user = "youruser";
String pw = "yourpassword";
final WBEMClient client = WBEMClientFactory.getClient(WBEMClientConstants.PROTOCOL_CIMXML);
final CIMObjectPath path = new CIMObjectPath(cimomUrl.getProtocol(),
cimomUrl.getHost(), String.valueOf(cimomUrl.getPort()), null, null, null);
final Subject subject = new Subject();
subject.getPrincipals().add(new UserPrincipal(user));
subject.getPrivateCredentials().add(new PasswordCredential(pw));
try {
client.initialize(path, subject, Locale.getAvailableLocales());
} catch (Exception e) {
e.printStackTrace();
}
try {
final CloseableIterator<CIMObjectPath> iterator = client.enumerateInstanceNames(new CIMObjectPath(
"CIM_RegisteredProfile", "root/cimv2"));
try {
while (iterator.hasNext()) {
final CIMObjectPath pathIter = iterator.next();
System.out.println(pathIter.toString());
}
} finally {
iterator.close();
}
} catch (WBEMException e) {
e.printStackTrace();
}