I've searched high and low to find out why my SOAP service get:
javax.xml.bind.UnmarshalException: unexpected element (uri:"http://xsd.banverket.se/T/Opera/Tagrapportering2.xsd", local:"Tagrapportering"). Expected elements are <{urn:BVTAF}Tagrapportering>,<{urn:BVTAF}MessageHeader>
when my web service receives this xml:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<MessageArray xmlns="urn:BVTAFMessageInbox">
<BVTagrapportering xmlns="urn:BVTAF">
<MessageHeader><MessageStatus>1</MessageStatus><MessageReference><MessageType MessageTypeCode="0"/><MessageNumber>5572098</MessageNumber><MessageDateTime>2017-10-31T19:56:22.4312743+01:00</MessageDateTime></MessageReference><Sender>10001</Sender><Recipient>10040</Recipient></MessageHeader>
<Tagrapportering xmlns="http://xsd.banverket.se/T/Opera/Tagrapportering2.xsd">
<Tag tagnr="xxxxx" avgangsdatum="2017-10-31" tagslag="RST" dest="M" trafikutovare="Trans...(I intentionally clipped the xml here)
Unmarshaller stubbornly says that it expects Tagrapportering in urn:BVTAF namespace but it is NOT in that namespace, this is the beginning of my BVTagrapportering class:
/**
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* <complexType>
* <complexContent>
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* <sequence>
* <element name="MessageHeader" type="{urn:BVTAF}MessageHeader"/>
* <element name="Tagrapportering" type="{http://xsd.banverket.se/T/Opera/Tagrapportering2.xsd}Tagrapportering"/>
* </sequence>
* </restriction>
* </complexContent>
* </complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "",
propOrder = {
"messageHeader",
"tagrapportering",
}
)
@XmlRootElement(name = "BVTagrapportering" )
public class BVTagrapportering {
@XmlElement(name = "MessageHeader", namespace = "urn:BVTAF", required = true)
protected MessageHeader messageHeader;
@XmlElement(name = "Tagrapportering", namespace = "http://xsd.banverket.se/T/Opera/Tagrapportering2.xsd", required = true)
protected Tagrapportering tagrapportering;
In my package I have this package.info.java:
@javax.xml.bind.annotation.XmlSchema(namespace = "urn:BVTAF",
elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED
)
package bvtaf;
The thing is that IF I remove the xmlns attribute in the Tagrapportering element from the incoming SOAP message the unmarshalling works like a charm, but I do not control the incoming SOAP messages so this approach is not a possible way forward for me...
I'm using Apache CXF 3.2.1 web service code generator from wsdl to java to generate my classes and I run it in Tomcat 8.5.
Can anyone please help me!? This is driving me insane...