Reputation: 586
I am using Apache CXF 3.0.2 for a client and a server. On the server there is a fairly simple web service that accepts various parameters, one of which is a String array:
<xs:complexType name="getThing">
<xs:sequence>
<xs:element minOccurs="0" name="connection" type="tns:connectionID"/>
<xs:element maxOccurs="unbounded" minOccurs="0" name="types" type="xs:string"/>
</xs:sequence>
</xs:complexType>
When the client calls this, it might be that it wishes to pass a single null value for "types" and that's where I encounter problems. The SOAP message from the client looks like this:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns2:getThing xmlns:ns2="http://serverl.url/">
<connection>Connection details....</connection>
<types xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
</ns2:getThing>
</soap:Body>
</soap:Envelope>
I think that's correct, but CXF on the server translates that into an array with a single empty string value; not an array containing a null value. This then causes various issues with the server code.
The interface the server implements looks like this?
ThingResult getThing(@WebParam(name = "connection") ConnectionID connection, @WebParam(name = "types") String[] types)
{ code }
And if 'nil="true"' isn't valid, then why is CXF generating it?
A null array works OK (the client omits the element from the message and the server interprets that as a null) but not an array containing a null value. Why is CXF behaving this way and how do I configure it so the server deserialises the SOAP message correctly back to what the client sent?
I have searched everywhere for the answer and am fairly sure I am missing something embarrassingly obvious!
edit: Added code sample
Upvotes: 1
Views: 1866
Reputation: 2104
A workaround is shown in Apache Mail Archives by steve666, where the SAAJOutInterceptor is used to allow a custom interceptor (i.e. another AbstractSoapInterceptor) to go through all elements and remove nil ones, based on the presence of the xsi:nil
attribute.
Upvotes: 0
Reputation: 586
I could find no way of making CXF behave (either in WSDL generation or client respect of the generated WSDL).
Instead I had to modify the server code to treat nulls and empty Strings as if they were equivalent.
An bit of a hack that shouldn't be needed, but seems to work.
Upvotes: 0
Reputation: 14607
The schema doesn't have a nillable="true" attribute for the types element. Thus, xsi:nil="true" is not a valid value for that element.
Upvotes: 2