Author: veithen
Date: Mon Sep 16 18:34:53 2013
New Revision: 1523751
URL: http://svn.apache.org/r1523751
Log:
SYNAPSE-881:
* Instead of using our own code, use the appropriate Axiom feature to clone
SOAPEnvelope objects.
* Also fixed an obvious bug in the code responsible for converting between SOAP
1.1 and 1.2. This bug was discovered because Axiom properly clones
SOAPHeaderBlocks as SOAPHeaderBlocks (and not plain OMElement instances).
Modified:
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/SOAPUtils.java
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/MessageHelper.java
Modified:
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/SOAPUtils.java
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/SOAPUtils.java?rev=1523751&r1=1523750&r2=1523751&view=diff
==============================================================================
---
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/SOAPUtils.java
(original)
+++
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/SOAPUtils.java
Mon Sep 16 18:34:53 2013
@@ -133,16 +133,16 @@ public class SOAPUtils {
} else {
newSOAPHeader.addAttribute(attr);
}
+ } // while(allAttributes.hasNext())
- Iterator itrChildren = soapHeader.getChildren();
- while (itrChildren.hasNext()) {
- OMNode node = (OMNode) itrChildren.next();
- itrChildren.remove();
- newSOAPHeader.addChild(node);
- }
+ Iterator itrChildren = soapHeader.getChildren();
+ while (itrChildren.hasNext()) {
+ OMNode node = (OMNode) itrChildren.next();
+ itrChildren.remove();
+ newSOAPHeader.addChild(node);
+ }
- newEnvelope.getHeader().addChild(newSOAPHeader);
- } // while(allAttributes.hasNext())
+ newEnvelope.getHeader().addChild(newSOAPHeader);
} else {
itr.remove();
@@ -289,17 +289,17 @@ public class SOAPUtils {
} else {
newSOAPHeader.addAttribute(attr);
}
+ }
- Iterator itrChildren = soapHeaderBlock.getChildren();
- while (itrChildren.hasNext()) {
- OMNode node = (OMNode) itrChildren.next();
- itrChildren.remove();
- newSOAPHeader.addChild(node);
- }
-
- newEnvelope.getHeader().addChild(newSOAPHeader);
+ Iterator itrChildren = soapHeaderBlock.getChildren();
+ while (itrChildren.hasNext()) {
+ OMNode node = (OMNode) itrChildren.next();
+ itrChildren.remove();
+ newSOAPHeader.addChild(node);
}
+ newEnvelope.getHeader().addChild(newSOAPHeader);
+
} else {
itr.remove();
newEnvelope.getHeader().addChild(omNode);
Modified:
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/MessageHelper.java
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/MessageHelper.java?rev=1523751&r1=1523750&r2=1523751&view=diff
==============================================================================
---
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/MessageHelper.java
(original)
+++
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/MessageHelper.java
Mon Sep 16 18:34:53 2013
@@ -242,41 +242,9 @@ public class MessageHelper {
* @return cloned SOAPEnvelope from the provided one
*/
public static SOAPEnvelope cloneSOAPEnvelope(SOAPEnvelope envelope) {
- SOAPFactory fac;
- if (SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI
- .equals(envelope.getBody().getNamespace().getNamespaceURI())) {
- fac = OMAbstractFactory.getSOAP11Factory();
- } else {
- fac = OMAbstractFactory.getSOAP12Factory();
- }
- SOAPEnvelope newEnvelope = fac.getDefaultEnvelope();
-
- if (envelope.getHeader() != null) {
- Iterator itr = envelope.getHeader().cloneOMElement().getChildren();
- while (itr.hasNext()) {
- OMNode node = (OMNode) itr.next();
- itr.remove();
- newEnvelope.getHeader().addChild(node);
- }
- }
-
- if (envelope.getBody() != null) {
- // treat the SOAPFault cloning as a special case otherwise a
cloning OMElement as the
- // fault would lead to class cast exceptions if accessed through
the getFault method
- if (envelope.getBody().hasFault()) {
- SOAPFault fault = envelope.getBody().getFault();
- newEnvelope.getBody().addFault(cloneSOAPFault(fault));
- } else {
- Iterator itr =
envelope.getBody().cloneOMElement().getChildren();
- while (itr.hasNext()) {
- OMNode node = (OMNode) itr.next();
- itr.remove();
- newEnvelope.getBody().addChild(node);
- }
- }
- }
-
- return newEnvelope;
+ OMCloneOptions options = new OMCloneOptions();
+ options.setPreserveModel(true);
+ return (SOAPEnvelope)envelope.clone(options);
}
/**
@@ -392,75 +360,6 @@ public class MessageHelper {
}
/**
- * Clones the SOAPFault, fault cloning is not the same as cloning the
OMElement because if the
- * Fault is accessed through the SOAPEnvelope.getBody().getFault() method
it will lead to a
- * class cast because the cloned element is just an OMElement but not a
Fault.
- *
- * @param fault that needs to be cloned
- * @return the cloned fault
- */
- public static SOAPFault cloneSOAPFault(SOAPFault fault) {
-
- SOAPFactory fac;
- int soapVersion;
- final int SOAP_11 = 1;
- final int SOAP_12 = 2;
- if (SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI
- .equals(fault.getNamespace().getNamespaceURI())) {
- fac = OMAbstractFactory.getSOAP11Factory();
- soapVersion = SOAP_11;
- } else {
- fac = OMAbstractFactory.getSOAP12Factory();
- soapVersion = SOAP_12;
- }
- SOAPFault newFault = fac.createSOAPFault();
-
- SOAPFaultCode code = fac.createSOAPFaultCode();
- SOAPFaultReason reason = fac.createSOAPFaultReason();
-
- switch (soapVersion) {
- case SOAP_11:
- code.setText(fault.getCode().getTextAsQName());
- reason.setText(fault.getReason().getText());
- break;
- case SOAP_12:
- SOAPFaultValue value = fac.createSOAPFaultValue(code);
- value.setText(fault.getCode().getTextAsQName());
- for (Object obj : fault.getReason().getAllSoapTexts()) {
- SOAPFaultText text = fac.createSOAPFaultText();
- text.setText(((SOAPFaultText) obj).getText());
- reason.addSOAPText(text);
- }
- break;
- }
-
- newFault.setCode(code);
- newFault.setReason(reason);
-
- if (fault.getNode() != null) {
- SOAPFaultNode soapfaultNode = fac.createSOAPFaultNode();
- soapfaultNode.setNodeValue(fault.getNode().getNodeValue());
- newFault.setNode(soapfaultNode);
- }
-
- if (fault.getRole() != null) {
- SOAPFaultRole soapFaultRole = fac.createSOAPFaultRole();
- soapFaultRole.setRoleValue(fault.getRole().getRoleValue());
- newFault.setRole(soapFaultRole);
- }
-
- if (fault.getDetail() != null) {
- SOAPFaultDetail soapFaultDetail = fac.createSOAPFaultDetail();
- for (Iterator itr = fault.getDetail().getAllDetailEntries();
itr.hasNext();) {
- soapFaultDetail.addDetailEntry(((OMElement)
itr.next()).cloneOMElement());
- }
- newFault.setDetail(soapFaultDetail);
- }
-
- return newFault;
- }
-
- /**
* Remove the headers that are marked as processed.
* @param axisMsgCtx the Axis2 Message context
* @param preserveAddressing if true preserve the addressing headers