It's all about the answers!

Ask a question

Problem with REST in Java


Marco Bormann (1611810) | asked Oct 07 '10, 10:02 a.m.
edited Oct 12 '17, 10:27 p.m. by David Lafreniere (4.5k7)

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

Accepted answer


permanent link
Steve Speicher (30765) | answered Oct 07 '10, 10:55 a.m.
JAZZ DEVELOPER
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

Comments
Marco Bormann commented Oct 07 '10, 1:38 p.m. | edited Oct 12 '17, 10:28 p.m.

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.


Steve Speicher commented Oct 07 '10, 1:50 p.m. | edited Oct 12 '17, 10:29 p.m.
JAZZ DEVELOPER

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?


Marco Bormann commented Oct 12 '10, 8:07 a.m. | edited Oct 12 '17, 10:32 p.m.

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?


Steve Speicher commented Oct 12 '10, 8:21 a.m. | edited Oct 12 '17, 10:29 p.m.
JAZZ DEVELOPER
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?


Marco Bormann commented Oct 12 '10, 9:39 a.m. | edited Oct 12 '17, 10:31 p.m.

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.


Marco Bormann commented Oct 13 '10, 3:41 a.m. | edited Oct 12 '17, 10:32 p.m.

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
Prathibha G R (16) | answered Oct 14 '10, 3:47 a.m.
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.

Comments
Michael Valenta commented Oct 14 '10, 9:24 a.m. | edited Oct 12 '17, 10:30 p.m.
FORUM MODERATOR / JAZZ DEVELOPER

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 to post your answer.