Added methods to access attributes on SoapElement.

This commit is contained in:
Arjen Poutsma
2007-05-05 10:35:31 +00:00
parent 68d9220e29
commit 5a70005990
29 changed files with 545 additions and 312 deletions

View File

@@ -23,8 +23,8 @@ import javax.xml.transform.Source;
/**
* Represents a protocol-agnostic XML message.
*
* <p>Contains methods that provide access to the payload of the message.
* <p/>
* Contains methods that provide access to the payload of the message.
*
* @author Arjen Poutsma
* @see org.springframework.ws.soap.SoapMessage
@@ -33,18 +33,18 @@ import javax.xml.transform.Source;
public interface WebServiceMessage {
/**
* Returns the contents of the message as a {@link java.xml.transform.Source}.
*
* <p>Depending on the implementation, this can be retrieved multiple times, or just a single time.
* Returns the contents of the message as a {@link Source}.
* <p/>
* Depending on the implementation, this can be retrieved multiple times, or just a single time.
*
* @return the message contents
*/
Source getPayloadSource();
/**
* Returns the contents of the message as a {@link java.xml.transform.Result}.
*
* <p>Implementations that are read-only will throw an {@link UnsupportedOperationException}.
* Returns the contents of the message as a {@link Result}.
* <p/>
* Implementations that are read-only will throw an {@link UnsupportedOperationException}.
*
* @return the message contents
* @throws UnsupportedOperationException if the message is read-only
@@ -64,12 +64,13 @@ public interface WebServiceMessage {
* Does this message have a fault?
*
* @return <code>true</code> if the message has a fault; <code>false</code> otherwise
* @see #getFaultReason()
* @see #getFaultReason()
*/
boolean hasFault();
/**
* Returns the fault reason message, if any. Returns <code>null</code> when no fault is present.
*
* @see #hasFault()
*/
String getFaultReason();

View File

@@ -16,6 +16,7 @@
package org.springframework.ws.soap;
import java.util.Iterator;
import javax.xml.namespace.QName;
import javax.xml.transform.Source;
@@ -42,4 +43,28 @@ public interface SoapElement {
*/
Source getSource();
/**
* Adds an attribute with the specified qualified name and value to this element.
*
* @param name the qualified name of the attribute
* @param value the value of the attribute
*/
void addAttribute(QName name, String value);
/**
* Returns the value of the attribute with the specified qualified name.
*
* @param name the qualified name
* @return the value, or <code>null</code> if there is no such attribute
*/
String getAttributeValue(QName name);
/**
* Returns an <code>Iterator</code> over all of the attributes in element as {@link QName qualified names}.
*
* @return an iterator over all the attribute names
*/
Iterator getAllAttibutes();
}

View File

@@ -0,0 +1,38 @@
/*
* Copyright 2007 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;
/**
* Exception thrown when a SOAP element could not be accessed.
*
* @author Arjen Poutsma
*/
public class SoapElementException extends SoapMessageException {
public SoapElementException(String msg) {
super(msg);
}
public SoapElementException(String msg, Throwable ex) {
super(msg, ex);
}
public SoapElementException(Throwable ex) {
super("Could not access element: " + ex.getMessage(), ex);
}
}

View File

@@ -49,22 +49,22 @@ class AxiomSoap11Body extends AxiomSoapBody implements Soap11Body {
public SoapFault addMustUnderstandFault(String faultString, Locale locale) {
SOAPFault fault = addStandardFault(SOAP11Constants.FAULT_CODE_MUST_UNDERSTAND, faultString, locale);
return new AxiomSoap11Fault(fault, axiomFactory);
return new AxiomSoap11Fault(fault, getAxiomFactory());
}
public SoapFault addClientOrSenderFault(String faultString, Locale locale) {
SOAPFault fault = addStandardFault(SOAP11Constants.FAULT_CODE_SENDER, faultString, locale);
return new AxiomSoap11Fault(fault, axiomFactory);
return new AxiomSoap11Fault(fault, getAxiomFactory());
}
public SoapFault addServerOrReceiverFault(String faultString, Locale locale) {
SOAPFault fault = addStandardFault(SOAP11Constants.FAULT_CODE_RECEIVER, faultString, locale);
return new AxiomSoap11Fault(fault, axiomFactory);
return new AxiomSoap11Fault(fault, getAxiomFactory());
}
public SoapFault addVersionMismatchFault(String faultString, Locale locale) {
SOAPFault fault = addStandardFault(SOAP11Constants.FAULT_CODE_VERSION_MISMATCH, faultString, locale);
return new AxiomSoap11Fault(fault, axiomFactory);
return new AxiomSoap11Fault(fault, getAxiomFactory());
}
public Soap11Fault addFault(QName code, String faultString, Locale locale) {
@@ -76,15 +76,15 @@ class AxiomSoap11Body extends AxiomSoapBody implements Soap11Body {
}
try {
detachAllBodyChildren();
SOAPFault fault = axiomFactory.createSOAPFault(axiomBody);
SOAPFaultCode faultCode = axiomFactory.createSOAPFaultCode(fault);
SOAPFault fault = getAxiomFactory().createSOAPFault(getAxiomBody());
SOAPFaultCode faultCode = getAxiomFactory().createSOAPFaultCode(fault);
setValueText(code, fault, faultCode);
SOAPFaultReason faultReason = axiomFactory.createSOAPFaultReason(fault);
SOAPFaultReason faultReason = getAxiomFactory().createSOAPFaultReason(fault);
if (locale != null) {
addLangAttribute(locale, faultReason);
}
faultReason.setText(faultString);
return new AxiomSoap11Fault(fault, axiomFactory);
return new AxiomSoap11Fault(fault, getAxiomFactory());
}
catch (SOAPProcessingException ex) {
@@ -115,11 +115,11 @@ class AxiomSoap11Body extends AxiomSoapBody implements Soap11Body {
Assert.notNull(faultString, "No faultString given");
try {
detachAllBodyChildren();
SOAPFault fault = axiomFactory.createSOAPFault(axiomBody);
SOAPFaultCode faultCode = axiomFactory.createSOAPFaultCode(fault);
SOAPFault fault = getAxiomFactory().createSOAPFault(getAxiomBody());
SOAPFaultCode faultCode = getAxiomFactory().createSOAPFaultCode(fault);
faultCode.setText(
new QName(fault.getNamespace().getNamespaceURI(), localName, fault.getNamespace().getPrefix()));
SOAPFaultReason faultReason = axiomFactory.createSOAPFaultReason(fault);
SOAPFaultReason faultReason = getAxiomFactory().createSOAPFaultReason(fault);
if (locale != null) {
addLangAttribute(locale, faultReason);
}
@@ -132,8 +132,9 @@ class AxiomSoap11Body extends AxiomSoapBody implements Soap11Body {
}
private void addLangAttribute(Locale locale, SOAPFaultReason faultReason) {
OMNamespace xmlNamespace = axiomFactory.createOMNamespace("http://www.w3.org/XML/1998/namespace", "xml");
OMAttribute langAttribute = axiomFactory.createOMAttribute("lang", xmlNamespace, AxiomUtils.toLanguage(locale));
OMNamespace xmlNamespace = getAxiomFactory().createOMNamespace("http://www.w3.org/XML/1998/namespace", "xml");
OMAttribute langAttribute =
getAxiomFactory().createOMAttribute("lang", xmlNamespace, AxiomUtils.toLanguage(locale));
faultReason.addAttribute(langAttribute);
}

View File

@@ -37,20 +37,20 @@ class AxiomSoap11Fault extends AxiomSoapFault implements Soap11Fault {
}
public QName getFaultCode() {
return axiomFault.getCode().getTextAsQName();
return getAxiomFault().getCode().getTextAsQName();
}
public String getFaultStringOrReason() {
if (axiomFault.getReason() != null) {
return axiomFault.getReason().getText();
if (getAxiomFault().getReason() != null) {
return getAxiomFault().getReason().getText();
}
return null;
}
public Locale getFaultStringLocale() {
if (axiomFault.getReason() != null) {
if (getAxiomFault().getReason() != null) {
OMAttribute langAttribute =
axiomFault.getReason().getAttribute(new QName("http://www.w3.org/XML/1998/namespace", "lang"));
getAxiomFault().getReason().getAttribute(new QName("http://www.w3.org/XML/1998/namespace", "lang"));
if (langAttribute != null) {
String xmlLangString = langAttribute.getAttributeValue();
if (xmlLangString != null) {

View File

@@ -48,43 +48,43 @@ class AxiomSoap12Body extends AxiomSoapBody implements Soap12Body {
public SoapFault addMustUnderstandFault(String reason, Locale locale) {
Assert.notNull(locale, "No locale given");
SOAPFault fault = addStandardFault(SOAP12Constants.FAULT_CODE_MUST_UNDERSTAND, reason, locale);
return new AxiomSoap12Fault(fault, axiomFactory);
return new AxiomSoap12Fault(fault, getAxiomFactory());
}
public SoapFault addClientOrSenderFault(String reason, Locale locale) {
Assert.notNull(locale, "No locale given");
SOAPFault fault = addStandardFault(SOAP12Constants.FAULT_CODE_SENDER, reason, locale);
return new AxiomSoap12Fault(fault, axiomFactory);
return new AxiomSoap12Fault(fault, getAxiomFactory());
}
public SoapFault addServerOrReceiverFault(String reason, Locale locale) {
Assert.notNull(locale, "No locale given");
SOAPFault fault = addStandardFault(SOAP12Constants.FAULT_CODE_RECEIVER, reason, locale);
return new AxiomSoap12Fault(fault, axiomFactory);
return new AxiomSoap12Fault(fault, getAxiomFactory());
}
public SoapFault addVersionMismatchFault(String reason, Locale locale) {
Assert.notNull(locale, "No locale given");
SOAPFault fault = addStandardFault(SOAP12Constants.FAULT_CODE_VERSION_MISMATCH, reason, locale);
return new AxiomSoap12Fault(fault, axiomFactory);
return new AxiomSoap12Fault(fault, getAxiomFactory());
}
public Soap12Fault addDataEncodingUnknownFault(QName[] subcodes, String reason, Locale locale) {
Assert.notNull(locale, "No locale given");
SOAPFault fault = addStandardFault(SOAP12Constants.FAULT_CODE_DATA_ENCODING_UNKNOWN, reason, locale);
return new AxiomSoap12Fault(fault, axiomFactory);
return new AxiomSoap12Fault(fault, getAxiomFactory());
}
private SOAPFault addStandardFault(String localName, String faultStringOrReason, Locale locale) {
Assert.notNull(faultStringOrReason, "No faultStringOrReason given");
try {
detachAllBodyChildren();
SOAPFault fault = axiomFactory.createSOAPFault(axiomBody);
SOAPFaultCode code = axiomFactory.createSOAPFaultCode(fault);
SOAPFaultValue value = axiomFactory.createSOAPFaultValue(code);
SOAPFault fault = getAxiomFactory().createSOAPFault(getAxiomBody());
SOAPFaultCode code = getAxiomFactory().createSOAPFaultCode(fault);
SOAPFaultValue value = getAxiomFactory().createSOAPFaultValue(code);
value.setText(fault.getNamespace().getPrefix() + ":" + localName);
SOAPFaultReason reason = axiomFactory.createSOAPFaultReason(fault);
SOAPFaultText text = axiomFactory.createSOAPFaultText(reason);
SOAPFaultReason reason = getAxiomFactory().createSOAPFaultReason(fault);
SOAPFaultText text = getAxiomFactory().createSOAPFaultText(reason);
if (locale != null) {
text.setLang(AxiomUtils.toLanguage(locale));
}

View File

@@ -45,12 +45,12 @@ class AxiomSoap12Fault extends AxiomSoapFault implements Soap12Fault {
}
public QName getFaultCode() {
return axiomFault.getCode().getValue().getTextAsQName();
return getAxiomFault().getCode().getValue().getTextAsQName();
}
public Iterator getFaultSubcodes() {
List subcodes = new ArrayList();
SOAPFaultSubCode subcode = axiomFault.getCode().getSubCode();
SOAPFaultSubCode subcode = getAxiomFault().getCode().getSubCode();
while (subcode != null) {
subcodes.add(subcode.getValue().getTextAsQName());
subcode = subcode.getSubCode();
@@ -59,10 +59,10 @@ class AxiomSoap12Fault extends AxiomSoapFault implements Soap12Fault {
}
public void addFaultSubcode(QName subcode) {
SOAPFaultCode faultCode = axiomFault.getCode();
SOAPFaultCode faultCode = getAxiomFault().getCode();
SOAPFaultSubCode faultSubCode = null;
if (faultCode.getSubCode() == null) {
faultSubCode = axiomFactory.createSOAPFaultSubCode(faultCode);
faultSubCode = getAxiomFactory().createSOAPFaultSubCode(faultCode);
}
else {
faultSubCode = faultCode.getSubCode();
@@ -71,25 +71,25 @@ class AxiomSoap12Fault extends AxiomSoapFault implements Soap12Fault {
faultSubCode = faultSubCode.getSubCode();
}
else {
faultSubCode = axiomFactory.createSOAPFaultSubCode(faultSubCode);
faultSubCode = getAxiomFactory().createSOAPFaultSubCode(faultSubCode);
break;
}
}
}
SOAPFaultValue faultValue = axiomFactory.createSOAPFaultValue(faultSubCode);
SOAPFaultValue faultValue = getAxiomFactory().createSOAPFaultValue(faultSubCode);
setValueText(subcode, faultValue);
}
private void setValueText(QName code, SOAPFaultValue faultValue) {
String prefix = QNameUtils.getPrefix(code);
if (StringUtils.hasLength(code.getNamespaceURI()) && StringUtils.hasLength(prefix)) {
OMNamespace namespace = axiomFault.findNamespaceURI(prefix);
OMNamespace namespace = getAxiomFault().findNamespaceURI(prefix);
if (namespace == null) {
axiomFault.declareNamespace(code.getNamespaceURI(), prefix);
getAxiomFault().declareNamespace(code.getNamespaceURI(), prefix);
}
}
else if (StringUtils.hasLength(code.getNamespaceURI())) {
OMNamespace namespace = axiomFault.findNamespace(code.getNamespaceURI(), null);
OMNamespace namespace = getAxiomFault().findNamespace(code.getNamespaceURI(), null);
if (namespace == null) {
throw new IllegalArgumentException("Could not resolve namespace of code [" + code + "]");
}
@@ -99,7 +99,7 @@ class AxiomSoap12Fault extends AxiomSoapFault implements Soap12Fault {
}
public String getFaultNode() {
SOAPFaultNode faultNode = axiomFault.getNode();
SOAPFaultNode faultNode = getAxiomFault().getNode();
if (faultNode == null) {
return null;
}
@@ -110,9 +110,9 @@ class AxiomSoap12Fault extends AxiomSoapFault implements Soap12Fault {
public void setFaultNode(String uri) {
try {
SOAPFaultNode faultNode = axiomFactory.createSOAPFaultNode(axiomFault);
SOAPFaultNode faultNode = getAxiomFactory().createSOAPFaultNode(getAxiomFault());
faultNode.setNodeValue(uri);
axiomFault.setNode(faultNode);
getAxiomFault().setNode(faultNode);
}
catch (SOAPProcessingException ex) {
throw new AxiomSoapFaultException(ex);
@@ -124,17 +124,17 @@ class AxiomSoap12Fault extends AxiomSoapFault implements Soap12Fault {
}
public String getFaultReasonText(Locale locale) {
SOAPFaultReason faultReason = axiomFault.getReason();
SOAPFaultReason faultReason = getAxiomFault().getReason();
String language = AxiomUtils.toLanguage(locale);
SOAPFaultText faultText = faultReason.getSOAPFaultText(language);
return faultText != null ? faultText.getText() : null;
}
public void setFaultReasonText(Locale locale, String text) {
SOAPFaultReason faultReason = axiomFault.getReason();
SOAPFaultReason faultReason = getAxiomFault().getReason();
String language = AxiomUtils.toLanguage(locale);
try {
SOAPFaultText faultText = axiomFactory.createSOAPFaultText(faultReason);
SOAPFaultText faultText = getAxiomFactory().createSOAPFaultText(faultReason);
faultText.setLang(language);
faultText.setText(text);
}

View File

@@ -42,11 +42,12 @@ class AxiomSoap12Header extends AxiomSoapHeader implements Soap12Header {
public SoapHeaderElement addNotUnderstoodHeaderElement(QName headerName) {
try {
SOAPHeaderBlock notUnderstood = axiomHeader.addHeaderBlock("NotUnderstood", axiomHeader.getNamespace());
SOAPHeaderBlock notUnderstood =
getAxiomHeader().addHeaderBlock("NotUnderstood", getAxiomHeader().getNamespace());
OMNamespace headerNamespace =
notUnderstood.declareNamespace(headerName.getNamespaceURI(), QNameUtils.getPrefix(headerName));
notUnderstood.addAttribute("qname", headerNamespace.getPrefix() + ":" + headerName.getLocalPart(), null);
return new AxiomSoapHeaderElement(notUnderstood, axiomFactory);
return new AxiomSoapHeaderElement(notUnderstood, getAxiomFactory());
}
catch (SOAPProcessingException ex) {
throw new AxiomSoapHeaderException(ex);
@@ -55,14 +56,14 @@ class AxiomSoap12Header extends AxiomSoapHeader implements Soap12Header {
public SoapHeaderElement addUpgradeHeaderElement(String[] supportedSoapUris) {
try {
SOAPHeaderBlock upgrade = axiomHeader.addHeaderBlock("Upgrade", axiomHeader.getNamespace());
SOAPHeaderBlock upgrade = getAxiomHeader().addHeaderBlock("Upgrade", getAxiomHeader().getNamespace());
for (int i = 0; i < supportedSoapUris.length; i++) {
OMElement supportedEnvelope =
axiomFactory.createOMElement("SupportedEnvelope", axiomHeader.getNamespace(), upgrade);
OMElement supportedEnvelope = getAxiomFactory()
.createOMElement("SupportedEnvelope", getAxiomHeader().getNamespace(), upgrade);
OMNamespace namespace = supportedEnvelope.declareNamespace(supportedSoapUris[i], "");
supportedEnvelope.addAttribute("qname", namespace.getPrefix() + ":Envelope", null);
}
return new AxiomSoapHeaderElement(upgrade, axiomFactory);
return new AxiomSoapHeaderElement(upgrade, getAxiomFactory());
}
catch (OMException ex) {
throw new AxiomSoapHeaderException(ex);

View File

@@ -17,7 +17,6 @@
package org.springframework.ws.soap.axiom;
import java.util.Iterator;
import javax.xml.namespace.QName;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.sax.SAXResult;
@@ -27,7 +26,6 @@ import org.apache.axiom.om.OMException;
import org.apache.axiom.soap.SOAPBody;
import org.apache.axiom.soap.SOAPFactory;
import org.apache.axiom.soap.SOAPFault;
import org.springframework.util.Assert;
import org.springframework.ws.soap.SoapBody;
import org.springframework.ws.soap.SoapFault;
import org.springframework.xml.transform.StaxSource;
@@ -37,19 +35,12 @@ import org.springframework.xml.transform.StaxSource;
*
* @author Arjen Poutsma
*/
abstract class AxiomSoapBody implements SoapBody {
protected final SOAPBody axiomBody;
protected final SOAPFactory axiomFactory;
abstract class AxiomSoapBody extends AxiomSoapElement implements SoapBody {
private boolean payloadCaching;
protected AxiomSoapBody(SOAPBody axiomBody, SOAPFactory axiomFactory, boolean payloadCaching) {
Assert.notNull(axiomBody, "No axiomBody given");
Assert.notNull(axiomFactory, "No axiomFactory given");
this.axiomBody = axiomBody;
this.axiomFactory = axiomFactory;
super(axiomBody, axiomFactory);
this.payloadCaching = payloadCaching;
}
@@ -72,33 +63,25 @@ abstract class AxiomSoapBody implements SoapBody {
}
public Result getPayloadResult() {
return new SAXResult(new AxiomContentHandler(axiomBody));
return new SAXResult(new AxiomContentHandler(getAxiomBody()));
}
public boolean hasFault() {
return axiomBody.hasFault();
return getAxiomBody().hasFault();
}
public SoapFault getFault() {
SOAPFault axiomFault = axiomBody.getFault();
return axiomFault != null ? new AxiomSoap11Fault(axiomFault, axiomFactory) : null;
}
public QName getName() {
return axiomBody.getQName();
}
public Source getSource() {
return new StaxSource(axiomBody.getXMLStreamReader());
SOAPFault axiomFault = getAxiomBody().getFault();
return axiomFault != null ? new AxiomSoap11Fault(axiomFault, getAxiomFactory()) : null;
}
private OMElement getPayloadElement() throws OMException {
return axiomBody.getFirstElement();
return getAxiomBody().getFirstElement();
}
protected void detachAllBodyChildren() {
try {
for (Iterator iterator = axiomBody.getChildElements(); iterator.hasNext();) {
for (Iterator iterator = getAxiomBody().getChildElements(); iterator.hasNext();) {
OMElement child = (OMElement) iterator.next();
child.detach();
}
@@ -109,4 +92,7 @@ abstract class AxiomSoapBody implements SoapBody {
}
protected final SOAPBody getAxiomBody() {
return (SOAPBody) getAxiomElement();
}
}

View File

@@ -0,0 +1,113 @@
/*
* Copyright 2007 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 java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.xml.namespace.QName;
import javax.xml.transform.Source;
import org.apache.axiom.om.OMAttribute;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMException;
import org.apache.axiom.om.OMNamespace;
import org.apache.axiom.soap.SOAPFactory;
import org.springframework.util.Assert;
import org.springframework.ws.soap.SoapElement;
import org.springframework.xml.transform.StaxSource;
/**
* Axiom-specific version of {@link SoapElement}.
*
* @author Arjen Poutsma
*/
class AxiomSoapElement implements SoapElement {
private final OMElement axiomElement;
private final SOAPFactory axiomFactory;
protected AxiomSoapElement(OMElement axiomElement, SOAPFactory axiomFactory) {
Assert.notNull(axiomElement, "axiomElement must not be null");
Assert.notNull(axiomFactory, "axiomFactory must not be null");
this.axiomElement = axiomElement;
this.axiomFactory = axiomFactory;
}
public final QName getName() {
try {
return axiomElement.getQName();
}
catch (OMException ex) {
throw new AxiomSoapElementException(ex);
}
}
public final Source getSource() {
try {
return new StaxSource(axiomElement.getXMLStreamReader());
}
catch (OMException ex) {
throw new AxiomSoapElementException(ex);
}
}
public final void addAttribute(QName name, String value) {
try {
OMNamespace namespace = getAxiomFactory().createOMNamespace(name.getNamespaceURI(), name.getPrefix());
OMAttribute attribute = getAxiomFactory().createOMAttribute(name.getLocalPart(), namespace, value);
getAxiomElement().addAttribute(attribute);
}
catch (OMException ex) {
throw new AxiomSoapElementException(ex);
}
}
public final String getAttributeValue(QName name) {
try {
return getAxiomElement().getAttributeValue(name);
}
catch (OMException ex) {
throw new AxiomSoapElementException(ex);
}
}
public final Iterator getAllAttibutes() {
try {
List results = new ArrayList();
for (Iterator iterator = getAxiomElement().getAllAttributes(); iterator.hasNext();) {
OMAttribute attribute = (OMAttribute) iterator.next();
results.add(attribute.getQName());
}
return results.iterator();
}
catch (OMException ex) {
throw new AxiomSoapElementException(ex);
}
}
protected final OMElement getAxiomElement() {
return axiomElement;
}
protected final SOAPFactory getAxiomFactory() {
return axiomFactory;
}
}

View File

@@ -0,0 +1,34 @@
/*
* Copyright 2007 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.springframework.ws.soap.SoapElementException;
public class AxiomSoapElementException extends SoapElementException {
public AxiomSoapElementException(String msg) {
super(msg);
}
public AxiomSoapElementException(String msg, Throwable ex) {
super(msg, ex);
}
public AxiomSoapElementException(Throwable ex) {
super(ex);
}
}

View File

@@ -1,65 +1,45 @@
package org.springframework.ws.soap.axiom;
import org.apache.axiom.om.OMException;
import org.apache.axiom.soap.*;
import org.springframework.util.Assert;
import org.apache.axiom.soap.SOAP11Constants;
import org.apache.axiom.soap.SOAP12Constants;
import org.apache.axiom.soap.SOAPBody;
import org.apache.axiom.soap.SOAPEnvelope;
import org.apache.axiom.soap.SOAPFactory;
import org.apache.axiom.soap.SOAPHeader;
import org.springframework.ws.soap.SoapBody;
import org.springframework.ws.soap.SoapEnvelope;
import org.springframework.ws.soap.SoapHeader;
import org.springframework.xml.transform.StaxSource;
import javax.xml.namespace.QName;
import javax.xml.transform.Source;
/**
* Axiom-Specific version of <code>org.springframework.ws.soap.SoapEnvelope</code>.
*
* @author Arjen Poutsma
*/
class AxiomSoapEnvelope implements SoapEnvelope {
private final SOAPEnvelope axiomEnvelope;
private final SOAPFactory axiomFactory;
class AxiomSoapEnvelope extends AxiomSoapElement implements SoapEnvelope {
boolean payloadCaching;
private AxiomSoapBody body;
public AxiomSoapEnvelope(SOAPEnvelope axiomEnvelope, SOAPFactory axiomFactory, boolean payloadCaching) {
Assert.notNull(axiomEnvelope, "No axiomEnvelope given");
Assert.notNull(axiomFactory, "No axiomFactory given");
this.axiomEnvelope = axiomEnvelope;
this.axiomFactory = axiomFactory;
super(axiomEnvelope, axiomFactory);
this.payloadCaching = payloadCaching;
}
public QName getName() {
return axiomEnvelope.getQName();
}
public Source getSource() {
try {
return new StaxSource(axiomEnvelope.getXMLStreamReader());
}
catch (OMException ex) {
throw new AxiomSoapEnvelopeException(ex);
}
}
public SoapHeader getHeader() {
try {
if (axiomEnvelope.getHeader() == null) {
if (getAxiomEnvelope().getHeader() == null) {
return null;
}
else {
SOAPHeader axiomHeader = axiomEnvelope.getHeader();
String namespaceURI = axiomEnvelope.getNamespace().getNamespaceURI();
SOAPHeader axiomHeader = getAxiomEnvelope().getHeader();
String namespaceURI = getAxiomEnvelope().getNamespace().getNamespaceURI();
if (SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(namespaceURI)) {
return new AxiomSoapHeader(axiomHeader, axiomFactory);
return new AxiomSoapHeader(axiomHeader, getAxiomFactory());
}
else if (SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(namespaceURI)) {
return new AxiomSoap12Header(axiomHeader, axiomFactory);
return new AxiomSoap12Header(axiomHeader, getAxiomFactory());
}
else {
throw new AxiomSoapEnvelopeException("Unknown SOAP namespace \"" + namespaceURI + "\"");
@@ -74,13 +54,13 @@ class AxiomSoapEnvelope implements SoapEnvelope {
public SoapBody getBody() {
if (body == null) {
try {
SOAPBody axiomBody = axiomEnvelope.getBody();
String namespaceURI = axiomEnvelope.getNamespace().getNamespaceURI();
SOAPBody axiomBody = getAxiomEnvelope().getBody();
String namespaceURI = getAxiomEnvelope().getNamespace().getNamespaceURI();
if (SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(namespaceURI)) {
body = new AxiomSoap11Body(axiomBody, axiomFactory, payloadCaching);
body = new AxiomSoap11Body(axiomBody, getAxiomFactory(), payloadCaching);
}
else if (SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(namespaceURI)) {
body = new AxiomSoap12Body(axiomBody, axiomFactory, payloadCaching);
body = new AxiomSoap12Body(axiomBody, getAxiomFactory(), payloadCaching);
}
else {
throw new AxiomSoapEnvelopeException("Unknown SOAP namespace \"" + namespaceURI + "\"");
@@ -92,4 +72,9 @@ class AxiomSoapEnvelope implements SoapEnvelope {
}
return body;
}
protected SOAPEnvelope getAxiomEnvelope() {
return (SOAPEnvelope) getAxiomElement();
}
}

View File

@@ -16,50 +16,30 @@
package org.springframework.ws.soap.axiom;
import javax.xml.namespace.QName;
import javax.xml.transform.Source;
import org.apache.axiom.om.OMException;
import org.apache.axiom.soap.SOAPFactory;
import org.apache.axiom.soap.SOAPFault;
import org.apache.axiom.soap.SOAPFaultDetail;
import org.apache.axiom.soap.SOAPFaultRole;
import org.apache.axiom.soap.SOAPProcessingException;
import org.springframework.util.Assert;
import org.springframework.ws.soap.SoapFault;
import org.springframework.ws.soap.SoapFaultDetail;
import org.springframework.xml.transform.StaxSource;
/** @author Arjen Poutsma */
abstract class AxiomSoapFault implements SoapFault {
protected final SOAPFault axiomFault;
protected final SOAPFactory axiomFactory;
abstract class AxiomSoapFault extends AxiomSoapElement implements SoapFault {
protected AxiomSoapFault(SOAPFault axiomFault, SOAPFactory axiomFactory) {
Assert.notNull(axiomFault, "No axiomFault given");
Assert.notNull(axiomFactory, "No axiomFactory given");
this.axiomFault = axiomFault;
this.axiomFactory = axiomFactory;
}
public QName getName() {
return axiomFault.getQName();
}
public Source getSource() {
return new StaxSource(axiomFault.getXMLStreamReader());
super(axiomFault, axiomFactory);
}
public String getFaultActorOrRole() {
SOAPFaultRole faultRole = axiomFault.getRole();
SOAPFaultRole faultRole = getAxiomFault().getRole();
return faultRole != null ? faultRole.getRoleValue() : null;
}
public void setFaultActorOrRole(String actor) {
try {
SOAPFaultRole axiomFaultRole = axiomFactory.createSOAPFaultRole(axiomFault);
SOAPFaultRole axiomFaultRole = getAxiomFactory().createSOAPFaultRole(getAxiomFault());
axiomFaultRole.setRoleValue(actor);
}
catch (SOAPProcessingException ex) {
@@ -70,8 +50,8 @@ abstract class AxiomSoapFault implements SoapFault {
public SoapFaultDetail getFaultDetail() {
try {
SOAPFaultDetail axiomFaultDetail = axiomFault.getDetail();
return axiomFaultDetail != null ? new AxiomSoapFaultDetail(axiomFaultDetail, axiomFactory) : null;
SOAPFaultDetail axiomFaultDetail = getAxiomFault().getDetail();
return axiomFaultDetail != null ? new AxiomSoapFaultDetail(axiomFaultDetail, getAxiomFactory()) : null;
}
catch (OMException ex) {
throw new AxiomSoapFaultException(ex);
@@ -81,12 +61,17 @@ abstract class AxiomSoapFault implements SoapFault {
public SoapFaultDetail addFaultDetail() {
try {
SOAPFaultDetail axiomFaultDetail = axiomFactory.createSOAPFaultDetail(axiomFault);
return new AxiomSoapFaultDetail(axiomFaultDetail, axiomFactory);
SOAPFaultDetail axiomFaultDetail = getAxiomFactory().createSOAPFaultDetail(getAxiomFault());
return new AxiomSoapFaultDetail(axiomFaultDetail, getAxiomFactory());
}
catch (OMException ex) {
throw new AxiomSoapFaultException(ex);
}
}
protected SOAPFault getAxiomFault() {
return (SOAPFault) getAxiomElement();
}
}

View File

@@ -19,40 +19,30 @@ package org.springframework.ws.soap.axiom;
import java.util.Iterator;
import javax.xml.namespace.QName;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.sax.SAXResult;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMException;
import org.apache.axiom.soap.SOAPFactory;
import org.apache.axiom.soap.SOAPFaultDetail;
import org.springframework.util.Assert;
import org.springframework.ws.soap.SoapFaultDetail;
import org.springframework.ws.soap.SoapFaultDetailElement;
import org.springframework.xml.transform.StaxSource;
/**
* Axiom-specific version of <code>org.springframework.ws.soap.SoapFaultDetail</code>.
*
* @author Arjen Poutsma
*/
class AxiomSoapFaultDetail implements SoapFaultDetail {
private final SOAPFaultDetail axiomFaultDetail;
private final SOAPFactory axiomFactory;
class AxiomSoapFaultDetail extends AxiomSoapElement implements SoapFaultDetail {
public AxiomSoapFaultDetail(SOAPFaultDetail axiomFaultDetail, SOAPFactory axiomFactory) {
Assert.notNull(axiomFaultDetail, "No axiomFaultDetail given");
Assert.notNull(axiomFactory, "No axiomFactory given");
this.axiomFaultDetail = axiomFaultDetail;
this.axiomFactory = axiomFactory;
super(axiomFaultDetail, axiomFactory);
}
public SoapFaultDetailElement addFaultDetailElement(QName name) {
try {
OMElement element = axiomFactory.createOMElement(name, axiomFaultDetail);
return new AxiomSoapFaultDetailElement(element);
OMElement element = getAxiomFactory().createOMElement(name, getAxiomFaultDetail());
return new AxiomSoapFaultDetailElement(element, getAxiomFactory());
}
catch (OMException ex) {
throw new AxiomSoapFaultException(ex);
@@ -61,24 +51,15 @@ class AxiomSoapFaultDetail implements SoapFaultDetail {
}
public Iterator getDetailEntries() {
return new AxiomSoapFaultDetailElementIterator(axiomFaultDetail.getAllDetailEntries());
}
public QName getName() {
return axiomFaultDetail.getQName();
}
public Source getSource() {
try {
return new StaxSource(axiomFaultDetail.getXMLStreamReader());
}
catch (OMException ex) {
throw new AxiomSoapFaultException(ex);
}
return new AxiomSoapFaultDetailElementIterator(getAxiomFaultDetail().getAllDetailEntries());
}
public Result getResult() {
return new SAXResult(new AxiomContentHandler(axiomFaultDetail));
return new SAXResult(new AxiomContentHandler(getAxiomFaultDetail()));
}
protected SOAPFaultDetail getAxiomFaultDetail() {
return (SOAPFaultDetail) getAxiomElement();
}
private class AxiomSoapFaultDetailElementIterator implements Iterator {
@@ -96,7 +77,7 @@ class AxiomSoapFaultDetail implements SoapFaultDetail {
public Object next() {
try {
OMElement axiomElement = (OMElement) axiomIterator.next();
return new AxiomSoapFaultDetailElement(axiomElement);
return new AxiomSoapFaultDetailElement(axiomElement, getAxiomFactory());
}
catch (OMException ex) {
throw new AxiomSoapFaultException(ex);

View File

@@ -16,32 +16,28 @@
package org.springframework.ws.soap.axiom;
import javax.xml.namespace.QName;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.sax.SAXResult;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMException;
import org.apache.axiom.soap.SOAPFactory;
import org.springframework.ws.soap.SoapFaultDetailElement;
import org.springframework.xml.transform.StaxSource;
/**
* Axiom-specific version of <code>org.springframework.ws.soap.SoapFaultDetailElement</code>.
*
* @author Arjen Poutsma
*/
class AxiomSoapFaultDetailElement implements SoapFaultDetailElement {
class AxiomSoapFaultDetailElement extends AxiomSoapElement implements SoapFaultDetailElement {
private final OMElement axiomElement;
public AxiomSoapFaultDetailElement(OMElement axiomElement) {
this.axiomElement = axiomElement;
public AxiomSoapFaultDetailElement(OMElement axiomElement, SOAPFactory soapFactory) {
super(axiomElement, soapFactory);
}
public Result getResult() {
try {
return new SAXResult(new AxiomContentHandler(axiomElement));
return new SAXResult(new AxiomContentHandler(getAxiomElement()));
}
catch (OMException ex) {
throw new AxiomSoapFaultException(ex);
@@ -51,24 +47,11 @@ class AxiomSoapFaultDetailElement implements SoapFaultDetailElement {
public void addText(String text) {
try {
axiomElement.setText(text);
getAxiomElement().setText(text);
}
catch (OMException ex) {
throw new AxiomSoapFaultException(ex);
}
}
public QName getName() {
return axiomElement.getQName();
}
public Source getSource() {
try {
return new StaxSource(axiomElement.getXMLStreamReader());
}
catch (OMException ex) {
throw new AxiomSoapFaultException(ex);
}
}
}

View File

@@ -19,7 +19,6 @@ package org.springframework.ws.soap.axiom;
import java.util.Iterator;
import javax.xml.namespace.QName;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.sax.SAXResult;
import org.apache.axiom.om.OMException;
@@ -27,47 +26,31 @@ import org.apache.axiom.om.OMNamespace;
import org.apache.axiom.soap.SOAPFactory;
import org.apache.axiom.soap.SOAPHeader;
import org.apache.axiom.soap.SOAPHeaderBlock;
import org.springframework.util.Assert;
import org.springframework.ws.soap.SoapHeader;
import org.springframework.ws.soap.SoapHeaderElement;
import org.springframework.xml.namespace.QNameUtils;
import org.springframework.xml.transform.StaxSource;
/**
* Axiom-specific version of <code>org.springframework.ws.soap.SoapHeader</code>.
*
* @author Arjen Poutsma
*/
class AxiomSoapHeader implements SoapHeader {
protected final SOAPHeader axiomHeader;
protected final SOAPFactory axiomFactory;
class AxiomSoapHeader extends AxiomSoapElement implements SoapHeader {
AxiomSoapHeader(SOAPHeader axiomHeader, SOAPFactory axiomFactory) {
Assert.notNull(axiomHeader, "No axiomHeader given");
Assert.notNull(axiomFactory, "No axiomFactory given");
this.axiomHeader = axiomHeader;
this.axiomFactory = axiomFactory;
}
public QName getName() {
return axiomHeader.getQName();
}
public Source getSource() {
return new StaxSource(axiomHeader.getXMLStreamReader());
super(axiomHeader, axiomFactory);
}
public Result getResult() {
return new SAXResult(new AxiomContentHandler(axiomHeader));
return new SAXResult(new AxiomContentHandler(getAxiomHeader()));
}
public SoapHeaderElement addHeaderElement(QName name) {
try {
OMNamespace namespace = axiomFactory.createOMNamespace(name.getNamespaceURI(), QNameUtils.getPrefix(name));
SOAPHeaderBlock axiomHeaderBlock = axiomHeader.addHeaderBlock(name.getLocalPart(), namespace);
return new AxiomSoapHeaderElement(axiomHeaderBlock, axiomFactory);
OMNamespace namespace =
getAxiomFactory().createOMNamespace(name.getNamespaceURI(), QNameUtils.getPrefix(name));
SOAPHeaderBlock axiomHeaderBlock = getAxiomHeader().addHeaderBlock(name.getLocalPart(), namespace);
return new AxiomSoapHeaderElement(axiomHeaderBlock, getAxiomFactory());
}
catch (OMException ex) {
throw new AxiomSoapHeaderException(ex);
@@ -76,7 +59,7 @@ class AxiomSoapHeader implements SoapHeader {
public Iterator examineMustUnderstandHeaderElements(String role) {
try {
return new AxiomSoapHeaderElementIterator(axiomHeader.examineMustUnderstandHeaderBlocks(role));
return new AxiomSoapHeaderElementIterator(getAxiomHeader().examineMustUnderstandHeaderBlocks(role));
}
catch (OMException ex) {
throw new AxiomSoapHeaderException(ex);
@@ -85,7 +68,7 @@ class AxiomSoapHeader implements SoapHeader {
public Iterator examineAllHeaderElements() {
try {
return new AxiomSoapHeaderElementIterator(axiomHeader.examineAllHeaderBlocks());
return new AxiomSoapHeaderElementIterator(getAxiomHeader().examineAllHeaderBlocks());
}
catch (OMException ex) {
throw new AxiomSoapHeaderException(ex);
@@ -93,6 +76,10 @@ class AxiomSoapHeader implements SoapHeader {
}
protected SOAPHeader getAxiomHeader() {
return (SOAPHeader) getAxiomElement();
}
private class AxiomSoapHeaderElementIterator implements Iterator {
private final Iterator axiomIterator;
@@ -108,7 +95,7 @@ class AxiomSoapHeader implements SoapHeader {
public Object next() {
try {
SOAPHeaderBlock axiomHeaderBlock = (SOAPHeaderBlock) axiomIterator.next();
return new AxiomSoapHeaderElement(axiomHeaderBlock, axiomFactory);
return new AxiomSoapHeaderElement(axiomHeaderBlock, getAxiomFactory());
}
catch (OMException ex) {
throw new AxiomSoapHeaderException(ex);

View File

@@ -16,71 +16,40 @@
package org.springframework.ws.soap.axiom;
import javax.xml.namespace.QName;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.sax.SAXResult;
import org.apache.axiom.om.OMAttribute;
import org.apache.axiom.om.OMException;
import org.apache.axiom.om.OMNamespace;
import org.apache.axiom.soap.SOAPFactory;
import org.apache.axiom.soap.SOAPHeaderBlock;
import org.springframework.util.Assert;
import org.springframework.ws.soap.SoapHeaderElement;
import org.springframework.ws.soap.SoapHeaderException;
import org.springframework.xml.namespace.QNameUtils;
import org.springframework.xml.transform.StaxSource;
/**
* Axiom-specific version of <code>org.springframework.ws.soap.SoapHeaderHeaderElement</code>.
*/
class AxiomSoapHeaderElement implements SoapHeaderElement {
private final SOAPHeaderBlock axiomHeaderBlock;
private final SOAPFactory axiomFactory;
/** Axiom-specific version of <code>org.springframework.ws.soap.SoapHeaderHeaderElement</code>. */
class AxiomSoapHeaderElement extends AxiomSoapElement implements SoapHeaderElement {
public AxiomSoapHeaderElement(SOAPHeaderBlock axiomHeaderBlock, SOAPFactory axiomFactory) {
Assert.notNull(axiomHeaderBlock, "No axiomHeaderBlock given");
Assert.notNull(axiomFactory, "No axiomFactory given");
this.axiomHeaderBlock = axiomHeaderBlock;
this.axiomFactory = axiomFactory;
}
public QName getName() {
return axiomHeaderBlock.getQName();
}
public Source getSource() {
try {
return new StaxSource(axiomHeaderBlock.getXMLStreamReader());
}
catch (OMException ex) {
throw new AxiomSoapHeaderException(ex);
}
super(axiomHeaderBlock, axiomFactory);
}
public String getActorOrRole() {
return axiomHeaderBlock.getRole();
return getAxiomHeaderBlock().getRole();
}
public void setActorOrRole(String role) {
axiomHeaderBlock.setRole(role);
getAxiomHeaderBlock().setRole(role);
}
public boolean getMustUnderstand() {
return axiomHeaderBlock.getMustUnderstand();
return getAxiomHeaderBlock().getMustUnderstand();
}
public void setMustUnderstand(boolean mustUnderstand) {
axiomHeaderBlock.setMustUnderstand(mustUnderstand);
getAxiomHeaderBlock().setMustUnderstand(mustUnderstand);
}
public Result getResult() {
try {
return new SAXResult(new AxiomContentHandler(axiomHeaderBlock));
return new SAXResult(new AxiomContentHandler(getAxiomHeaderBlock()));
}
catch (OMException ex) {
throw new AxiomSoapHeaderException(ex);
@@ -88,14 +57,8 @@ class AxiomSoapHeaderElement implements SoapHeaderElement {
}
public void addAttribute(QName name, String value) throws SoapHeaderException {
try {
OMNamespace namespace = axiomFactory.createOMNamespace(name.getNamespaceURI(), QNameUtils.getPrefix(name));
OMAttribute attribute = axiomFactory.createOMAttribute(name.getLocalPart(), namespace, value);
axiomHeaderBlock.addAttribute(attribute);
}
catch (OMException ex) {
throw new AxiomSoapHeaderException(ex);
}
protected SOAPHeaderBlock getAxiomHeaderBlock() {
return (SOAPHeaderBlock) getAxiomElement();
}
}

View File

@@ -82,6 +82,25 @@ public class Saaj11Implementation implements SaajImplementation {
return new SAXResult(new SaajContentHandler(element));
}
public void addAttribute(SOAPElement element, QName name, String value) throws SOAPException {
Name attributeName = SaajUtils.toName(name, element);
element.addAttribute(attributeName, value);
}
public String getAttributeValue(SOAPElement element, QName name) throws SOAPException {
Name attributeName = SaajUtils.toName(name, element);
return element.getAttributeValue(attributeName);
}
public Iterator getAllAttibutes(SOAPElement element) {
List results = new ArrayList();
for (Iterator iterator = element.getAllAttributes(); iterator.hasNext();) {
Name attributeName = (Name) iterator.next();
results.add(SaajUtils.toQName(attributeName));
}
return results.iterator();
}
public QName getFaultCode(SOAPFault fault) {
String code = fault.getFaultCode();
int idx = code.indexOf(':');

View File

@@ -18,7 +18,9 @@ package org.springframework.ws.soap.saaj;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import javax.activation.DataHandler;
import javax.activation.DataSource;
@@ -103,6 +105,25 @@ public class Saaj12Implementation implements SaajImplementation {
return new DOMResult(element);
}
public void addAttribute(SOAPElement element, QName name, String value) throws SOAPException {
Name attributeName = SaajUtils.toName(name, element);
element.addAttribute(attributeName, value);
}
public String getAttributeValue(SOAPElement element, QName name) throws SOAPException {
Name attributeName = SaajUtils.toName(name, element);
return element.getAttributeValue(attributeName);
}
public Iterator getAllAttibutes(SOAPElement element) {
List results = new ArrayList();
for (Iterator iterator = element.getAllAttributes(); iterator.hasNext();) {
Name attributeName = (Name) iterator.next();
results.add(SaajUtils.toQName(attributeName));
}
return results.iterator();
}
public SOAPEnvelope getEnvelope(SOAPMessage message) throws SOAPException {
return message.getSOAPPart().getEnvelope();
}

View File

@@ -140,6 +140,18 @@ public class Saaj13Implementation implements SaajImplementation {
return new DOMResult(element);
}
public void addAttribute(SOAPElement element, QName name, String value) throws SOAPException {
element.addAttribute(name, value);
}
public String getAttributeValue(SOAPElement element, QName name) throws SOAPException {
return element.getAttributeValue(name);
}
public Iterator getAllAttibutes(SOAPElement element) {
return element.getAllAttributesAsQNames();
}
public SOAPEnvelope getEnvelope(SOAPMessage message) throws SOAPException {
return message.getSOAPPart().getEnvelope();
}

View File

@@ -53,6 +53,15 @@ public interface SaajImplementation {
/** Returns the writable <code>Result</code> of the given element. */
Result getResult(SOAPElement element);
/** Adds an attribute to the specified element. */
void addAttribute(SOAPElement element, QName name, String value) throws SOAPException;
/** Returns the attribute value * */
String getAttributeValue(SOAPElement element, QName name) throws SOAPException;
/** Returns all attributes as an iterator of QNames. * */
Iterator getAllAttibutes(SOAPElement element);
/** Returns the envelope of the given message. */
SOAPEnvelope getEnvelope(SOAPMessage message) throws SOAPException;

View File

@@ -16,12 +16,10 @@
package org.springframework.ws.soap.saaj;
import org.springframework.ws.soap.SoapEnvelopeException;
import org.springframework.ws.soap.SoapBodyException;
/**
* @author Arjen Poutsma
*/
public class SaajSoapBodyException extends SoapEnvelopeException {
/** @author Arjen Poutsma */
public class SaajSoapBodyException extends SoapBodyException {
public SaajSoapBodyException(String msg) {
super(msg);

View File

@@ -16,8 +16,10 @@
package org.springframework.ws.soap.saaj;
import java.util.Iterator;
import javax.xml.namespace.QName;
import javax.xml.soap.SOAPElement;
import javax.xml.soap.SOAPException;
import javax.xml.transform.Source;
import org.springframework.util.Assert;
@@ -46,11 +48,33 @@ class SaajSoapElement implements SoapElement {
return getImplementation().getName(element);
}
protected SOAPElement getSaajElement() {
public void addAttribute(QName name, String value) {
try {
getImplementation().addAttribute(element, name, value);
}
catch (SOAPException ex) {
throw new SaajSoapElementException(ex);
}
}
public String getAttributeValue(QName name) {
try {
return getImplementation().getAttributeValue(element, name);
}
catch (SOAPException ex) {
throw new SaajSoapElementException(ex);
}
}
public Iterator getAllAttibutes() {
return getImplementation().getAllAttibutes(element);
}
protected final SOAPElement getSaajElement() {
return element;
}
protected SaajImplementation getImplementation() {
protected final SaajImplementation getImplementation() {
if (SaajUtils.getSaajVersion() == SaajUtils.SAAJ_13) {
return Saaj13Implementation.getInstance();
}

View File

@@ -0,0 +1,35 @@
/*
* Copyright 2007 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.saaj;
import org.springframework.ws.soap.SoapElementException;
/** @author Arjen Poutsma */
public class SaajSoapElementException extends SoapElementException {
public SaajSoapElementException(String msg) {
super(msg);
}
public SaajSoapElementException(String msg, Throwable ex) {
super(msg, ex);
}
public SaajSoapElementException(Throwable ex) {
super(ex);
}
}

View File

@@ -17,23 +17,17 @@
package org.springframework.ws.soap;
import java.util.Locale;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import org.custommonkey.xmlunit.XMLTestCase;
import org.springframework.xml.transform.StringResult;
import org.springframework.xml.transform.StringSource;
public abstract class AbstractSoapBodyTestCase extends XMLTestCase {
public abstract class AbstractSoapBodyTestCase extends AbstractSoapElementTestCase {
protected SoapBody soapBody;
protected Transformer transformer;
protected final void setUp() throws Exception {
TransformerFactory transformerFactory = TransformerFactory.newInstance();
transformer = transformerFactory.newTransformer();
protected final SoapElement createSoapElement() throws Exception {
soapBody = createSoapBody();
return soapBody;
}
protected abstract SoapBody createSoapBody() throws Exception;

View File

@@ -0,0 +1,51 @@
/*
* Copyright 2007 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;
import java.util.Iterator;
import javax.xml.namespace.QName;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import org.custommonkey.xmlunit.XMLTestCase;
public abstract class AbstractSoapElementTestCase extends XMLTestCase {
private SoapElement soapElement;
protected Transformer transformer;
protected final void setUp() throws Exception {
TransformerFactory transformerFactory = TransformerFactory.newInstance();
transformer = transformerFactory.newTransformer();
soapElement = createSoapElement();
}
protected abstract SoapElement createSoapElement() throws Exception;
public void testAttributes() throws Exception {
QName name = new QName("http://springframework.org/spring-ws", "attribute");
String value = "value";
soapElement.addAttribute(name, value);
assertEquals("Invalid attribute value", value, soapElement.getAttributeValue(name));
Iterator allAttributes = soapElement.getAllAttibutes();
assertTrue("Iterator is empty", allAttributes.hasNext());
}
}

View File

@@ -16,21 +16,13 @@
package org.springframework.ws.soap;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import org.custommonkey.xmlunit.XMLTestCase;
public abstract class AbstractSoapEnvelopeTestCase extends XMLTestCase {
public abstract class AbstractSoapEnvelopeTestCase extends AbstractSoapElementTestCase {
protected SoapEnvelope soapEnvelope;
protected Transformer transformer;
protected final void setUp() throws Exception {
TransformerFactory transformerFactory = TransformerFactory.newInstance();
transformer = transformerFactory.newTransformer();
protected final SoapElement createSoapElement() throws Exception {
soapEnvelope = createSoapEnvelope();
return soapEnvelope;
}
protected abstract SoapEnvelope createSoapEnvelope() throws Exception;

View File

@@ -18,23 +18,17 @@ package org.springframework.ws.soap;
import java.util.Iterator;
import javax.xml.namespace.QName;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import org.custommonkey.xmlunit.XMLTestCase;
import org.springframework.xml.transform.StringResult;
import org.springframework.xml.transform.StringSource;
public abstract class AbstractSoapHeaderTestCase extends XMLTestCase {
public abstract class AbstractSoapHeaderTestCase extends AbstractSoapElementTestCase {
protected SoapHeader soapHeader;
protected Transformer transformer;
protected final void setUp() throws Exception {
TransformerFactory transformerFactory = TransformerFactory.newInstance();
transformer = transformerFactory.newTransformer();
protected final SoapElement createSoapElement() throws Exception {
soapHeader = createSoapHeader();
return soapHeader;
}
protected abstract SoapHeader createSoapHeader() throws Exception;

View File

@@ -6,6 +6,7 @@
</properties>
<body>
<release version="1.0-RC1">
<action dev="poutsma" type="add">Add methods to access attributes on SoapElement</action>
<action dev="poutsma" type="add">Added XPath template, for evaluating XPaths in a template-like fashion
</action>
<action dev="poutsma" type="add" issue="SWS-62">MTOM support</action>