Skip to content

Commit

Permalink
Add review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
arunans23 committed Dec 5, 2024
1 parent 7df17a8 commit 0ac97a0
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.apache.synapse.endpoints.EndpointDefinition;
import org.apache.synapse.endpoints.IndirectEndpoint;
import org.apache.synapse.mediators.AbstractMediator;
import org.apache.synapse.mediators.elementary.EnrichMediator;
import org.apache.synapse.mediators.elementary.Source;
import org.apache.synapse.mediators.elementary.Target;
import org.apache.synapse.message.senders.blocking.BlockingMsgSender;
Expand Down Expand Up @@ -167,8 +168,11 @@ public boolean mediate(MessageContext synInCtx) {
sourceForInboundPayload.setClone(true);
CallMediatorEnrichUtil
.doEnrich(synInCtx, sourceForInboundPayload, targetForOriginalPayload, originalMessageType);
CallMediatorEnrichUtil
.doEnrich(synInCtx, sourceForOutboundPayload, targetForOutboundPayload, getSourceMessageType());
if (!(EnrichMediator.BODY == sourceForOutboundPayload.getSourceType() &&
EnrichMediator.BODY == targetForOutboundPayload.getTargetType())) {
CallMediatorEnrichUtil
.doEnrich(synInCtx, sourceForOutboundPayload, targetForOutboundPayload, getSourceMessageType());
}
if (!sourceMessageType.equalsIgnoreCase(originalMessageType)) {
CallMediatorEnrichUtil.setContentType(synInCtx, sourceMessageType, sourceMessageType);
if (originalMessageType.equalsIgnoreCase(JSON_TYPE)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import org.apache.synapse.mediators.eip.EIPUtils;
import org.apache.synapse.util.CallMediatorEnrichUtil;
import org.apache.synapse.util.InlineExpressionUtil;
import org.apache.synapse.util.synapse.expression.constants.ExpressionConstants;
import org.apache.synapse.util.xpath.SynapseJsonPath;
import org.apache.synapse.util.xpath.SynapseXPath;
import org.apache.synapse.util.xpath.SynapseXPathConstants;
Expand Down Expand Up @@ -239,6 +240,27 @@ public void insert(MessageContext synContext,
}else{
synContext.setProperty(property, sourceNodeList);
}
} else if (targetType == EnrichMediator.VARIABLE) {
if (action.equalsIgnoreCase(ACTION_REPLACE)) {
String key = variable.evaluateValue(synContext);
if (StringUtils.isEmpty(key)) {
synLog.error("Variable key cannot be null");
throw new SynapseException("Variable key cannot be null");
}
Map<String, Object> result = new HashMap<>();
result.put(ExpressionConstants.PAYLOAD, sourceNodeList);
Map transportHeaders = (Map)((Axis2MessageContext) synContext).getAxis2MessageContext()
.getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS);
JsonObject headers = EIPUtils.convertMapToJsonObj(transportHeaders);
result.put(ExpressionConstants.HEADERS, headers);
result.put(ExpressionConstants.ATTRIBUTES, CallMediatorEnrichUtil.populateTransportAttributes(synContext));
synContext.setVariable(key, result);
} else {
synLog.error("Action " + action + " is not supported when enriching variables");
}
} else {
synLog.error("Invalid Target type");
throw new SynapseException("Invalid Target type");
}
}

Expand Down Expand Up @@ -468,14 +490,19 @@ public void insertJson(MessageContext synCtx, Object sourceJsonElement, SynapseL
}
case EnrichMediator.VARIABLE:
if (action.equalsIgnoreCase(ACTION_REPLACE)) {
String key = variable.evaluateValue(synCtx);
if (StringUtils.isEmpty(key)) {
synLog.error("Variable key cannot be null");
return;
}
Map<String, Object> result = new HashMap<>();
result.put("payload", sourceJsonElement);
result.put(ExpressionConstants.PAYLOAD, sourceJsonElement);
Map transportHeaders = (Map)((Axis2MessageContext) synCtx).getAxis2MessageContext()
.getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS);
JsonObject headers = EIPUtils.convertMapToJsonObj(transportHeaders);
result.put("headers", headers);
result.put("attributes", CallMediatorEnrichUtil.populateTransportAttributes(synCtx));
synCtx.setVariable(variable.evaluateValue(synCtx), result);
result.put(ExpressionConstants.HEADERS, headers);
result.put(ExpressionConstants.ATTRIBUTES, CallMediatorEnrichUtil.populateTransportAttributes(synCtx));
synCtx.setVariable(key, result);
}
break;
default: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,6 @@ public class ExpressionConstants {

public static final String UNKNOWN = "unknown";
public static final String VAULT_LOOKUP = "wso2:vault-lookup('";
public static final String HEADERS = "headers";
public static final String ATTRIBUTES = "attributes";
}

0 comments on commit 0ac97a0

Please sign in to comment.