We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

Handling optional attributes in Web Service

LeoKris
LeoKris asked
on
Medium Priority
619 Views
Last Modified: 2012-06-22
Hi, I am invoking a web service using the stub classes. When Axis converts Java object into SOAP request (on invoking _call operation), it also inserts the attributes which Ihave not set with null value. The tag looks like:

<AttributeName xmlns="" xsi:nil="true" />

The problem is that the XSD on the server does not accept "nil" value for the attribute. Either the attribute should not be there, or it should have some value other than "nil".

One way to handle this would be to apply XSLT transformation in Axis handlers to remove unwanted attributes, but I don't find it very clean.  Is there anything else I can do rmeove the unwanted attributes? May be some kind of option in Axis to include only those attributes which have been set in the Java object.

Any sugeestions please?

Thanks

Leo
Comment
Watch Question

Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
Sounds like a problem with the XSD. Are both ends using the same XSD?
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
What is nillable set to in the XSD?

Author

Commented:
it is set to false. Here is how it looks in the stub classes:

 elemField = new org.apache.axis.description.ElementDesc();
        elemField.setFieldName("AttributeName");
        elemField.setXmlName(new javax.xml.namespace.QName("", "AttributeName"));
        elemField.setXmlType(new javax.xml.namespace.QName("urn:abc:names:xyz:ef:TRAN:2:0", "AttributeNameType"));
        elemField.setMinOccurs(0);
        elemField.setNillable(false);
        typeDesc.addFieldDesc(elemField);
Java Developer
CERTIFIED EXPERT
Top Expert 2010
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
It is 1.4

Author

Commented:
thanks Objects. The link gave a patch to fix this problem. But, my situation is a bit more complex that uses multiple XSDs. So, I am using XSLT transformation (just before signing the SOAP request) to remove the tags which are nill. It works fine.

Thanks for your help.

Leo

Author

Commented:
Though solution did not fix the problem, it helped identify that it is a bug with Axis 1.4 libraries.
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.