How to use OSLC Change Request API to create a new Work Item
2 answers
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
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.
In order to get this to work, do I have to include any namespaces, or will the xml simply work as given?
Hi David
In order to create a new workitem you need to add additional header
X-Jazz-CSRF-Prevent and use the current JSESSIONID Value as the valueYou get 403 error if this header is not present
1) what is JSESSIONID? Where does it come from?
1)You can get JSESSIONID value from the cookies.
2)The way you generate this url is
GET - https://jazz.server.com:9443/ccm/oslc/workitems/catalog (Where jazz.server.com is the jazz server your hitting )
Then from response you take ServiceProvider element for particular project (There is one service provider for each project)
GET - https://jazz.server.com:9443/ccm/oslc/contexts/_3_a4Ai-JEeO3Tb4Rjq0l3w/workitems/services.xml
Then from the response you choose the url for the creation dialog.
So you cannot use my URL above , you need to generate your own
More information about getting JSESSIONID value - https://jazz.net/forum/questions/112236/how-to-get-jsessionid-value-from-firefox-browser
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