use of org.jboss.pnc.bpm.model.MDCParameters in project pnc by project-ncl.
the class RestConnector method startProcess.
public Long startProcess(String processId, Object requestObject, String correlationKey, String accessToken) throws ProcessManagerException {
HttpPost request = endpointUrl.startProcessInstance(currentDeploymentId, processId, correlationKey);
log.debug("Starting new process using http endpoint: {}", request.getURI());
Map<String, Object> processParameters = new HashMap<>();
processParameters.put("auth", Collections.singletonMap("token", accessToken));
processParameters.put("mdc", new MDCParameters());
processParameters.put("task", requestObject);
Map<String, Map<String, Object>> body = Collections.singletonMap("initData", processParameters);
HttpEntity requestEntity;
try {
requestEntity = new StringEntity(JsonOutputConverterMapper.apply(body));
} catch (UnsupportedEncodingException e) {
throw new ProcessManagerException("Cannot prepare BPM REST call.", e);
}
request.setEntity(requestEntity);
configureRequest(accessToken, request);
try (CloseableHttpResponse response = httpClient.execute(request)) {
int statusCode = response.getStatusLine().getStatusCode();
if (statusCode == 201) {
Long processInstanceId = JsonOutputConverterMapper.readValue(response.getEntity().getContent(), Long.class);
log.info("Started new process instance with id: {}", processInstanceId);
return processInstanceId;
} else {
throw new ProcessManagerException("Cannot start new process instance, response status: " + statusCode);
}
} catch (IOException e) {
throw new ProcessManagerException("Cannot start new process instance.", e);
}
}
Aggregations