jaxb unmarshalling返回null

时间:2012-09-14 13:16:58

标签: java web-services soap jaxb2

我正在解密肥皂消息的响应,如下所示

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   <SOAP-ENV:Body>
      <m:soResponse SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:m="urn:tec">
         <Error/>
         <Order>
            <Number>6</Number>
         </Order>
      </m:soResponse>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope> 

我正在将jaxb注释绑定为

    @XmlAccessorType(XmlAccessType.FIELD)
    @XmlType(name = "", propOrder = {
        "body"
    })
    @XmlRootElement(name = "Envelope")
    public class Envelope {
    @XmlElement(name = "Body", namespace = "http://schemas.xmlsoap.org/soap/envelope/", required = true)
        protected Body body;
    //......
    }

    @XmlAccessorType(XmlAccessType.FIELD)
    @XmlType(name = "", propOrder = {
        "soResponse"
    })
    @XmlRootElement(name = "Body")
    public class Body {

        @XmlElement(namespace = "http://schemas.xmlsoap.org/soap/envelope/", required = true)
        protected soResponse;
    //-----------
    }
XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
    "error",
    "order"
})
@XmlRootElement(name = "soResponse")
public class soResponse{

    @XmlElement(name = "Error", required = true)
    protected soResponse.Error error;
    @XmlElement(name = "Order", required = true)
    protected soResponse.Order order;
    @XmlAttribute(name = "encodingStyle", namespace = "http://schemas.xmlsoap.org/soap/envelope/", required = true)
    @XmlSchemaType(name = "anyURI")
    protected String encodingStyle;
//-----------------------
}
问题是,我得到soResponse总是空的!!?

1 个答案:

答案 0 :(得分:4)

看起来你的

上有错误的命名空间
@XmlElement(namespace = "http://schemas.xmlsoap.org/soap/envelope/", required = true)
protected soResponse;

这会查找<SOAP-ENV:soResponse>,而不是<m:soResponse xmlns:m="urn:tec">