Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ballerina/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down
15 changes: 15 additions & 0 deletions ballerina/tests/test_data_binding_json.bal
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -33,6 +36,10 @@ service class WsService22101 {
remote function onMessage(string message) returns json {
return jsonMessageWithEscapedQuotes;
}

remote function onSubscribe(string message) returns stream<json> {
return [jsonMessageWithEscapedQuotes].toStream();
}
}

@test:Config {}
Expand All @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 {
Expand All @@ -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<String, Object> properties = ModuleUtils.getProperties(STREAMING_NEXT_FUNCTION);
StrandMetadata strandMetadata = new StrandMetadata(true, properties);
Expand Down
Loading