It's all about the answers!

Ask a question

How to use OSLC Change Request API to create a new Work Item


David Hatten (1112) | asked Oct 10 '13, 2:51 p.m.
edited Oct 10 '13, 4:01 p.m.
 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



permanent link
abhishek patti (9134) | answered Oct 10 '13, 3:23 p.m.
JAZZ DEVELOPER
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? 


abhishek patti commented Oct 10 '13, 7:24 p.m. | edited Oct 10 '13, 7:29 p.m.
JAZZ DEVELOPER

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 value 
You 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?


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?


abhishek patti commented Oct 11 '13, 1:02 p.m.
JAZZ DEVELOPER

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


abhishek patti commented Oct 11 '13, 1:03 p.m.
JAZZ DEVELOPER
showing 5 of 6 show 1 more comments

permanent link
Agustina Busto (1) | answered Oct 21 '13, 1:33 p.m.
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


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.