我已经搜索了高低,以找出我的SOAP服务获取的原因:
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>
当我的网络服务收到此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顽固地说,它希望在urn:BVTAF命名空间中使用 Tagrapportering ,但它不在该命名空间中,这是我的BVTagrapportering类的开头:
/**
* <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;
在我的包中,我有这个package.info.java:
@javax.xml.bind.annotation.XmlSchema(namespace = "urn:BVTAF",
elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED
)
package bvtaf;
问题是 IF 我从传入的SOAP消息中删除 Tagrapportering 元素中的 xmlns 属性,解组就像魅力一样,但我不控制传入的SOAP消息,所以这种方法对我来说不是一个可行的方法......
我使用Apache CXF 3.2.1 Web服务代码生成器从wsdl到java生成我的类,我在Tomcat 8.5中运行它。
任何人都可以帮助我!?这让我疯了......
答案 0 :(得分:0)
我的不好,这个问题令人痛苦的尴尬答案是我的编译器默默地停止编译并发布我的更改(就在我将命名空间定义添加到上面的java类中的@XmlElements之前,这显然解决了我的问题,尽管我从来没有意识到它,因为我的编译器已经停止工作了......)
我的编译器停止的原因是我前一段时间升级了我的Mac OS,这显然打破了Eclipse环境(After OSX upgrade, eclipse is missing applescriptengine.jar)。我没有注意到我的环境崩溃了,因为Eclipse对它非常微妙,我只是继续做我正在做的事情。
我向所有可能在我的问题上花时间的人道歉 - 尽管没有人因为明显的原因回答。