How to use OSLC Change Request API to create a new Work Item
I'm attempting to using the OSLC API to script out creation of work items. I can update work item statuses and add comments, but so far I have been unable to create one. I either get a response of 400 or 403 from the jazz server. Now, the 400 is wrong syntax and I'm trying to get a solution for that, but the 403 doesn't make any sense because I'm using the exact same code to connect and execute the HTTP POST request as with Work Item updating. Here's the xml string that I'm using that is returning an error code 400
(See attached image for XML)
http://imgur.com/88WwYHI
Neither one works, but as you can see, Jazz is returning an authentication error on what appears to be malformed xml, and is throwing a bad request error when the xml appears to be valid. Am I missing some necessary argument? I've had a hard time trying to find any documentation describing how to do this task, so any information can help.
edit: looks like the formatting on the xml is destined to be messed up no matter what I do. Screencap attached instead
edit2: Looks like jazz can't actually attach pictures. I've posted an imgur link with the image.
2 answers
There is a workshop for OSLC - https://jazz.net/wiki/pub/Main/OSLCWorkshopDownload/2012-11-26-OSLC-workshop.pdf
Here is an example for creating story type work item
Here is an example for creating story type work item
<oslc:CreationFactory> <dcterms:title rdf:parseType="Literal">Location for creation of Story change requests </dcterms:title> <oslc:usage rdf:resource="http://open-services.net/ns/cm#planItem"/> <oslc:resourceType rdf:resource="http://open-services.net/ns/cm#ChangeRequest"/> <oslc:resourceType rdf:resource="https://localhost:9443/jazz/oslc/types/_xSXuEKDOEeGWLtJtsNXRew/com.ibm.team.apt.workItemType.story"/> <oslc:resourceShape rdf:resource="https://localhost:9443/jazz/oslc/context/_xSXuEKDOEeGWLtJtsNXRew/shapes/workitems/com.ibm.team.apt.workItemType.story"/> <oslc:creation rdf:resource="https://localhost:9443/jazz/oslc/contexts/_xSXuEKDOEeGWLtJtsNXRew/workitems/com.ibm.team.apt.workItemType.story"/> </oslc:CreationFactory>
Comments
showing 5 of 6
show 1 more comments
Hello! I suggest you for to generate the JSESSIONID use this fragment of code:
CookieStore cookieStore = new BasicCookieStore();
HttpContext localContext = new BasicHttpContext();
localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
List<Cookie> cookies1 = cookieStore.getCookies();
for (Iterator<Cookie> iterator = cookies1.iterator(); iterator.hasNext();) {
Cookie cookie = (Cookie) iterator.next();
if(cookie.getName().equals("JSESSIONID")){
// myCookie = cookie.getValue();
post.addHeader("X-Jazz-CSRF-Prevent", cookie.getValue());
}
}
and when you set is in:
HttpResponse documentResponse = httpClient.execute(post, localContext);
and the POST header looks like:
Response Headers:
- Server: Apache-Coyote/1.1
- Set-Cookie: JSESSIONID=E1E5C6EBE8B3ECC44309A6982545D234; Path=/ccm/; Secure; HttpOnly
- X-com-ibm-team-repository-web-auth-msg: authrequired
- Location: https://localhost:9443/ccm/authenticated/identity?redirectPath=%2Fccm%2Foslc%2Fcontexts%2F_H8I3UB8LEeOQ4ObPSFrJ0w%2Fworkitems%2Fdefect
- Content-Length: 0
- Date: Mon, 21 Oct 2013 17:32:33 GMT
CookieStore cookieStore = new BasicCookieStore();
HttpContext localContext = new BasicHttpContext();
localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
List<Cookie> cookies1 = cookieStore.getCookies();
for (Iterator<Cookie> iterator = cookies1.iterator(); iterator.hasNext();) {
Cookie cookie = (Cookie) iterator.next();
if(cookie.getName().equals("JSESSIONID")){
// myCookie = cookie.getValue();
post.addHeader("X-Jazz-CSRF-Prevent", cookie.getValue());
}
}
and when you set is in:
HttpResponse documentResponse = httpClient.execute(post, localContext);
and the POST header looks like:
Response Headers:
- Server: Apache-Coyote/1.1
- Set-Cookie: JSESSIONID=E1E5C6EBE8B3ECC44309A6982545D234; Path=/ccm/; Secure; HttpOnly
- X-com-ibm-team-repository-web-auth-msg: authrequired
- Location: https://localhost:9443/ccm/authenticated/identity?redirectPath=%2Fccm%2Foslc%2Fcontexts%2F_H8I3UB8LEeOQ4ObPSFrJ0w%2Fworkitems%2Fdefect
- Content-Length: 0
- Date: Mon, 21 Oct 2013 17:32:33 GMT