About the SearchFilter sample

This sample demonstrates how a Java user-defined message processing node can be used as a filter node. The SearchFilter node searches for a specific customer name in an XML message that contains twenty customer names.

The following diagram shows the SearchFilter sample message flow:

This figure shows the SearchFilter message flow. The SFInput node is connected to the SearchFilter node and to the SFFailure node. The SearchFilter node is connected to the SFOutput node,  the NotFound node, and the SFFailure node. The NotFound node is connected to the SFOutput node and the SFFailure node.

The SearchFilter node searches the contents of the XML input message for a string that is contained in the SearchName element. For example:
<SearchName>
Surname of customer
</SearchName>

If the search name is displayed in the XML input message, the full customer name is added to the end of the message. For example, if "John Smith" is one of the twenty customer names in the input message, and the string "Smith" is contained in the SearchName element, the SearchFilter node adds "John Smith" to the end of the message.

In this sample, when the full customer name is found, it is added to the message five times. This sample demonstrates the additional functions of the SearchFilter node. The following example code is taken from the com.ibm.broker.ude.samples.SearchFilterNode.java Java source file and shows how the customer name is added to the message five times.

// if the search name was found then add <Result> tag to output message
         if (customerElement.getFirstChild().getValue().equals(searchName)) {
            // indicate that the search name has been found
            result = true;
            
            // construct a concatenation of 5 full names using String Buffer
            // as this has improved performance over ordinary String concatenation
            StringBuffer fiveNames = new StringBuffer();
            fiveNames.append(customerElement.getLastChild().getValue());
            fiveNames.append(" ");
            fiveNames.append(searchName);
            fiveNames.append(" ");
            
            searchName = fiveNames.toString();
            
            for (counter = 0; counter < 4; counter++) {
               fiveNames.append(searchName);
            }
            
            // Add a new <Result> tag to output message as the last child of <Message1>
            newtag = topOfBody.createElementAsLastChild(MbElement.TYPE_NAME, "Result", fiveNames.toString());            

            terminal = getOutputTerminal("True");
         }

The Java source file com.ibm.broker.ude.samples.SearchFilterNode.java is located in the UDESampleJavaCode Java project.

If the search name is not found in the XML input message, the string "Not found" is stored in the LocalEnvironment tree of the SearchFilter node. The NotFound node adds the string "Not found" to the output message.

The SearchFilter sample uses the following queues:

Back to About the User-defined Extension sample

Back to sample home