Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

Problem with REST in Java

I am trying to update workitems via the REST api, using Java

I refered to the following line in the documentation:

curl -D - -k -b $COOKIES -H "If-Match: _1am9cFm0Ed6ELJg2MQ68Kg" -H "Content-Type: application/x-oslc-cm-change-request+json" -H "Accept: application/x-oslc-cm-change-request+json" -X PUT --data-binary @wi-821.json $URL



Now here is my translation to java, which returns a 400,bad request response

URL url = new URL(Parameters.serverURL + pageURL);

HttpURLConnection httpCon = (HttpURLConnection) url.openConnection();
httpCon.setDoOutput(true);
httpCon.setRequestMethod("PUT");
httpCon.setRequestProperty("Cookie", cookie);
httpCon.setRequestProperty("If-Match", e_Tag);
httpCon.setRequestProperty("Content-Type", "application/x-oslc-cm-change-request+xml");
httpCon.setRequestProperty("Accept", "application/x-oslc-cm-change-request+xml");
OutputStreamWriter out = new OutputStreamWriter(httpCon.getOutputStream(), "UTF-8");
out.write(document);
out.close();
System.out.println(httpCon.getResponseCode()+"="+httpCon.getResponseMessage());



What am I doing wrong?

Thanks
Marco

0 votes


Accepted answer

Permanent link
Hard to say, what is the detailed message coming back with the 400 response?

In the CURL example you use JSON, in the Java one you use XML. Perhaps there is something different about the XML example using Java?
David Lafreniere selected this answer as the correct answer

0 votes

Comments

Concerning the XML, I found it easier to treat the data i get from Jazz in XML; and it is faily esay. There are quite a few examples where +json is replaced by +xml
Unfortunately I did not get any details, just "bad request". In the XML i send back, I simply altered the summary, so no major source of error there.

Just to make sure, using the exact same request URL and XML content, this works fine with CURL and not Java? Have you tried also in another client like Firefox add-ons: REST client or Poster?

Thanks Steve, Poster gave me some trouble with the authorization ...

But I did advance a little bit, leaving out .xml at the end of the page adress.

Now I get a "204, no content" message and no update has been done

According to the documentation I read, this means it worked all right: Isn't the update effected right away?

Now I get a "204, no content" message and no update has been done

According to the documentation I read, this means it worked all right: Isn't the update effected right away?



It should be immediate, unless there is some browser caching going on (like with Poster or Web UI of RTC). Sometimes I use the Developer toolbar plugin to Firefox and disable the cache.

I'm not sure why it would be giving you a 204 response on PUT/Update, it should just be 200 Ok if it worked. I don't think I've gotten 204 before. Perhaps your request Content body is missing for some reason?

if I fix the content-length in the header and then leave the body empty, it prompts an error, so it has to get the body somehow.

I also checked the encoding which seems to be alright.

I found a workable solution. What I tried was to PUT the workitem as whole with changes using a path like "resource/itemName/com.ibm.team.workitem.WorkItem/1598" as URL, sending back the changed XML file as String. That did not work and still doesn't. But if I specify the properties that I change and thus reduce the list using an appendix like "?oslc_cm.properties=dc:title" in the URL, I still get a 204 message, but the changes are done.

showing 5 of 6 show 1 more comments

One other answer

Permanent link
Hi,
I have created the svn dump file, and now trying to import it to the RTC . I get the below error message.
Error UUID Missing..
I have created a svnuser to jazz userid mapping .
My userid has jazzadmin rights.

0 votes

Comments

Could you post the complete error including the stacktrace? It should be
available from the Error Log view.

prangach wrote:

Hi,
I have created the svn dump file, and now trying to import it to the
RTC . I get the below error message.
Error UUID Missing..
I have created a svnuser to jazz userid mapping .
My userid has jazzadmin rights.

Your answer

Register or log in 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.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 10,936
× 478
× 369

Question asked: Oct 07 '10, 10:02 a.m.

Question was seen: 8,855 times

Last updated: Oct 12 '17, 10:32 p.m.

Confirmation Cancel Confirm