我遇到了一个异常,感觉它可能是一个缺陷。我想知道是否有其他人认为这有问题。这是我正在编写的简化但可运行的服务。
import ballerina.net.http;
import ballerina.lang.messages;
import ballerina.lang.jsons;
import ballerina.lang.system;
@http:BasePath("/weather")
service WeatherService {
@http:GET
@http:Path("/current")
resource current(message m) {
string url = "http://api.mesowest.net/v2/stations/nearesttime?stid=KBFI&within=60&vars=air_temp,wind_speed,wind_direction&obtimezone=local&token=demotoken";
http:ClientConnector weatherConnector = create http:ClientConnector(url);
message request = {};
message jsonResponse = http:ClientConnector.get(weatherConnector, "", request);
json jsonDocument = messages:getJsonPayload(jsonResponse);
json timestamp;
string timeString;
try {
timestamp = jsons:getJson(jsonDocument, "$..PERIOD_OF_RECORD.end");
}
catch (exception e) {
system:println("Error getting timestamp");
}
messages:setJsonPayload(m, timestamp);
reply m;
}
}
当我在调试器中运行它时,从下面的 JSON 摘录中为 json 变量“timestamp”分配了适当的值:
"STATION": [
{
"STATUS": "ACTIVE",
"MNET_ID": "1",
"PERIOD_OF_RECORD": {
"start": "1969-12-31T16:00:00-0800",
"end": "2017-02-27T19:40:00-0800"
}
当我更换线路时:
timestamp = jsons:getJson(jsonDocument, "$..PERIOD_OF_RECORD.end");
用线
timeString = jsons:getString(jsonDocument, "$..PERIOD_OF_RECORD.end");
并停止并重新启动服务并对其进行测试,它会在 getString 方法上引发异常。我还没有找到一种方法来打印异常或获取异常的属性以找出它失败的原因。控制台输出如下。
Running weather2.bal service.
ballerina: deploying service(s) in '/Users/clarkm2/Projects/Ballerina/Weather/weather2.bal'
ballerina: started server connector http-9090
Error getting timestamp
对此有想法吗?如果这是一个缺陷,这些是否会在 wso2.com JIRA 站点上报告?
谢谢。