JAXB 支持 SOAP 样式数组类型

JAXB support for SOAP style arrayType

我正在尝试制作一个新版本的服务器,该服务器以前使用 Axis 1.4 来响应使用 Spring-WS 的 SOAP RPC 请求。我有一些 RPC 调用在工作,但我一直在尝试满足期望 SOAP 主体的请求,如下所示:

<rpcCallResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
   <responseElement soapenc:arrayType="xsd:string[5]" 
        xsi:type="soapenc:Array" 
        xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
      <responseElement xsi:type="xsd:string">val1</responseElement>
      <responseElement xsi:type="xsd:string">val2</responseElement>
      <responseElement xsi:type="xsd:string">val3</responseElement>
      <responseElement xsi:type="xsd:string" xsi:nil="true"/>
      <responseElement xsi:type="xsd:string" xsi:nil="true"/>
   </responseElement>
</rpcCallResponse>

我正在努力为此编写 XML 架构,并让 JAXB 编组器将 xsi:type 注释推送到响应中。

用于正确编组 (Java -> XML) 的 use/set 注释的正确 XML 架构是什么?

我发现添加 arrayType 的一个解决方案是,不是从 http://schemas.xmlsoap.org/soap/encoding/ 模式派生,而是使用以下形式的自定义模式:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    targetNamespace="http://schemas.xmlsoap.org/soap/encoding/"
    elementFormDefault="qualified">
    <xs:attribute name="arrayType" type="xs:QName" />
</xs:schema>

...用 xs:QName 替换 arrayType 属性的类型(相对于实际类型,它只是 xs:string)。使用 QName 的优点似乎是 JAXB 将采用 QName 的命名空间,并在序列化发生时将其推送到元素上——这是获取上述工作模式的主要障碍。

上面的架构现在看起来像:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:encoding="http://schemas.xmlsoap.org/soap/encoding/"
    targetNamespace="http://foo.com/bar"
    elementFormDefault="qualified">

    <xs:import namespace="http://schemas.xmlsoap.org/soap/encoding/" schemaLocation="soapenc.xsd" />

    <xs:element name="rpcCallResponse">
        <xs:complexType>
            <xs:element name="responseElement">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element name="responseElement" maxOccurs="5" />
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
            <xs:attribute ref="soapenc:arrayType" />
        </xs:complexType>
    </xs:element>
</xs:schema>