Mule 如何使用Dataweave将纯文本字符串输出到Anypoint平台上的变量?

Mule 如何使用Dataweave将纯文本字符串输出到Anypoint平台上的变量?,mule,anypoint-studio,dataweave,Mule,Anypoint Studio,Dataweave,我觉得我疯了,因为我不知道如何做一些简单的事情,比如迭代一个对象,连接一个纯文本字符串,然后将结果输出到一个变量。下面是我做过的类似的事情,效果很好: %dw 2.0 output application/xml var promptParams = attributes.queryParams filterObject($$ startsWith "PROMPT") orderBy($$) --- { RESULT: { Prompts: promptParams m

我觉得我疯了,因为我不知道如何做一些简单的事情,比如迭代一个对象,连接一个纯文本字符串,然后将结果输出到一个变量。下面是我做过的类似的事情,效果很好:

%dw 2.0
output application/xml
var promptParams = attributes.queryParams filterObject($$ startsWith "PROMPT") orderBy($$)
---
{
RESULT: {
    Prompts: 
        promptParams mapObject(promptValue, promptName, index) -> {
            PROMPT: {
                UniquePromptName: promptName,
                FieldValue: promptValue
                }
        }
    }
}
因此,在本例中,我过滤url查询字符串参数以仅获取我想要的参数,然后迭代这些参数并构造xml输出。我遇到的问题是,如果我尝试做同样的事情,但输出一个纯文本字符串到一个变量,我无法得到任何工作

基本上我想要的是从这个输入:

https://example.com?PROMPT1=foo&PROMPT2=bar&PROMPT3=lorem&PROMPT4=ipsum&utm_source=Dolor&utm_campaign=SitAmet
对于存储在流量变量中的此输出:

foo!bar!lorem!ipsum

我一定错过了一些基本的东西,因为要做到这一点不会那么难。我做错了什么?

应该是这样的:

%dw 2.0
output text/plain
var promptParams = attributes.queryParams filterObject($$ startsWith "PROMPT")
---
promptParams pluck($) reduce ($$ ++ "!" ++ $)
输出:
foo!酒吧洛伦!ipsum


您要求使用纯文本,但如果您在流中使用变量,我建议使用application/java。

它应该是这样的:

%dw 2.0
output text/plain
var promptParams = attributes.queryParams filterObject($$ startsWith "PROMPT")
---
promptParams pluck($) reduce ($$ ++ "!" ++ $)
%dw 2.0
output text/plain
var promptParams = (((payload.message splitBy "?")[1]) splitBy "&") //stored url //in payload.message
---
promptParams map {
    a: ($ splitBy "=")[1]
}.a joinBy "!"
输出:
foo!酒吧洛伦!ipsum


您要求使用纯文本,但如果您在流中使用变量,我建议使用application/java。

您可以使用
pulk
joinBy
,只要确保在使用转换消息组件时将目标设置为变量即可

%dw 2.0
output text/plain
var promptParams = (((payload.message splitBy "?")[1]) splitBy "&") //stored url //in payload.message
---
promptParams map {
    a: ($ splitBy "=")[1]
}.a joinBy "!"
<ee:transform doc:name="Transform Message" >
    <ee:variables >
        <ee:set-variable variableName="promptAttributes" ><![CDATA[%dw 2.0
output text/plain
---
(attributes.queryParams[?($$ startsWith "PROMPT")] pluck $) joinBy "!"]] </ee:set-variable>
    </ee:variables>
</ee:transform>

您可以使用
pulk
joinBy
,如果您正在使用转换消息组件,只需确保将目标设置为变量即可

<ee:transform doc:name="Transform Message" >
    <ee:variables >
        <ee:set-variable variableName="promptAttributes" ><![CDATA[%dw 2.0
output text/plain
---
(attributes.queryParams[?($$ startsWith "PROMPT")] pluck $) joinBy "!"]] </ee:set-variable>
    </ee:variables>
</ee:transform>


如果HTTP连接器已经在queryParams属性中提供了查询参数,我认为DataWeave不应该分割查询参数,并且可能会处理编码问题。之所以这样做是因为我没有使用查询参数,而是使用表示url的字符串。我认为DataWeave不应该在HTTP连接器提供查询参数时分割查询参数已经在queryParams属性中提供了它们,并且可能会考虑编码问题。之所以这样做是因为我没有使用查询参数,而是使用表示url的字符串。这是最简洁的,也是我将如何做到的。这是最简洁的,也是我将如何做到的。这正是我所需要的。非常感谢。正是我需要的。非常感谢。