如何在 Mule 3 中拆分函数后删除 %20(URI 编码 space)

How to remove %20 (URI encoded space) after split function in Mule 3

我正在使用 split 函数根据结果创建一个数组,因此我可以使用 foreach 循环。 foreach 循环包含 HTTP 请求连接器,它将数组作为有效负载并循环遍历不同的 ID。问题是当数组进入循环时它显示 space 符号 (%20),这使得请求错误。没有 space 标志一切正常。所以我的问题是如何删除 http 请求中的 spaces? 下面我添加了输入和输出

拆分前

5598f15c-e4fb-482f-ba41-0ced971ec737,f6cb0890-3650-47c0-ba53-202229c8c5df,0de65b3b-b2c0-4dba-a54a-2bbef4e3bcf2

在上面的 Id 上拆分

#[java.util.Arrays.asList(flowVars.Id.split(','))] 

和 Mime 类型 application/java。在 split() 之后,它创建了一种 java.lang.String

0 = 5598f15c-e4fb-482f-ba41-0ced971ec737
1 = f6cb0890-3650-47c0-ba53-202229c8c5df
2 = 0de65b3b-b2c0-4dba-a54a-2bbef4e3bcf2

我在 HTTP 请求连接器中使用下一个作为基本路径 (我滥用了基本路径,所以我可以动态添加内容或负载;)

/request/change/odata/serviceRequest?$filter=id eq#[payload]

进入循环时我看到这个 URL

https://service.request.com/request/change/serviceRequest?$filter=id%20eq5598f15c-e4fb-482f-ba41-0ced971ec737/%20

预期的结果需要这样;

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

XML源代码;

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

<mule xmlns:http="http://www.mulesoft.org/schema/mule/http"
    xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw"
    xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
    xmlns:spring="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.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/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd">
    <http:request-config name="HTTP_Request_Configuration_Service"
        protocol="HTTPS" host="${service.host}"
        port="${service.port}"
        basePath="/request/change/serviceRequest?$filter=id eq #[payload]" 
        doc:name="HTTP Request Configuration" responseTimeout="${service.timeout}">
        <http:basic-authentication username="${service.user}" password="${service.password}" preemptive="true"/>
    </http:request-config>
        <foreach doc:name="For Each">
        <set-payload value="1234f15c-g4fb-511f-ba41-0ced971ec747,f6cb2052-3520-47c0-ba53-202029c8c5df,0ca68b3b-b2c0-4dba-a54a-2bbef4e8bcf2,12a8c48c-c221-4c10-82ab-c2222b5b2cac,3f394fda-d687-4d68-bb27-f532ca650803" doc:name="Incoming payload"/>
        <dw:transform-message doc:name="Fetch the id">
            <dw:set-variable variableName="id"><![CDATA[%dw 1.0
%output application/java
---
payload.value.id joinBy "," default ""]]></dw:set-variable>
        </dw:transform-message>
        <set-payload value="#[#[java.util.Arrays.asList(flowVars.id.split(','))]]" doc:name="Transform to array"/>
        <foreach doc:name="For Each">
            <http:request config-ref="HTTP_Request_Configuration_Service" path="" method="GET" doc:name="HTTP Request Service"/>
            <dw:transform-message doc:name="Append payload">
                <dw:set-variable variableName="outcome"><![CDATA[%dw 1.0
%output application/json
---
flowVars.outcome ++ payload]]></dw:set-variable>
            </dw:transform-message>
        </foreach>
        </foreach>
</mule>

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

<mule 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:request-config name="HTTP_Request_Configuration" host="service.request.com" port="443" doc:name="HTTP Request Configuration" basePath="/request/change/serviceRequest#[flowVars.path]"/>
    <objectstore:config name="ObjectStore__Connector" partition="timeStamp" persistent="true" doc:name="ObjectStore: Connector"/>
    <http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/>
    <flow name="ddddddddFlow1">
        <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"/>

        <foreach  doc:name="For Each" >
            <set-variable variableName="path" value="?$filter=id eq #[payload]" doc:name="set path"/>
            <http:request config-ref="HTTP_Request_Configuration" path="" method="GET" doc:name="HTTP Service Request">

            </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>

这真是在滥用基本路径。它不打算以这种方式使用。滥用 basePath 生成的 URL 与预期不同。将空格编码为“%020”是一个标准,应该不会导致任何问题。

尝试改为设置查询参数并在每次迭代中更改其值。类似于:

        <http:request config-ref="HTTP_Request_Configuration" path="/somepath" method="{METHOD}" doc:name="HTTP {METHOD}">
            <http:request-builder>
                <http:query-params expression="#[flowVars.params]"/>
            </http:request-builder>
        </http:request>

并使表达式成为整个字符串,而不仅仅是 id,将 flowVars.params 设置为类似以下内容:{"$filter": "id eq #[payload]"}