欠陥のように感じる例外が発生しています。他の誰かがこれに問題があると思うかどうか疑問に思っています。これは、私が書いている単純化された実行可能なサービスです。
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 変数 'timestamp' に、以下の JSON の抜粋から適切な値が割り当てられます。
"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 サイトで報告されますか?
ありがとう。