jueves, 26 de junio de 2014

Array/Item problem on JAX-WS - Axis 1.x interation

A few days ago I encountered a little problem with a Webservice that I was asked to interact with. The client in question was on other country, and the permissions on the VPN were not granted already.
My normal workflow dealing with WS is first asking for the WSDL for mocking and building the artifacts. So I launched SoapUI and started working on the integration. All worked just well with the mocks, and for a little moment I thought that all will be joy and bliss.

The artifacts the JAX Import that I used gave me the following model:

Having worked with JAX-WS as a client and server, and only as client with the server being Axis2 for example, I thought that because of the signature of the Webservice Interface I was dealing with a JAX server on the other end.

But when the real connection was made (without Mocks) the attribute on CustomerSubscriptionInfo was comming null from the server. I tried a few more times with different input data but was the same. The person responsable for the other end said to me that there was data, that shouldn't be null. So after a few moments of head scratching I launched SoapUI and tried to see the difference between the mock and the real server.



The one on the left is the mock, and on the right is the real server response. Spot the difference? The subscriptions node was having the children different. The next thing I do was ask to the creator of the WS for the source code of those classes, something that may not always be available, but luckly for me was provided without a problem.

When I had the source code the first thing I realised was that the ArrayOfSubscriptionInfo class was missing, and that the actual model was:



The source code showed me that there was no ArrayOfSubscriptionInfo, there was only a simple array. Maybe this class was generated by JAX Importer, and when I asked which technology the server was implementing they sayed Axis1.4 (remember that I thought JAX-WS was the server).

So, after seeing the generated artifacts I saw and fixed the following:


// Before
public class CustomerSubscriptionInfo extends CustomerInfo {

    @XmlElement(required = true, nillable = true)
    protected ArrayOfSubscriptionInfo subscriptions;

    ...

// After
public class CustomerSubscriptionInfo extends CustomerInfo {

    @XmlElementWrapper(name="subscriptions")
    @XmlElement(required = true, nillable = true)
    protected SubscriptionInfo[] subscriptions;


I added the XmlElementWrapper annotation and replaced the ArrayOfSubscriptionInfo to an array of SubscriptionInfo. After this simple change it worked wonders!

So I guess you should really know your way around XML and the annotations...

No hay comentarios:

Publicar un comentario