【问题标题】:Extract string from message using Dataweave使用 Dataweave 从消息中提取字符串
【发布时间】:2017-01-22 17:44:58
【问题描述】:

我想使用 Dataweave 提取第一个 : 和 first ( 在这种情况下是“文件不正确”但在其他情况下可能不同。

java.lang.Exception: File incorrect (javax.script.ScriptException). (org.mule.api.transformer.TransformerMessagingException).

我查看了一些可用的字符串操作,看起来只有在您知道文本的位置或要提取的文本的情况下才能使用它。

我该怎么做?

谢谢

【问题讨论】:

    标签: mule anypoint-studio dataweave


    【解决方案1】:

    U 可以使用 datatweave 中的正则表达式和匹配函数来提取它。试试下面的 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]
    

    【讨论】:

      【解决方案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>
      

      【讨论】:

        猜你喜欢
        • 2021-12-07
        • 1970-01-01
        • 2021-08-01
        • 1970-01-01
        • 1970-01-01
        • 2015-01-25
        • 2014-10-25
        • 2022-01-13
        相关资源
        最近更新 更多