I have a third-party web service for which I create a client using wsimport. Each web service call succeeds, but the response object that I return has all its fields equal to zero. Watching the network, I see that on the wire all the XML elements in the response message have values ββin them, so the object must contain non-zero data. In addition, the client for the same service generated by the old axis1 and called with the same data returns a non-empty response. Any idea what is going on? (If that matters, I use the MOXy implementation of JAXB).
Update . I was able to narrow it down. Wsdl defines an object in its own namespace, for example http://www.acme.com/ws . The answer I get from the service is
<?xml version="1.0" encoding="UTF-8"?> ... SOAP envelope ... <ns1:opINFOWLResponse xmlns:ns1="http://www.acme.com/ws" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <ns1:responseINFOWL xsi:type="ns1:responseINFOWL"> <result>6003</result> <ndserr/> <transid>61437594</transid> <descriptionerr>BLAH.</descriptionerr> </ns1:responseINFOWL> </ns1:opINFOWLResponse> ... SOAP closing tags ...
and not tied to non-empty OpINFOWLResponse , which wraps a non null responseINFOWL object with all fields set to null. Just for fun, I tried to write a couple of lines to unleash the above fragment (after removing SOAP overhead)
JAXBContext ctx = JAXBContext.newInstance(OpINFOWLResponse.class); Unmarshaller u = ctx.createUnmarshaller(); OpINFOWLResponse o = (OpINFOWLResponse) u.unmarshal(new StringReader(theSnippetAbove)); ResponseINFOWL w = o.getResponseINFOWL();
and I get the same result. If I changed the XML above to
<?xml version="1.0" encoding="UTF-8"?> <ns1:opINFOWLResponse xmlns:ns1="http://www.acme.com/ws" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <ns1:responseINFOWL xsi:type="ns1:responseINFOWL"> <ns1:result>6003</ns1:result> <ns1:ndserr/> <ns1:transid>61437594</ns1:transid> <ns1:descriptionerr>BLAH.</ns1:descriptionerr> </ns1:responseINFOWL> </ns1:opINFOWLResponse>
Everything works perfectly. Bummer.
Update (again) . Same behavior with both jaxb-RI and Moxy. Still don't know what happened.
Update (September 9th) . The suggestion below about the incorrect namespace name is interesting, but I assumed that wsimport would be ok. Anyway, this is my package-info.java
@XmlSchema( namespace = "http://www.acme.com/ws", elementFormDefault = XmlNsForm.QUALIFIED) package it.sky.guidaTv.service.remote; import javax.xml.bind.annotation.XmlSchema; import javax.xml.bind.annotation.XmlNsForm;
and this is the corresponding part of the responseINFOWL class
/* * <p>Java class for responseINFOWL complex type. * * <p>The following schema fragment specifies the expected content contained within this class. * * <pre> * <complexType name="responseINFOWL"> * <complexContent> * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> * <sequence> * <element name="result" type="{http://www.w3.org/2001/XMLSchema}string"/> * <element name="descriptionerr" type="{http://www.w3.org/2001/XMLSchema}string"/> * <element name="transid" type="{http://www.w3.org/2001/XMLSchema}string"/> * <element name="ndserr" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/> * <element name="wallet" type="{http://www.acme.com/ws}t_wallet" minOccurs="0"/> * </sequence> * </restriction> * </complexContent> * </complexType> * </pre> * * */ @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "responseINFOWL", propOrder = { "result", "descriptionerr", "transid", "ndserr", "wallet" }) public class ResponseINFOWL { @XmlElement(required = true) protected String result; @XmlElement(required = true) protected String descriptionerr; @XmlElement(required = true) protected String transid; protected String ndserr; protected TWallet wallet; // getters, setters and all. }
I tried to play a little with namespaces in package-info , but still I'm not happy.