Return Values from HTTPTask Rest Call

Hello,

I am new to Flowable, but i have successfully called an external RESTful API thru HTTP Task, but i want the response from HTTP Task returned back to me so i could return it back to the caller, is this possible?

Sample code:
public CommonResponse startProcess(Interview interview) {

    repositoryService.createDeployment()
        .addClasspathResource("processes/sample-timer-process.bpmn20.xml").deploy();

    CommonResponse commonResponse = new CommonResponse(
        CommonResponse.SUCCESS, CommonResponse.SUCCESS);

    try {
        Map<String, Object> variables = new HashMap<String, Object>();
        variables.put("sampleRequestBody", interview);

        runtimeService.startProcessInstanceByKey("timerProcess", variables);
    } catch (FlowableObjectNotFoundException  e) {
        commonResponse.setStatus(CommonResponse.ERROR);
        commonResponse.setMessage(e.getMessage());
        return commonResponse;
    }

    return null;
}

So instead of returning null at the bottom, i would like to return the response from the call.

Hi,

Has the process instance finished immediately after the start process instance was started? Or is it still running and waiting in a user task for example?
If the process instance is still running you can use the runtimeService getVariables method to get the process variables. If the process instance has ended you could use the HistoryService to get the process variables.

Best regards,

Tijs

Thanks for the reply.

The process instance has ended, and i have added History Service code already but got no process variables.
See code below:
runtimeService.startProcessInstanceByKey(“timerProcess”, variables);

        List<HistoricProcessInstance> history =
            historyService.createHistoricProcessInstanceQuery()
                .processDefinitionKey("timerProcess").finished().list();

        for (HistoricProcessInstance historyInstance: history) {
            Map<String, Object> response = historyInstance.getProcessVariables();
            for (Entry<String, Object> entry : response.entrySet()){
                System.out.println(entry.getKey() + " " + entry.getValue());
            }
        }

Please help why there is no process variables? Is it because “returnVariables” is not set to true?
If yes, how to set “returnVariables” to true thru Java?

I think i have gotten the response using this code snippet:
List history =
historyService.createHistoricVariableInstanceQuery()
.variableName(“httpPost.responseBody”)
.orderBy(new TaskQueryProperty()).desc()
.listPage(0, 1);

Hi,

if in this query you also add

.includeProcessVariables()

you can then access process variables also for a particular process instance otherwise you have to write history variable query also which you posted in your last comment.

Thanks,
Arpit

1 Like