cancel
Showing results for 
Search instead for 
Did you mean: 

Activiti REST POST

thysmichels
Champ in-the-making
Champ in-the-making

   public static String claimAndCompleteTaskByProcessIdAndActorName(String processInstanceId, String actorName) throws JSONException, IOException {
      String uri = REST_URI + "/runtime/tasks?candidate=" +actorName + "&size=1&order=asc";
      Representation response = getClientResource(uri).get(MediaType.APPLICATION_JSON);
      JSONObject object = new JSONObject(response.getText());
      System.out.println("OBJECT: " + object);
      if (object != null) {
         JSONArray arr = (JSONArray) object.get("data");
         for (int i = 0; i < arr.length(); i++) {
            JSONObject ob = (JSONObject) arr.get(i);
            if (ob.get("processDefinitionId").equals(processInstanceId)) {
               logger.info("Returned task: " + ob);
               if (ob.get("id")!=null) {
                  String claimUri = REST_URI + "/runtime/tasks/" + ob.get("id");
                  
                  JSONStringer jsRequest = new JSONStringer();
                  jsRequest.object().key("action").value("claim");
                  jsRequest.key("assignee").value(actorName);
                  jsRequest.endObject();
                  
                  Representation claimResponse = getClientResource(claimUri).post(jsRequest.toString(), MediaType.APPLICATION_JSON);
                  JSONObject claimObject = new JSONObject(claimResponse.getText());
                  System.out.println("Claimed task " + claimObject);
                  if (claimObject.get("success").equals(true)) {
                     String completeUri = REST_URI + "/runtime/tasks/" + ob.get("id");
                     Map<String, String> completeVariable = new HashMap<String, String>();
                     completeVariable.put("action", "complete");
                     Representation completeResponse = getClientResource(completeUri).post(completeVariable, MediaType.APPLICATION_JSON);
                     JSONObject completeObject = new JSONObject(completeResponse.getText());
                     
                     System.out.println("Completed task " + completeObject);
                     if (completeObject.get("success").equals(true))
                        return ob.getString("description");
                  }
               }
            }
         }
      }
      return null;
   }


<blockcode>
Getting:
Unsupported Media Type (415) - Unsupported Media Type
   at org.restlet.resource.ClientResource.doError(ClientResource.java:612)
   at org.restlet.resource.ClientResource.handleInbound(ClientResource.java:1202)
   at org.restlet.resource.ClientResource.handle(ClientResource.java:1069)
   at org.restlet.resource.ClientResource.handle(ClientResource.java:1086)
   at org.restlet.resource.ClientResource.post(ClientResource.java:1437)
   at com.nuke.activiti.client.NucleusClient.claimAndCompleteTaskByProcessIdAndActorName(NucleusClient.java:74)
</blockcode>

I want to claim a task and is sending a post request with body:
{"action":"claim","assignee":"qatester_tools"}
to
http://localhost:8090/api/nuke/v1/runtime/tasks/313

Any suggestions?
3 REPLIES 3

martin_grofcik
Confirmed Champ
Confirmed Champ
Hi,

Can you try to put "Content-Type" "application/json" to the header?

Regards
Martin

thysmichels
Champ in-the-making
Champ in-the-making
Worked thanks Smiley Happy Is it correct if it returns a null?Or is there a return expected when claiming a task?

martin_grofcik
Confirmed Champ
Confirmed Champ
I think there are only response codes:
http://www.activiti.org/userguide/#N14935
Regards
Martin