Skip to content

Commit

Permalink
Fix issue 48 (camunda-community-hub#48 )
Browse files Browse the repository at this point in the history
  • Loading branch information
NickTheArchitect authored and Nick James committed Mar 2, 2019
1 parent 224cd75 commit 8d79820
Showing 1 changed file with 19 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

public abstract class CamelServiceCommonImpl implements CamelService {

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

protected ProcessEngine processEngine;
protected CamelContext camelContext;
Expand All @@ -43,15 +43,16 @@ public Object sendTo(String endpointUri, String processVariables) {

@Override
public Object sendTo(String endpointUri, String processVariables,
String correlationId) {
String correlationId) {
Collection<String> vars;
if (processVariables == null) {
vars = new LinkedList<String>();
ActivityExecution execution = Context.getBpmnExecutionContext()
.getExecution();
.getExecution();
final Set<String> variableNames = execution.getVariableNames();
if (variableNames != null) {
for (String variableName : variableNames) {
// Append a ? character to turn off the null check for the variable's value
vars.add(variableName + "?");
}
}
Expand All @@ -64,32 +65,32 @@ public Object sendTo(String endpointUri, String processVariables,
}

private Object sendToInternal(String endpointUri,
Collection<String> variables, String correlationKey) {
ActivityExecution execution = (ActivityExecution) Context
.getBpmnExecutionContext().getExecution();
Collection<String> variables, String correlationKey) {
ActivityExecution execution = Context
.getBpmnExecutionContext().getExecution();
Map<String, Object> variablesToSend = new HashMap<String, Object>();
for (String var : variables) {
Object value;
if (var.endsWith("?")) {
value = execution.getVariable(var.substring(0, var.length() - 1));
} else {
value = execution.getVariable(var);
if (value == null) {
throw new IllegalArgumentException("Process variable '" + var
+ "' no found!");
}
String variableName = var;
if (variableName.endsWith("?")){
// The ? denotes that the value shouldn't be checked for a null value
variableName = var.substring(0, var.length() - 1);
}
Object value = execution.getVariable(variableName);
if ((!var.endsWith("?")) && value == null) {
throw new IllegalArgumentException("Process variable '" + variableName
+ "' not found!");
}
variablesToSend.put(var, value);
variablesToSend.put(variableName, value);
}

log.debug("Sending process variables '{}' as a map to Camel endpoint '{}'",
variablesToSend, endpointUri);
variablesToSend, endpointUri);
ProducerTemplate producerTemplate = camelContext.createProducerTemplate();
String businessKey = execution.getBusinessKey();

Exchange exchange = new DefaultExchange(camelContext);
exchange.setProperty(EXCHANGE_HEADER_PROCESS_INSTANCE_ID,
execution.getProcessInstanceId());
execution.getProcessInstanceId());
if (businessKey != null) {
exchange.setProperty(EXCHANGE_HEADER_BUSINESS_KEY, businessKey);
}
Expand Down

0 comments on commit 8d79820

Please sign in to comment.