CXF: Unmarshalling error: unexpected elements, what {} means?
Asked Answered
C

5

8

I get error while connecting to my web service:

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

Service is exposed using org.apache.cxf.transport.servlet.CXFServlet and jaxws:endpoint annotation. The client is generated using CXF. Firstly, suprising for me is that I'm using the same technology on both ends and the solution is not working, secondly, this mysterious {} in error messages.

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

Crenelation answered 15/5, 2012 at 12:10 Comment(0)
P
15

Have you noted space between OrderID and '>'? Expected is <{}OrderID > and you send "OrderID". Check if you don't have spaces in your element names.

Pilot answered 15/5, 2012 at 13:3 Comment(4)
Yes, you're right, I haven't mekred someone added space there.Crenelation
+1 for saving me time, as your tip helped me find a typo in an element name (not an extra space, just a different name) that resulted in the same not-very-clear error message.Telepathist
Simple and straight answer. I have read so many comments but this is the best one.Xavier
In my case, related Java class property was missing @XmlElement(name="Case-sensitivePropertyName"). Either, calling SOAP with actual propertyname in request OR adding @XmlElement in Java class is the solution.Straightway
P
22

Have you noted space between OrderID and '>'? Expected is <{}OrderID > and you send >"OrderID". Check if you don't have spaces in your element names.

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

It means that the JAX-B Unmarshaller is expecting your OrderID element to have no namespace, i.e. the namespace uri for that element needs to be equal to "".

See here for a brief intro on XML Namespaces

Problematic answered 21/8, 2012 at 17:57 Comment(0)
P
15

Have you noted space between OrderID and '>'? Expected is <{}OrderID > and you send "OrderID". Check if you don't have spaces in your element names.

Pilot answered 15/5, 2012 at 13:3 Comment(4)
Yes, you're right, I haven't mekred someone added space there.Crenelation
+1 for saving me time, as your tip helped me find a typo in an element name (not an extra space, just a different name) that resulted in the same not-very-clear error message.Telepathist
Simple and straight answer. I have read so many comments but this is the best one.Xavier
In my case, related Java class property was missing @XmlElement(name="Case-sensitivePropertyName"). Either, calling SOAP with actual propertyname in request OR adding @XmlElement in Java class is the solution.Straightway
F
3

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

That's for the WSDL-first approach, if you use code-first approach, you may consider add the change as

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

Farouche answered 15/8, 2014 at 20:14 Comment(0)
S
3

I got same error,

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

Then I find on the web service side the response type added a new property 'country'.

To ignore the new added property, add following propertys in '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>
Sunnisunnite answered 25/1, 2018 at 3:9 Comment(0)
I
-2

Sometimes you have to specify the names used in the 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;
Itis answered 21/9, 2013 at 11:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.