{"action":"opened","issue":{"url":"https://api.github.com/repos/ballerina-platform/ballerina-lang/issues/10531","repository_url":"https://api.github.com/repos/ballerina-platform/ballerina-lang","labels_url":"https://api.github.com/repos/ballerina-platform/ballerina-lang/issues/10531/labels{/name}","comments_url":"https://api.github.com/repos/ballerina-platform/ballerina-lang/issues/10531/comments","events_url":"https://api.github.com/repos/ballerina-platform/ballerina-lang/issues/10531/events","html_url":"https://github.com/ballerina-platform/ballerina-lang/issues/10531","id":363398622,"node_id":"MDU6SXNzdWUzNjMzOTg2MjI=","number":10531,"title":"\"Call Failed\" when the datable converted to JSON is set as the payload","user":{"login":"JayathmaChathurangani","id":31263300,"node_id":"MDQ6VXNlcjMxMjYzMzAw","avatar_url":"https://avatars1.githubusercontent.com/u/31263300?v=4","gravatar_id":"","url":"https://api.github.com/users/JayathmaChathurangani","html_url":"https://github.com/JayathmaChathurangani","followers_url":"https://api.github.com/users/JayathmaChathurangani/followers","following_url":"https://api.github.com/users/JayathmaChathurangani/following{/other_user}","gists_url":"https://api.github.com/users/JayathmaChathurangani/gists{/gist_id}","starred_url":"https://api.github.com/users/JayathmaChathurangani/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JayathmaChathurangani/subscriptions","organizations_url":"https://api.github.com/users/JayathmaChathurangani/orgs","repos_url":"https://api.github.com/users/JayathmaChathurangani/repos","events_url":"https://api.github.com/users/JayathmaChathurangani/events{/privacy}","received_events_url":"https://api.github.com/users/JayathmaChathurangani/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-09-25T03:42:26Z","updated_at":"2018-09-25T03:42:26Z","closed_at":null,"author_association":"NONE","body":"I am writing a simple ballerina program using the version 0.981.1 to retrieve some values from a mysql database. \r\n\r\n**Code:**\r\n```\r\nimport ballerina/http;\r\nimport ballerina/mysql;\r\nimport ballerina/log;\r\nimport ballerina/io;\r\n\r\n// Mysql as the database\r\nendpoint mysql:Client testDB {\r\n    host: \"localhost\",\r\n    port: 3306,\r\n    name: \"type1SportsNewsDb\",\r\n    username: \"root\",\r\n    password: \"user\",\r\n    poolOptions: { maximumPoolSize: 50 },\r\n    dbOptions: { useSSL: false }\r\n};\r\n\r\nservice<http:Service> serviceSports bind { port: 8082 } {\r\n\r\n    getAll(endpoint caller, http:Request req) {\r\n        http:Response res = new;\r\n\r\n        try {\r\n            var selectRet = testDB->select(\"SELECT * FROM type1SportsNewsDb.news;\", ());\r\n\r\n            //json returnValue;\r\n            match selectRet {\r\n                table tableReturned => {\r\n                    //convert to json\r\n                    var jsonConversionRet = <json>tableReturned;\r\n                    match jsonConversionRet {\r\n                        json jsonRes => {\r\n                            res.setPayload(untaint jsonRes);\r\n                            tableReturned.close();\r\n                        }\r\n                        error e => {\r\n                            tableReturned.close();\r\n                            res.statusCode = 500;\r\n                            res.setPayload({\"Error\": \"Internal Error\"});\r\n                        }\r\n                    }\r\n                }\r\n                error e => {\r\n                    //log:printError(e.message);\r\n                    res.statusCode = 500;\r\n                    res.setPayload({\"Error\": \"Internal Error\"});\r\n                }\r\n            }\r\n        } catch (error err) {\r\n            res.statusCode = 500;\r\n            res.setPayload({\"Error\": \"Internal Error\"});\r\n        }\r\n\r\n        _ = caller -> respond(res);\r\n    }\r\n\r\n    @http:ResourceConfig {\r\n        methods: [\"GET\"],\r\n        path:\"test\"\r\n    }\r\n    testService(endpoint caller, http:Request req) {\r\n        http:Response res = new;\r\n        res.setPayload(\"hello, this service provide sports news\");\r\n        _ = caller -> respond(res);\r\n    }\r\n}\r\n\r\n```\r\n**curl command:**\r\n\r\ncurl -i -X GET http://localhost:8082/serviceSports/getAll\r\n\r\n**Response received:** \r\n\r\nHTTP/1.1 500 Internal Server Error\r\ncontent-type: text/plain\r\ncontent-length: 11\r\nserver: ballerina/0.981.1\r\ndate: Tue, 25 Sep 2018 09:00:19 +0530\r\n\r\ncall failed\r\n\r\n**Error in console:**\r\n\r\nballerina: initiating service(s) in 'serviceB'\r\nballerina: started HTTP/WS endpoint 0.0.0.0:8082\r\nerror: ballerina/runtime:CallFailedException, message: call failed\r\n\tat serviceB:0.0.0:serviceSports.getAll(service-b.bal:57)\r\ncaused by error, message: trying to perform hasNext operation over a closed table\r\n\tat ballerina/http:respond(http_connection.bal:49)\r\n\r\n\r\nworker errors: {default={message:\"Trying to perform hasNext operation over a closed table\", cause:null}}\r\n{message:null, cause:null}\r\n\r\nI am using the following remedies to fix it. Actually it is required to convert the JSON to string. \r\nlog:printDebug(jsonRes.toString()); or\r\nio:println(jsonRes.toString()); or\r\nstring ans = jsonRes.toString();\r\n\r\nThen everything run smoothly. \r\nActually this was there in version 0.95 as well."}}
{"actor":{"display_login":"JayathmaChathurangani"}}