org.omg.PortableServer.POA rootPOA =
org.omg.PortableServer.POAHelper.narrow(orb.resolve_initial_references("RootPOA"));
// Intialize my Callback interface:
BlasterCallbackPOATie callbackTie = new BlasterCallbackPOATie(new RawCallback(glob, ME));
BlasterCallback callback = BlasterCallbackHelper.narrow(rootPOA.servant_to_reference( callbackTie ));
rootPOA.the_POAManager().activate();
//----------- Login to the server (the new way) ---------
try {
String passwd = "some";
// The xmlBlaster server takes this IOR string and uses it to connect
// to our client-side callback interface to deliver updates back
String callbackIOR = orb.object_to_string(callback);
// Create a XML based qos (quality of service) which hold the IOR (the CORBA
// address of our callback server)
String qos = "<qos>\n" +
" <securityService type=\"simple\" version=\"1.0\">\n" +
" <user>" + loginName + "</user>\n" +
" <passwd>" + passwd + "</passwd>\n" +
" </securityService>\n" +
" <callback type='IOR'>\n" +
callbackIOR + "\n" +
" </callback>\n" +
"</qos>\n";
String retXml = authServer.connect(qos);
// Parse the returned string, it contains the server IOR
ConnectReturnQos returnQos = new ConnectReturnQos(glob, retXml);
log.info("Login (Connect) done.");
log.info("Used QoS=\n" + qos);
log.info("Returned QoS=\n" + returnQos.toXml());
// Get the CORBA handle of xmlBlaster ...
String xmlBlasterIOR = returnQos.getServerRef().getAddress();
xmlBlaster = ServerHelper.narrow(orb.string_to_object(xmlBlasterIOR));
} catch(org.xmlBlaster.protocol.corba.serverIdl.XmlBlasterException e) {
log.warning("XmlBlasterException: " + e.getMessage());
}
//----------- Subscribe to messages with XPATH -------
{
log.fine("Subscribing using XPath syntax ...");
String xmlKey = "<?xml version='1.0' encoding='ISO-8859-1' ?>\n" +
"<key oid='' queryType='XPATH'>\n" +
"/xmlBlaster/key/AGENT" +
"</key>";
stop.restart();
try {
xmlBlaster.subscribe(xmlKey, "<qos></qos>");
} catch(org.xmlBlaster.protocol.corba.serverIdl.XmlBlasterException e) {
log.warning("XmlBlasterException: " + e.getMessage());
}
log.info("Subscribe done, there should be no Callback" + stop.nice());
}
delay(2000); // Wait some time ...
//----------- Construct a message and publish it ---------
{
String xmlKey = "<?xml version='1.0' encoding='ISO-8859-1' ?>\n" +
"<key oid='' contentMime='text/xml'>\n" +
" <AGENT id='192.168.124.10' subId='1' type='generic'>" +
" <DRIVER id='FileProof' pollingFreq='10'>" +
" </DRIVER>"+
" </AGENT>" +
"</key>";
String content = "Yeahh, i'm the new content";
MessageUnit msgUnit = new MessageUnit(xmlKey, content.getBytes(), "<qos></qos>");
log.info("Publishing ...");
stop.restart();
try {
String publishOid = xmlBlaster.publish(msgUnit);
log.fine("Returned oid=" + publishOid);
} catch(org.xmlBlaster.protocol.corba.serverIdl.XmlBlasterException e) {
log.warning("XmlBlasterException: " + e.getMessage());
}
log.info("Publishing done, there should be a callback now" + stop.nice());
}
delay(1000); // Wait some time ...
// orb.run(); // Usually your client won't exit after this, uncomment the run() method
ask("logout()");
//----------- Logout --------------------------------------
log.info("Logout ...");
try {
authServer.logout(xmlBlaster);
authServer._release();
xmlBlaster._release();
} catch(org.xmlBlaster.protocol.corba.serverIdl.XmlBlasterException e) {
log.warning("XmlBlasterException: " + e.getMessage());
}
//----------- Shutdown my callback server -----------------
try {
callback._release();
rootPOA.deactivate_object(rootPOA.reference_to_id(callback));
} catch(Exception e) { log.warning("POA deactivate callback failed"); }
//----------- Stop the POA --------------------------------