【问题标题】:JAX-WS and SWA AttachmentsJAX-WS 和 SWA 附件
【发布时间】:2020-03-07 01:22:07
【问题描述】:

我正在构建与 SOAP API 的集成。第二方面迫使我使用 SWA(带有附件的 SOAP https://www.w3.org/TR/SOAP-attachments)。我不能使用 MTOM。它也不是 SWA-Ref(?)。我用 Eclipse 和 Apache CXF 成功生成了 SOAP 客户端和 SOAP 服务器。简单消息与基本身份验证和 HTTPS 完美配合。

我需要处理附件。我的 SOAP 客户端必须发送文件,我的服务器必须接收和保存文件。 JAX-WS 可以处理 MIME 附件吗?

这是示例 SOAP 消息的一部分:

<ns3:attachments>
<ns0:attachment href="cid:5d1499240031a00380006998" contentId="cid:5d1499240031a00380006998" action="add" name="example.txt" type="text/plain" len="88" />
</ns3:attachments>

这是定义附件部分的 WSDL 解析:

<xs:complexType name="AttachmentType">
<xs:attribute name="href" type="xs:string" use="optional"/>
<xs:attribute name="contentId" type="xs:string" use="optional"/>
<xs:attribute name="action" type="xs:string" use="optional"/>
<xs:attribute name="name" type="xs:string" use="required"/>
<xs:attribute name="type" type="xs:string" use="required"/>
<xs:attribute name="len" type="xs:int" use="optional"/>
<xs:attribute name="charset" type="xs:string" use="optional"/>
<xs:attribute name="upload.by" type="xs:string" use="optional"/>
<xs:attribute name="upload.date" type="xs:string" use="optional"/>
<xs:attribute name="attachmentType" type="xs:string" use="optional"/>
</xs:complexType>
<xs:complexType name="AttachmentsType">
<xs:sequence>
<xs:element maxOccurs="unbounded" minOccurs="0" name="attachment" type="AttachmentType"/>
</xs:sequence>
</xs:complexType>

【问题讨论】:

    标签: java soap jax-ws attachment


    【解决方案1】:

    根据JAX-WS documentation

    在 JAX-WS 2.0 RI FCS 版本中添加了

    MTOM 和 swaRef 支持。 JAX-WS 2.0 规范需要 MTOM 和 swaref 支持。

    并根据this

    WS-I Attachment Profile 1.0 定义了使用 swaRef 引用 MIME 附件部分的机制。在此机制中,wsi:swaRef 类型的 XML 元素的内容作为 MIME 附件发送,并且 SOAP Body 内的元素在 RFC 2111 定义的 CID URI 方案中保存对此附件的引用。 JAXB 2.0 定义了 wsi:swaRef 模式类型到 javax.activation.DataHandler 的映射。应用程序将使用数据和适当的 MIME 类型构造 DataHandler,并且 JAX-WS 将与 JAXB 和 SAAJ 协调以将其作为附件 MIME 部分发送。

    Here你可以找到一个例子来完成这个。

    【讨论】:

      猜你喜欢
      • 2014-03-01
      • 2011-06-29
      • 2011-12-16
      • 1970-01-01
      • 2011-11-04
      • 1970-01-01
      • 2013-03-15
      • 2010-10-23
      • 2011-02-25
      相关资源
      最近更新 更多