package org.camunda.bpm.camel.common;

import org.apache.camel.CamelContext;
import org.apache.camel.ExchangePattern;
import org.apache.camel.ProducerTemplate;
import org.camunda.bpm.engine.ProcessEngine;
import org.camunda.bpm.engine.impl.pvm.delegate.ActivityExecution;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Required;

public abstract class CamelServiceCommonImpl implements CamelService {

  final Logger log = LoggerFactory.getLogger(this.getClass());

  protected ProcessEngine processEngine;
  protected CamelContext camelContext;

  @Override
  public Object sendTo(ActivityExecution execution, String uri, String processVariableForMessageBody) {
    log.debug("Process execution:" + execution.toString());

    log.debug("Sending process variable '{}' as body of message to Camel endpoint '{}'", processVariableForMessageBody, uri);

    ProducerTemplate producerTemplate = camelContext.createProducerTemplate();

    // FIXME: Map<String, Object> processVariables = execution.getVariables();

    Object messageBody = execution.getVariable(processVariableForMessageBody);

    Object routeResult = producerTemplate.sendBodyAndProperty(uri, ExchangePattern.InOut, messageBody,
      CamundaBpmProducer.PROCESS_ID_PROPERTY, execution.getProcessInstanceId());

    return routeResult;
  }

  @Required
  public abstract void setProcessEngine(ProcessEngine processEngine);

  @Required
  public abstract void setCamelContext(CamelContext camelContext);
}

@@ -32,16 +32,65 @@
 ommon;%0A%0A
+import java.util.HashMap;%0Aimport java.util.Map;%0A%0A
 import o
@@ -1118,21 +1118,131 @@
 ();%0A
+    
 %0A    
-Object m
+Map%3CString, Object%3E processVariables = new HashMap%3CString, Object%3E();%0A    processVariables.put(processVariableForM
 essa
@@ -1247,18 +1247,17 @@
 sageBody
- =
+,
  executi
@@ -1301,16 +1301,17 @@
 ageBody)
+)
 ;%0A%0A    O
@@ -1399,19 +1399,24 @@
 ut, 
-messageBody
+processVariables
 ,%0A  

send process variable wrapped in map, to support send-receive round trip