You are viewing a plain text version of this content. The canonical link for it is here.
Posted to soap-user@ws.apache.org by "Mittermaier, Christian" <Ch...@fabasoft.com> on 2002/02/05 17:54:00 UTC

A note on Body.unmarshall()

Hi all,

I want to contribute a note on the Body.unmarshall() method of Apache SOAP 2.2 and 
additionally maybe someone can help me to get clar about this point, as it seems somehow 
strange to me.

The point is the following:
I am using document style SOAP for my requests and services. When writing a Java client
I was constructing the XML information as a DOM tree as in the following example:

Document doc = new DocumentImpl();
Element query = doc.createElement("Query");
query.appendChild(doc.createTextNode("Some Query String"));
doc.appendChild(query);

Then I tried to put this DOM tree into the body of my SOAP-message:

Envelope soapEnv = new Envelope();
Body soapBody = Body.unmarshall(query, new SOAPContext());
soapEnv.setBody(soapBody);

I considered this to be valid (in whatever sense) and intuitively clear, but it 
is definitely not. I always received an empty <Body> element at the server side.

Inspecting the source code of the unmarshall() method of the Body class, I 
realized that DOMUtils.getFirstChildElement() is applied to the node input parameter
of unmarshall(). So actually, as in my example there is only the "root" element with
no further children, nothing was unmarshalled.

When I put an additional element on top of the <Query> element, i.e. make the 
XML look like the following:
<Wrap>
  <Query>Some Query String</Query>
</Wrap>

it works out fine.

I don't know if this behavior is intended, at least I did not find any documentation
about it and it seems to be a pitfall, anyway.

Hope to get some suggestions/clarifications,

Chris