ballerina-platform / ballerina-library

The Ballerina Library
https://ballerina.io/learn/api-docs/ballerina/
Apache License 2.0
136 stars 64 forks source link

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

Open daneshk opened 5 years ago

daneshk commented 5 years ago

Issue by dushansachinda Monday Jun 11, 2018 at 02:56 GMT Originally opened as https://github.com/ballerina-platform/ballerina-lang/issues/8973


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/

daneshk commented 5 years ago

Comment by riyafa Monday Jul 02, 2018 at 08:55 GMT


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