2

I am trying to send a request through wso2 ESB 5.0.0 to external HTTP API which require application/x-www-form-urlencoded format. I found this post:

Sending Content-Type application/x-www-form-urlencoded WSO2 ESB

and it's almost works, but this vendor also require parameters in array format like this:

to[email@email.com][message_id]=message_id

Unfortunately xml nor json doesn't allow me to build parameters with square brackets in xml node names or in json key names. Escaping through %5B %5D also won`t help.

I also tried ExpandingMessageFormatter but with no success - I can`t build well-formed property and replace message of a body with it's content. For example:

<property name="messageBody" scope="default" type="STRING" value="to%5Bemail%40email.com%5D%5Bmessage_id%5D=id&amp;to%5Bemail%40email.com%5D%5Breciver_name%5D=Name%20Surname&amp;smtp_account=2.xxx.smtp&amp;subject=Test%20temat&amp;html=%3Chtml%3E%3Cb%3ETEST%3C%2Fb%3E%3C%2Fhtml%3E&amp;from=email%40email.com&amp;from_name=xxx"/>
    <payloadFactory media-type="json">
        <format>"$ctx:messageBody"</format>
        <args/>
    </payloadFactory>

or with EnrichMediator:

    <enrich>
        <source clone="true" property="messageBody" type="property"/>
        <target type="body"/>
    </enrich>

Please, any advise will be helpful.

Community
  • 1
  • 1
Kamil
  • 23
  • 3

1 Answers1

0

Long time after the question, but maybe it will help someone. I put the script mediator before building

<script description="EncodedUrl" language="js"><![CDATA[resId = mc.getProperty('resId')
mc.setProperty("EncodedUrl", encodeURI("/rest/all/V1/api/products?searchCriteria[filterGroups][0][filters][0][field]=resource_id&searchCriteria[filterGroups][0][filters][0][value]=" + resId</script>
<property description="REST_URL_POSTFIX" expression="get-property('EncodedUrl')" name="REST_URL_POSTFIX" scope="axis2" type="STRING"/>

and it worked for me. We can even likely set the REST_URL_POSTFIX directly in the script.

Gandalf
  • 155
  • 1
  • 12