Reviewers

An inbound reviewer is the first exit to receive the document after parse. An outbound reviewer is the last exit to receive the document prior to the actual emit operation. These exits are intended for envelope handling, but can be used for any desired purpose.

Reviewers are similar to business agents, in that they receive as input the incoming document, and are responsible for loading the outbound document with the appropriate information after the review. For example, an inbound reviewer might handle the WS-SECURITY header, operating on the payload of the document as directed by the fields in the header.

If more than one reviewer is defined for a message they are chained, such that the output of each reviewer is the input to the next. Several reviewers, one following the other, might each be responsible for handling one type of envelope header.

The reviewer receives control at its execute() method, which is as described for business agents. The method must fill in the outbound document, and should return "success" or throw an exception.

This example handles a bit of the WS-ADDRESSING envelope header. The document looks like this:

<S:Envelope xmlns:S="http://www.w3.org/2003/05/soap-envelope"
    xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/03/addressing">
    <S:Header>
       <wsa:ReplyTo>
         <wsa:Address>http://business456.com/client1</wsa:Address>
       </wsa:ReplyTo>
       <wsa:To>http://fabrikam123.com/Purchasing</wsa:To>
       <wsa:Action>AgentToDO?patm1=fred&amp;parm2=tom</wsa:Action>
    </S:Header>
    <S:Body>
       <some xml message that the agent or flow can handle>
    </S:Body>
</S:Envelope>

The code to locate the Action and push the agent for execution might look like this:

public String execute(XDDocument docIn, XDDocument docOut)
        throws XDException
{
   copyTree(docIn, docOut); // make sure we have output
   XDNode root = docOut.getRoot();
   Iterator iter = root.getAttributeNames();
   String addrPrefix="";
   while (iter.hasNext())  // find my namespace prefix
   {
       String attrName = (String)iter.next();
       String attVal = root.getAttribute(attrName);
       if (attVal.equalsIgnoreCase(
           "http://schemas.xmlsoap.org/ws/2004/03/addressing"))
       {
           int ax = attrName.indexOf(':');
           addrPrefix= attrName.substring(ax+1);
           addrPrefix+=":";
           break;
       }
   }
   XDNode saNode = root.findByName(addrPrefix+"Action"); 
   if (saNode == null)
   {
       debug("Did not locate action");
       return "success";
   }
   String agname = saNode.getValue();
   String parmStr = null;
   int qmix = agname.indexOf('?');
   if (qmix == -1)
   {
   }
   else
   {
       parmStr = agname.substring(qmix+1);
       agname = agname.substring(0,qmix);
   }
   XDDictionary dict = getDictionaryDocument();
   XDNode dictroot = dict.getRoot();
   XDNode sysNode = dictroot.findChild("system");
   XDNode defNode = sysNode.findChild("define");
   XDNode agNode = defNode.findChild("agent");
   XDNode exNode = agNode.findByValue(agname);
   if (exNode == null)   // not found
   {
       worker.pushAgentName(agname);
   }
   else  // found it in defined agents
   {
       XDNode loadNode = XDNode.cloneTree(exNode); // make a parm
       // now set values
       if (parmStr != null)
       {
           String key;
           String val;
           StringTokenizer pst = new StringTokenizer(parmStr,"&");
           while (pst.hasMoreTokens())
           {
               String tok = pst.nextToken();
               int ix = tok.indexOf('=');
               key = tok.substring(0,ix);
               val = tok.substring(ix+1);
               XDNode pn = loadNode.findByAttributeValue("name",key);
               if (pn == null)
               {
                   pn=new XDNode("parm");
                   pn.setAttribute("name",key);
                   loadNode.setLastChild(pn);
               }
               pn.setValue(val);
           }
       }
       worker.pushAgentName(agname, loadNode);
   }
   saNode.snipNode();  // remove this from the envelope
   return "success";
}

iWay Software