In wso2 ESB when multipart/formdata request comes for ESB API I want to first store the request and then afterwards I want to use that property.
Below is the API code.
<api context="/multi" name="multi" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="POST">
<inSequence>
<property name="messageType" scope="axis2" type="STRING" value="application/json"/>
<property name="ContentType" scope="axis2" type="STRING" value="application/json"/>
<property name="messageType" scope="axis2" type="STRING" value="multipart/form-data"/>
<property name="ContentType" scope="axis2" type="STRING" value="multipart/form-data"/>
<respond/>
</inSequence>
<outSequence>
<send/>
</outSequence>
<faultSequence/>
</resource>
</api>
Request:
key : file value:image
key : json value:{"a":"b"}
Response i'm getting is correct:
--MIMEBoundary_9e01467992befaaccfd1aa25f3e48a26d18d37e547e64c30
Content-Disposition: form-data; name="file"; filename="file.png"
Content-Type: image/png; charset=ISO-8859-1
Content-Transfer-Encoding: binary
--MIMEBoundary_9e01467992befaaccfd1aa25f3e48a26d18d37e547e64c30
Content-Disposition: form-data; name="json"
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 8bit
sdkjahkshdkkhk..............(Image)
{ "a":"b"}
--MIMEBoundary_9e01467992befaaccfd1aa25f3e48a26d18d37e547e64c30--
But as I wanted to process the property mediator having json payload of multipart request to use afterwards and convert to multipart format, so if I use below API code I' getting wrong response.
<api context="/multi" name="multi" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="POST">
<inSequence>
<property name="messageType" scope="axis2" type="STRING" value="application/json"/>
<property name="ContentType" scope="axis2" type="STRING" value="application/json"/>
<property expression="json-eval($.)" name="inputPayLoad" scope="default" type="STRING"/>
<script language="js"><![CDATA[var rp = mc.getProperty("inputPayLoad");
mc.setPayloadJSON(rp);]]></script>
<property name="messageType" scope="axis2" type="STRING" value="multipart/form-data"/>
<property name="ContentType" scope="axis2" type="STRING" value="multipart/form-data"/>
<respond/>
</inSequence>
<outSequence>
<send/>
</outSequence>
<faultSequence/>
</resource>
</api>
But response I'm getting is
--MIMEBoundary_9e01467992befaacae1a7a25f3e48a26818d37e547e64c30
Content-Disposition: form-data; name="mediate"
Content-Type: application/xml; charset=US-ASCII
Content-Transfer-Encoding: 8bit
<mediate><file>iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAIAAAAiOj........./file><json>{ "a":"b"}</json></mediate>
--MIMEBoundary_9e01467992befaacae1a7a25f3e48a26818d37e547e64c30--
There is a difference between two response, but both the request before converting to multipart/formdata format(property mediator) are same like
{
"mediate":{
"file":"dksad..",
"json":"{"a":"b"}"
}
}
But I am not understanding why ESB is giving different response for same request(json) before converting to multipart.