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
Accepted answer
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?
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.
One other answer
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
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.