我正在尝试使用换行符分割消息并使用以下脚本:
def mesType = "";
def lines = message.getPayload().split("\n");
if ( lines[0][0..6] == '123456' || lines[1][0..6] == '123456') {
mesType = "MES1";
}
if ( lines[0][0..7] == '654321' || lines[1][0..7] == '654321') {
mesType = "MES2";
}
if ( lines[0][0..7] == '234561' || lines[1][0..7] == '234561') {
mesType = "MES3";
}
message.setProperty('mesType', mesType);
return message.getPayload();
但是当我使用它时,在我的日志文件中出现了以下错误:
groovy.lang.MissingMethodException: No signature of method: [B.split() is applicable for argument types: (java.lang.String) values: {"\n"} (javax.script.ScriptException)
当我将分割线更改为以下内容时:
def lines = message.getPayload().toString().split("\n");
我遇到了一个数组越界的错误,所以看起来它仍然没有处理换行符。
收到的消息(message.getPayload
)是来自文件系统的消息,其中包含换行符。它长这样:
ABCDFERGDSFF
123456SDFDSFDSFDSF
JGHJGHFHFH
我做错了什么?消息是通过Mule 2.X收集的。
take
函数只在 Groovy 1.8.1 及以上版本中才添加到数组中。 - tim_yatesmesType
保持为空(我用文本“空”填充了默认值)。看起来它没有循环遍历所有行。 - Mark Veenstra