aspose file tools*
The moose likes Web Services and the fly likes Axis2 parameter ordering is wrong when not all elements are not passed Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "Axis2 parameter ordering is wrong when not all elements are not passed" Watch "Axis2 parameter ordering is wrong when not all elements are not passed" New topic
Author

Axis2 parameter ordering is wrong when not all elements are not passed

Masrudyn Main
Greenhorn

Joined: May 13, 2009
Posts: 20
Hi I'm using Axis2 for my webservices. My service has 5 parameters:
- <xs:sequence>
<xs:element minOccurs="0" name="CIF" nillable="true" type="xs:string" />
<xs:element minOccurs="0" name="NRIC" nillable="true" type="xs:string" />
<xs:element minOccurs="0" name="PP" nillable="true" type="xs:string" />
<xs:element minOccurs="0" name="CountryOfPPIssue" nillable="true" type="xs:string" />
<xs:element minOccurs="0" name="FIN" nillable="true" type="xs:string" />
</xs:sequence>

When the request does not passed in all the elements, Axis2 will reorder the parameter, thus screwing up my code. Eg. when the first parameter CIF is not passed in, now the second parameter NRIC becomes the first parameter CIF:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:int="http://interact.unica.ocbc.com">
<soapenv:Header/>
<soapenv:Body>
<int:getPartyId>
<int:NRIC>S7654321F</int:NRIC>
</int:getPartyId>
</soapenv:Body>
</soapenv:Envelope>

Is there something wrong in my config? Please help. Thanks.

Lester Burnham
Rancher

Joined: Oct 14, 2008
Posts: 1337
"If the first parameter is not passed, then the second parameter becomes the first" - that makes sense to me. If the receiving side can not handle a missing parameter, why don't you send a dummy value that indicates "null" or "N/A"?
Masrudyn Main
Greenhorn

Joined: May 13, 2009
Posts: 20
Hi,

Thanks for your reply - I was expecting Axis to figure out which parameter the request has by looking at the element name. In the example request:
<int:getPartyId>
<int:NRIC>S7654321F</int:NRIC>
</int:getPartyId>

I was passing element NRIC - so shouldn't Axis assign that to the second parameter (NRIC), instead? Or this is not how it works?

The problem here is that my Webservice is being accessed by another middleware and it will not pass any elements if they are null.

If the above is the right behaviour, does that mean I have to change my code to use name value pairs instead?
Lester Burnham
Rancher

Joined: Oct 14, 2008
Posts: 1337
I'm confused - the example you posted shows a single NRIC element. Are you saying that the actual SOAP that gets sent has the NRIC value in a CIF element? If so, are you sure that the correct setter is being called (the one for NRIC, not the one for CIF)?

If some part of the XML pipeline expects all parameter to be present, you should set appropriate minOccurs and maxOccurs values.
Masrudyn Main
Greenhorn

Joined: May 13, 2009
Posts: 20
The SOAP request sends only the NRIC element and value but when it gets to Axis2, it interprets it as the CIF element value. I found out by printing all the parameters that has been passed to my web service class.

I've already set the minOccurs= 0 in my WSDL (see my first post). Actually the WSDL was generated by Axis2. I'm writing a bottom-up webservice

Masrudyn Main
Greenhorn

Joined: May 13, 2009
Posts: 20
BTW, it seems to me that Axis2 is processing the parameters by position rather than by name. This is the first time I am using Axis2 for writing webservices. Is that how Axis2 behaves?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Axis2 parameter ordering is wrong when not all elements are not passed