cancel
Showing results for 
Search instead for 
Did you mean: 

Return value to service task that delegates to Camel

engywook
Champ in-the-making
Champ in-the-making
Hi,
I have a service task that delegates to Camel, and the service task has 2 outbound flows.  I'd like the decision for which flow to take to be based on the result of the Camel route.  Is there a way to feed that result back to Activiti (i.e. to set a process variable or to some how make the Activiti process aware of the value)?
Here is the relevant part of my bpmn file.

<serviceTask id="task1" name="Service Task" activiti:delegateExpression="${camel}"></serviceTask>
<sequenceFlow id="flow1" name="Can continue" sourceRef="task1" targetRef="receivetask1">
  <conditionExpression xsi:type="tFormalExpression"><![CDATA[${result == true}]]></conditionExpression>
</sequenceFlow>
<sequenceFlow id="flow2" name="Cannot continue" sourceRef="task1" targetRef="endevent1">
  <conditionExpression xsi:type="tFormalExpression"><![CDATA[${result != true}]]></conditionExpression>
</sequenceFlow>
Here's a simplified version of the Camel route.

from("activiti:processName:task1")
  .beanRef("beanName", "methodName") // returned value will be in the exchange body
  .setProperty("result").body();
I'm using Activiti 5.11 and Camel 2.10.3.
Thanks for the help
3 REPLIES 3

trademak
Star Contributor
Star Contributor
Hi,

Yes you can easily copy the Camel payload and message header properties back as process variables.
In your route definition you could add .setBody().properties() at the end to copy all header properties to the Camel body and then they are automatically copied as process variables.
In the Activiti Camel module you can find a route class SampleCamelRoute in the test folder that uses this.

Best regards,

engywook
Champ in-the-making
Champ in-the-making
Thanks for the reply.  In addition to copying the body to the exchange properties, I also needed to include copyVariablesFromProperties=true in the Activiti uri.

from("activitiSmiley TonguerocessName:activityName?copyVariablesFromProperties=true")

jean-charles_la
Champ in-the-making
Champ in-the-making
Hi,
I'm using Activiti 5.17.0.
I have a camel task with a result but I can't get the result back in activiti.
<code>
  <process id="MyProcess" name="MyProcess" isExecutable="true" isClosed="false" processType="None">
    <startEvent id="start" name="start"></startEvent>
    <endEvent id="end" name="end"></endEvent>
    <userTask id="FormulationBesoin" name="FormulationBesoin" startQuantity="1" completionQuantity="1" isForCompensation="false" implementation="##unspecified"></userTask>
    <sequenceFlow id="flow1" sourceRef="start" targetRef="FormulationBesoin"></sequenceFlow>
    <userTask id="EngagementClient" name="EngagementClient" startQuantity="1" completionQuantity="1" isForCompensation="false" implementation="##unspecified"></userTask>
    <serviceTask id="ElaborationProposition" name="ElaborationProposition" activiti:type="camel"></serviceTask>
    <sequenceFlow id="flow2" sourceRef="FormulationBesoin" targetRef="ElaborationProposition"></sequenceFlow>
    <userTask id="AccordClient" name="AccordClient" startQuantity="1" completionQuantity="1" isForCompensation="false" implementation="##unspecified"></userTask>
    <sequenceFlow id="flow4" sourceRef="AccordClient" targetRef="EngagementClient"></sequenceFlow>
    <sequenceFlow id="flow3" sourceRef="ElaborationProposition" targetRef="AccordClient"></sequenceFlow>
    <sequenceFlow id="flow6" sourceRef="EngagementClient" targetRef="end"></sequenceFlow>
  </process>
</code>
<code>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

<bean id="dataSource" class="org.springframework.jdbc.datasource.SimpleDriverDataSource">
  <property name="driverClass" value="org.h2.Driver" />
  <property name="url" value="jdbc:h2:mem:activiti;DB_CLOSE_DELAY=1000" />
  <property name="username" value="sa" />
  <property name="password" value="" />
</bean>


<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
  <property name="dataSource" ref="dataSource" />
</bean>

<bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
  <property name="dataSource" ref="dataSource" />
  <property name="transactionManager" ref="transactionManager" />
  <property name="databaseSchemaUpdate" value="true" />
  <property name="jobExecutorActivate" value="false" />
</bean>

<bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">
  <property name="processEngineConfiguration" ref="processEngineConfiguration" />
</bean>

<bean id="activitiRule" class="org.activiti.engine.test.ActivitiRule">
  <property name="processEngine" ref="processEngine" />
</bean>


<bean id="repositoryService" factory-bean="processEngine" factory-method="getRepositoryService" />
<bean id="runtimeService" factory-bean="processEngine" factory-method="getRuntimeService" />
<bean id="taskService" factory-bean="processEngine" factory-method="getTaskService" />
<bean id="historyService" factory-bean="processEngine" factory-method="getHistoryService" />
<bean id="managementService" factory-bean="processEngine" factory-method="getManagementService" />

<camel:camelContext id="camelContext">
<camel:route id="route1">
  <camel:from
    uri="activiti:ElaborationProposition?copyVariablesFromProperties=true" />
  <camel:log message="CAMEL : ElaborationProposition" />  
  <camelSmiley Tonguerocess ref="HelloWorldProcessor" />   
</camel:route>
<bean id="HelloWorldProcessor" class="com.company.activiti.camel.processor.HelloWorldProcessor" />
</beans>
</code>
<java>
public class HelloWorldProcessor implements Processor {
private final static Logger LOGGER = LoggerFactory
   .getLogger("HelloWorldProcessor");
@Override
public void process(Exchange exchange) throws Exception {
  LOGGER.info("Hello World ! - Le message transmis est : {}",
    exchange.getProperty("message"));
  exchange.setProperty("result", "response from camel");
}
}
</java>
Thanks for help.
Best regards,
jcharles.