0

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>
 * &lt;complexType>
 *   &lt;complexContent>
 *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
  *       &lt;sequence>
  *         &lt;element name="MessageHeader" type="{urn:BVTAF}MessageHeader"/>
  *         &lt;element name="Tagrapportering" type="{http://xsd.banverket.se/T/Opera/Tagrapportering2.xsd}Tagrapportering"/>
  *       &lt;/sequence>
  *     &lt;/restriction>
  *   &lt;/complexContent>
  * &lt;/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...

Flirp
  • 1
  • 1

1 Answers1

0

My bad, the painful embarrassing answer to this question is that my compiler silently stopped to compile and publish my changes (just before I added the namespace definition to the @XmlElements in the above java class, which apparently solved my problem although I never became aware of it because my compiler had stopped working)...

The reason to why my compiler stopped is that I upgraded my Mac OS some time ago, which apparently breaks the Eclipse environment (After OSX upgrade, eclipse is missing applescriptengine.jar). I did not notice that my environment broke down because Eclipse was quite subtle about it and I just continued doing what I was doing.

I apologise to everyone who might have spent time on my question - although no one answered for apparent reasons.

Flirp
  • 1
  • 1