我使用CXF從第三方wsdl(不由我們維護)生成java代碼。cxf wsdl2java可選和必需元素
我有這兩個片段工作不像預期的那樣,當編組到soap信息。
XML:
<choice>
<sequence>
<element name="x" type="xt" nillable="true" minOccurs="0" />
</sequence>
<element name="y" type="yt"
nillable="true" minOccurs="0" />
</choice>
Java:
@XmlElement(name = "x", nillable = true)
protected Xx;
@XmlElement(name = "y", nillable = true)
protected Y y;
如果我添加X,而不是y以(通過代碼)SOAP消息那麼它看起來像:
<x>123456782</x>
<y xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:nil="true" />
爲什麼加y以SOAP消息,雖然這是一個可選的元素?
類似的事情是在這個片段中發生的事情:
XML:
<attribute ref="z" use="required" fixed="XXX" />
Java:
@XmlAttribute(name = "z", namespace = "http://www.egem.nl/StUF/StUF0301",
required = true)
protected String z;
這裏CXF(與真正的模式驗證)抱怨,如果我不通過代碼添加的元素。 如果我打開模式驗證然後不創建元素添加全部。
這個元素是必需的,並且有一個固定的屬性,爲什麼不創建它,如果我不添加它(通過代碼)?
編輯: 在開發過程中,我意識到cxf正在生成一個.package-info.java文件,它給了我命名空間的麻煩。所以我正在尋找一種禁用.package-info.java文件生成的方法。解決方案是在pom文件中將一個extraarg放入cxf codegen插件:-xjc-npa。在pom中的那部分看起來像:
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>${cxf.version}</version>
<configuration>
<defaultOptions>
<extraargs>
<extraarg>-xjc-npa</extraarg>
</extraargs>
</defaultOptions>
</configuration>
</plugin>
但是,在重新生成類文件後,我驚訝地發現所有固定元素現在都是常量。沒有更多的getters/setters產生。但遺憾的是選項仍然存在問題。