SWS-464
This commit is contained in:
@@ -74,4 +74,13 @@ public interface SoapElement {
|
||||
*/
|
||||
Iterator getAllAttributes();
|
||||
|
||||
/**
|
||||
* Adds a namespace declaration with the specified prefix and URI to this element.
|
||||
*
|
||||
* @param prefix the namespace prefix. Can be empty or null to declare the default namespace
|
||||
* @param namespaceUri the namespace uri
|
||||
* @throws SoapElementException in case of errors
|
||||
*/
|
||||
void addNamespaceDeclaration(String prefix, String namespaceUri);
|
||||
|
||||
}
|
||||
|
||||
@@ -178,15 +178,18 @@ public abstract class AbstractAddressingVersion extends TransformerObjectSupport
|
||||
if (address == null) {
|
||||
return null;
|
||||
}
|
||||
List referenceProperties = referencePropertiesExpression != null ?
|
||||
referencePropertiesExpression.evaluateAsNodeList(node) : Collections.EMPTY_LIST;
|
||||
List referenceParameters = referenceParametersExpression != null ?
|
||||
referenceParametersExpression.evaluateAsNodeList(node) : Collections.EMPTY_LIST;
|
||||
List referenceProperties =
|
||||
referencePropertiesExpression != null ? referencePropertiesExpression.evaluateAsNodeList(node) :
|
||||
Collections.EMPTY_LIST;
|
||||
List referenceParameters =
|
||||
referenceParametersExpression != null ? referenceParametersExpression.evaluateAsNodeList(node) :
|
||||
Collections.EMPTY_LIST;
|
||||
return new EndpointReference(address, referenceProperties, referenceParameters);
|
||||
}
|
||||
|
||||
public void addAddressingHeaders(SoapMessage message, MessageAddressingProperties map) {
|
||||
SoapHeader header = message.getSoapHeader();
|
||||
header.addNamespaceDeclaration(getNamespacePrefix(), getNamespaceUri());
|
||||
// To
|
||||
if (map.getTo() != null) {
|
||||
SoapHeaderElement to = header.addHeaderElement(getToName());
|
||||
|
||||
@@ -29,6 +29,7 @@ import org.apache.axiom.om.OMNamespace;
|
||||
import org.apache.axiom.soap.SOAPFactory;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.ws.soap.SoapElement;
|
||||
import org.springframework.xml.transform.StaxSource;
|
||||
|
||||
@@ -116,6 +117,20 @@ class AxiomSoapElement implements SoapElement {
|
||||
}
|
||||
}
|
||||
|
||||
public void addNamespaceDeclaration(String prefix, String namespaceUri) {
|
||||
try {
|
||||
if (StringUtils.hasLength(prefix)) {
|
||||
getAxiomElement().declareNamespace(namespaceUri, prefix);
|
||||
}
|
||||
else {
|
||||
getAxiomElement().declareDefaultNamespace(namespaceUri);
|
||||
}
|
||||
}
|
||||
catch (OMException ex) {
|
||||
throw new AxiomSoapElementException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
protected final OMElement getAxiomElement() {
|
||||
return axiomElement;
|
||||
}
|
||||
|
||||
@@ -283,6 +283,10 @@ class Saaj11Implementation extends SaajImplementation {
|
||||
return element.getChildElements(elementName);
|
||||
}
|
||||
|
||||
void addNamespaceDeclaration(SOAPElement element, String prefix, String namespaceUri) throws SOAPException {
|
||||
element.addNamespaceDeclaration(prefix, namespaceUri);
|
||||
}
|
||||
|
||||
public void writeTo(SOAPMessage message, OutputStream outputStream) throws SOAPException, IOException {
|
||||
if (message.saveRequired()) {
|
||||
message.saveChanges();
|
||||
|
||||
@@ -233,6 +233,10 @@ class Saaj12Implementation extends SaajImplementation {
|
||||
return element.getChildElements(elementName);
|
||||
}
|
||||
|
||||
void addNamespaceDeclaration(SOAPElement element, String prefix, String namespaceUri) throws SOAPException {
|
||||
element.addNamespaceDeclaration(prefix, namespaceUri);
|
||||
}
|
||||
|
||||
public void writeTo(SOAPMessage message, OutputStream outputStream) throws SOAPException, IOException {
|
||||
if (message.saveRequired()) {
|
||||
message.saveChanges();
|
||||
|
||||
@@ -259,6 +259,10 @@ class Saaj13Implementation extends SaajImplementation {
|
||||
return element.getChildElements(name);
|
||||
}
|
||||
|
||||
void addNamespaceDeclaration(SOAPElement element, String prefix, String namespaceUri) throws SOAPException {
|
||||
element.addNamespaceDeclaration(prefix, namespaceUri);
|
||||
}
|
||||
|
||||
public void writeTo(SOAPMessage message, OutputStream outputStream) throws SOAPException, IOException {
|
||||
if (message.saveRequired()) {
|
||||
message.saveChanges();
|
||||
|
||||
@@ -82,6 +82,9 @@ abstract class SaajImplementation {
|
||||
/** Returns an iterator over all the child elements with the specified name. */
|
||||
abstract Iterator getChildElements(SOAPElement element, QName name) throws SOAPException;
|
||||
|
||||
/** Declares a namespace. */
|
||||
abstract void addNamespaceDeclaration(SOAPElement element, String prefix, String namespaceUri) throws SOAPException;
|
||||
|
||||
/*
|
||||
* SOAPMessage
|
||||
*/
|
||||
@@ -231,5 +234,4 @@ abstract class SaajImplementation {
|
||||
|
||||
/** Adds a text node to the given detail entry. */
|
||||
abstract void addTextNode(DetailEntry detailEntry, String text) throws SOAPException;
|
||||
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ class SaajSoapElement implements SoapElement {
|
||||
|
||||
private final SOAPElement element;
|
||||
|
||||
public SaajSoapElement(SOAPElement element) {
|
||||
SaajSoapElement(SOAPElement element) {
|
||||
Assert.notNull(element, "element must not be null");
|
||||
this.element = element;
|
||||
}
|
||||
@@ -80,6 +80,15 @@ class SaajSoapElement implements SoapElement {
|
||||
return getImplementation().getAllAttibutes(element);
|
||||
}
|
||||
|
||||
public void addNamespaceDeclaration(String prefix, String namespaceUri) {
|
||||
try {
|
||||
getImplementation().addNamespaceDeclaration(element, prefix, namespaceUri);
|
||||
}
|
||||
catch (SOAPException ex) {
|
||||
throw new SaajSoapElementException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
protected final SOAPElement getSaajElement() {
|
||||
return element;
|
||||
}
|
||||
|
||||
@@ -44,7 +44,18 @@ public abstract class AbstractSoapElementTestCase extends XMLTestCase {
|
||||
assertEquals("Invalid attribute value", value, soapElement.getAttributeValue(name));
|
||||
Iterator allAttributes = soapElement.getAllAttributes();
|
||||
assertTrue("Iterator is empty", allAttributes.hasNext());
|
||||
}
|
||||
|
||||
public void testAddNamespaceDeclaration() throws Exception {
|
||||
String prefix = "p";
|
||||
String namespace = "http://springframework.org/spring-ws";
|
||||
soapElement.addNamespaceDeclaration(prefix, namespace);
|
||||
}
|
||||
|
||||
public void testAddDefaultNamespaceDeclaration() throws Exception {
|
||||
String prefix = "";
|
||||
String namespace = "http://springframework.org/spring-ws";
|
||||
soapElement.addNamespaceDeclaration(prefix, namespace);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user