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

I'm using a split function to create an array from the results, so I can use the foreach loop. The foreach loop contain HTTP request connector that takes the array as payload and loops over the different ids. The problem is when the array enters the loop it shows space sign (%20) which make the request wrong. Without space sign everything works fine. So my question how can i remove the spaces inside the http request? Below I have added the input and output

before splitby

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

splitby on the above Id's

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

and Mime type application/java. After split() it creates a type of java.lang.String

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

I use the next as Base Path in the HTTP request connector (I misabuse the basepath so I can add dynamically content or payload ;)

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

when entering the loop I see this URL

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

The expected result need to be like this;

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

The XML source code;

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


Solution 1:[1]

That's truly abusing base path. It is not intended to be used in that way. The URL generated by abusing basePath is different to the expected. Having spaces encoded as "%020" is a standard and should not cause problems either way.

Try setting a query param instead and change its value in each iteration. Something like:

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

and make the expression the whole string, not just the id, set flowVars.params to something like: {"$filter": "id eq #[payload]"}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 aled