AXIS2无法从SOAP MTOM/XOP消息中获取附件

最近,同事在与其他厂商做IHE测试,测试的CASE多数都可以通过。唯独一个测试无法通过:对方需要通过MTOM/XOP消息发送一个文件到我们的服务,我们可以正常的收到消息,但无法解析消息得到附件。

经过沟通,发现另一个厂商居然是用CPP自己手动拼接的SOAP消息,也是醉了。

首先是解决了几个命名空间填写不正确的问题,调整完毕以后,AXIS2会报下面的错误:

org.apache.axiom.om.OMException: javax.xml.stream.XMLStreamException: Expected xop:Include as the sole child of an element information item (see section 3.2 of http://www.w3.org/TR/xop10/). This is due to the fact that the element (<xdsb:Document id="Document01">   </xdsb:Document>)  (OMElement obtained after axis2 processing)  that should contains the base64 value of document, is empty. But observing the same message sniffed from wireshark it seems that the Document is present.

这个问题好诡异啊。

经过一番搜索,在apache找到了答案:
由于对方发送附件时,多了一个换行符(XOP协议明确规定不允许的),导致了该错误的发生:

<xdsb:Document id="Document01"><xop:Include href="cid:1.11a262e2-bf65-1e01-28a7-000c29c7ee2b@apache.org" xmlns:xop="http://www.w3.org/2004/08/xop/include"/>
</xdsb:Document>

去掉换行符以后,就好了:

<xdsb:Document id="Document01"><xop:Include href="cid:1.11a262e2-bf65-1e01-28a7-000c29c7ee2b@apache.org" xmlns:xop="http://www.w3.org/2004/08/xop/include"/></xdsb:Document>

这个也是醉了。

大家如果收发SOAP消息,还是不要手工拼接这样写的好啊。

Leave a Reply

Your email address will not be published. Required fields are marked *

*