From bf60f3210e41bc66708182e2a1ea5ccc14935e45 Mon Sep 17 00:00:00 2001 From: ayash Date: Thu, 24 Apr 2025 17:09:31 +0530 Subject: [PATCH 1/3] [Automated] Update the native jar versions --- ballerina/Dependencies.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index 729ac223f..c7eb28985 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -76,7 +76,7 @@ dependencies = [ [[package]] org = "ballerina" name = "http" -version = "2.14.0" +version = "2.14.1" dependencies = [ {org = "ballerina", name = "auth"}, {org = "ballerina", name = "cache"}, From 3a8d19e6d779adb2829dc04bfa2923c34f00fe9d Mon Sep 17 00:00:00 2001 From: ayash Date: Thu, 24 Apr 2025 18:04:39 +0530 Subject: [PATCH 2/3] Convert ballerina object to jsonString instead of string in ReturnStreamUnitCallBack --- .../stdlib/websocket/ReturnStreamUnitCallBack.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/native/src/main/java/io/ballerina/stdlib/websocket/ReturnStreamUnitCallBack.java b/native/src/main/java/io/ballerina/stdlib/websocket/ReturnStreamUnitCallBack.java index 236c06bbf..933afc229 100644 --- a/native/src/main/java/io/ballerina/stdlib/websocket/ReturnStreamUnitCallBack.java +++ b/native/src/main/java/io/ballerina/stdlib/websocket/ReturnStreamUnitCallBack.java @@ -44,6 +44,7 @@ import static io.ballerina.stdlib.websocket.WebSocketResourceDispatcher.dispatchOnError; import static io.ballerina.stdlib.websocket.actions.websocketconnector.WebSocketConnector.fromText; import static io.ballerina.stdlib.websocket.actions.websocketconnector.WebSocketConnector.release; +import static org.ballerinalang.langlib.value.ToJsonString.toJsonString; /** * Call back class registered for returning streams. @@ -67,9 +68,8 @@ public class ReturnStreamUnitCallBack implements Handler { public void notifySuccess(Object response) { if (response != null) { PromiseCombiner promiseCombiner = new PromiseCombiner(ImmediateEventExecutor.INSTANCE); - String content; if (response instanceof BError) { - content = ((BError) response).getMessage(); + String content = ((BError) response).getMessage(); webSocketConnection.terminateConnection(1011, String.format("streaming failed: %s", content)); } else { @@ -78,8 +78,11 @@ public void notifySuccess(Object response) { sendCloseFrame(contentObj, connectionInfo); return; } - content = contentObj.toString(); - sendTextMessageStream(StringUtils.fromString(content), promiseCombiner); + if (contentObj instanceof BString bString) { + sendTextMessageStream(bString, promiseCombiner); + } else { + sendTextMessageStream(toJsonString(contentObj), promiseCombiner); + } Thread.startVirtualThread(() -> { Map properties = ModuleUtils.getProperties(STREAMING_NEXT_FUNCTION); StrandMetadata strandMetadata = new StrandMetadata(true, properties); From 6ffc5061a6fc1ab00d751768961d03f4f14cd19f Mon Sep 17 00:00:00 2001 From: ayash Date: Thu, 24 Apr 2025 18:05:08 +0530 Subject: [PATCH 3/3] Add testEscapedDoubleQuoteInJsonStream test case --- ballerina/tests/test_data_binding_json.bal | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/ballerina/tests/test_data_binding_json.bal b/ballerina/tests/test_data_binding_json.bal index a6a5558f7..d0d49ee4b 100644 --- a/ballerina/tests/test_data_binding_json.bal +++ b/ballerina/tests/test_data_binding_json.bal @@ -20,6 +20,9 @@ final readonly & json jsonMessageWithEscapedQuotes = { "message": "Cannot query field \"invalidField\" on type \"Subscription\"." }; +@ServiceConfig { + dispatcherKey: "event" +} service / on new Listener(22101) { resource function get .() returns Service|UpgradeError { @@ -33,6 +36,10 @@ service class WsService22101 { remote function onMessage(string message) returns json { return jsonMessageWithEscapedQuotes; } + + remote function onSubscribe(string message) returns stream { + return [jsonMessageWithEscapedQuotes].toStream(); + } } @test:Config {} @@ -42,3 +49,11 @@ public function testEscapedDoubleQuoteInJson() returns error? { json response = check wsClient->readMessage(); test:assertEquals(response, jsonMessageWithEscapedQuotes); } + +@test:Config {} +public function testEscapedDoubleQuoteInJsonStream() returns error? { + Client wsClient = check new ("ws://localhost:22101"); + check wsClient->writeMessage({event: "subscribe", data: "test"}); + json response = check wsClient->readMessage(); + test:assertEquals(response, jsonMessageWithEscapedQuotes); +}