1

我安装了本地 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 文档。但是,我看不出我的代码和我在插件中所做的事情之间有任何区别。

4

2 回答 2

0

你可以在这里找到答案。

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

于 2012-04-15T07:19:46.843 回答
0

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

特别是请参阅本

此 API 以 XML 格式响应

还有ReportableRestAPIs可以在代码中使用此 URL 来满足您的需求:

 https://<server>:<port>/ccm/rpt/repository/foundation?fields=foundation/projectArea/(name|teamMembers/userId)
于 2016-08-26T05:47:23.373 回答