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

Updating work item using Rest API (HttpPut) is not working!

Hi,

 I am working on updating a workitem status / description using Rest APIs(HttpPut). I am following the steps detailed in the OSLC Workshop book. Below is the code snippet. But some how work item is not getting updated after executing the code.

I am using JTS 4.0.1.


************************************************

private void updateChangeRequest(String usrName, String password, String paName, String wiID, String status, String description)
 {
  String server = "https://localhost:9443/ccm";
  HttpResponse response = null;
  String catalogURI;
  String jsonObj="";
  try {
     catalogURI = getServiceProviderCatalog(usrName,password);
    
    HttpClient httpclient = new DefaultHttpClient();
    HttpUtils.setupLazySSLSupport(httpclient);
    
    String projectAreaURI = getServiceProvider(usrName,password,catalogURI, paName);
    String simpleQueryURI = getSimpleQueryURI(usrName,password,projectAreaURI);
   
     ChangeRequest cr = getChangeRequest(usrName, password,simpleQueryURI, wiID);
    cr.setDcDescription(description); //updating the description only
    
    HttpResponse response1 = updateChangeRequest(cr,server,usrName,password,httpclient);
    
    HttpUtils.printResponseHeaders(response1);
    HttpUtils.printResponseBody(response1);
    
   } catch (ClientProtocolException e) {
    e.printStackTrace();
   } catch (IOException e) {
    e.printStackTrace();
   } catch (XPathExpressionException e) {
    e.printStackTrace();
   } catch (InvalidCredentialsException e) {
    e.printStackTrace();
   } finally {
    // Shutdown the HTTP connection
   
   }

 
 }
 

private HttpResponse updateChangeRequest(final ChangeRequest cr, String server,String login, String password, HttpClient httpclient) throws InvalidCredentialsException, IOException {
  // How to fill the request body (Content Producer)
  ContentProducer cp = new ContentProducer() {
      public void writeTo(OutputStream outstream) throws IOException {
          Writer writer = new OutputStreamWriter(outstream, HTTP.UTF_8);       
          cr.writeXML(writer);
          writer.flush();
      }
  };

  HttpEntity entity = new EntityTemplate(cp);
  HttpPut put = new HttpPut(cr.getUri());  
  put.addHeader("Accept", "application/rdf+xml");
  put.addHeader("Content-type", "application/xml");
  put.setEntity(entity);
  
  // Call the PUT method against the Change Request URI
  return HttpUtils.sendPutForSecureDocument(
       server, cp, put, login, password, httpclient);
 }


************************************************

Anyone has faced similar challenges & was able to resolve it, please let me know.


Thanks
Guru

0 votes



One answer

Permanent link
do you get any error, if no, what is the response (status code, header and body) you receive.

one check you can do is to print the URL fetched for the work item id and use that URL in browser or REST client to verify if the work item is fetched correctly.

I would use below code to do that :
system.out.println("URL for " + wiID + " is : " + cr.getUri());
system.out.println("Existing Description " + cr.getDcDescription());


0 votes

Comments

Thanks for the quick reply. Here is what I get when I sysout.

cr.getUri()==https://localhost:9443/ccm/resource/itemName/com.ibm.team.workitem.WorkItem/6  & the description is the latest one which I have set.


Somehow Status code is coming as 302...HTTP/1.1 302 Moved Temporarily


Also Response header contains the below details.

*******************
PUT(1) https://localhost:9443/ccm/resource/itemName/com.ibm.team.workitem.WorkItem/6
>> Response Headers:
 - Server: Apache-Coyote/1.1
 - Cache-Control: private
 - Expires: Thu, 01 Jan 1970 05:30:00 IST
 - Set-Cookie: JSESSIONID=DC5E766318F0BD31E4E32B50C7F04D0A; Path=/ccm/; Secure; HttpOnly
 - X-com-ibm-team-repository-web-auth-msg: authrequired
 - Location: https://localhost:9443/ccm/authenticated/identity?redirectPath=%2Fccm%2Fresource%2FitemName%2Fcom.ibm.team.workitem.WorkItem%2F6
 - Content-Length: 0
 - Date: Thu, 06 Jun 2013 12:02:30 GMT
*******************

the response header with
 - X-com-ibm-team-repository-web-auth-msg: authrequired
suggests authentication failure.

the status code 302, is the redirection for authentication.

even though I cant figure out anything wrong in your code that should result in this, I would try making httpclient global.

Hi,

   I am now getting 'HTTP/1.1 409 Conflict - Illegal Value' error. Can you please advise?

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,950

Question asked: Jun 06 '13, 6:50 a.m.

Question was seen: 5,305 times

Last updated: Jun 28 '13, 3:28 a.m.

Confirmation Cancel Confirm