Skip to content

Commit

Permalink
Avoid cloning the message envelope when iterating
Browse files Browse the repository at this point in the history
In iterate mediator json message flow, we don't need to clone the entire envelope since we are replacing it with iterated message later.
Adding an empty envelope instead improves the performance.
Fixes wso2/api-manager/issues/2196
  • Loading branch information
GDLMadushanka committed Oct 5, 2023
1 parent 63f9910 commit 56fde8d
Showing 1 changed file with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import com.jayway.jsonpath.JsonPath;
import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMNode;
import org.apache.axiom.soap.SOAP11Constants;
import org.apache.axiom.soap.SOAPEnvelope;
import org.apache.axiom.soap.SOAPFactory;
import org.apache.axis2.AxisFault;
import org.apache.axis2.Constants;
import org.apache.axis2.context.OperationContext;
Expand Down Expand Up @@ -372,10 +375,17 @@ private MessageContext getIteratedMessage(MessageContext synCtx, int msgNumber,
throws AxisFault, JaxenException {

// clone the message for the mediation in iteration
MessageContext newCtx = MessageHelper.cloneMessageContext(synCtx);

//Remove the original jsonstream from the context
JsonUtil.removeJsonPayload(((Axis2MessageContext) newCtx).getAxis2MessageContext());
MessageContext newCtx = MessageHelper.cloneMessageContext(synCtx, false, false);
// Adding an empty envelope since JsonUtil.getNewJsonPayload requires an envelope
SOAPFactory fac;
if (SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI
.equals(synCtx.getEnvelope().getBody().getNamespace().getNamespaceURI())) {
fac = OMAbstractFactory.getSOAP11Factory();
} else {
fac = OMAbstractFactory.getSOAP12Factory();
}
SOAPEnvelope newEnvelope = fac.getDefaultEnvelope();
newCtx.setEnvelope(newEnvelope);

if (id != null) {
// set the parent correlation details to the cloned MC -
Expand Down

0 comments on commit 56fde8d

Please sign in to comment.