3 Replies Latest reply on Mar 25, 2015 12:35 PM by Maciej Swiderski

    How to start process with correlation key using rest commands?

    Melissa Ferenal Newbie

      Hi,

       

      I need to start a process with a correlation key using REST call.

      I looked into the documentation and I found this http://docs.jboss.org/jbpm/v6.2/userguide/ch17.html#remote.rest.execute

      However, I'm not sure how make the rest call.

       

      I tried calling http://localhost:8080/jbpm-console/rest/runtime/task/execute but it returned an error

       

      Could not find resource for full path: http://localhost:8080/jbpm-console/rest/runtime/task/execute
      

       

      How do I use the  execute command rest api? Is there an example I can follow?

       

      Thanks.

        • 1. Re: How to start process with correlation key using rest commands?
          Maciej Swiderski Master

          you should use /runtime/{deploymentId}/execute end point and then use StartCorrelatedProcessCommand to actually start it. I'd recommend looking at Remote Java API as it can do that for you. If you need to use end point directly then best would be to once use the Remote Java API to see the payload of the message that is generated - it will be xml of the command.

           

          HTH

          1 of 1 people found this helpful
          • 2. Re: How to start process with correlation key using rest commands?
            Melissa Ferenal Newbie

            Got it working.. Thanks...

             

             

             

            public static List<JaxbCommandResponse<?>> executeCommand(List<Command> commands)
              throws Exception {
              URL address = new URL(appUrl +"/rest/execute");
              ClientRequest restRequest = createRequest(address);
              JaxbCommandsRequest commandMessage = new JaxbCommandsRequest();
              commandMessage.setDeploymentId(deploymentId);
              commandMessage.setCommands(commands);
              String body = convertJaxbObjectToString(commandMessage);
            
            
              restRequest.body(MediaType.APPLICATION_XML, body);
              ClientResponse<JaxbCommandsResponse> responseObj = restRequest
              .post(JaxbCommandsResponse.class);
              // checkResponse(responseObj);
              JaxbCommandsResponse cmdsResp = responseObj.getEntity();
              return cmdsResp.getResponses();
              }
            
            
            public static void main(String args[]) {
              StartProcessTest s = new StartProcessTest();
              List<Command> list = new ArrayList<Command>();
            
            
              CorrelationKeyFactory factory = KieInternalServices.Factory.get().newCorrelationKeyFactory();
            
            
              List<String> keys = new ArrayList<String>();
              keys.add("str1");
              keys.add("str2");
            
              CorrelationKey key = factory.newCorrelationKey(keys);
              list.add(new StartCorrelatedProcessCommand(
              "Sub_Process_Test.TestConfirmOrder", key));
            
            
              try {
              s.executeCommand(list);
              } catch (Exception e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
              }
              System.out.println("------Done-----");
              }
            
            
            
            
            
            
            
            • 3. Re: How to start process with correlation key using rest commands?
              Maciej Swiderski Master

              in case you'd like to use directly Remote Java API provided by jBPM you can do as follows:

               

              RuntimeEngine engine = RemoteRuntimeEngineFactory.newRestBuilder()
                              .addDeploymentId("org.jbpm:HR:1.0")
                              .addUrl(deploymentUrl)
                              .addUserName("user")
                              .addPassword("password")
                              .addTimeout(5000)
                              .build();
              
                Map<String, Object> parameters = new HashMap<String, Object>();
                String inputData = "john";
                parameters.put("name", inputData);
              
              
                StartCorrelatedProcessCommand cmd = new StartCorrelatedProcessCommand();
                cmd.setCorrelationKey("test");
                cmd.setProcessId("hiring");
                cmd.setParameter(ConversionUtil.convertMapToJaxbStringObjectPairArray(parameters));
              
                ProcessInstance processInstance = engine.getKieSession().execute(cmd);
              

              to start hiring process from HR example project.

               

              Just for completeness.