Search code examples
javaweb-servicessoapjaxb2

jaxb unmarshalling returns null


I'm unmarshalling a response for soap message like the following

<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> 

and i'm binding the jaxb annotation as

    @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;
//-----------------------
}

the problem is, that i'm getting soResponse always null !!?


Solution

  • It looks like you've got the wrong namespace on your

    @XmlElement(namespace = "http://schemas.xmlsoap.org/soap/envelope/", required = true)
    protected soResponse;
    

    This would look for a <SOAP-ENV:soResponse>, not a <m:soResponse xmlns:m="urn:tec">.