Skip to content

Commit

Permalink
Merge pull request #1717 from arunans23/graaljs
Browse files Browse the repository at this point in the history
Preserve backward compatibility and avoid warnings in datamapper
  • Loading branch information
arunans23 committed Jun 17, 2024
2 parents 75de8b2 + 054da7e commit 0efff11
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ public ScriptExecutor(ScriptExecutorType scriptExecutorType) {
}
case GRAALJS:
try {
// Set the system property to disable the warning messages
System.setProperty("polyglot.engine.WarnInterpreterOnly", "false");
scriptEngine = new ScriptEngineManager().getEngineByName(DataMapperEngineConstants.GRAALJS_ENGINE_NAME);
bindings = scriptEngine.createBindings();
log.debug("Setting Graal.js as Script Engine");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
import org.wso2.carbon.mediator.datamapper.engine.output.OutputMessageBuilder;
import org.wso2.carbon.mediator.datamapper.engine.utils.DataMapperEngineUtils;

import java.util.AbstractList;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -121,6 +123,9 @@ private void traverseMap(Map<Object, Object> outputMap) throws SchemaException,
throw new WriterException(e.getMessage(),e);
}
}
if (value instanceof AbstractList) {
value = convertListToMap((AbstractList)value);
}
if (value instanceof Map) {
// key value is a type of object or an array
if (arrayType) {
Expand Down Expand Up @@ -166,6 +171,14 @@ private void traverseMap(Map<Object, Object> outputMap) throws SchemaException,
}
}

private Map convertListToMap(AbstractList polyglotList) {
Map<Object, Object> map = new HashMap<>();
for (int i = 0; i < polyglotList.size(); i++) {
map.put(i, polyglotList.get(i));
}
return map;
}

private void sendPrimitiveEvent(String key, Object value) throws SchemaException, WriterException {
getOutputMessageBuilder().notifyEvent(new ReaderEvent(ReaderEventType.PRIMITIVE, key, value));
}
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2701,7 +2701,7 @@
<!-- OAS3 Versions -->
<swagger.parser.orbit.version>2.1.18.wso2v1</swagger.parser.orbit.version>
<transport.http.netty>6.3.50</transport.http.netty>
<graalvm.version>23.0.4</graalvm.version>
<graalvm.version>22.3.4</graalvm.version>
<icu.version>72.1</icu.version>
<runtime.diagnostics.version>1.1.0</runtime.diagnostics.version>
</properties>
Expand Down

0 comments on commit 0efff11

Please sign in to comment.