- 在 COMPLEX 消息定义中(在名称空间 www.complex.net 中),创建名为 addev6in 和 addev6out 的消息,这些消息具有以下结构:
addev6in
hexdata (xsd:hexBinary) local element
addev6out
decval (xsd:decimal) local element
fltval (xsd:float) local element
intval (xsd:int) local element
- 创建名为 addev6 的消息流,该消息流包含以下映射:> Mapping > MQOutput。
- 打开映射并选择 addev6in 作为源,addev6out 作为目标。
- 在 MAPPING3_COMPLEX_flows 项目中,创建名为 addev6 的 ESQL 文件,并将以下函数放入该文件:
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";
- 创建名为 addev6.java 的 java 源文件,该文件内容如下:
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;
}
}
- 编译 java 代码并将类文件的位置添加到系统类路径中。 如果您编辑 CLASSPATH,可能需要重新启动 Windows。
- 在消息映射编辑器的电子表格窗格中,展开目标消息并将目标 decval 设置为值 esql:decFromBinary($source/comp:addev6in/bval)。
- 将目标 fltval 设置为 esql:fltFromBinary($source/comp:addev6in/bval)。
- 将目标 intval 设置为 esql:intFromBinary($source/comp:addev6in/bval)。
- 展开“属性”目标并将值进行如下设置:
MessageType | 'addev6out
- 使用适当的 RFH2 头创建以下实例消息:
<comp:addev6in xmlns:comp="http://www.complex.net">
<bval>
<![CDATA[64656376616c20202031342e3238666c7476616c
2020312e34452b32696e7476616c2020202020313230]]>
</bval>
</comp:addev6in>