File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Services and the fly likes Problem with empty elements is SOAP message Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Web Services
Reply Bookmark "Problem with empty elements is SOAP message" Watch "Problem with empty elements is SOAP message" New topic
Author

Problem with empty elements is SOAP message

Andrey Karachoun
Greenhorn

Joined: Jan 14, 2003
Posts: 7
Hi all,

I have WSDL file and need to develop a client that sends SOAP request with some required and optional elements. I use WSDL2Java tool from Axis to generate client stubs from WSDL.

In WSDL optional elements are marked by attribute minOccurs in the following way:

<xsd:element name="quantityRequested" type="tns:Individuals" minOccurs="0"/>

In my client I don't fill this optional element with any value. So when client generates SOAP message this empty element is described like this:

...
<quantityRequested xsi:type="xsd:long" xsi:nil="true"/>
...

The server processes request and when parsing this element it throws NumberFormatException because this element is empty. So I make a conclusion that the server does not expect any optional empty elements in messages, instead it prefers the message not to contain such elements at all.

My question is: how should I handle this and what is the best way to make client generate SOAP messages w/out empty optional elements?

Thanks,
Andrey
Andrey Karachoun
Greenhorn

Joined: Jan 14, 2003
Posts: 7
Hi,

Unfortunately in current Axis release (Axis 1.2 RC2) this problem can
not be resolved in any configuraton way, so I just had to patch two
Axis source files: SerializationContext and RPCParam.

org.apache.axis.encoding.SerializationContext

old way:
134: /**
135: * Send an element with an xsi:nil="true" attribute for null
136: * variables (if Boolean.TRUE), or nothing (if Boolean.FALSE).
137: */
138: private Boolean sendNull = Boolean.TRUE;

new way:
134: /**
135: * Send an element with an xsi:nil="true" attribute for null
136: * variables (if Boolean.TRUE), or nothing (if Boolean.FALSE).
137: */
138: private Boolean sendNull = Boolean.FALSE;

org.apache.axis.message.RPCParam

old way:
177: context.serialize(getQName(), // element qname
178: null, // no extra attrs
179: value, // value
180: xmlType, // java/xml type
181: Boolean.TRUE, wantXSIType);

new way:
177: context.serialize(getQName(), // element qname
178: null, // no extra attrs
179: value, // value
180: xmlType, // java/xml type
181: Boolean.FALSE, wantXSIType);

Regards,
Andrey
 
 
subject: Problem with empty elements is SOAP message
 
Threads others viewed
Elements minOccurs=0 nillable=true
Oracle BPEL result SOAP message
java.io.IOException: Type {http://lang.java}Exception is referenced but not defined.
Web Service message level Encryption Decryption through public and private key
problem in 'generate client' for WSDL in WSAD
WebSphere development made easy
without the weight of IBM tools
http://www.myeclipseide.com