public static List<CIMInstance> enumerateInstances(WBEMClient pClient, String pNamespace,
CIMObjectPath pClassName,String[] pPropertyList) {
try {
/* final CloseableIterator<CIMInstance> iterator = pClient.enumerateInstances(
pClassName, true, false,
false, pPropertyList);*/
String pFilterQuery="SELECT * FROM CIM_ComputerSystem";
final CloseableIterator<CIMInstance> iterator = pClient.execQuery(pClassName, pFilterQuery, "WQL");
/* public EnumerateResponse<CIMInstance> enumerateInstances(CIMObjectPath pObjectName,
boolean pDeepInheritance, boolean pIncludeClassOrigin, String[] pPropertyList,
String pFilterQueryLanguage, String pFilterQuery, UnsignedInteger32 pTimeout,
boolean pContinueOnError, UnsignedInteger32 pMaxObjects) throws WBEMException {*/
/* final EnumerateResponse<CIMInstance> iterators = pClient.enumerateInstances(pClassName,
true, false,pPropertyList,
null,null, null, false, null);
final CloseableIterator<CIMInstance> iterator=iterators.getResponses();*/
try {
final List<CIMInstance> result = new ArrayList<CIMInstance>();
while (iterator.hasNext()) {
final CIMInstance instance = iterator.next();
result.add(instance);
System.out.println(Jsr48CimSample.toMof(instance));
}
return result;
} finally {
iterator.close();
}
} catch (final WBEMException e) {
e.printStackTrace();
}
return null;
}文档和资料就是这样写的 但是找个错误太深了 无能为力啊、
WBEMException: CIM_ERR_NOT_SUPPORTED
at org.sblim.cimclient.internal.wbem.CloseableIteratorSAX.hasNext(CloseableIteratorSAX.java:122)
at org.sblim.cimclient.internal.wbem.WBEMClientCIMXML.getIterator(WBEMClientCIMXML.java:2206)
at org.sblim.cimclient.internal.wbem.WBEMClientCIMXML.execQuery(WBEMClientCIMXML.java:1223)
at org.sblim.cimclient.samples.Jsr48OperationSample.enumerateInstances(Jsr48OperationSample.java:153)
at org.sblim.cimclient.samples.Jsr48OperationSample.main(Jsr48OperationSample.java:404)
存储JavaString
CIMObjectPath pClassName,String[] pPropertyList) {
try {
/* final CloseableIterator<CIMInstance> iterator = pClient.enumerateInstances(
pClassName, true, false,
false, pPropertyList);*/
String pFilterQuery="SELECT * FROM CIM_ComputerSystem";
final CloseableIterator<CIMInstance> iterator = pClient.execQuery(pClassName, pFilterQuery, "WQL");
/* public EnumerateResponse<CIMInstance> enumerateInstances(CIMObjectPath pObjectName,
boolean pDeepInheritance, boolean pIncludeClassOrigin, String[] pPropertyList,
String pFilterQueryLanguage, String pFilterQuery, UnsignedInteger32 pTimeout,
boolean pContinueOnError, UnsignedInteger32 pMaxObjects) throws WBEMException {*/
/* final EnumerateResponse<CIMInstance> iterators = pClient.enumerateInstances(pClassName,
true, false,pPropertyList,
null,null, null, false, null);
final CloseableIterator<CIMInstance> iterator=iterators.getResponses();*/
try {
final List<CIMInstance> result = new ArrayList<CIMInstance>();
while (iterator.hasNext()) {
final CIMInstance instance = iterator.next();
result.add(instance);
System.out.println(Jsr48CimSample.toMof(instance));
}
return result;
} finally {
iterator.close();
}
} catch (final WBEMException e) {
e.printStackTrace();
}
return null;
}文档和资料就是这样写的 但是找个错误太深了 无能为力啊、
WBEMException: CIM_ERR_NOT_SUPPORTED
at org.sblim.cimclient.internal.wbem.CloseableIteratorSAX.hasNext(CloseableIteratorSAX.java:122)
at org.sblim.cimclient.internal.wbem.WBEMClientCIMXML.getIterator(WBEMClientCIMXML.java:2206)
at org.sblim.cimclient.internal.wbem.WBEMClientCIMXML.execQuery(WBEMClientCIMXML.java:1223)
at org.sblim.cimclient.samples.Jsr48OperationSample.enumerateInstances(Jsr48OperationSample.java:153)
at org.sblim.cimclient.samples.Jsr48OperationSample.main(Jsr48OperationSample.java:404)
存储JavaString
final List<CIMInstance> result = new ArrayList<CIMInstance>();
while (iterator.hasNext()) {
final CIMInstance instance = iterator.next();
result.add(instance);
System.out.println(Jsr48CimSample.toMof(instance));
}
return result;
} finally {
iterator.close();
}去掉所有的final看下
找后面没关系 public CloseableIterator<CIMInstance> execQuery(CIMObjectPath pPath, String pQuery,
String pQueryLanguage) throws WBEMException { final String operation = "ExecQuery";
final LogAndTraceBroker logger = LogAndTraceBroker.getBroker();
logger.entry(); checkState(); try {
if (pPath == null || pPath.getNamespace() == null) { throw new WBEMException(
WBEMException.CIM_ERR_INVALID_PARAMETER, "Invalid object path"); } HttpHeader hh = new HttpHeader();
hh.addField("CIMObject", HttpHeader.encode(pPath.getNamespace(), "UTF-8", "US-ASCII")); Document doc = this.iXmlHelper.newDocument();
this.iXmlHelper.createCIMMessage(doc, this.iXmlHelper.execQuery_request(doc, pPath,
pQuery, pQueryLanguage)); /* TransformerFactory tfac = TransformerFactory.newInstance();
Transformer tra = tfac.newTransformer();
DOMSource doms = new DOMSource(doc);
File file = new File("C:\\newStu.xml");
FileOutputStream outstream = new FileOutputStream(file);
StreamResult sr = new StreamResult(outstream);
tra.transform(doms,sr);*/
InputStreamReader is = transmitRequest("ExecQuery", hh, doc);
/* BufferedWriter writer = new BufferedWriter(new FileWriter("C:\\isStu.xml"));
BufferedReader bufReader = new BufferedReader(is);
while (bufReader.ready()) {
// 1. 得到每一行数据
String dataLine = bufReader.readLine();
writer.write(dataLine);
System.out.println(dataLine);
}*/
CloseableIterator<CIMInstance> iter = getIterator(is, pPath);
return iter; } catch (WBEMException e) {
logger.trace(Level.FINE, operation + " request resulted in CIM Error", e);
throw e;
} catch (Exception e) {
if (e.getCause() != null && e.getCause() instanceof WBEMException) {
logger
.trace(Level.FINE, operation + " request resulted in CIM Error", e
.getCause());
throw (WBEMException) e.getCause();
}
logger.trace(Level.FINE, operation + " request failed", e);
throw new WBEMException(WBEMException.CIM_ERR_FAILED, null, null, e);
} finally {
logger.exit();
}
}
Java HotSpot(TM) Client VM warning: MaxNewSize (262144k) is equal to or greater than the entire heap (262144k). A new generation size of 262080k will be used.
<?xml version="1.0" encoding="UTF-8"?>
<CIM CIMVERSION="2.0" DTDVERSION="2.0">
<MESSAGE ID="238876" PROTOCOLVERSION="1.0">
<SIMPLERSP>
<IMETHODRESPONSE NAME="ExecQuery">
<ERROR CODE="7" />
</IMETHODRESPONSE>
</SIMPLERSP>
</MESSAGE>
</CIM><ERROR CODE="7" />这个是错误码 我猜就得找到对应解析的位置 直接发最底层
下面代码的 返回数据没看明白怎么得到的