It's all about the answers!

Ask a question

RTC REST API to create a project area


0
1
Sefa Sevtekin (2345) | asked Jul 22 '14, 2:58 p.m.
edited Jul 22 '14, 6:32 p.m. by Jared Burns (4.5k29)
Hi,

I am trying to create a RTC Project Area using the REST API. I am following the documentation on https://jazz.net/wiki/bin/view/Main/DraftTeamProcessRestApi#POST_project_areas_collection. I get a 403 response when I post the request. I am using the RTC admin user the create the project. I believe the issue is with the owningApplicationKey parameter (please see the java code)

Thanks,
Sefa

public static void createRTCProjectArea(String server, String login,
String password, String projectAreaName) {
String rootServices = server + "/rootservices";
String catalogXPath = "/rdf:Description/oslc_cm:cmServiceProviders/@rdf:resource";
String serviceProviderTitleXPath = "//oslc:ServiceProvider/dcterms:title";

System.out.println(" - Root Services URI: " + rootServices);
System.out.println(" - Service Providers catalog XPath expression: "
+ catalogXPath);
System.out.println(" - Service Provider title XPath expression: "
+ serviceProviderTitleXPath);
System.out.println(" - Login: " + login);
System.out.println(" - Password: ******");

// Setup the HttClient
HttpClient httpclient = new DefaultHttpClient();
HttpUtils.setupLazySSLSupport(httpclient);

// Setup the rootServices request
HttpGet rootServiceDoc = new HttpGet(rootServices);
rootServiceDoc.addHeader("Accept", "application/rdf+xml");
rootServiceDoc.addHeader("OSLC-Core-Version", "2.0");

try {
// Request the Root Services document
HttpResponse rootServicesResponse = HttpUtils
.sendGetForSecureDocument(server, rootServiceDoc, login,
password, httpclient);

if (rootServicesResponse.getStatusLine().getStatusCode() == 200) {
// Define the XPath evaluation environment
XPathFactory factory = XPathFactory.newInstance();
XPath xpath = factory.newXPath();
xpath.setNamespaceContext(new NamespaceContextMap(new String[] {
"rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
"oslc_cm", "http://open-services.net/xmlns/cm/1.0/" }));

// Parse the response body to retrieve the catalog URI
InputSource source = new InputSource(rootServicesResponse
.getEntity().getContent());
Node attribute = (Node) (xpath.evaluate(catalogXPath, source,
XPathConstants.NODE));
String serviceProvidersCatalog = attribute.getTextContent();
rootServicesResponse.getEntity().consumeContent();

// Setup the catalog request
HttpGet catalogDoc = new HttpGet(serviceProvidersCatalog);
catalogDoc.addHeader("Accept", "application/xml");
catalogDoc.addHeader("OSLC-Core-Version", "2.0");

// Access to the Service Providers catalog
HttpResponse catalogResponse = HttpUtils
.sendGetForSecureDocument(server, catalogDoc, login,
password, httpclient);
if (catalogResponse.getStatusLine().getStatusCode() == 200) {
// Define the XPath evaluation environment
XPath xpath2 = factory.newXPath();
xpath2.setNamespaceContext(new NamespaceContextMap(
new String[] { "oslc",
"http://open-services.net/ns/core#",
"dcterms", "http://purl.org/dc/terms/" }));

// Parse the response body to retrieve the Service Provider
source = new InputSource(catalogResponse.getEntity()
.getContent());
NodeList titleNodes = (NodeList) (xpath2.evaluate(
serviceProviderTitleXPath, source,
XPathConstants.NODESET));

// Print out the title of each Service Provider
int length = titleNodes.getLength();
System.out.println(">> Project Areas:");
for (int i = 0; i < length; i++) {
System.out.println(">> \t - "
+ titleNodes.item(i).getTextContent());
}
}
}

rootServicesResponse.getEntity().consumeContent();
final String content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><jp06:project-area xmlns:jp06=\"http://jazz.net/xmlns/prod/jazz/process/0.6/\" jp06:name=\""
+ projectAreaName
+ "Test02\" "
+ "jp06:templateId=\"simple.process.ibm.com\" jp06:templateLocale=\"en_US\"><jp06:summary>The summary</jp06:summary>"
+ "<jp06:summary>The summary</jp06:summary>"
+ "<jp06:description>The description</jp06:description>"
+ "<jp06:visibility jp06:access=\"PUBLIC\"/></jp06:project-area>";
ContentProducer cp = new ContentProducer() {
public void writeTo(OutputStream outstream) throws IOException {
Writer writer = new OutputStreamWriter(outstream,
HTTP.UTF_8);
writer.write(content);
writer.flush();
}
};

HttpEntity entity = new EntityTemplate(cp);
HttpPost post = new HttpPost(server + "/process/project-areas?owningApplicationKey=0106d6fea98e4bdbab1c5e3cd40fb4af");
post.addHeader("Accept", "application/rdf+xml");
post.addHeader("Content-type", "application/xml");
post.addHeader("X-Jazz-CSRF-Prevent","1");
post.setEntity(entity);

HttpResponse paResponse=HttpUtils.sendPostForSecureDocument(server, cp, post, login, password,
httpclient);
entity = paResponse.getEntity();
   String strContent = EntityUtils.toString(entity);
   System.out.println(paResponse.getStatusLine().getStatusCode());
            System.out.println(strContent);

} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (XPathExpressionException e) {
e.printStackTrace();
} catch (InvalidCredentialsException e) {
e.printStackTrace();
} finally {
// Shutdown the HTTP connection
httpclient.getConnectionManager().shutdown();
}
}

}


Comments
Jared Burns commented Jul 22 '14, 6:33 p.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

Administrative note: I edited the summary and description of this question to say "REST" instead of "OSLC". There's no project area concept in OSLC.

Accepted answer


permanent link
Martha (Ruby) Andrews (3.0k44251) | answered Jul 22 '14, 8:19 p.m.
JAZZ DEVELOPER
Hello,
There appears to be a permissions issue with your request. I suspect some piece of information regarding authentication is missing, but I do not know what.

Perhaps one of these will help:
OSLC Workshop
Using Process API with cURL

Ruby

Jared Burns selected this answer as the correct answer

Comments
Sefa Sevtekin commented Jul 23 '14, 11:19 a.m. | edited Aug 11 '14, 6:28 p.m.

 I got it working. My HttpClient was not authenticating. After changing the login process it worked. I only used "X-Jazz-CSRF-Prevent" header.



String jsessionid = "";
for (Cookie cookie : httpClient.getCookieStore().getCookies()) {
if (cookie.getName().equals("JSESSIONID")) {
jsessionid = cookie.getValue();
}
}
post.setHeader("X-Jazz-CSRF-Prevent", jsessionid);

2 other answers



permanent link
Jared Burns (4.5k29) | answered Jul 22 '14, 6:34 p.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
owningApplicationKey is not a required parameter and is ignored by the CCM server. So that's not the source of your problem.

permanent link
Martha (Ruby) Andrews (3.0k44251) | answered Jul 22 '14, 6:27 p.m.
JAZZ DEVELOPER
Hello,
I notice that the X-Jazz-CSRF-Prevent header value you are sending is not valid. It should be the value of the JSESSONID. This can cause a 403 response.

Ruby
Martha (Ruby) Andrews
Jazz Foundation L3 Team Lead

Comments
Rosa Naranjo commented Feb 06 '17, 1:22 p.m.
FORUM MODERATOR / JAZZ DEVELOPER

Martha,
Is this supported? Does this still apply for versions 6.x?

Your answer


Register or to post your answer.


Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.