From 64dc63b818b91277d7714fd0b7877be3d9d91163 Mon Sep 17 00:00:00 2001 From: Nadeeshan96 Date: Fri, 7 Apr 2023 15:41:45 +0530 Subject: [PATCH 1/2] [Automated] Update the native jar versions --- ballerina/Ballerina.toml | 4 ++-- ballerina/Dependencies.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ballerina/Ballerina.toml b/ballerina/Ballerina.toml index 5ab6c6b9c..273a6d81e 100644 --- a/ballerina/Ballerina.toml +++ b/ballerina/Ballerina.toml @@ -19,13 +19,13 @@ path = "../native/build/libs/websocket-native-2.7.0-SNAPSHOT.jar" groupId = "io.ballerina.stdlib" artifactId = "http-native" version = "2.7.0" -path = "./lib/http-native-2.7.0-20230403-150500-d370511.jar" +path = "./lib/http-native-2.7.0-20230404-164000-63f9bb4.jar" [[platform.java11.dependency]] groupId = "io.ballerina.stdlib" artifactId = "mime-native" version = "2.7.0" -path = "./lib/mime-native-2.7.0-20230403-120400-3dbbe01.jar" +path = "./lib/mime-native-2.7.0-20230404-141500-dadad37.jar" [[platform.java11.dependency]] groupId = "io.ballerina.stdlib" diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index b0be4ea93..c98599df8 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -5,7 +5,7 @@ [ballerina] dependencies-toml-version = "2" -distribution-version = "2201.5.0-20230401-003700-e9cbdd41" +distribution-version = "2201.5.0-20230404-105200-b8aec90e" [[package]] org = "ballerina" From 1a39fb8bfdcc1b834f05d53e6091ef16ae847422 Mon Sep 17 00:00:00 2001 From: Nadeeshan96 Date: Fri, 7 Apr 2023 16:31:34 +0530 Subject: [PATCH 2/2] Use convert API instead of cloneWithType --- .../websocket/WebSocketResourceDispatcher.java | 14 +++++++------- .../listener/SyncClientConnectorListener.java | 18 +++++++++++++----- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/native/src/main/java/io/ballerina/stdlib/websocket/WebSocketResourceDispatcher.java b/native/src/main/java/io/ballerina/stdlib/websocket/WebSocketResourceDispatcher.java index 759ae3cfa..cebc5eb73 100644 --- a/native/src/main/java/io/ballerina/stdlib/websocket/WebSocketResourceDispatcher.java +++ b/native/src/main/java/io/ballerina/stdlib/websocket/WebSocketResourceDispatcher.java @@ -36,6 +36,7 @@ import io.ballerina.runtime.api.utils.JsonUtils; import io.ballerina.runtime.api.utils.StringUtils; import io.ballerina.runtime.api.utils.TypeUtils; +import io.ballerina.runtime.api.utils.ValueUtils; import io.ballerina.runtime.api.utils.XmlUtils; import io.ballerina.runtime.api.values.BArray; import io.ballerina.runtime.api.values.BError; @@ -69,7 +70,6 @@ import io.netty.handler.codec.CorruptedFrameException; import io.netty.handler.codec.http.HttpHeaders; import org.ballerinalang.langlib.value.CloneReadOnly; -import org.ballerinalang.langlib.value.CloneWithType; import org.ballerinalang.langlib.value.FromJsonString; import org.ballerinalang.langlib.value.FromJsonStringWithType; import org.slf4j.Logger; @@ -470,13 +470,13 @@ public static void dispatchOnText(WebSocketConnectionInfo connectionInfo, WebSoc bValue = XmlUtils.parse(stringAggregator.getAggregateString()); break; case TypeTags.RECORD_TYPE_TAG: - bValue = CloneWithType.convert(param, JsonUtils.parse( - stringAggregator.getAggregateString())); + bValue = ValueUtils.convert(JsonUtils.parse(stringAggregator.getAggregateString()), + param); break; case TypeTags.UNION_TAG: if (WebSocketUtil.hasStringType(param)) { - bValue = CloneWithType.convert(param, - StringUtils.fromString(stringAggregator.getAggregateString())); + bValue = ValueUtils.convert( + StringUtils.fromString(stringAggregator.getAggregateString()), param); break; } // fall through @@ -702,11 +702,11 @@ private static void createBvaluesForBinary(MethodType onBinaryMessageResource, B bValue = XmlUtils.parse(getBString(byteArray));; break; case TypeTags.RECORD_TYPE_TAG: - bValue = CloneWithType.convert(param, JsonUtils.parse(getBString(byteArray))); + bValue = ValueUtils.convert(JsonUtils.parse(getBString(byteArray)), param); break; case TypeTags.UNION_TAG: if (hasByteArrayType(param)) { - bValue = CloneWithType.convert(param, ValueCreator.createArrayValue(byteArray)); + bValue = ValueUtils.convert(ValueCreator.createArrayValue(byteArray), param); break; } // fall through diff --git a/native/src/main/java/io/ballerina/stdlib/websocket/client/listener/SyncClientConnectorListener.java b/native/src/main/java/io/ballerina/stdlib/websocket/client/listener/SyncClientConnectorListener.java index a46ba8237..07be49251 100644 --- a/native/src/main/java/io/ballerina/stdlib/websocket/client/listener/SyncClientConnectorListener.java +++ b/native/src/main/java/io/ballerina/stdlib/websocket/client/listener/SyncClientConnectorListener.java @@ -24,6 +24,7 @@ import io.ballerina.runtime.api.utils.JsonUtils; import io.ballerina.runtime.api.utils.StringUtils; import io.ballerina.runtime.api.utils.TypeUtils; +import io.ballerina.runtime.api.utils.ValueUtils; import io.ballerina.runtime.api.utils.XmlUtils; import io.ballerina.runtime.api.values.BError; import io.ballerina.runtime.api.values.BObject; @@ -41,7 +42,6 @@ import io.ballerina.stdlib.websocket.WebSocketUtil; import io.ballerina.stdlib.websocket.observability.WebSocketObservabilityUtil; import io.ballerina.stdlib.websocket.server.WebSocketConnectionInfo; -import org.ballerinalang.langlib.value.CloneWithType; import org.ballerinalang.langlib.value.FromJsonStringWithType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -94,12 +94,12 @@ public void onMessage(WebSocketTextMessage webSocketTextMessage) { message = XmlUtils.parse(stringAggregator.getAggregateString()); break; case TypeTags.RECORD_TYPE_TAG: - message = CloneWithType.convert(targetType, JsonUtils.parse( + message = cloneWithType(targetType, JsonUtils.parse( stringAggregator.getAggregateString())); break; case TypeTags.UNION_TAG: if (WebSocketUtil.hasStringType(targetType)) { - message = CloneWithType.convert(targetType, + message = cloneWithType(targetType, StringUtils.fromString(stringAggregator.getAggregateString())); break; } @@ -188,11 +188,11 @@ public void onMessage(WebSocketBinaryMessage webSocketBinaryMessage) { message = XmlUtils.parse(getBString(binMsg));; break; case TypeTags.RECORD_TYPE_TAG: - message = CloneWithType.convert(targetType, JsonUtils.parse(getBString(binMsg))); + message = cloneWithType(targetType, JsonUtils.parse(getBString(binMsg))); break; case TypeTags.UNION_TAG: if (WebSocketUtil.hasByteArrayType(targetType)) { - message = CloneWithType.convert(targetType, ValueCreator.createArrayValue(binMsg)); + message = cloneWithType(targetType, ValueCreator.createArrayValue(binMsg)); break; } // fall through @@ -318,4 +318,12 @@ public void setTargetType(BTypedesc targetType) { public void setFutureCompleted(AtomicBoolean futureCompleted) { this.futureCompleted = futureCompleted; } + + private Object cloneWithType(Type targetType, Object value) { + try { + return ValueUtils.convert(value, targetType); + } catch (BError e) { + return e; + } + } }