Search in sources :

Example 1 with MDCParameters

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);
    }
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) HttpEntity(org.apache.http.HttpEntity) HashMap(java.util.HashMap) UnsupportedEncodingException(java.io.UnsupportedEncodingException) MDCParameters(org.jboss.pnc.bpm.model.MDCParameters) IOException(java.io.IOException) StringEntity(org.apache.http.entity.StringEntity) ProcessManagerException(org.jboss.pnc.spi.exception.ProcessManagerException) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 HttpEntity (org.apache.http.HttpEntity)1 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)1 HttpPost (org.apache.http.client.methods.HttpPost)1 StringEntity (org.apache.http.entity.StringEntity)1 MDCParameters (org.jboss.pnc.bpm.model.MDCParameters)1 ProcessManagerException (org.jboss.pnc.spi.exception.ProcessManagerException)1