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
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 <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
David Hatten
commented Oct 10 '13, 4:03 p.m.
This looks like it should work, but I'm wondering why the more simple type of syntax I've posted won't work here. It worked for the other interactions, and I'd like to keep things consistent and not have to re-write everything to do so if that's possible.
David Hatten
commented Oct 10 '13, 5:01 p.m.
In order to get this to work, do I have to include any namespaces, or will the xml simply work as given? Hi David
X-Jazz-CSRF-Prevent and use the current JSESSIONID Value as the valueYou get 403 error if this header is not present
David Hatten
commented Oct 11 '13, 11:54 a.m.
1) what is JSESSIONID? Where does it come from?
2) in the example you provided, you have "... https://localhost:9443/jazz/oslc/types/_xSXuEKDOEeGWLtJtsNXRew/com.ibm.team.apt.workItemType.story"
How am I supposed to generate this url? Should "localhost" be the jazz server I'm hitting? What about that string of characters in the middle of the URL?
1)You can get JSESSIONID value from the cookies.
More information about getting JSESSIONID value - https://jazz.net/forum/questions/112236/how-to-get-jsessionid-value-from-firefox-browser
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 |
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.