How to trigger execution from rest call ?

3,273 views
Skip to first unread message

Tom Connolly

unread,
Mar 15, 2014, 7:49:21 AM3/15/14
to camunda-...@googlegroups.com
Hi All

I'm attempting to signal a receive task from a rest call.
In my unit test I successfully perform the following actions i.e. receive a message and correlate;

Execution execution = runtimeService.createExecutionQuery()
                .processInstanceId(processInstance.getId()).activityId("Receive_Task").singleResult();
Map<String, Object> processVars = new HashMap<String, Object>();
processVars.put("accepted", "No");
processVars.put("correlationId", "12349");
runtimeService.signal(execution.getId(), processVars);   

The documentation describes the rest call to use
http://docs.camunda.org/latest/api-references/rest/#execution-trigger-execution

I invoke the following query to get the id (I'd like a recommendation on how I should be doing this...)
http://localhost:8080/engine-rest/engine/default/history/activity-instance?activityId=Receive_Task

Using the returned {id} I execute
http://localhost:8080/engine-rest/engine/default/execution/6dca9956-dd28-11e3-984c-a41731bf77d7/signal
with Content-Type : application/json
{ "accepted" : "No", "correlationId" : "12349" }

The receive task is followed by a XOR gateway with an expression ${accepted == "No"} on a sequence flow, which works fine in the unit test.
However when deployed I get the error
  1. {
  2.    "type": "RestException",
  3.    "message": "Cannot signal execution 6dca9956-dd28-11e3-984c-a41731bf77d7: Unknown property used in expression: ${accepted == "No"}. Cause: Cannot resolve identifier 'accepted'"
  4. }
Any ideas on how I should be calling from REST and why the error above?
Any help appreciated.

Regards
    Tom

webcyberrob

unread,
Mar 16, 2014, 1:24:42 AM3/16/14
to camunda-...@googlegroups.com
Hi Tom,

rather than use the two calls, have you tried using the message REST API? The message API performs the correlation for you.


regards

Rob

Tom Connolly

unread,
Mar 16, 2014, 1:59:46 AM3/16/14
to camunda-...@googlegroups.com
Hi Rob

Yes, but I could see how to add a message to the ReceiveTask from the modeller. I needed an event defined in order to invoke.
I did hack around a bit, and add a messageRef to the source of the ReceiveTask,
    :
  <bpmn2:message id="Message_1" name="ReceiveTaskMessage"/>
    :
  <bpmn2:receiveTask id="Blah_Response" name="blah blah" messageRef="Message_1">
    :

Note I tried without messageRef but this failed...

Using the following body (tried different permutations as I'm not sure I fully understand what's happening...)

{"messageName" : "ReceiveTaskMessage",
"businessKey" : "<BusinessKey>",
"correlationKeys" : {
    "correlationId" : {"correlationId" : "12345", "type": "String"}
},
"processVariables" : {
    "accepted" : {"accepted" : "No", "type": "String"},
    "correlationId" : {"correlationId" : "12345", "type": "String"}
}}

The only example I could find was inter-process-communication-ws. Similar to this example I could expose a custom service but struggling with how Camunda does this.

Regards
    Tom.

webcyberrob

unread,
Mar 16, 2014, 3:08:49 AM3/16/14
to camunda-...@googlegroups.com
Hi Tom,

I put a simple example up on Camunda Share, UTRL below;


This is a scripted example, hence you can copy the xml down and run it...

To start this using the Rest API, my Rest API looks like;


The body is;

{"variables": 
    {},
 "businessKey" : "AAA001"
}

Hence I have a businessKey AAA001 which will be used as a correlation key for the inbound event.

To signal the inbound message, my Rest API looks like;


The body is;

{"messageName" : "QualificationResultMsg",
"businessKey" : "AAA001",
"correlationKeys" : {
},
"processVariables" : {
    "Accepted" : {"value" : "No", "type": "String"}
}}

Hence the business key is sufficient to resolve correlation and thus I dont have any additional correlation keys. In addition, the Accepetd parameter gets instantiated as a process variable and this is tested on the flows out of the XOR gate. If I change the value of accepted, I can trigger the different flows. Given I use a script task, I see either Yes! or No! printed on the Java console.

Note to setup the event configuration in the receive task, I had to edit the native XML rather than use the visual modeller...


regards

Rob

On Saturday, March 15, 2014 10:49:21 PM UTC+11, Tom Connolly wrote:

Tom Connolly

unread,
Mar 16, 2014, 6:08:02 AM3/16/14
to camunda-...@googlegroups.com
Hi Rob

Excellent example, thanks for the help.
Finally got the process working end to end.

I was not using the businessKey and process variables correctly!
I had already added the message & messageRef manually but I was loathe to manually edit it! Also thanks for confirming it is necessary. 

Regards
    Tom.

Christopher Campbell

unread,
May 27, 2014, 8:31:39 AM5/27/14
to camunda-...@googlegroups.com
Hi webcyberrob,

I think this is Topic related so I am posting my question as a reply to you answer. 

I am running a standalone tomcat camunda Version: v7.1.0-Final.

I have a process instance running with an intermediate catch event waiting for an "ordershipped" msg. 

The process instance BusinessKey==Somekey_89, and the following process variables are set orderId=89,orderNumber=ABCDEF123

When I execute a POST call on: 
With a json-format request payload:
{
        "messageName":"ordershipped",
        "businessKey":"Somekey_89",
        "correlationKeys":{
                "orderId":{"value":"89","type":"String"},
                "orderNumber":{"value":"ABCDEF123","type":"String"}
        },
        "processVariables":{
                "orderStatus":{"name":"orderStatus","type":"String","value":"shipping"}
        }
}
I get:
  1. {
  2. "type": "RestException",
  3. "message": "org.camunda.bpm.engine.MismatchingMessageCorrelationException: Cannot correlate message ordershipped: No process definition or execution matches the parameters"
  4. }

Any ideas what is wrong?
P.S. I am using a REST Client plugin which works fine with other REST-API calls to the camunda rest-engine. 

cheers in advance...

BR,
Chris 

webcyberrob

unread,
May 27, 2014, 10:05:05 AM5/27/14
to camunda-...@googlegroups.com
Hi Chris,

At face value this looks reasonable. Hence my first question; Your process looks like a form attached to the start event, followed by a user task with its own form. Hence for a process instance to be waiting for your event, you would have to initiate the process with the first form post, followed by completing the first user task. Hence have you completed the first user task prior to generating your event?

regards

Rob

Christopher Campbell

unread,
May 27, 2014, 12:10:58 PM5/27/14
to camunda-...@googlegroups.com
Hi webcyberrob,

thanks for the reply and sorry for the lack of detail ("myopia" there for you).
Yes the two prior process "entities" executed correctly - both via REST-API calls.
The start event via the /process-definition/key/{key}/submit-form  plus the appropriate json variables in the request payload. The user-task executed fine too.

Camunda Cockpit shows the process waiting patiently at the "Order Shipped" intermediate event with all process variables set as they should be...

I can't see anything wrong with the process or the rest-call (currently).

What irks me is that it worked once in previous testing, the only difference being that the businessKey was a tad longer of the format <someName>-<some-2digit-id>-<datetime> instead of <someName>_<someId>, but that shouldn't matter or?

BR
Chris

Christian Lipphardt

unread,
May 27, 2014, 1:04:12 PM5/27/14
to camunda-...@googlegroups.com
Hi Chris,

Did you try to correlate the message just with the business key without specifiying the correlationKeys?

Cheers,
Christian


--
You received this message because you are subscribed to the Google Groups "camunda BPM users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to camunda-bpm-us...@googlegroups.com.
To post to this group, send email to camunda-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/camunda-bpm-users/fbe06254-b6f4-4b31-9bb7-21edcb3e9932%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Christopher Campbell

unread,
May 27, 2014, 3:29:22 PM5/27/14
to camunda-...@googlegroups.com
Hi Christian,

yes I used the json message format mentioned in my initial posing above. 
I used two process variables in addition to the business key to correlate things.

P.S. I also tried it with the business key alone to no avail.

Thanks,

Christopher Campbell

unread,
May 28, 2014, 5:46:32 AM5/28/14
to camunda-...@googlegroups.com
Hi eveyone,

My problem is fixed and things now work as they were expected to.
I haven't verified this yet but the problem seems to be as follows:

1) My BPMN Process (http://camunda.org/share/#/process/968c76d9-2bbd-4bb8-b9c6-26b81814f2b6) had an error at the exclusive gateway where i fork based on the value orderStatus process variable.
    My Statement was ${orderStatus == shipping} which must be ${orderStatus == "shipping"}. Once I changed this and loaded the process on a fresh database things worked again.

2) This probably didn't bother the camunda-engine until I sent the first signal to one of the process instances waiting at the "Order Shipped" intermediate event point.
    (Note: till that point none of the process instances had executed further than the "Order Shipped" event point)

3) Once the first process instance "token" reached the "Confirm Fulfillment" user task - situated in sequence directly after the "Order Shipped" event point -  
  (and after I tried to complete that user task in the camunda tasklist web-interface) things stopped working.

From this I am guessing the error in the process bpmn at the exclusie gateway mucks up the camunda-engine execution for all other process instances (can someone with more knowledge of camunda's inner workings verify this?) 

NOTE: I was tail'ing the tomcat logfiles and did see an exception being thrown: "WARNING: org.camunda.bpm.engine.rest.exception.RestException: org.camunda.bpm.engine.MismatchingMessageCorrelationException: Cannot correlate message ordershipped: No process definition or execution matches the parameters" but this didn't point me to the problem.   

Like I said I am just guessing. 

Thanks to webcyberrob and Christian for their replys.

BR,
Chris
Reply all
Reply to author
Forward
0 new messages