ws-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Andreas Veithen (JIRA)" <>
Subject [jira] [Commented] (AXIOM-430) Inconsistent serialization of SOAPEnvelope
Date Sun, 08 Jun 2014 09:51:01 GMT


Andreas Veithen commented on AXIOM-430:

The issue described here implies that it is not possible to produce a SOAP message with an
empty SOAP header if one uses the standard serialization methods. There have been user complaints
about this. See for example:

I also encountered a similar issue when writing code sending messages to WebSphere’s JMX
over SOAP connector. It expects a SOAP header without children, but having attributes:

<SOAP-ENV:Header xmlns:ns0="admin" ns0:JMXMessageVersion="1.2.0" ns0:JMXVersion=“1.2.0”/>

In order to produce such a message with Axiom it is necessary to add a dummy child to the
SOAP header.

Although one may argue that this is not in line with the SOAP spec (There is no semantic difference
between a SOAP message without header and a SOAP message with an empty header. Also, information
in a SOAP header should be represented as child elements, not attributes.), Axiom should nevertheless
support generating such messages.

The current behavior also means that SOAP message are not round-trippable (in the sense that
the XML infoset is not preserved): parsing and subsequently serializing a SOAP message will
strip an empty SOAP header. This may potentially cause issues with certain security schemes
(other than WS-Security because a SOAP message with WS-Security will never have an empty SOAP

Finally, the issue described here may also be part of the explanation for AXIS2-5001.

As a conclusion, Axiom should always serialize the SOAP envelope as is, and not attempt to
strip empty SOAP headers. Changing this behavior will impact existing code that uses SOAPFactory#getDefaultEnvelope().
However, it is expected that this will not break anything because an empty SOAP header should
be ignored by the receiver.

To avoid generating empty SOAP headers unnecessarily, one may be tempted to change the behavior
of getDefaultEnvelope() so that it doesn’t add a SOAP header. However, this is not an option.
The reason is that existing code that uses SOAPFactory#getDefaultEnvelope() will likely use
SOAPEnvelope#getHeader() and rely on the assumption that this method returns a non null result
in this case.

Nevertheless Axiom should provide a simple way to produce SOAP messages without SOAP headers.
For this purpose, a new SOAPFactory#createDefaultEnvelope() method would be introduced. That
method would create a SOAP envelope with just an empty SOAP body, but without SOAP header.
It would then be used in conjunction with SOAPEnvelope#getOrCreateHeader(). Basically, old
code would use getDefaultEnvelope/getHeader, while new application code would use createDefaultEnvelope/getOrCreateHeader.
The getDefaultEnvelope() method would eventually disappear in a future Axiom version (which
is a good thing because the method name is inconsistent anyway).

> Inconsistent serialization of SOAPEnvelope
> ------------------------------------------
>                 Key: AXIOM-430
>                 URL:
>             Project: Axiom
>          Issue Type: Bug
>          Components: DOOM, LLOM
>    Affects Versions: 1.2.13
>            Reporter: Andreas Veithen
>            Priority: Minor
> The SOAPEnvelopeImpl#internalSerialize method contains code that skips the serialization
of the SOAP header if it is empty. Presumably this code is there because SOAPFactory#getDefaultEnvelope()
always creates a SOAP header, but one doesn't want that header to appear in the output if
there are no header blocks. However, this only works when the SOAPEnvelope is serialized to
an XMLStreamWriter, OutputStream or Writer. The header is still present in the sequence of
events produced by getXMLStreamReader or getSAXSource. This can be shown using the following
piece of code:
> {code:java}
> SOAPFactory factory = OMAbstractFactory.getSOAP11Factory();
> SOAPEnvelope envelope = factory.getDefaultEnvelope();
> factory.createOMElement(new QName("urn:test", "test", "p"), envelope.getBody());
> envelope.serialize(System.out);
> System.out.println();
> TransformerFactory.newInstance().newTransformer().transform(envelope.getSAXSource(true),
new StreamResult(System.out));
> {code}
> The output is: 
> {code:xml}
> <?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv=""><soapenv:Body><p:test
> <?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv=""><soapenv:Header/><soapenv:Body><p:test
> {code}
> In addition to that, SOAPEnvelopeImpl#internalSerialize also skips serialization of whitespace
and comments.

This message was sent by Atlassian JIRA

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message