Looking for an example on rest service(POST) orchestration though camunda

I am actually looking for a quickfix … sorry abt that .

can some one share a sample example for orchestrating restful webservices using camunda.

I am trying to do something like

  1. fire a login service 2) get the auth-token from the login service and use it to call a search user service. 3) use the authtoken to call the logout service.

If anyone has a sample project on github . please share the link.

I started with the rest service example available and tweaked it to invoke my own rest service:

<?xml version="1.0" encoding="UTF-8"?>

<bpmn2:definitions xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance” xmlns:bpmn2=“http://www.omg.org/spec/BPMN/20100524/MODEL” xmlns:bpmndi=“http://www.omg.org/spec/BPMN/20100524/DI” xmlns:camunda=“http://camunda.org/schema/1.0/bpmn” xmlns:dc=“http://www.omg.org/spec/DD/20100524/DC” xmlns:di=“http://www.omg.org/spec/DD/20100524/DI” xsi:schemaLocation=“http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd” id="_B0ppIPFYEeOlke_H2tkzCA" exporter=“camunda modeler” exporterVersion=“2.6.0” targetNamespace=“http://camunda.org/examples”>
<bpmn2:process id=“loginSearchLogout” name=“login and search” isExecutable=“true”>
<bpmn2:startEvent id=“StartEvent_1” name=“start with date”>
bpmn2:outgoingSequenceFlow_1</bpmn2:outgoing>
</bpmn2:startEvent>
<bpmn2:serviceTask id=“ServiceTask_1” name=“fire login service”>
bpmn2:extensionElements

    <camunda:connector>
      <camunda:connectorId>http-connector</camunda:connectorId>
      <camunda:inputOutput>

        <camunda:inputParameter name="url">
          http://localhost:7001/middleware/bda/BancsService
        </camunda:inputParameter>

        <camunda:inputParameter name="method">
          POST
        </camunda:inputParameter>

        <camunda:inputParameter name="headers">
          <camunda:map>
            <camunda:entry key="Accept">
              application/json
            </camunda:entry>
            x-tcs-servicename:login
			 <camunda:entry key="x-tcs-backofficeid">
              Bancs
            </camunda:entry>
             <camunda:entry key="x-tcs-language">
              1
            </camunda:entry>
             <camunda:entry key="x-tcs-deviceid">
             gfy45768686trydry
            </camunda:entry>
       		<camunda:entry key="x-tcs-servicename">
            login
            </camunda:entry>
          </camunda:map>
        </camunda:inputParameter>
		
		<camunda:inputParameter name="payload">
		 {"data":{"type":"com.tcs.bfsarch.security.callback.LoginDetails","id":"loginDetails","attributes":{"loginId":"SYSADMIN1","password":"abcd1234","ouid":"G"}}}
		 </camunda:inputParameter>

       
      </camunda:inputOutput>
    </camunda:connector>

  </bpmn2:extensionElements>
  <bpmn2:incoming>SequenceFlow_1</bpmn2:incoming>
  <bpmn2:outgoing>SequenceFlow_2</bpmn2:outgoing>
</bpmn2:serviceTask>

</bpmn2:process>
</bpmn2:definitions>

The output of this service http://localhost:7001/middleware/bda/BancsService should be a json like below , however this webservice call does not happen or i am unable to get the result json
{
“data”: [
{
“type”: “com.middleware.common.UserToken”,
“attributes”: {
“status”: “SUCCESS”,
“authToken”: “1795013009”,
“description”: “Login Successful.”,
“txn_DTL”: null,
“auditTableName”: null
}
}
]
}

  1. I get the below error with the below code:

RuntimeService runtimeService = processEngineRule.getRuntimeService();
TaskService taskService = processEngineRule.getTaskService();

runtimeService.startProcessInstanceByKey("loginSearchLogout", variables);

Task task = taskService.createTaskQuery().singleResult();

INFO: ENGINE-00001 Process Engine default created.
Dec 27, 2016 3:36:09 PM org.camunda.commons.logging.BaseLogger logError
SEVERE: ENGINE-16004 Exception while closing command context: execution 4 doesn’t exist: execution is null
org.camunda.bpm.engine.exception.NullValueException: execution 4 doesn’t exist: execution is null
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.Delegat

  1. what code will give the output json mentioned above to me as a string from which i can take out the authtoken and call another service?

Based on your explanation you would use 3 Service tasks. Use Process Variables to store the different responses from each task.

See: HTTP-Connector POST Payload configuration and GET URL Parameters with variables? - #10 by StephenOTT for examples of GET and POST web service calls and how to parse your data using Camunda SPIN.

thanks for the reply Stephen . @StephenOTT

But when i call my post method using the below connector . nothing happens . i get no error nor does the service gets called

camunda:connector
camunda:connectorIdhttp-connector</camunda:connectorId>
camunda:inputOutput

    <camunda:inputParameter name="url">
      http://localhost:7001/middleware/bda/BancsService
    </camunda:inputParameter>

    <camunda:inputParameter name="method">
      POST
    </camunda:inputParameter>

    <camunda:inputParameter name="headers">
      <camunda:map>
        <camunda:entry key="Accept">
          application/json
        </camunda:entry>
  			 <camunda:entry key="x-tcs-backofficeid">
          Bancs
        </camunda:entry>
         <camunda:entry key="x-tcs-language">
          1
        </camunda:entry>
         <camunda:entry key="x-tcs-deviceid">
         gfy45768686trydry
        </camunda:entry>
   		<camunda:entry key="x-tcs-servicename">
        login
        </camunda:entry>
      </camunda:map>
    </camunda:inputParameter>
	
	<camunda:inputParameter name="payload">
	 {"data":{"type":"com.tcs.bfsarch.security.callback.LoginDetails","id":"loginDetails","attributes":{"loginId":"SYSADMIN1","password":"abcd1234","ouid":"G"}}}
	 </camunda:inputParameter>
 
  </camunda:inputOutput>
</camunda:connector>

> This is the code i am using to call it

RuntimeService runtimeService = processEngineRule.getRuntimeService();
TaskService taskService = processEngineRule.getTaskService();

ProcessInstance pi = runtimeService.startProcessInstanceByKey("loginSearchLogout", variables);
Task task = taskService.createTaskQuery().singleResult();

output has no errors:

Dec 28, 2016 1:46:21 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [camunda.cfg.xml]
Dec 28, 2016 1:46:22 PM org.camunda.commons.logging.BaseLogger logInfo
INFO: ENGINE-12003 Plugin ‘ConnectProcessEnginePlugin’ activated on process engine ‘default’
Dec 28, 2016 1:46:22 PM org.camunda.commons.logging.BaseLogger logInfo
INFO: CNCT-01004 Discovered provider for connector id ‘http-connector’ and class ‘org.camunda.connect.httpclient.impl.HttpConnectorImpl’: ‘org.camunda.connect.httpclient.impl.HttpConnectorProviderImpl’
Dec 28, 2016 1:46:22 PM org.camunda.commons.logging.BaseLogger logInfo
INFO: ENGINE-12003 Plugin ‘SpinProcessEnginePlugin’ activated on process engine ‘default’
Dec 28, 2016 1:46:22 PM org.camunda.commons.logging.BaseLogger logInfo
INFO: SPIN-01010 Discovered Spin data format provider: org.camunda.spin.impl.json.jackson.format.JacksonJsonDataFormatProvider[name = application/json]
Dec 28, 2016 1:46:22 PM org.camunda.commons.logging.BaseLogger logInfo
INFO: SPIN-01009 Discovered Spin data format: org.camunda.spin.impl.json.jackson.format.JacksonJsonDataFormat[name = application/json]
Dec 28, 2016 1:46:25 PM org.camunda.commons.logging.BaseLogger logInfo
INFO: ENGINE-03016 Performing database operation ‘create’ on component ‘engine’ with resource ‘org/camunda/bpm/engine/db/create/activiti.h2.create.engine.sql’
Dec 28, 2016 1:46:25 PM org.camunda.commons.logging.BaseLogger logInfo
INFO: ENGINE-03016 Performing database operation ‘create’ on component ‘history’ with resource ‘org/camunda/bpm/engine/db/create/activiti.h2.create.history.sql’
Dec 28, 2016 1:46:25 PM org.camunda.commons.logging.BaseLogger logInfo
INFO: ENGINE-03016 Performing database operation ‘create’ on component ‘identity’ with resource ‘org/camunda/bpm/engine/db/create/activiti.h2.create.identity.sql’
Dec 28, 2016 1:46:25 PM org.camunda.commons.logging.BaseLogger logInfo
INFO: ENGINE-03016 Performing database operation ‘create’ on component ‘case.engine’ with resource ‘org/camunda/bpm/engine/db/create/activiti.h2.create.case.engine.sql’
Dec 28, 2016 1:46:25 PM org.camunda.commons.logging.BaseLogger logInfo
INFO: ENGINE-03016 Performing database operation ‘create’ on component ‘case.history’ with resource ‘org/camunda/bpm/engine/db/create/activiti.h2.create.case.history.sql’
Dec 28, 2016 1:46:25 PM org.camunda.commons.logging.BaseLogger logInfo
INFO: ENGINE-03016 Performing database operation ‘create’ on component ‘decision.engine’ with resource ‘org/camunda/bpm/engine/db/create/activiti.h2.create.decision.engine.sql’
Dec 28, 2016 1:46:25 PM org.camunda.commons.logging.BaseLogger logInfo
INFO: ENGINE-03016 Performing database operation ‘create’ on component ‘decision.history’ with resource ‘org/camunda/bpm/engine/db/create/activiti.h2.create.decision.history.sql’
Dec 28, 2016 1:46:25 PM org.camunda.commons.logging.BaseLogger logInfo
INFO: ENGINE-03067 No history level property found in database
Dec 28, 2016 1:46:25 PM org.camunda.commons.logging.BaseLogger logInfo
INFO: ENGINE-03065 Creating historyLevel property in database for level: HistoryLevelAudit(name=audit, id=2)
Dec 28, 2016 1:46:25 PM org.camunda.commons.logging.BaseLogger logInfo
INFO: ENGINE-00001 Process Engine default created.

can you suggest what can be the problem.