Start Process with Java

Hi,

I’m trying to start an instance without using the API REST, making my own API REST.

I using this part of a example code:

RuntimeService runtimeService;
ProcessInstanceWithVariables instance = runtimeService.createProcessInstanceByKey(“invoice”)
.startBeforeActivity(“SendInvoiceReceiptTask”)
.setVariable(“creditor”, “Nice Pizza Inc.”)
.startBeforeActivity(“DeliverPizzaSubProcess”)
.setVariableLocal(“destination”, “12 High Street”)
.executeWithVariablesInReturn();

How can I initialize the runtimeService?

Thanks,

1 Like

Hi @Ignacio_Requena_Elvi,

please have a look at the docs: https://docs.camunda.org/manual/7.9/user-guide/process-engine/process-engine-bootstrapping/

Does this help you?

Best regards,
Philipp

1 Like

Thanks for the help, in my case I read this: https://docs.camunda.org/manual/7.6/user-guide/process-engine/process-engine-api/ and with this i make this:

@POST
@Path("/firmar")
@Consumes(MediaType.APPLICATION_JSON)
public Response firmar(InputStream incomingData) {
String nombrePdf = null;
String datos="";

    JsonParser jsonParser = new JsonParser();
    try {
        JsonObject jsonObject = (JsonObject)jsonParser.parse(
              new InputStreamReader(incomingData, "UTF-8"));
        nombrePdf=jsonObject.get("nombre").getAsString();
        datos=jsonObject.get("contenido").getAsString();
      
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      
    } 
    System.out.println("Data Received: " + datos.toString());
    
    Map<String, Object> variables=new HashMap<>();
    variables.put("nombrePdf",nombrePdf);
    variables.put("datos",datos);
    
    ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
    RuntimeService runtimeService=processEngine.getRuntimeService();
   
    ProcessInstanceWithVariables instance = runtimeService.createProcessInstanceByKey("POCFirma")
        .setVariables(variables)
        .executeWithVariablesInReturn();
    // return HTTP response 200 in case of success
    return Response.status(200).entity(datos.toString()).build();
}

And with this code i can initialize a instance with a variables of a REST service.

Note: it isn’t the best code style but it’s functional for a POC lol

Best regards,

Ignacio

2 Likes

Thanks for sharing your solution.

That’s the spirit :slight_smile:

Hi i am getting null, when i call ProcessEngines.getDefaultProcessEngine(). Any help.

Can you create a new topic for this question - giving a lot more detail about the problem.
This thread is 2 years old.