【发布时间】:2021-05-27 17:24:57
【问题描述】:
我需要创建 Soap Operation GetFile 以使用 MTOM 响应文件内容和附加标签(响应 Content-Type multipart/related):
<Response>
<file>
<id>1</id>
<name>Filename.pdf</name>
<content>
<xop:Include href="cid:test" xmlns:xop="http://www.w3.org/2004/08/xop/include"/>
</content>
</file>
</Response>
我有代理,它调用外部服务来获取文件内容,然后我使用 PayloadFactory 调解器生成有效负载(在这种情况下,$body/* 是来自外部服务的文件二进制内容,为简单起见,id 和名称是硬编码的):
<payloadFactory media-type="xml"> <format> <Response> <file> <id>$1</id> <name>$2</name> <content>$3</content> </file> </Response> </format> <args> <arg value="1"/> <arg value="fileName.pdf"/> <arg evaluator="xml" expression="$body/*"/> </args> </payloadFactory> <property name="enableMTOM" scope="axis2" type="STRING" value="true"/> <respond/>
作为回应,我得到:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<Response xmlns="http://ws.apache.org/ns/synapse">
<file>
<id>1</id>
<name>fileName.pdf</name>
<content>base64content</content>
</file>
</Response>
</soapenv:Body>
</soapenv:Envelope>
如果我删除该 payloadFactory,那么我会得到正确的多部分/相关响应,因此 enableMTOM 属性有效(但我需要额外的自定义标签):
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<ns:binary xmlns:ns="http://ws.apache.org/commons/ns/payload">
<xop:Include href="cid:1" xmlns:xop="http://www.w3.org/2004/08/xop/include"/>
</ns:binary>
</soapenv:Body>
</soapenv:Envelope>
在这种情况下,是否只有带有 messageContext.addAttachment 的自定义调解器解决方案?在这种情况下有什么最佳做法 - 将接收到的文件内容保存在本地服务器上,然后将其用作附件?
【问题讨论】: