【发布时间】:2018-07-29 13:00:28
【问题描述】:
在 wso2 ESB 中,当 ESB API 的 multipart/formdata 请求到来时,我想先存储请求,然后再使用该属性。
以下是 API 代码。
<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"}
我得到的回应是正确的:
--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--
但由于我想处理具有多部分请求的 json 有效负载的属性中介以供以后使用并转换为多部分格式,所以如果我使用下面的 API 代码,我会得到错误的响应。
<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>
但我得到的回应是
--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--
两个响应有区别,但是转换为multipart/formdata格式(property mediator)之前的请求都是一样的
{
"mediate":{
"file":"dksad..",
"json":"{"a":"b"}"
}
}
但我不明白为什么 ESB 在转换为多部分之前对相同的请求(json)给出不同的响应。
【问题讨论】: