WebSphere Message Brokers
File: ar25251_11_
Writer: Cerys Giddings

Task topic

This build: July 31, 2007 21:36:23

Develop a message flow using a user-defined Java procedure

Before you start
This is the eleventh stage of the scenario to perform simple message enrichment. This topic demonstrates how to develop a message flow using a user-defined Java procedure. It also involves developing corresponding message models and instance documents.
  1. In the COMPLEX message definition, in namespace www.complex.net, create messages called addev6in and addev6out, which have the following structures:
    addev6in
        hexdata                (xsd:hexBinary) local element
    addev6out
        decval                  (xsd:decimal) local element
        fltval                     (xsd:float) local element
        intval                    (xsd:int) local element
  2. Create a message flow called addev6, which contains the following mapping: MQInput> Mapping> MQOutput.
  3. Open the map and select addev6in as the source and addev6out as the target.
  4. In the MAPPING3_COMPLEX_flows project, create an ESQL file called addev6 and put these functions in it:
    CREATE PROCEDURE decFromBinary( IN hexval BLOB )
     RETURNS DECIMAL
     LANGUAGE JAVA
     EXTERNAL NAME "addev6.decFromBinary";
    CREATE PROCEDURE fltFromBinary( IN hexval BLOB )
     RETURNS DECIMAL
     LANGUAGE JAVA
     EXTERNAL NAME "addev6.fltFromBinary";
    CREATE PROCEDURE intFromBinary( IN hexval BLOB )
     RETURNS DECIMAL
     LANGUAGE JAVA
     EXTERNAL NAME "addev6.intFromBinary";
  5. Create a java source file called addev6.java, which has the following contents:
    import java.lang.*;
    import java.math.*;
    
    public class addev6 {
        //
        // Return decimal element from binary string
        //
        public static BigDecimal decFromBinary( byte[] hexval) {
        // Look for element named decval
        String search = "decval";
        String snval = findElement(hexval ,search );
        // Convert the value to decimal type
        BigDecimal numval = new BigDecimal(snval);
        return numval;
        }
        //
        // Return float element from binary string
        //
        public static Double fltFromBinary( byte[] hexval) {
        // Look for element named fltval
        String search = "fltval";
        String snval = findElement(hexval ,search );
        // Convert the value to float type
        Double numval = new Double(snval);
        return numval;
        }
        //
        // Return integer element from binary string
        //
        public static Long intFromBinary( byte[] hexval) {
        // Look for element named intval
        String search = "intval";
        String snval = findElement(hexval ,search );
        // Convert the value to integer type
        Long numval = new Long(snval);
        return numval;
        }
        //
        // Locate the named element and its value in the binary data
        //
        private static String findElement( byte[] hexval, String search ) {
        // Convert bytes to string
        String hexstr = new String(hexval);
        // Fixed length label/value pairs (length=14)
        int nvals = hexstr.length() / 14;
        String numval = "";
        String[] label = new String[nvals];
        String[] value = new String[nvals];
        // Loop over number of label/value pairs
        for ( int i=0; i < nvals; i ++ ) {
            // get start position
            int st = i * 14;
            // label is length 6
            int endl = st + 6;
            // value is length 8
            int endv = endl + 8;
            // extract label and value from string
            label[i] = hexstr.substring( st, endl);
            value[i] = hexstr.substring( (endl+1), endv);
            // Check whether the current pair has the label requested
            if ( label[i].compareTo( search) == 0 ) {
            // trim padding from the value
            numval = value[i].trim();
            }
        }
        return numval;
        }
    }
  6. Compile the java code and add the location of the class file to the system classpath. You might need to restart Windows if you edit the CLASSPATH.
  7. In the Spreadsheet pane of the Message Mapping editor, expand the target message and set the target decval to the value esql:decFromBinary($source/comp:addev6in/bval).
  8. Set the target fltval to esql:fltFromBinary($source/comp:addev6in/bval).
  9. Set the target intval to esql:intFromBinary($source/comp:addev6in/bval).
  10. Expand the Properties target and set the values shown:
    MessageType     |     'addev6out
  11. Create the following instance message, with appropriate RFH2 headers:
    <comp:addev6in xmlns:comp="http://www.complex.net">
    <bval>
    <![CDATA[64656376616c20202031342e3238666c7476616c
    2020312e34452b32696e7476616c2020202020313230]]>
    </bval>
    </comp:addev6in>
You have created the following resources:
Now deploy the message set and message flow.

Deploy the message set and message flow

This is the final stage of the scenario to perform simple message enrichment. This topic demonstrates how to deploy the message set and message flow and run the instance message through the broker.
  1. Create a bar file called addev6.
  2. Add the message set MAPPING3_COMPLEX_messages and the message flow addev6 to the bar file.
  3. Deploy the bar file to the broker.
  4. Put the instance documents on the input queue.
The output message looks like this:
<comp:addev6out xmlns:comp="http://www.complex.net">
<decval>14.28</decval>
<fltval>1.4E+2</fltval>
<intval>120</intval>
</comp:addev6out>
You have completed this scenario.
Notices | Trademarks | Downloads | Library | Support | Feedback

Copyright IBM Corporation 1999, 2007Copyright IBM Corporation 1999, 2007. All Rights Reserved.
This build: July 31, 2007 21:36:23

ar25251_11_ This topic's URL is: