如何从Rally java rest API获取连接ID / AuthToken

时间:2013-04-29 08:43:41

标签: java rest rally

要查找连接,我们是否在响应中有cookie或某些连接ID,身份验证令牌

1 个答案:

答案 0 :(得分:0)

在最新的Java REST API for Rally中,RallyRestApi类通过受保护的attachSecurityInfo()方法获取Rally SecurityToken。您可以从第377行开始查看上面链接中的源代码,以了解attachSecurityInfo如何请求令牌,但其中的症结如下所示:

protected static final String SECURITY_TOKEN_PARAM_KEY = "key";
private static final String SECURITY_TOKEN_URL = "/security/authorize";
protected static final String SECURITY_TOKEN_KEY = "SecurityToken";

GetResponse getResponse = getWithForceReauth(new GetRequest(SECURITY_TOKEN_URL));
JsonObject operationResult = getResponse.getObject();
JsonPrimitive securityTokenPrimitive = operationResult.getAsJsonPrimitive(SECURITY_TOKEN_KEY);
securityToken = securityTokenPrimitive.getAsString();

public GetResponse getWithForceReauth(GetRequest request) throws IOException {
    return get(request, true);
}

请注意,这仅适用于Java REST包1.07或更高版本,并且需要(并且需要)Rally Webservices API 1.42或更高版本。