从定义SOAP消息的XSD生成Java Source

时间:2012-04-07 16:16:07

标签: java soap xsd

我有一个XSD,用于定义远程设备的SOAP消息。我想采用这个XSD并从中生成Java源代码来创建这些消息。 XSD中的一条消息示例如下:

<xs:element name="get-ethernet-stats">
    <xs:annotation>
        <xs:documentation>Ethernet stats information</xs:documentation>
    </xs:annotation>
    <xs:complexType>
        <xs:sequence>
            <xs:element name="mode" type="response-mode"/>
        </xs:sequence>
    </xs:complexType>
</xs:element>
<xs:element name="get-ethernet-stats-resp">
    <xs:complexType>
        <xs:annotation>
            <xs:documentation>Ethernet Stats</xs:documentation>
        </xs:annotation>
        <xs:sequence>
            <xs:element ref="status"/>
            <xs:element name="result" minOccurs="0">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element name="rx" type="xs:int"/>
                        <xs:element name="tx" type="xs:int"/>
                        <xs:element name="drops" type="xs:int"/>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
        </xs:sequence>
    </xs:complexType>
</xs:element>

有关如何执行此操作的任何建议?我查看了JAXB,但是我没有原始的源文件,当我运行“xjc file.xsd”来获取源文件时,这里是输出的一部分:

parsing a schema...
compiling a schema...
[ERROR] A class/interface with the same name "file.MemosReceipt" is already in use. Use a class customization to resolve this conflict.
  line 7669 of file:/Users/rwb7041/Documents/file/xsd/file.xsd.xsd

[ERROR] (Relevant to above error) another "MemosReceipt" is generated from here.
  line 8242 of file:/Users/rwb7041/Documents/file/xsd/file.xsd.xsd

[ERROR] A class/interface with the same name "file.InstructionsReceipt" is already in use. Use a class customization to resolve this conflict.
  line 7720 of file:/Users/rwb7041/Documents/file/xsd/file.xsd.xsd

[ERROR] (Relevant to above error) another "InstructionsReceipt" is generated from here.
  line 8341 of file:/Users/rwb7041/Documents/file/xsd/file.xsd.xsd

[ERROR] Two declarations cause a collision in the ObjectFactory class.
  line 7686 of file:/Users/rwb7041/Documents/file/xsd/file.xsd.xsd

[ERROR] (Related to above error) This is the other declaration.   
  line 8267 of file:/Users/rwb7041/Documents/file/xsd/file.xsd.xsd

[ERROR] Two declarations cause a collision in the ObjectFactory class.
  line 8626 of file:/Users/rwb7041/Documents/file/xsd/file.xsd.xsd

[ERROR] (Related to above error) This is the other declaration.   
  line 6114 of file:/Users/rwb7041/Documents/file/xsd/file.xsd.xsd

Failed to produce code.

1 个答案:

答案 0 :(得分:0)

我建议您查看jaxws-rt-2.1.4.jar。这允许两种方式提供要在SOAP消息中发送的XML:
(1)仅提供身体内容;代码负责根据检索到的wsdl添加Envelope / Header / Body加名称空间 (2)提供完整的Envelope,以及命名空间

不需要生成代码。

例如参见jaxws-guide.html