使用wso2 esb multipart / form数据

问题描述 投票:1回答:1

在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格式(属性中介)之前的请求都是相同的

{
"mediate":{
"file":"dksad..",
"json":"{"a":"b"}"
}
}

但我不明白为什么ESB在转换为multipart之前对同一请求(json)给出不同的响应。

wso2 wso2esb
1个回答
0
投票

你得到的响应是base64编码,你可以使用base64解码器解码它,看看响应

© www.soinside.com 2019 - 2024. All rights reserved.