// Parse the returned XML string and retrieve the secret sessionId
ConnectReturnQos conRetQos = new ConnectReturnQos(glob, retXml);
sessionId = conRetQos.getSecretSessionId();
String publishOid = "";
StopWatch stop = new StopWatch();
//----------- Construct a message and publish it ---------
{
String xmlKey = "<?xml version='1.0' encoding='ISO-8859-1' ?>\n" +
"<key oid='' contentMime='text/xml'>" +
" <AGENT id='192.168.124.10' subId='1' type='generic'>" +
" <DRIVER id='FileProof' pollingFreq='10'>" +
" </DRIVER>"+
" </AGENT>" +
"</key>";
String content = "<file><size>1024 kBytes</size><creation>1.1.2000</creation></file>";
MsgUnitRaw msgUnit = new MsgUnitRaw(xmlKey, content.getBytes(), "<qos></qos>");
log.fine("Publishing ...");
stop.restart();
try {
String pubXml = blasterServer.publish(sessionId, msgUnit);
// Parse the returned XML string
PublishReturnQos q = new PublishReturnQos(glob, pubXml);
publishOid = q.getKeyOid();
log.info(" Returned oid=" + publishOid);
} catch(XmlBlasterException e) {
log.warning("XmlBlasterException: " + e.getMessage());
}
log.fine("Publishing done" + stop.nice());
}
//----------- get() the previous message OID -------
{
log.fine("get() using the exact oid ...");
String xmlKey = "<key oid='" + publishOid + "' queryType='EXACT'>\n" +
"</key>";
stop.restart();
MsgUnitRaw[] msgArr = null;
try {
msgArr = blasterServer.get(sessionId, xmlKey, "<qos></qos>");
log.info("Got " + msgArr.length + " messages:");
for (int ii=0; ii<msgArr.length; ii++) {
System.out.println(msgArr[ii].getKey() +
"\n################### RETURN CONTENT: ##################\n\n" +
new String(msgArr[ii].getContent()) +
"\n\n#######################################");
}
} catch(XmlBlasterException e) {
log.severe("XmlBlasterException: " + e.getMessage());
System.exit(1);
}
}
//----------- Construct a second message and publish it ---------
{
String xmlKey = "<?xml version='1.0' encoding='ISO-8859-1' ?>\n" +
"<key oid='Export-11' contentMime='text/plain'>" +
"<AGENT id='192.168.124.29' subId='1' type='generic'>" +
"<DRIVER id='ProgramExecute'>" +
"<EXECUTABLE>export</EXECUTABLE>" +
"<FILE>out.txt</FILE>" +
"</DRIVER>" +
"</AGENT>" +
"</key>";
String content = "Export program started";
MsgUnitRaw msgUnit = new MsgUnitRaw(xmlKey, content.getBytes(), "<qos></qos>");
log.fine("Publishing ...");
stop.restart();
try {
String pubXml = blasterServer.publish(sessionId, msgUnit);
// Parse the returned XML string
PublishReturnQos q = new PublishReturnQos(glob, pubXml);
publishOid = q.getKeyOid();
log.info(" Returned oid=" + publishOid);
} catch(XmlBlasterException e) {
log.warning("XmlBlasterException: " + e.getMessage());
}
log.fine("Publishing done" + stop.nice());
}
//----------- get() with XPath -------
log.fine("get() using the Xpath query syntax ...");
String xmlKey = "<key oid='' queryType='XPATH'>\n" +
" //DRIVER[@id='ProgramExecute']" +
"</key>";
stop.restart();
MsgUnitRaw[] msgArr = null;
try {
msgArr = blasterServer.get(sessionId, xmlKey, "<qos></qos>");
} catch(XmlBlasterException e) {
log.severe("XmlBlasterException: " + e.getMessage());