Backported SWS-266 to 1.0 branch
This commit is contained in:
@@ -42,8 +42,11 @@ public interface WebServiceMessage {
|
||||
Source getPayloadSource();
|
||||
|
||||
/**
|
||||
* Returns the contents of the message as a {@link Result}. <p>Implementations that are read-only will throw an
|
||||
* {@link UnsupportedOperationException}.
|
||||
* Returns the contents of the message as a {@link Result}.
|
||||
* <p/>
|
||||
* Calling this method removes the current payload.
|
||||
* <p/>
|
||||
* Implementations that are read-only will throw an {@link UnsupportedOperationException}.
|
||||
*
|
||||
* @return the message contents
|
||||
* @throws UnsupportedOperationException if the message is read-only
|
||||
|
||||
@@ -20,6 +20,8 @@ import java.util.Locale;
|
||||
import javax.xml.transform.Result;
|
||||
import javax.xml.transform.Source;
|
||||
|
||||
import org.springframework.ws.WebServiceMessage;
|
||||
|
||||
/**
|
||||
* Represents the <code>Body</code> element in a SOAP message. A SOAP body contains the <strong>payload</strong> of the
|
||||
* message. This payload can be custom XML, or a <code>SoapFault</code> (but not both).
|
||||
@@ -40,13 +42,17 @@ public interface SoapBody extends SoapElement {
|
||||
* Returns a <code>Source</code> that represents the contents of the body.
|
||||
*
|
||||
* @return the message contents
|
||||
* @see WebServiceMessage#getPayloadSource()
|
||||
*/
|
||||
Source getPayloadSource();
|
||||
|
||||
/**
|
||||
* Returns a <code>Result</code> that represents the contents of the body.
|
||||
* <p/>
|
||||
* Calling this method removes the current content of the body.
|
||||
*
|
||||
* @return the message contents
|
||||
* @see WebServiceMessage#getPayloadResult()
|
||||
*/
|
||||
Result getPayloadResult();
|
||||
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
/*
|
||||
* Copyright 2006 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.ws.soap.axiom;
|
||||
|
||||
import org.apache.axiom.om.OMElement;
|
||||
import org.apache.axiom.om.impl.builder.SAXOMBuilder;
|
||||
import org.springframework.util.Assert;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
/**
|
||||
* Specific SAX ContentHandler that adds the resulting AXIOM OMElement to a specified parent element when
|
||||
* <code>endDocument</code> is called. Used for returing <code>SAXResult</code>s from Axiom elements.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class AxiomContentHandler extends SAXOMBuilder {
|
||||
|
||||
private OMElement parentElement = null;
|
||||
|
||||
public AxiomContentHandler(OMElement parentElement) {
|
||||
Assert.notNull(parentElement, "No parentElement given");
|
||||
this.parentElement = parentElement;
|
||||
}
|
||||
|
||||
public void endDocument() throws SAXException {
|
||||
super.endDocument();
|
||||
parentElement.addChild(super.getRootElement());
|
||||
}
|
||||
}
|
||||
@@ -28,6 +28,7 @@ import org.apache.axiom.soap.SOAPFactory;
|
||||
import org.apache.axiom.soap.SOAPFault;
|
||||
import org.springframework.ws.soap.SoapBody;
|
||||
import org.springframework.ws.soap.SoapFault;
|
||||
import org.springframework.ws.soap.axiom.support.AxiomUtils;
|
||||
import org.springframework.xml.transform.StaxSource;
|
||||
|
||||
/**
|
||||
@@ -64,7 +65,8 @@ abstract class AxiomSoapBody extends AxiomSoapElement implements SoapBody {
|
||||
}
|
||||
|
||||
public Result getPayloadResult() {
|
||||
return new SAXResult(new AxiomContentHandler(getAxiomBody()));
|
||||
AxiomUtils.removeContents(getAxiomBody());
|
||||
return new SAXResult(new AxiomHandler(getAxiomBody(), getAxiomFactory()));
|
||||
}
|
||||
|
||||
public boolean hasFault() {
|
||||
|
||||
@@ -56,7 +56,7 @@ class AxiomSoapFaultDetail extends AxiomSoapElement implements SoapFaultDetail {
|
||||
}
|
||||
|
||||
public Result getResult() {
|
||||
return new SAXResult(new AxiomContentHandler(getAxiomFaultDetail()));
|
||||
return new SAXResult(new AxiomHandler(getAxiomFaultDetail(), getAxiomFactory()));
|
||||
}
|
||||
|
||||
protected SOAPFaultDetail getAxiomFaultDetail() {
|
||||
|
||||
@@ -38,7 +38,7 @@ class AxiomSoapFaultDetailElement extends AxiomSoapElement implements SoapFaultD
|
||||
|
||||
public Result getResult() {
|
||||
try {
|
||||
return new SAXResult(new AxiomContentHandler(getAxiomElement()));
|
||||
return new SAXResult(new AxiomHandler(getAxiomElement(), getAxiomFactory()));
|
||||
}
|
||||
catch (OMException ex) {
|
||||
throw new AxiomSoapFaultException(ex);
|
||||
|
||||
@@ -44,7 +44,7 @@ abstract class AxiomSoapHeader extends AxiomSoapElement implements SoapHeader {
|
||||
}
|
||||
|
||||
public Result getResult() {
|
||||
return new SAXResult(new AxiomContentHandler(getAxiomHeader()));
|
||||
return new SAXResult(new AxiomHandler(getAxiomHeader(), getAxiomFactory()));
|
||||
}
|
||||
|
||||
public SoapHeaderElement addHeaderElement(QName name) {
|
||||
|
||||
@@ -49,7 +49,7 @@ class AxiomSoapHeaderElement extends AxiomSoapElement implements SoapHeaderEleme
|
||||
|
||||
public Result getResult() {
|
||||
try {
|
||||
return new SAXResult(new AxiomContentHandler(getAxiomHeaderBlock()));
|
||||
return new SAXResult(new AxiomHandler(getAxiomHeaderBlock(), getAxiomFactory()));
|
||||
}
|
||||
catch (OMException ex) {
|
||||
throw new AxiomSoapHeaderException(ex);
|
||||
|
||||
@@ -16,12 +16,16 @@
|
||||
|
||||
package org.springframework.ws.soap.axiom.support;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Locale;
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
import org.apache.axiom.om.OMContainer;
|
||||
import org.apache.axiom.om.OMElement;
|
||||
import org.apache.axiom.om.OMException;
|
||||
import org.apache.axiom.om.OMNamespace;
|
||||
import org.apache.axiom.om.OMNode;
|
||||
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.xml.namespace.QNameUtils;
|
||||
|
||||
@@ -81,5 +85,13 @@ public abstract class AxiomUtils {
|
||||
return StringUtils.parseLocaleString(language);
|
||||
}
|
||||
|
||||
/** Removes the contents (i.e. children) of the container. */
|
||||
public static void removeContents(OMContainer container) {
|
||||
for (Iterator iterator = container.getChildren(); iterator.hasNext();) {
|
||||
OMNode child = (OMNode) iterator.next();
|
||||
child.detach();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -17,6 +17,11 @@
|
||||
package org.springframework.ws.soap;
|
||||
|
||||
import java.util.Locale;
|
||||
import javax.xml.transform.dom.DOMResult;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
import org.springframework.xml.transform.StringResult;
|
||||
import org.springframework.xml.transform.StringSource;
|
||||
@@ -34,11 +39,21 @@ public abstract class AbstractSoapBodyTestCase extends AbstractSoapElementTestCa
|
||||
|
||||
public void testPayload() throws Exception {
|
||||
String payload = "<payload xmlns='http://www.springframework.org' />";
|
||||
StringSource contents = new StringSource(payload);
|
||||
transformer.transform(contents, soapBody.getPayloadResult());
|
||||
transformer.transform(new StringSource(payload), soapBody.getPayloadResult());
|
||||
assertPayloadEqual(payload);
|
||||
}
|
||||
|
||||
public void testGetPayloadResultTwice() throws Exception {
|
||||
String payload = "<payload xmlns='http://www.springframework.org' />";
|
||||
transformer.transform(new StringSource(payload), soapBody.getPayloadResult());
|
||||
transformer.transform(new StringSource(payload), soapBody.getPayloadResult());
|
||||
DOMResult domResult = new DOMResult();
|
||||
transformer.transform(soapBody.getSource(), domResult);
|
||||
Element bodyElement = ((Document) domResult.getNode()).getDocumentElement();
|
||||
NodeList children = bodyElement.getChildNodes();
|
||||
assertEquals("Invalid amount of child nodes", 1, children.getLength());
|
||||
}
|
||||
|
||||
public void testNoFault() throws Exception {
|
||||
assertFalse("body has fault", soapBody.hasFault());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user