如何从Java Team Server检索所有项目区域



我安装了一个本地Java Team Server,版本为3.0.1。我正在尝试使用REST web服务来检索所有项目区域。为此,我首先验证了自己:

public HttpContext login() throws ClientProtocolException, IOException {
        client = new DefaultHttpClient();
        CookieStore cookieStore = new BasicCookieStore();
        HttpContext localContext = new BasicHttpContext();
        localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
        HttpGet httpGetID = new HttpGet("https://localhost:9443/ccm/authenticated/identity");
        client.execute(httpGetID, localContext);
        httpGetID.abort();
        List<Cookie> cookies1 = cookieStore.getCookies();
        for (Cookie cookie : cookies1) {
            System.out.println("t"+cookie.getName()+" : "+cookie.getValue());
        }
        List<NameValuePair> authFormParams = new ArrayList<NameValuePair>();
        authFormParams.add(new BasicNameValuePair("j_username", "ADMIN"));
        authFormParams.add(new BasicNameValuePair("j_password", "ADMIN"));
        UrlEncodedFormEntity entity = new UrlEncodedFormEntity(authFormParams, "UTF-8");
        HttpPost httpPostAuth = new HttpPost("https://localhost:9443/ccm/authenticated/j_security_check");
        httpPostAuth.addHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
        httpPostAuth.setEntity(entity);
        client.execute(httpPostAuth, localContext);
        //httpPostAuth.abort();
        List<Cookie> cookies2 = cookieStore.getCookies();
        for (Cookie cookie : cookies2) {
            System.out.println("t"+cookie.getName()+" : "+cookie.getValue());
        }
        return localContext;
    }

然后我尝试使用以下代码获取项目区域:

HttpGet getProjectsRequest = new HttpGet("https://localhost:9443/ccm/oslc-scm/catalog");
        getProjectsRequest.addHeader("Content-Type", "application/xml;charset=UTF-8");
        getProjectsRequest.addHeader("Accept-Charset", "UTF-8");
        getProjectsRequest.addHeader("Accept", "application/x-oslc-cm-change-request+xml");
        ResponseHandler<String> handler = new BasicResponseHandler();
        String projectResponse = client.execute(getProjectsRequest, handler, localContext);
        System.out.println(projectResponse);

不幸的是,答案总是一样的:

{
    "userId": "ADMIN",
    "roles": [
        "JazzUsers",
        "JazzProjectAdmins",
        "JazzAdmins"]
}

这看起来像一个JSON对象。相反,我应该得到一个XML文档,其中列出了所有项目。我已经用Firefox的REST插件尝试了相同的REST服务。这样我就得到了预期的XML文档。然而,我看不出我的代码和我在插件中做的事情之间有任何区别。

你可以在这里找到答案。

这是我的理解:基本上,你需要访问另一个页面来接收一个cookie,然后运行你的查询。只要运行两次相同的execute,你就明白我的意思了。

您可以使用DraftTeamProcessRestAPIs获取特定用户的所有项目区域

,特别是参见本节

这个API响应XML

还有ReportableRestAPIs,它可以在代码中使用这个URL实现你想要的:

 https://<server>:<port>/ccm/rpt/repository/foundation?fields=foundation/projectArea/(name|teamMembers/userId)

相关内容

  • 没有找到相关文章

最新更新