{
glob = new Global(args);
orb = org.omg.CORBA.ORB.init(args,null);
try {
AuthServer authServer;
ME = glob.getProperty().get("loginName", ME);
String loginName = ME;
String fileName = glob.getProperty().get("dispatch/connection/plugin/ior/iorFile", (String)null); // a file with the IOR string
String authServerIOR = glob.getProperty().get("dispatch/connection/plugin/ior/iorString", (String)null); // the IOR string
if (fileName != null) authServerIOR = FileLocator.readAsciiFile(fileName);
if (authServerIOR != null) {
authServer = AuthServerHelper.narrow(orb.string_to_object(authServerIOR));
}
else {
// asking Name Service CORBA compliant:
NamingContext nc = NamingContextHelper.narrow(orb.resolve_initial_references("NameService"));
NameComponent [] name = new NameComponent[1];
name[0] = new NameComponent();
name[0].id = "xmlBlaster-Authenticate";
name[0].kind = "MOM";
if (nc == null) {
System.out.println("\nSorry, please pass the server IOR string to the client, e.g.:\n"
+ "Start the server:\n"
+ " jaco org.xmlBlaster.Main -dispatch/connection/plugin/ior/iorFile /tmp/NS_Ref\n"
+ "Start this client:\n"
+ " jaco javaclients.corba.ClientRawSecurity -dispatch/connection/plugin/ior/iorFile /tmp/NS_Ref\n");
usage();
log.severe("Read xmlBlaster/INSTALL for help");
System.exit(1);
}
authServer = AuthServerHelper.narrow(nc.resolve(name));
}
StopWatch stop = new StopWatch();
//---------- Building a Callback server ----------------------
// Getting the default POA implementation "RootPOA"
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());
}