【发布时间】:2021-05-11 07:14:09
【问题描述】:
我在 WSO2 ESB 7.1.0 中遇到二进制响应问题 - 看起来答案被截断为 375B(正文部分 - 二进制数据)。
这是我的序列片段 - 响应构建:
<payloadFactory description="Build Payload Response" media-type="xml">
<format>
<ns:binary xmlns:ns="http://ws.apache.org/commons/ns/payload">BASE64_FILE_CONTENT</ns:binary>
</format>
<args/>
</payloadFactory>
<script language="js"><![CDATA[var binaryNode = mc.getEnvelope().getBody().getFirstElement().getFirstOMChild();
binaryNode.setBinary(true);]]></script>
<propertyGroup description="Set Content-Type">
<property action="remove" name="TRANSPORT_HEADERS" scope="axis2"/>
<property name="DISABLE_CHUNKING" scope="axis2" type="STRING" value="true"/>
<property name="messageType" scope="axis2" type="STRING" value="application/octet-stream"/>
<property name="ContentType" scope="axis2" type="STRING" value="application/pdf"/>
</propertyGroup>
<header description="Set Content-Disposition" name="Content-Disposition" scope="transport" value="attachment; filename="raport.pdf""/>
当然在 BASE64_FILE_CONTENT 我把真实的文件内容用 BASE64 编码。 消息格式化程序配置(我使用 application/octeat-stream 或 application/pdf -> org.wso2.carbon.relay.ExpandingMessageFormatter 结果相同):
<messageFormatters>
<messageFormatter contentType="application/x-www-form-urlencoded" class="org.apache.synapse.commons.formatters.XFormURLEncodedFormatter"/>
<messageFormatter contentType="multipart/form-data" class="org.apache.axis2.transport.http.MultipartFormDataFormatter"/>
<messageFormatter contentType="application/xml" class="org.apache.axis2.transport.http.ApplicationXMLFormatter"/>
<messageFormatter contentType="text/xml" class="org.apache.axis2.transport.http.SOAPMessageFormatter"/>
<messageFormatter contentType="application/soap+xml" class="org.apache.axis2.transport.http.SOAPMessageFormatter"/>
<messageFormatter contentType="text/plain" class="org.apache.axis2.format.PlainTextFormatter"/>
<messageFormatter contentType="application/json" class="org.wso2.micro.integrator.core.json.JsonStreamFormatter"/>
<messageFormatter contentType="application/json/badgerfish" class="org.apache.axis2.json.JSONBadgerfishMessageFormatter"/>
<messageFormatter contentType="text/javascript" class="org.apache.axis2.json.JSONMessageFormatter"/>
<messageFormatter contentType="application/octet-stream" class="org.wso2.carbon.relay.ExpandingMessageFormatter"/>
<messageFormatter contentType="application/binary" class="org.apache.axis2.format.BinaryFormatter"/>
<messageFormatter contentType="application/pdf" class="org.wso2.carbon.relay.ExpandingMessageFormatter"/>
</messageFormatters>
我尝试了一些示例文件,结果始终相同 - 标头和二进制数据的开头看起来不错,但数据在 375B 上被截断:
Postman screenshot - 375B for body
这个值 (375B) 是否来自任何参数?谁能建议如何在 WSO2 中正确返回文件(作为响应中的二进制数据)?
最好的问候
马辛·奥林斯基
【问题讨论】:
标签: binary wso2 binary-data wso2ei