如何在查询参数 Mule 3 中添加#[payload] 作为值

How to add #[payload] as value in the query params Mule 3

遗憾的是我还没有能够解决它。如果有人能调查一下,我将不胜感激。谢谢大家

我 运行 Mule 3 的一个问题是有效负载在 HTTP 请求连接器部分的查询参数中无法识别。

这是因为查询参数必须被引用才能被识别为值。我试过转义引号并将过滤器保存为变量,但不幸的是这也不起作用。

过滤器也必须准确执行,否则会得到完整的负载。所以我的最终 URL 应该完全像这样,否则它不会过滤,我将获得完整的有效负载:

https://service.request.com/request/change/serviceRequest?$filter=id eq 5598f15c-e4fb-482f-ba41-0ced971ec737

在 id 上,我有 foreach 循环遍历每个 id 并发出请求。

下面我添加了 xml 代码。

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns:objectstore="http://www.mulesoft.org/schema/mule/objectstore" xmlns:sftp="http://www.mulesoft.org/schema/mule/sftp"
    xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw"
    xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:spring="http://www.springframework.org/schema/beans" xmlns="http://www.mulesoft.org/schema/mule/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/sftp http://www.mulesoft.org/schema/mule/sftp/current/mule-sftp.xsd
http://www.mulesoft.org/schema/mule/ee/dw http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/objectstore http://www.mulesoft.org/schema/mule/objectstore/current/mule-objectstore.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd">
    <http:request-config name="HTTP_Request_Configuration_1" host="service.request.com" port="443" doc:name="HTTP Request Configuration" />
    <objectstore:config name="ObjectStore__Connector_1" partition="timeStamp" persistent="true" doc:name="ObjectStore: Connector"/>
    <http:listener-config name="HTTP_Listener_Configuration_1" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/>
    <flow name="main_flow">
        <http:listener config-ref="HTTP_Listener_Configuration" path="/test" doc:name="HTTP"/>
        <flow-ref name="time_now" doc:name="time_now"/>
        <flow-ref name="retrieve_and_save_time" doc:name="retrieve_and_save_time"/>
        <flow-ref name="dynamic_call" doc:name="dynamic_call"/>
        <flow-ref name="Store_after_succes" doc:name="Store_after_succes"/>
    </flow>
    <sub-flow name="time_now">
        <set-variable variableName="serverTime" value="#[server.dateTime.format(&quot;yyyy-MM-dd'T'HH:mm:ss'Z'&quot;)] " doc:name="Now Time"/>
    </sub-flow>
    
    <sub-flow name="retrieve_and_save_time">
        <objectstore:retrieve config-ref="ObjectStore__Connector" key="time" defaultValue-ref="#[(server.dateTime.plusHours(-2).format(&quot;yyyy-MM-dd'T'HH:mm:ss'Z'&quot;))]" doc:name="retrieve time last succes"/>
        <set-variable variableName="subTime" value="#[payload]" doc:name="save retrieve time in var"/>
    </sub-flow>
<sub-flow name="dynamic_call">
        <set-variable variableName="result" value="#[[]]" doc:name="set emtpy array"/>
        <set-payload value="[&quot;5598f15c-e4fb-482f-ba41-0ced971ec737&quot;, &quot;f6cb0890-3650-47c0-ba53-202229c8c5df&quot;, &quot;0de65b3b-b2c0-4dba-a54a-2bbef4e3bcf2&quot;]" doc:name="Payload Array" mimeType="application/java"/>

        <foreach  doc:name="For Each" >
            <http:request config-ref="HTTP_Request_Configuration" path="/request/change/serviceRequest" method="GET" doc:name="HTTP Service Request">
                <http:request-builder>
                    <http:query-params expression="{&quot;?$filter&quot;: &quot;id eq #[payload]&quot;}"/>
                </http:request-builder>

            </http:request>
            <dw:transform-message doc:name="Append payload">
                <dw:set-variable variableName="result"><![CDATA[%dw 1.0
%output application/json
---
flowVars.result ++ payload]]></dw:set-variable>
            </dw:transform-message>
        </foreach>
        <http:request config-ref="HTTP_Request_Configuration" path="/request/change/serviceRequest" method="GET" doc:name="HTTP Request Ticket">
            <http:request-builder>
                <http:query-params expression="{&quot;?$filter&quot;: &quot;callDate lt #[flowVars.serverTime] and callDate gt #[flowVars.subTime]&quot;}"/>

            </http:request-builder>
        </http:request>

        <dw:transform-message doc:name="Append payload and set to JSON">
            <dw:set-payload><![CDATA[%dw 1.0
%output application/json
---
flowVars.result ++ payload]]></dw:set-payload>
        </dw:transform-message>
        <file:outbound-endpoint path="C:\Users" outputPattern="test.json" responseTimeout="10000" doc:name="File"/>
    </sub-flow>
<sub-flow name="Store_after_succes">
        <objectstore:store config-ref="ObjectStore__Connector" key="time" value-ref="#[server.dateTime.format(&quot;yyyy-MM-dd'T'HH:mm:ss'Z'&quot;)] " doc:name="ObjectStore"/>
    </sub-flow>
</mule>

您可以像这样添加查询参数。它将解析有效载荷的值,并且不会在查询参数

中发送文字 "#[payload]
<http:request config-ref="HTTP_Request_Configuration" path="/request/change/serviceRequest" method="GET" doc:name="HTTP Service Request">
    <http:request-builder>
        <http:query-param paramName="$filter" value="id eq #[payload]"/>
    </http:request-builder>
</http:request>