Exploring WS-Notification

by Marco Aiello, Alessandro Zolet, and Manuel Zanoni



Listing One



<?xml version="1.0" encoding="UTF-8"?>



<wstop:topicSpace name=

       "Event" targetNamespace="event broker namespace URI" 

        xmlns:esns=" event broker namespace URI " 

        xmlns:wstop="http://www.ibm.com/xmlns/stdwip/web-services/WS-Topics" >

    <wstop:topic name="Topics" final="true" />

    <wstop:topic name="MySubscribedEvents" final="true" />

    <wstop:topic name="Health" >

        <wstop:topic name="Fall" />

        <wstop:topic name="Irregular heartbeat" />

    </wstop:topic>

</wstop:topicSpace>





Listing Two



<?xml version="1.0" encoding="UTF-8"?>

<wstop:topicSpace name=

      "Event" targetNamespace="my event broker namespace URI" 

       xmlns:esns=" event broker namespace URI" 

       xmlns:wstop="http://www.ibm.com/xmlns/stdwip/web-services/WS-Topics" >

    <wstop:topic name="Topics" final="true" />

    <wstop:topic name="MySubscribedEvents" final="true" />

    <wstop:topic name="Health" >

        <wstop:topic name="Fall">

           <esns:Address name="127.0.0.1:1234" 

                 end="1103934000750" id="11020014327817175" />

</wstop:topic name="Fall">

        <wstop:topic name="Irregular heartbeat" />

    </wstop:topic>

</wstop:topicSpace>





Listing Three



Socket resp=new Socket(hostAddress,port);

PrintStream ps=new PrintStream(resp.getOutputStream());



String response="<s12:Envelope";

response=response+"xmlns:s12=\""+Property.s12+"\" ";

response=response+"xmlns:wsa=\""+Property.wsa+"\" ";

response=response+"xmlns:esns=\""+Property.esns+"\" ";

response=response+"xmlns:wsnt=\""+Property.wsnt+"\">\n";

response=response+"<s12:Header>\n";

response=response+"<wsa:Action>\n";

response=response+" 

  http://www.ibm.com/xmlns/stdwip/web-services/WS-BaseNotification/Notify\n";

response=response+"</wsa:Action>\n";

response=response+"</s12:Header>\n";

response=response+"<s12:Body>\n";

response=response+"<wsnt:Notify>\n";

response=response+"<wsnt:NotificationMessage>\n";

response=response+"

         <wsnt:Topic dialect=\""+Property.topicExpressionDialect+"\">\n";

response=response+"esns:"+topic+"\n";

response=response+"</wsnt:Topic>\n";

response=response+"<wsnt:Message>\n";

response=response+message+"\n";

response=response+"</wsnt:Message>\n";

response=response+"</wsnt:NotificationMessage>\n";

response=response+"</wsnt:Notify>\n";

response=response+"</s12:Body>\n";

response=response+"</s12:Envelope>\n";

ps.println(response);





Listing Four



while(true) {

   try {

    errCode++;

    scn = (ServerSocketConnection)Connector.open

                   ("socket://:"+app.myDefaultPort);

    errCode++;

    sc = (SocketConnection)scn.acceptAndOpen();

    errCode++;

    is = sc.openInputStream();

    errCode++;

    while((c = is.read())>=0){

     incoming = incoming+(char)c;

    }

    ParsingManager pman = 

            new ParsingManager(incoming, null, this.app, this.eventsTree);

    pman.start();

    incoming = null;

    errCode++;

    is.close();

    errCode++;

    sc.close();

    errCode++;

    scn.close();

    errCode++;

   } catch(Exception e) {

    String errMsg = null;

    switch(errCode) {

       case 1: errMsg = "Failed while opening server socket connection!";

       break;

       case 2: errMsg = "Failed while waiting for an incoming connection!";

  break;

  case 3: errMsg = "Failed while opening input stream!"; break;

     case 4: errMsg = "Failed while reading an incoming message!"; break;

     case 5: errMsg = "Failed while closing input stream!"; break;

     case 6: errMsg = "Failed while closing socket connection!"; break;

     case 7: errMsg = "Failed while closing server socket connection!";

 break;

  }

  Alert a = new Alert("Error!", errMsg, null, AlertType.ERROR);

  a.setTimeout(3000);

  app.d.setCurrent(a);

}















3



