[
https://issues.apache.org/jira/browse/AXIOM-430?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14021164#comment-14021164
]
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:
http://mail-archives.apache.org/mod_mbox/axis-java-user/201401.mbox/%3cof6d1bfa4f.3be95504-onc1257c6a.00537566-c1257c6d.00498...@kisters.de%3E
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:
{code:xml}
<SOAP-ENV:Header xmlns:ns0="admin" ns0:JMXMessageVersion="1.2.0"
ns0:JMXVersion=“1.2.0”/>
{code}
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 header).
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: https://issues.apache.org/jira/browse/AXIOM-430
> 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="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><p:test
> xmlns:p="urn:test"/></soapenv:Body></soapenv:Envelope>
> <?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope
> xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Header/><soapenv:Body><p:test
> xmlns:p="urn:test"/></soapenv:Body></soapenv:Envelope>
> {code}
> In addition to that, SOAPEnvelopeImpl#internalSerialize also skips
> serialization of whitespace and comments.
--
This message was sent by Atlassian JIRA
(v6.2#6252)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]