CXF: undo error: unexpected elements, what does {} mean?

I get an error when connecting to my web service:

javax.xml.ws.soap.SOAPFaultException: Unmarshalling Error: unexpected element (uri: ", local:" OrderID "). Expected elements <{} Login>, <{} CrewId>, <{} OrderID>, <{} OrderNumber>

The service is opened using org.apache.cxf.transport.servlet.CXFServlet and jaxws:endpoint annotations. A client is created using CXF. Firstly, the surprise for me is that I use the same technology at both ends, and the solution does not work, and secondly, it is cryptic {} in the error messages.

So, what's wrong and how to understand this {}?

+6
source share
5 answers

Have you noticed a space between OrderID and '>'? <{}OrderID > is expected, and you send "OrderID" . Check if you have spaces in the names of your elements.

+10
source

Have you noticed a space between OrderID and '>'? The expected one is <{} OrderID> and you send> "OrderID". Check if you have spaces in the names of your elements.

While the above answer from Stepan Vihor helped you get what you need, let me answer your question about what "{}" means:

This means that the Unmarshaller JAX-B expects your OrderID element to have no namespace, i.e. The namespace uri for this element must be "".

See here for a brief introduction to XML Namespaces.

+15
source

@icyitscold, the comment I want to add from my experience is that you can change elementFormDefault to "qualified" as elementFormDefault="qualified" in the xs:schema element. By default, a namespace will be assigned.

What for the WSDL-first approach, if you use a code-based approach, you might consider adding a change as

@javax.xml.bind.annotation.XmlSchema( attributeFormDefault = javax.xml.bind.annotation.XmlNsForm.UNQUALIFIED, elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED)

+2
source

I got the same error

javax.xml.ws.soap.SOAPFaultException: Unmarshalling Error: unexpected element (uri: ", local:" country "). Expected elements: <{} seconds>, ​​<{} month>, <{} hour>, <{} year>, <{} minutes>, <{} day>

Then I find that on the web service side, the response type adds the new country property.

To ignore the newly added property, add the following properties to the jaxws: client setting.

 <jaxws:client id="abc" serviceClass="someClass" address="url"> <jaxws:properties> <entry key="schema-validation-enabled" value="false"/> <entry key="set-jaxb-validation-event-handler" value="false"/> </jaxws:properties> </jaxws:client> 
0
source

Sometimes you need to specify the names used in wsdl (case sensitive): <{Log}>, <{} CrewId>, <{} OrderID>, <{} OrderNumber>

 @XmlElement(name = "CrewId") protected String crewId; @XmlElement(name = "OrderID ") protected String orderID; @XmlElement(name = "Login") protected String login; @XmlElement(name = "OrderNumber") protected String orderNumber; 
-1
source

Source: https://habr.com/ru/post/915788/


All Articles