From 252b852068dc1fc1915ff67f87eb30377c1dfef7 Mon Sep 17 00:00:00 2001 From: Thuvarakan Sritharan Date: Tue, 8 Apr 2025 19:31:53 +0530 Subject: [PATCH 1/4] Wrap value with special characters in cdata for connector --- .../mediatorService/MediatorHandler.java | 17 ++++++++++++++++- .../customservice/synapse/utils/Constant.java | 1 + .../synapse/utils/UISchemaMapper.java | 15 ++++++++++++++- .../mediators/430/templates/connector.mustache | 2 +- .../mediators/440/templates/connector.mustache | 2 +- 5 files changed, 33 insertions(+), 4 deletions(-) diff --git a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/customservice/synapse/mediatorService/MediatorHandler.java b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/customservice/synapse/mediatorService/MediatorHandler.java index ffde9965d..7b23c1bda 100644 --- a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/customservice/synapse/mediatorService/MediatorHandler.java +++ b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/customservice/synapse/mediatorService/MediatorHandler.java @@ -196,6 +196,7 @@ private SynapseConfigResponse generateConnectorSynapseConfig(STNode node, String protected Map processConnectorParameter(Object data) { Map dataValue = new HashMap<>(); + boolean isExpressionField = false; if (data instanceof String) { dataValue.put(Constant.VALUE, String.format("%s", data)); } else if (data instanceof Boolean) { @@ -205,7 +206,9 @@ protected Map processConnectorParameter(Object data) { Object isExpressionObj = dataValue.get(Constant.IS_EXPRESSION); boolean isExpression = isExpressionObj == null ? false : (boolean) isExpressionObj; if (isExpression) { + isExpressionField = true; dataValue.put(Constant.VALUE, String.format("{%s}", dataValue.get(Constant.VALUE))); + dataValue.put(Constant.IS_EXPRESSION, true); } else { if (dataValue.get(Constant.VALUE).toString().startsWith("{") && dataValue.get(Constant.VALUE).toString().endsWith("}")) { @@ -232,16 +235,28 @@ protected Map processConnectorParameter(Object data) { dataValue.put(Constant.VALUE, String.format("%s", dataValueStr)); } if (dataValue.get(Constant.VALUE) != null && dataValue.get(Constant.VALUE).toString().startsWith("")) { value = value.substring(0, value.length() - 3); // Remove ]]> } dataValue.put(Constant.VALUE, value); } + if (!isExpressionField && hasSpecialXmlCharacter(dataValue.get(Constant.VALUE))) { + dataValue.put(Constant.IS_CDATA, true); + } return dataValue; } + private boolean hasSpecialXmlCharacter(Object o) { + + if (!(o instanceof String)) { + return false; + } + String value = (String) o; + return value.contains("&") || value.contains("<") || value.contains(">") || value.contains("\""); + } + protected ConnectorAction getConnectorOperation(STNode node, String mediator) { String connectorName; diff --git a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/customservice/synapse/utils/Constant.java b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/customservice/synapse/utils/Constant.java index bc7e19cab..5cc803e6a 100644 --- a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/customservice/synapse/utils/Constant.java +++ b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/customservice/synapse/utils/Constant.java @@ -604,6 +604,7 @@ public class Constant { public static final String REQUESTS = "requests"; public static final String DEFAULT_REQUEST = "defaultRequest"; public static final String CONTENT = "content"; + public static final String IS_CDATA = "isCDATA"; static { // AI Connection to Display Name bi-Mapping diff --git a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/customservice/synapse/utils/UISchemaMapper.java b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/customservice/synapse/utils/UISchemaMapper.java index b5d741fed..89cc15697 100644 --- a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/customservice/synapse/utils/UISchemaMapper.java +++ b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/customservice/synapse/utils/UISchemaMapper.java @@ -23,6 +23,7 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonPrimitive; +import org.apache.commons.lang3.StringUtils; import org.eclipse.lemminx.customservice.synapse.connectors.entity.Connection; import org.eclipse.lemminx.customservice.synapse.mediatorService.MediatorUtils; import org.eclipse.lemminx.customservice.synapse.mediatorService.pojo.Namespace; @@ -85,6 +86,9 @@ private static void processElement(JsonObject elementData, JsonObject elementObj currentValue.getAsString().substring(1, currentValue.getAsString().length() - 1)); } else if (isCheckBox(value)) { currentValue = new JsonPrimitive(currentValue.getAsBoolean()); + } else if (currentValue.isJsonPrimitive()) { + String sanitizedValue = removeCDATATag(currentValue.getAsString()); + currentValue = new JsonPrimitive(sanitizedValue); } value.add("currentValue", currentValue); } @@ -100,8 +104,9 @@ private static boolean isCheckBox(JsonObject value) { return false; } - private static JsonArray generateTableDataForConnector(String tableFieldValue) { + private static JsonArray generateTableDataForConnector(String tableFieldCDATA) { + String tableFieldValue = removeCDATATag(tableFieldCDATA); JsonArray result = new JsonArray(); JSONArray tableValues = new JSONArray(tableFieldValue); for (int i = 0; i < tableValues.length(); i++) { @@ -126,6 +131,14 @@ private static JsonArray generateTableDataForConnector(String tableFieldValue) { return result; } + private static String removeCDATATag(String value) { + + if (StringUtils.isEmpty(value)) { + return StringUtils.EMPTY; + } + return value.replaceAll("", ""); + } + public static JsonObject mapInputToUISchemaForConnector(Connector connector, JsonObject uiSchema) { JsonObject data = new JsonObject(); diff --git a/org.eclipse.lemminx/src/main/resources/org/eclipse/lemminx/mediators/430/templates/connector.mustache b/org.eclipse.lemminx/src/main/resources/org/eclipse/lemminx/mediators/430/templates/connector.mustache index 8be311e2d..5afa03a56 100644 --- a/org.eclipse.lemminx/src/main/resources/org/eclipse/lemminx/mediators/430/templates/connector.mustache +++ b/org.eclipse.lemminx/src/main/resources/org/eclipse/lemminx/mediators/430/templates/connector.mustache @@ -1,5 +1,5 @@ <{{tag}} {{#configKey}}configKey="{{{configKey}}}"{{/configKey}}> {{#parameters}} - <{{{name}}} {{#value}}{{#namespaces}} xmlns:{{{prefix}}}="{{{uri}}}"{{/namespaces}}>{{#isCDATA}}{{/isCDATA}}{{^isCDATA}}{{value}}{{/isCDATA}}{{/value}} + <{{{name}}} {{#value}}{{#namespaces}} xmlns:{{{prefix}}}="{{{uri}}}"{{/namespaces}}>{{#isCDATA}}{{/isCDATA}}{{^isCDATA}}{{#isExpression}}{{value}}{{/isExpression}}{{^isExpression}}{{{value}}}{{/isExpression}}{{/isCDATA}}{{/value}} {{/parameters}} diff --git a/org.eclipse.lemminx/src/main/resources/org/eclipse/lemminx/mediators/440/templates/connector.mustache b/org.eclipse.lemminx/src/main/resources/org/eclipse/lemminx/mediators/440/templates/connector.mustache index 8be311e2d..5afa03a56 100644 --- a/org.eclipse.lemminx/src/main/resources/org/eclipse/lemminx/mediators/440/templates/connector.mustache +++ b/org.eclipse.lemminx/src/main/resources/org/eclipse/lemminx/mediators/440/templates/connector.mustache @@ -1,5 +1,5 @@ <{{tag}} {{#configKey}}configKey="{{{configKey}}}"{{/configKey}}> {{#parameters}} - <{{{name}}} {{#value}}{{#namespaces}} xmlns:{{{prefix}}}="{{{uri}}}"{{/namespaces}}>{{#isCDATA}}{{/isCDATA}}{{^isCDATA}}{{value}}{{/isCDATA}}{{/value}} + <{{{name}}} {{#value}}{{#namespaces}} xmlns:{{{prefix}}}="{{{uri}}}"{{/namespaces}}>{{#isCDATA}}{{/isCDATA}}{{^isCDATA}}{{#isExpression}}{{value}}{{/isExpression}}{{^isExpression}}{{{value}}}{{/isExpression}}{{/isCDATA}}{{/value}} {{/parameters}} From 2c4c01ebb21d9079817c9501fe69a5956b4093dc Mon Sep 17 00:00:00 2001 From: Thuvarakan Sritharan Date: Wed, 9 Apr 2025 09:55:41 +0530 Subject: [PATCH 2/4] Fix connector syntax tree for cdata values --- .../factory/mediators/ConnectorFactory.java | 3 +-- .../synapse/utils/UISchemaMapper.java | 12 ++---------- .../customservice/synapse/utils/Utils.java | 18 ++++++++++++++++++ 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/customservice/synapse/syntaxTree/factory/mediators/ConnectorFactory.java b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/customservice/synapse/syntaxTree/factory/mediators/ConnectorFactory.java index a01ed4108..0d8d6a642 100644 --- a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/customservice/synapse/syntaxTree/factory/mediators/ConnectorFactory.java +++ b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/customservice/synapse/syntaxTree/factory/mediators/ConnectorFactory.java @@ -75,9 +75,8 @@ private void addConnectorParameters(Connector connector, DOMElement element) { if (isExpression) { parameter.setExpression(inline); } else { - parameter.setValue(inline); + parameter.setValue(Utils.removeCDATATag(inline)); } - parameter.setValue(Utils.getInlineString(childElement.getFirstChild())); parameters.add(parameter); } } diff --git a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/customservice/synapse/utils/UISchemaMapper.java b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/customservice/synapse/utils/UISchemaMapper.java index 89cc15697..ef2034222 100644 --- a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/customservice/synapse/utils/UISchemaMapper.java +++ b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/customservice/synapse/utils/UISchemaMapper.java @@ -87,7 +87,7 @@ private static void processElement(JsonObject elementData, JsonObject elementObj } else if (isCheckBox(value)) { currentValue = new JsonPrimitive(currentValue.getAsBoolean()); } else if (currentValue.isJsonPrimitive()) { - String sanitizedValue = removeCDATATag(currentValue.getAsString()); + String sanitizedValue = Utils.removeCDATATag(currentValue.getAsString()); currentValue = new JsonPrimitive(sanitizedValue); } value.add("currentValue", currentValue); @@ -106,7 +106,7 @@ private static boolean isCheckBox(JsonObject value) { private static JsonArray generateTableDataForConnector(String tableFieldCDATA) { - String tableFieldValue = removeCDATATag(tableFieldCDATA); + String tableFieldValue = Utils.removeCDATATag(tableFieldCDATA); JsonArray result = new JsonArray(); JSONArray tableValues = new JSONArray(tableFieldValue); for (int i = 0; i < tableValues.length(); i++) { @@ -131,14 +131,6 @@ private static JsonArray generateTableDataForConnector(String tableFieldCDATA) { return result; } - private static String removeCDATATag(String value) { - - if (StringUtils.isEmpty(value)) { - return StringUtils.EMPTY; - } - return value.replaceAll("", ""); - } - public static JsonObject mapInputToUISchemaForConnector(Connector connector, JsonObject uiSchema) { JsonObject data = new JsonObject(); diff --git a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/customservice/synapse/utils/Utils.java b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/customservice/synapse/utils/Utils.java index 04236e2c9..b6b4ca181 100644 --- a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/customservice/synapse/utils/Utils.java +++ b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/customservice/synapse/utils/Utils.java @@ -1391,4 +1391,22 @@ public static boolean isValidProject(String projectRoot) { } return true; } + + /** + * Remove CDATA tags from the given xml string. + *

+ * * Example: + * ]]> will be converted to + *

+ * + * @param value the xml string + * @return the xml string without CDATA tags + */ + public static String removeCDATATag(String value) { + + if (StringUtils.isEmpty(value)) { + return StringUtils.EMPTY; + } + return value.replaceAll("", ""); + } } From ef34fde6be37218537bb9adad89aa0d56f17facf Mon Sep 17 00:00:00 2001 From: Thuvarakan Sritharan Date: Thu, 10 Apr 2025 09:35:23 +0530 Subject: [PATCH 3/4] Fix review comment --- .../customservice/synapse/mediatorService/MediatorHandler.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/customservice/synapse/mediatorService/MediatorHandler.java b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/customservice/synapse/mediatorService/MediatorHandler.java index 7b23c1bda..23d06e399 100644 --- a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/customservice/synapse/mediatorService/MediatorHandler.java +++ b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/customservice/synapse/mediatorService/MediatorHandler.java @@ -254,7 +254,8 @@ private boolean hasSpecialXmlCharacter(Object o) { return false; } String value = (String) o; - return value.contains("&") || value.contains("<") || value.contains(">") || value.contains("\""); + return value.contains("&") || value.contains("<") || value.contains(">") || value.contains("\"") || + value.contains("'"); } protected ConnectorAction getConnectorOperation(STNode node, String mediator) { From 1ad193af246b67babb8d0b1b628902b4f2853f4e Mon Sep 17 00:00:00 2001 From: Thuvarakan Sritharan Date: Wed, 16 Apr 2025 10:40:32 +0530 Subject: [PATCH 4/4] Fix special character check for connector parameter values --- .../customservice/synapse/mediatorService/MediatorHandler.java | 3 +-- .../org/eclipse/lemminx/customservice/synapse/utils/Utils.java | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/customservice/synapse/mediatorService/MediatorHandler.java b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/customservice/synapse/mediatorService/MediatorHandler.java index 23d06e399..55a81ae2b 100644 --- a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/customservice/synapse/mediatorService/MediatorHandler.java +++ b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/customservice/synapse/mediatorService/MediatorHandler.java @@ -254,8 +254,7 @@ private boolean hasSpecialXmlCharacter(Object o) { return false; } String value = (String) o; - return value.contains("&") || value.contains("<") || value.contains(">") || value.contains("\"") || - value.contains("'"); + return value.contains("&") || value.contains("<") || value.contains(">"); } protected ConnectorAction getConnectorOperation(STNode node, String mediator) { diff --git a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/customservice/synapse/utils/Utils.java b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/customservice/synapse/utils/Utils.java index b6b4ca181..e52a256f2 100644 --- a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/customservice/synapse/utils/Utils.java +++ b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/customservice/synapse/utils/Utils.java @@ -1396,7 +1396,7 @@ public static boolean isValidProject(String projectRoot) { * Remove CDATA tags from the given xml string. *

* * Example: - * ]]> will be converted to + * {@code ]]>} will be converted to {@code } *

* * @param value the xml string