3

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?

Donal Fellows
  • 133,037
  • 18
  • 149
  • 215
john
  • 176
  • 1
  • 2
  • 5

1 Answers1

9

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.

Majid
  • 13,853
  • 15
  • 77
  • 113
Daniel Kulp
  • 14,447
  • 4
  • 45
  • 37
  • 5
    Thank you very much indeed for your help. This not only that solved the problem I had with 'unexpected element' error when elements of response are prefixed with namespace but also fixed another problem i had with wsdl2java not creating the 'namespace' attribute for @XmlType annotation in the generated java classes. I run my application as a standalone application in JVM and have a custom class loader which loads the classes generated by wsdl2java. I could see that package-info.java is loaded by the class loader but the namespace attribute from package was for @XmlSchema not for @XmlType – john Jun 03 '11 at 07:04
  • This also helped me. I don't know if package-info.class wasn't being picked up, or if it contained the wrong information, but the option to avoid using package-info made it all work. – galmok Jan 24 '23 at 08:14