I was completing work on a web service using JAX-WS on the server side. In many of the domain objects I used @XmlRootElement
to help facilitate the unmarshaling of XML files into the service using JAXB. All went well and the output was what I expected to see using SoapUI.
However, when I used wsimport to create the client (as a convenience DAO for other developers), I started encountering NullPointerExceptions in my client integration-test class.
The call to the webservice worked correctly, and a response was received by the client, but my more-complex objects were null. Simple attributes, like Strings, were returning full of usable data, but not the larger objects.
Through iterations of recreating services using simple Strings and migrating to more complex objects, I discovered that when the client received objects that were declared on the server with @XmlRootElement
, these were the objects that were null. If the server object did not have the @XmlRootElement
annotation, the client received all of the data in all of its complex glory.
Initially the lack of @XmlRootElement
gave me fits with unmarshaling the data on the server, but this answer helped me out.
So, the phenomenon of the wsimport client silently failing on the unmarshaling of the web service response because of the @XmlRootElement
annotation (on the server!) has me concerned. In this case I had control of both sides and could do something about it. But, what if I don't have control of the server? How would I have resolved this with just the wsimport-generated code?