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.
- 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
- Create a message flow called addev6, which contains the following
mapping: MQInput> Mapping> MQOutput.
- Open the map and select addev6in as the source and addev6out as
the target.
- 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";
- 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;
}
}
- 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.
- 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).
- Set the target fltval to esql:fltFromBinary($source/comp:addev6in/bval).
- Set the target intval to esql:intFromBinary($source/comp:addev6in/bval).
- Expand the Properties target and set the values shown:
MessageType | 'addev6out
- Create the following instance message, with appropriate RFH2 headers:
<comp:addev6in xmlns:comp="http://www.complex.net">
<bval>
<![CDATA[64656376616c20202031342e3238666c7476616c
2020312e34452b32696e7476616c2020202020313230]]>
</bval>
</comp:addev6in>
Now deploy the message set and message flow.