我正在尝试使用Java中的Rally REST API创建缺陷。
我插入缺陷的代码如下所示:
JsonObject newDefect = new JsonObject();
newDefect.addProperty("Workspace", workspaceRef);
newDefect.addProperty("Project", projectRef);
newDefect.addProperty("Name", d.name);
newDefect.addProperty("Description", d.description);
newDefect.addProperty("Notes", d.notes);
newDefect.addProperty("Owner", getUserReference(restApi, d.owner));
System.out.println("Creating defect: " + d.qcid + " - " + d.name);
CreateRequest createRequest = new CreateRequest("defect", newDefect);
CreateResponse createResponse = restApi.create(createRequest);
getUserReference实现如下:
private String getUserReference(RallyRestApi restApi, String name) throws Exception
{
// Read User
QueryRequest userRequest = new QueryRequest("User");
userRequest.setFetch(new Fetch("UserName", "Subscription", "DisplayName"));
userRequest.setQueryFilter(new QueryFilter("UserName", "=", name));
QueryResponse userQueryResponse = restApi.query(userRequest);
JsonArray userQueryResults = userQueryResponse.getResults();
JsonElement userQueryElement = userQueryResults.get(0);
JsonObject userQueryObject = userQueryElement.getAsJsonObject();
String userRef = userQueryObject.get("_ref").toString();
return userRef;
}
问题:我在用户上收到错误'无法解析对象引用'。当我使用实际名称(user@domain.com)或上面描述的用户参考时,我得到它。
我得到的当前错误是:无法解析“https://rally1.rallydev.com/slm/webservice/v2.0/user/14659049875”“
中的对象引用我做错了什么?
感谢 阿萨夫
答案 0 :(得分:1)
请使用getAsString方法而不是toString。
尝试:
String userRef = userQueryObject.get("_ref").getAsString();
而不是
String userRef = userQueryObject.get("_ref").toString();
答案 1 :(得分:0)
遇到类似的问题, 设置旧版本的WSAPI帮助我解决了这个问题
restApi = new RallyRestApi(new URI(rallyUrl), rallyUser, rallyPassword);
restApi.setWsapiVersion("1.36");