0

我发生了一些奇怪的脑筋急转弯。在给定的 xsd 文件中,我们找到一个 xml 元素,内容如下:

<xsd:element name="getAllOperationsSystemsRequest">
    <xsd:annotation>
      <xsd:documentation>
      </xsd:documentation>
    </xsd:annotation>
</xsd:element>

并且 wsdl 操作链接到该元素

   <wsdl:operation name="getAllOperationsSystems">
     <wsdl:input message="tns:getAllOperationsSystemsRequest"/>
     <wsdl:output message="tns:getAllOperationsSystemsResponse"/>
     <wsdl:fault name="getAllOperationsSystemsException" message="tns:getAllOperationsSystemsException"/>
  </wsdl:operation> 

显然,getAllOperationsSystemsRequest 没有绑定到任何已知类型(缺少属性“type”。结果,在我们执行 wsdl2java 工具后,我们终于得到了一个方法定义:

public org.tmforum.mtop.mri.xsd.osr.v1.MultipleObjectsResponseType getAllOperationsSystems(
    javax.xml.ws.Holder<org.tmforum.mtop.fmw.xsd.hdr.v1.Header> mtopHeader,
    java.lang.**Object** mtopBody
  )throws GetAllOperationsSystemsException

生成一个 Object 而不是 OperationsSystemsRequest 作为输入参数类型,(实际上 OperationsSystemsRequest 从未存在过。

最后,我们在 marshall/unmarshall 中得到一个大胆的运行时错误

原因:com.sun.istack.SAXException2:“javax.xml.bind.JAXBElement”的实例正在替换“java.lang.Object”,但“javax.xml.bind.JAXBElement”绑定到匿名类型。

我非常感谢任何人提供信息来解决它。Tnanks 提前。

4

1 回答 1

0

根据 XML Schema 规范,getAllOperationsSystemsRequest 元素的“类型”是 xsd:anyType。基本上,任何东西。这就是代码中生成 Object 的原因。代码生成器为类型生成,而不是元素(大部分)。如果类型仅在元素中表示,那么它将获得一个 @XmlRootElement 注释,但在大多数情况下,您必须考虑类型。

我建议将架构更改为:

<xsd:element name="getAllOperationsSystemsRequest">
    <xsd:annotation>
      <xsd:documentation>
      </xsd:documentation>
    </xsd:annotation>
    <xsd:complexType>
        <xsd:sequence/>
    </xsd:complexType>
</xsd:element>

那应该生成一个类型并将元素限制为空元素。

于 2013-11-07T13:33:31.340 回答