AnsweredAssumed Answered

Activiti REST POST

Question asked by thysmichels on Jun 14, 2014
Latest reply on Jun 17, 2014 by martin.grofcik

   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?

Outcomes