Skip to content

Commit 1d9a6b5

Browse files
veithengregturn
authored andcommitted
SWS-929 Fix namespace prefix handling with StreamingPayload
The getName() method in JaxbStreamingPayload doesn't report the actual namespace prefix that is later generated by the writeTo method. With Axiom 1.2.13 that didn't cause problems, but 1.2.14 is less lenient, causing an error as described in AXIOM-463. This change: * Updates the StreamingPayload documentation to specify that the namespace prefix in the QName returned by getName() has no significance (which is effectively how things are currently). * Updates AxiomSoapBody so that it Axiom is aware that the namespace prefix of the created OMSourcedElement is unknown. * Modifies the unit test for setStreamingPayload so that it uses a StreamingPayload with a prefix mismatch.
1 parent 6907b50 commit 1d9a6b5

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

spring-ws-core/src/main/java/org/springframework/ws/soap/axiom/AxiomSoapBody.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.ws.soap.axiom;
1818

19+
import javax.xml.namespace.QName;
1920
import javax.xml.transform.Result;
2021
import javax.xml.transform.Source;
2122

@@ -71,7 +72,11 @@ protected final SOAPBody getAxiomBody() {
7172
public void setStreamingPayload(StreamingPayload payload) {
7273
Assert.notNull(payload, "'payload' must not be null");
7374
OMDataSource dataSource = new StreamingOMDataSource(payload);
74-
OMElement payloadElement = getAxiomFactory().createOMElement(dataSource, payload.getName());
75+
SOAPFactory factory = getAxiomFactory();
76+
QName name = payload.getName();
77+
// Ignore the prefix; only the namespace URI and local name are significant
78+
OMElement payloadElement = factory.createOMElement(dataSource, name.getLocalPart(),
79+
factory.createOMNamespace(name.getNamespaceURI(), null));
7580

7681
SOAPBody soapBody = getAxiomBody();
7782
AxiomUtils.removeContents(soapBody);

spring-ws-core/src/main/java/org/springframework/ws/stream/StreamingPayload.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@
3030
public interface StreamingPayload {
3131

3232
/**
33-
* Returns the qualified name of the payload.
33+
* Returns the qualified name of the payload. Only the namespace URI and local part of the
34+
* returned qualified name are significant; they must match the name of the root element
35+
* produced by {@link #writeTo(XMLStreamWriter)}.
3436
*
3537
* @return the qualified name
3638
*/

spring-ws-core/src/test/java/org/springframework/ws/soap/AbstractSoapMessageTestCase.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,15 @@ public void testSetStreamingPayload() throws Exception {
102102
}
103103
StreamingWebServiceMessage streamingMessage = (StreamingWebServiceMessage) soapMessage;
104104

105-
final QName name = new QName("http://springframework.org", "root", "prefix");
105+
final QName name = new QName("http://springframework.org", "root", "");
106106
streamingMessage.setStreamingPayload(new StreamingPayload() {
107107
public QName getName() {
108108
return name;
109109
}
110110

111111
public void writeTo(XMLStreamWriter streamWriter) throws XMLStreamException {
112-
streamWriter.writeStartElement(name.getPrefix(), name.getLocalPart(), name.getNamespaceURI());
112+
// Use a prefix that is different from the one reported by getName()
113+
streamWriter.writeStartElement("prefix", name.getLocalPart(), name.getNamespaceURI());
113114
streamWriter.writeNamespace("prefix", name.getNamespaceURI());
114115
streamWriter.writeStartElement(name.getNamespaceURI(), "child");
115116
streamWriter.writeCharacters("Foo");

0 commit comments

Comments
 (0)