Reputation:
I installed a local Java Team Server, version 3.0.1. I'm trying to use the REST web services to retrieve all the project areas. For that I first authenticated myself:
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;
}
Then I try to get the project areas with the following code:
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);
Unfortunately, the answer is always the same:
{
"userId": "ADMIN",
"roles": [
"JazzUsers",
"JazzProjectAdmins",
"JazzAdmins"]
}
This looks for me like a JSON object. Instead I should get a XML document, that lists all projects. I already tried the same REST service with a REST plugin for Firefox. There I get the XML document as expected. However, I can't see any differences between my code and the things I do in the plugin.
Upvotes: 1
Views: 1993
Reputation: 1809
You can get All Project Areas of a particular user using DraftTeamProcessRestAPIs
and in particular see this section
This API responses in XML
and also there are ReportableRestAPIs which can fulfill what you want using this URL in the code:
https://<server>:<port>/ccm/rpt/repository/foundation?fields=foundation/projectArea/(name|teamMembers/userId)
Upvotes: 0