CXF JAXB JAXBEncoderDecoder unmarshalling error : unexpected element when having qualified elements

早过忘川 提交于 2019-12-12 19:51:10

问题


I have the following problem and cannot find a solution:
The WSDL has elementFormDefault="qualified", in the response that I receive in my CXF client all the elements are prefixed with namespace but JAXB throws an exception

org.apache.cxf.interceptor.Fault: Unmarshalling Error: unexpected element (uri:"unm:ENTSCWS", local:"searchReturn"). Expected elements are 
    at org.apache.cxf.jaxb.JAXBEncoderDecoder.unmarshall(JAXBEncoderDecoder.java:661)
    at org.apache.cxf.jaxb.JAXBEncoderDecoder.unmarshall(JAXBEncoderDecoder.java:533)
    at org.apache.cxf.jaxb.io.DataReaderImpl.read(DataReaderImpl.java:128) ...

If i change in the WSDL elementFormDefault="unqualified" it is working, but I am not allowed to change the WSDL, it should have the elements prefixed with the namespace.

The package-info.java contains the annotaction:

@javax.xml.bind.annotation.XmlSchema(namespace = "unm:ENTSCWS", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
package entscws;

The response class contains the annotation:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
    "searchReturn"
})
@XmlRootElement(name = "searchResponse")
public class SearchResponse {

Do you have any idea why I get this error?


回答1:


Are you running in OSGi? I've seen some similar issues with package-info's not being picked up properly there.

Another option could be to add the -xjc-npa flag to the wsdl2java command to have it not use the package-info at all and stick the namespaces in all the other places.



来源:https://stackoverflow.com/questions/6198993/cxf-jaxb-jaxbencoderdecoder-unmarshalling-error-unexpected-element-when-having

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!