【问题标题】:How to use MEL in dataweave to replace characters in a string如何在 dataweave 中使用 MEL 替换字符串中的字符
【发布时间】:2017-02-21 11:25:37
【问题描述】:
我正在使用 Anypoint Studio 6.1 和 Mule 3.8.1,并使用此 MEL 表达式将任何文本 \n 替换为新的换行符/回车符。
payload.replace('\\n', System.getProperty('line.separator'))
我想将此功能移至 Dataweave,但无法使 MEL 表达式工作或在 Dataweave 中找到执行此操作的方法。
如何在 Dataweave 中重用 MEL 表达式?
谢谢
【问题讨论】:
标签:
mule
newline
anypoint-studio
dataweave
mel
【解决方案1】:
你应该调查全局函数
喜欢:
<configuration doc:name="Global MEL-Functions">
<expression-language>
<global-functions file="mel/extraFunctions.mvel">
</global-functions>
</expression-language>
</configuration>
并在资源文件中创建您的全局函数以供重用
def UUID() {
return java.util.UUID.randomUUID().toString();
}
def decode(value) {
return java.util.Base64.getDecoder().decode(value);
}
def encode(value) {
return java.util.Base64.getEncoder().encodeToString(value.getBytes());
}
def stringToAscii(value) {
StringBuilder sb = new StringBuilder();
for (char c : value.toCharArray())sb.append((int)c);
return new BigInteger(sb.toString());
}
并在您的数据编织中引用您的全局函数
payload map
{
target: stringToAscii($) as :string
}
【解决方案2】:
DW 是 Mule 中自己的迷你语言,除了 MEL 之外,它是如何向我描述的,并使用不同的语法来做你正在尝试的事情。我没有专门做新行,因为我的 DW 表达式使用行分隔符作为记录分隔符,但同样的一般策略应该有效。以下是在 dw 有效负载映射中将逗号更改为空格的示例:
AcctID:$.ACCOUNT_ID 将“,”替换为“”,