Mule 使用Dataweave从消息中提取字符串

Mule 使用Dataweave从消息中提取字符串,mule,anypoint-studio,dataweave,Mule,Anypoint Studio,Dataweave,我想使用Dataweave拉出第一个:和第一个之间的文本(在本例中是“文件不正确”,但在其他情况下可能不同) java.lang.Exception: File incorrect (javax.script.ScriptException). (org.mule.api.transformer.TransformerMessagingException). 我已经研究了一些可用的字符串操作,看起来只有知道文本或要提取的文本的位置时才能使用它 我该怎么做 谢谢您可以使用Datatwave中的r

我想使用Dataweave拉出第一个:和第一个之间的文本(在本例中是“文件不正确”,但在其他情况下可能不同)

java.lang.Exception: File incorrect (javax.script.ScriptException). (org.mule.api.transformer.TransformerMessagingException).
我已经研究了一些可用的字符串操作,看起来只有知道文本或要提取的文本的位置时才能使用它

我该怎么做


谢谢

您可以使用Datatwave中的regex和match函数提取它。请尝试下面的Dwl

%dw 1.0

%var exceptionMsg = 'java.lang.Exception: File incorrect( javax.script.ScriptException). (org.mule.api.transformer.TransformerMessagingException).'
%output application/json
---
trim (exceptionMsg match /^(.*):([^(]*).*$/)[2]

您可以从Dateweave调用groovy函数来提取所需字符串,如下面所示:

<configuration doc:name="Configuration">
<expression-language autoResolveVariables="false">
<global-functions>
def extractmsg(messageString) {
    int firstindex = messageString.indexOf(":");
    int endindex = messageString.indexOf("(");
    String msg = messageString.substring(firstindex+1, endindex).trim();
    return msg;
}
</global-functions>
</expression-language>
</configuration>

def extractmsg(消息字符串){
int firstindex=messageString.indexOf(“:”);
int endindex=messageString.indexOf(“”);
String msg=messageString.substring(firstindex+1,endindex.trim();
返回味精;
}