ballerina-platform / ballerina-lang

The Ballerina Programming Language
https://ballerina.io/
Apache License 2.0
3.58k stars 737 forks source link

JSON messages receiving through JMS objects having escape character causes JSON path to be broken #8973

Closed dushansachinda closed 5 years ago

dushansachinda commented 6 years ago

Regarding $subject, this is a showstopper none of the json path functionalities working when jms retrieved via jms object as part of JMS consumer service. You may try to retrive 'jms:Message message' and covert that to JSON object and peform json path operations, it will return you null

Sample [1]

service<jms:Consumer> orderDeliverySystem bind jmsConsumer {
    // Triggered whenever an order is added to the 'OrderQueue'
    onMessage(endpoint consumer, jms:Message message) {
        log:printInfo("New order received from the JMS Queue");
        http:Request orderToDeliver;
        // Retrieve the string payload using native function
        string stringPayload = check message.getTextMessageContent();
        log:printInfo("Order Details: " + stringPayload);
        json jsonOrder = <json>stringPayload;
        orderToDeliver.setJsonPayload(jsonOrder);
        http:Response courierRes= check courierEP -> post("/delivery", request = orderToDeliver);
        //upon backend service response or backend service unavailability we need to ack
        //back to the broker.
        json courerResponseJSON = check courierRes.getJsonPayload();
        log:printInfo("courier service response ||| " +courerResponseJSON.toString());
        log:printInfo("courier service response status code ||| " +courierRes.statusCode);       
} 

There is a workaround suggested as given below, but following is not a viable option thus required immediate fix

function getJson(string content, string encoding) returns json {
   io:StringReader reader = new io:StringReader(content, encoding = encoding);
   json result = check reader.readJson();
   var closeResult = reader.close();
   return result;
}

[1] https://ballerina.io/learn/by-guide/messaging-with-jms-queues/

riyafa commented 6 years ago

@dushansachinda why do you say that the provided solution is not viable?

daneshk commented 5 years ago

I am closing this issue. Since we moved JMS module to https://github.com/wso2-ballerina/module-jms repository. Please refer wso2-ballerina/module-jms#21 to get latest updates of this issue