You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by dm...@apache.org on 2018/11/30 10:43:04 UTC

[camel] branch camel-2.23.x updated (478a99f -> e58bb7c)

This is an automated email from the ASF dual-hosted git repository.

dmvolod pushed a change to branch camel-2.23.x
in repository https://gitbox.apache.org/repos/asf/camel.git.


    from 478a99f  Add version 2.23.0 to XML schema files
     new a0fc18b  CAMEL-12964: Initial import of jBPM CamelWIH and Command.
     new 2dace2c  CamelCommand splitted in a separate command for Camel DeploymentContext and GlobalContext. WorkItemHandler can now be configured with default route. WIH supports both InOut and InOnly MEPs. Added tests that use a test CamelContext and test-routes to verify behaviour on Exceptions.
     new 734c2ce  Replaced hard-coded strings with constants. Changed WorkItem parameter names to be inline with other WorkItemHandlers.
     new 66f3c4e  Removed TODO comments.
     new e58bb7c  CAMEL-12964: Fix CS

The 5 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 components/camel-jbpm/pom.xml                      |  27 +++
 .../apache/camel/component/jbpm/JBPMConstants.java |   8 +
 .../jbpm/server/CamelKieServerExtension.java       |  32 ++--
 .../jbpm/workitem/AbstractCamelCommand.java        |  81 ++++++++
 .../workitem/AbstractCamelWorkItemHandler.java     | 152 +++++++++++++++
 .../workitem/DeploymentContextCamelCommand.java    |  71 +++++++
 .../jbpm/workitem/GlobalContextCamelCommand.java   |  56 ++++++
 .../jbpm/workitem/InOnlyCamelWorkItemHandler.java  | 106 +++++++++++
 .../jbpm/workitem/InOutCamelWorkItemHandler.java   | 116 ++++++++++++
 .../jbpm/JBPMComponentIntegrationTest.java         |   1 -
 .../CamelWorkItemHandlerIntegrationTests.java      | 204 +++++++++++++++++++++
 .../DeploymentContextCamelCommandTest.java         |  95 ++++++++++
 .../workitem/GlobalContextCamelCommandTest.java    |  95 ++++++++++
 .../workitem/InOnlyCamelWorkItemHandlerTest.java   |  97 ++++++++++
 .../workitem/InOutCamelWorkItemHandlerTest.java    | 148 +++++++++++++++
 15 files changed, 1272 insertions(+), 17 deletions(-)
 create mode 100644 components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/AbstractCamelCommand.java
 create mode 100644 components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/AbstractCamelWorkItemHandler.java
 create mode 100644 components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/DeploymentContextCamelCommand.java
 create mode 100644 components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/GlobalContextCamelCommand.java
 create mode 100644 components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/InOnlyCamelWorkItemHandler.java
 create mode 100644 components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/InOutCamelWorkItemHandler.java
 create mode 100644 components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/workitem/CamelWorkItemHandlerIntegrationTests.java
 create mode 100644 components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/workitem/DeploymentContextCamelCommandTest.java
 create mode 100644 components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/workitem/GlobalContextCamelCommandTest.java
 create mode 100644 components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/workitem/InOnlyCamelWorkItemHandlerTest.java
 create mode 100644 components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/workitem/InOutCamelWorkItemHandlerTest.java


[camel] 04/05: Removed TODO comments.

Posted by dm...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

dmvolod pushed a commit to branch camel-2.23.x
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 66f3c4e38762f9f8d7d3e1b0faba7a58f67b756b
Author: Duncan Doyle <Du...@gmail.com>
AuthorDate: Fri Nov 30 09:34:22 2018 +0100

    Removed TODO comments.
---
 .../org/apache/camel/component/jbpm/workitem/AbstractCamelCommand.java | 3 +--
 .../camel/component/jbpm/workitem/AbstractCamelWorkItemHandler.java    | 2 --
 .../camel/component/jbpm/workitem/GlobalContextCamelCommand.java       | 1 -
 3 files changed, 1 insertion(+), 5 deletions(-)

diff --git a/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/AbstractCamelCommand.java b/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/AbstractCamelCommand.java
index adfd413..a26aa32 100644
--- a/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/AbstractCamelCommand.java
+++ b/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/AbstractCamelCommand.java
@@ -56,8 +56,7 @@ public abstract class AbstractCamelCommand implements Command,
     @Override
     public ExecutionResults execute(CommandContext ctx) throws Exception {
         
-        
-    	WorkItem workItem = (WorkItem) ctx.getData("workItem");
+        WorkItem workItem = (WorkItem) ctx.getData("workItem");
     	
     	String camelEndpointId = (String) workItem.getParameter(JBPMConstants.CAMEL_ENDPOINT_ID_WI_PARAM);
 		
diff --git a/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/AbstractCamelWorkItemHandler.java b/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/AbstractCamelWorkItemHandler.java
index 743393c..23d7a35 100644
--- a/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/AbstractCamelWorkItemHandler.java
+++ b/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/AbstractCamelWorkItemHandler.java
@@ -69,7 +69,6 @@ public abstract class AbstractCamelWorkItemHandler extends AbstractLogOrThrowWor
 
     public AbstractCamelWorkItemHandler(String camelEndointId) {
         CamelContext globalCamelContext = (CamelContext) ServiceRegistry.get().service(JBPMConstants.GLOBAL_CAMEL_CONTEXT_SERVICE_KEY);
-        // TODO: Should we allow to set the maximumCacheSize on the producer?
         this.producerTemplate = globalCamelContext.createProducerTemplate();
         this.camelEndpointId = camelEndointId;
     }
@@ -85,7 +84,6 @@ public abstract class AbstractCamelWorkItemHandler extends AbstractLogOrThrowWor
     public AbstractCamelWorkItemHandler(RuntimeManager runtimeManager, String camelEndpointId) {
         String runtimeCamelContextKey = runtimeManager.getIdentifier() + JBPMConstants.DEPLOYMENT_CAMEL_CONTEXT_SERVICE_KEY_POSTFIX;
         CamelContext runtimeCamelContext = (CamelContext) ServiceRegistry.get().service(runtimeCamelContextKey);
-        // TODO: Should we allow to set the maximumCacheSize on the producer?
         this.producerTemplate = runtimeCamelContext.createProducerTemplate();
         this.camelEndpointId = camelEndpointId;
     }
diff --git a/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/GlobalContextCamelCommand.java b/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/GlobalContextCamelCommand.java
index 10950b3..e129a12 100644
--- a/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/GlobalContextCamelCommand.java
+++ b/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/GlobalContextCamelCommand.java
@@ -36,7 +36,6 @@ public class GlobalContextCamelCommand extends AbstractCamelCommand {
     
     public GlobalContextCamelCommand() {
         CamelContext globalCamelContext = (CamelContext) ServiceRegistry.get().service(JBPMConstants.GLOBAL_CAMEL_CONTEXT_SERVICE_KEY);
-        // TODO: Should we allow to set the maximumCacheSize on the producer?
         this.globalContextProducerTemplate = globalCamelContext.createProducerTemplate();
     }
     


[camel] 03/05: Replaced hard-coded strings with constants. Changed WorkItem parameter names to be inline with other WorkItemHandlers.

Posted by dm...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

dmvolod pushed a commit to branch camel-2.23.x
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 734c2ce66cc0ad25b092570bf9234b7e4824a2d8
Author: Duncan Doyle <Du...@gmail.com>
AuthorDate: Fri Nov 30 09:24:45 2018 +0100

    Replaced hard-coded strings with constants. Changed WorkItem parameter names to be inline with other WorkItemHandlers.
---
 .../apache/camel/component/jbpm/JBPMConstants.java |  8 +++++
 .../jbpm/server/CamelKieServerExtension.java       |  5 ++--
 .../jbpm/workitem/AbstractCamelCommand.java        | 15 ++++------
 .../workitem/AbstractCamelWorkItemHandler.java     | 35 +++++++++++-----------
 .../workitem/DeploymentContextCamelCommand.java    |  5 ++--
 .../jbpm/workitem/GlobalContextCamelCommand.java   |  5 ++--
 .../jbpm/workitem/InOnlyCamelWorkItemHandler.java  |  7 +++--
 .../jbpm/workitem/InOutCamelWorkItemHandler.java   | 14 ++++-----
 .../CamelWorkItemHandlerIntegrationTests.java      | 33 ++++++++++----------
 .../DeploymentContextCamelCommandTest.java         |  9 +++---
 .../workitem/GlobalContextCamelCommandTest.java    |  9 +++---
 .../workitem/InOnlyCamelWorkItemHandlerTest.java   |  5 ++--
 .../workitem/InOutCamelWorkItemHandlerTest.java    | 13 ++++----
 13 files changed, 85 insertions(+), 78 deletions(-)

diff --git a/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/JBPMConstants.java b/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/JBPMConstants.java
index 8341cfd..94ff0ca 100644
--- a/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/JBPMConstants.java
+++ b/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/JBPMConstants.java
@@ -43,4 +43,12 @@ public interface JBPMConstants {
     String JBPM_TASK_EVENT_LISTENER = "task";
     String JBPM_CASE_EVENT_LISTENER = "case";
     String JBPM_EVENT_EMITTER = "emitter";
+    
+    String GLOBAL_CAMEL_CONTEXT_SERVICE_KEY = "GlobalCamelService";
+    String DEPLOYMENT_CAMEL_CONTEXT_SERVICE_KEY_POSTFIX = "_CamelService";
+    String CAMEL_ENDPOINT_ID_WI_PARAM = "CamelEndpointId";
+    String RESPONSE_WI_PARAM = "Response";
+    String MESSAGE_WI_PARAM = "Message";
+
+    
 }
diff --git a/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/server/CamelKieServerExtension.java b/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/server/CamelKieServerExtension.java
index 0e297be..659a498 100644
--- a/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/server/CamelKieServerExtension.java
+++ b/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/server/CamelKieServerExtension.java
@@ -23,6 +23,7 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.camel.component.jbpm.JBPMConstants;
 import org.apache.camel.impl.DefaultCamelContext;
 import org.apache.camel.model.FromDefinition;
 import org.apache.camel.model.RouteDefinition;
@@ -85,7 +86,7 @@ public class CamelKieServerExtension implements KieServerExtension {
             }
         }
 
-        ServiceRegistry.get().register("GlobalCamelService", this.camel);
+        ServiceRegistry.get().register(JBPMConstants.GLOBAL_CAMEL_CONTEXT_SERVICE_KEY, this.camel);
     }
 
     @Override
@@ -117,7 +118,7 @@ public class CamelKieServerExtension implements KieServerExtension {
                 context.start();
                 camelContexts.put(id, context);
 
-                ServiceRegistry.get().register(id + "_CamelService", context);
+                ServiceRegistry.get().register(id + JBPMConstants.DEPLOYMENT_CAMEL_CONTEXT_SERVICE_KEY_POSTFIX, context);
 
             }
         } catch (Exception e) {
diff --git a/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/AbstractCamelCommand.java b/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/AbstractCamelCommand.java
index 3cb1ee4..adfd413 100644
--- a/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/AbstractCamelCommand.java
+++ b/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/AbstractCamelCommand.java
@@ -22,6 +22,7 @@ import org.apache.camel.Exchange;
 import org.apache.camel.Message;
 import org.apache.camel.ProducerTemplate;
 import org.apache.camel.builder.ExchangeBuilder;
+import org.apache.camel.component.jbpm.JBPMConstants;
 import org.jbpm.services.api.service.ServiceRegistry;
 import org.kie.api.executor.Command;
 import org.kie.api.executor.CommandContext;
@@ -40,17 +41,13 @@ import org.slf4j.LoggerFactory;
  * {link WorkItem} via the <code>camel-endpoint-id</code> parameter, this {@link Command} will send the {@link WorkItem} to 
  * the Camel URI <code>direct://myCamelEndpoint</code>.  
  * <p/>
- * The body of the result {@link Message} of the invocation is returned via the <code>response</code> parameter. Access to the raw response 
- * {@link Message} is provided via the <code>message</code> parameter. This gives the user access to more advanced fields like message headers 
+ * The body of the result {@link Message} of the invocation is returned via the <code>Response</code> parameter. Access to the raw response 
+ * {@link Message} is provided via the <code>Message</code> parameter. This gives the user access to more advanced fields like message headers 
  * and attachments.
  */
 public abstract class AbstractCamelCommand implements Command,
                                           Cacheable {
 
-	private static final String CAMEL_ENDPOINT_ID_PARAM = "camel-endpoint-id";
-	private static final String RESPONSE_PARAM = "response";
-	private static final String MESSAGE_PARAM = "out-headers";
-	
     private static final Logger logger = LoggerFactory.getLogger(AbstractCamelCommand.class);
 
 	public AbstractCamelCommand() {
@@ -62,7 +59,7 @@ public abstract class AbstractCamelCommand implements Command,
         
     	WorkItem workItem = (WorkItem) ctx.getData("workItem");
     	
-    	String camelEndpointId = (String) workItem.getParameter(CAMEL_ENDPOINT_ID_PARAM);
+    	String camelEndpointId = (String) workItem.getParameter(JBPMConstants.CAMEL_ENDPOINT_ID_WI_PARAM);
 		
 		// We only support direct. We don't need to support more, as direct simply gives us the entrypoint into the actual Camel Routes.
 		String camelUri = "direct://" + camelEndpointId;
@@ -78,8 +75,8 @@ public abstract class AbstractCamelCommand implements Command,
 		
 		ExecutionResults results = new ExecutionResults();
 		Object response = outMessage.getBody();
-		results.setData(RESPONSE_PARAM, response);
-		results.setData(MESSAGE_PARAM, outMessage);
+		results.setData(JBPMConstants.RESPONSE_WI_PARAM, response);
+		results.setData(JBPMConstants.MESSAGE_WI_PARAM, outMessage);
     	
         return results;
     }
diff --git a/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/AbstractCamelWorkItemHandler.java b/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/AbstractCamelWorkItemHandler.java
index db88e70..743393c 100644
--- a/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/AbstractCamelWorkItemHandler.java
+++ b/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/AbstractCamelWorkItemHandler.java
@@ -21,6 +21,7 @@ import org.apache.camel.CamelContext;
 import org.apache.camel.Exchange;
 import org.apache.camel.Message;
 import org.apache.camel.ProducerTemplate;
+import org.apache.camel.component.jbpm.JBPMConstants;
 import org.jbpm.process.workitem.core.AbstractLogOrThrowWorkItemHandler;
 import org.jbpm.services.api.service.ServiceRegistry;
 import org.kie.api.runtime.manager.RuntimeManager;
@@ -35,29 +36,24 @@ import org.slf4j.LoggerFactory;
  * Camel jBPM {@link WorkItemHandler} which allows to call Camel routes with a <code>direct</code> endpoint.
  * <p/>
  * The handler passes the {@WorkItem} to the route that has a consumer on the endpoint-id that can be passed with the
- * <code>camel-endpoint-id</code>{@link WorkItem} parameter. E.g. when a the value "myCamelEndpoint" is passed to the {link WorkItem} via
- * the <code>camel-endpoint-id</code> parameter, this command will send the {@link WorkItem} to the Camel URI
+ * <code>CamelEndpointId</code>{@link WorkItem} parameter. E.g. when a the value "myCamelEndpoint" is passed to the {link WorkItem} via
+ * the <code>CamelEndpointId</code> parameter, this command will send the {@link WorkItem} to the Camel URI
  * <code>direct://myCamelEndpoint</code>.
  * <p/>
- * The body of the result {@link Message} of the invocation is returned via the <code>response</code> parameter. Access to the raw response
- * {@link Message} is provided via the <code>message</code> parameter. This gives the user access to more advanced fields like message
+ * The body of the result {@link Message} of the invocation is returned via the <code>Response</code> parameter. Access to the raw response
+ * {@link Message} is provided via the <code>Message</code> parameter. This gives the user access to more advanced fields like message
  * headers and attachments.
  * <p/>
  * This handler can be constructed in multiple ways. When you don't pass a {@link RuntimeManager} to the constructor, the handler will try
  * to find the global KIE {@link CamelContext} from the <code>jBPM</code> {@link ServiceRegistry}. When the {@link RuntimeManager} is passed
  * to the constructor, the handler will retrieve and use the {@link CamelContext} bound to the {@link RuntimeManage} from the
- * {@link ServiceRegistry}. When a <code>camel-endpoint-id</code> is passed to the constructor, the handler will send all requests to the
- * Camel route that is consuming from that endpoint, unless the endpoint is overridden by passing a the <code>camel-endpoint-id</code> in
+ * {@link ServiceRegistry}. When a <code>CamelEndpointId</code> is passed to the constructor, the handler will send all requests to the
+ * Camel route that is consuming from that endpoint, unless the endpoint is overridden by passing a the <code>CamelEndpointId</code> in
  * the {@link WorkItem} parameters.
  * 
  */
 public abstract class AbstractCamelWorkItemHandler extends AbstractLogOrThrowWorkItemHandler implements Cacheable {
 
-    private static final String GLOBAL_CAMEL_CONTEXT_SERVICE_KEY = "GlobalCamelService";
-    private static final String RUNTIME_CAMEL_CONTEXT_SERVICE_POSTFIX = "_CamelService";
-
-    private static final String CAMEL_ENDPOINT_ID_PARAM = "camel-endpoint-id";
-
     private static Logger logger = LoggerFactory.getLogger(AbstractCamelWorkItemHandler.class);
 
     private final ProducerTemplate producerTemplate;
@@ -72,7 +68,7 @@ public abstract class AbstractCamelWorkItemHandler extends AbstractLogOrThrowWor
     }
 
     public AbstractCamelWorkItemHandler(String camelEndointId) {
-        CamelContext globalCamelContext = (CamelContext) ServiceRegistry.get().service(GLOBAL_CAMEL_CONTEXT_SERVICE_KEY);
+        CamelContext globalCamelContext = (CamelContext) ServiceRegistry.get().service(JBPMConstants.GLOBAL_CAMEL_CONTEXT_SERVICE_KEY);
         // TODO: Should we allow to set the maximumCacheSize on the producer?
         this.producerTemplate = globalCamelContext.createProducerTemplate();
         this.camelEndpointId = camelEndointId;
@@ -87,7 +83,7 @@ public abstract class AbstractCamelWorkItemHandler extends AbstractLogOrThrowWor
     }
 
     public AbstractCamelWorkItemHandler(RuntimeManager runtimeManager, String camelEndpointId) {
-        String runtimeCamelContextKey = runtimeManager.getIdentifier() + RUNTIME_CAMEL_CONTEXT_SERVICE_POSTFIX;
+        String runtimeCamelContextKey = runtimeManager.getIdentifier() + JBPMConstants.DEPLOYMENT_CAMEL_CONTEXT_SERVICE_KEY_POSTFIX;
         CamelContext runtimeCamelContext = (CamelContext) ServiceRegistry.get().service(runtimeCamelContextKey);
         // TODO: Should we allow to set the maximumCacheSize on the producer?
         this.producerTemplate = runtimeCamelContext.createProducerTemplate();
@@ -115,13 +111,15 @@ public abstract class AbstractCamelWorkItemHandler extends AbstractLogOrThrowWor
         }
     }
 
-    private String getCamelEndpointId(WorkItem workItem) {
-        String workItemCamelEndpointId = (String) workItem.getParameter(CAMEL_ENDPOINT_ID_PARAM);
+    protected String getCamelEndpointId(WorkItem workItem) {
+        String workItemCamelEndpointId = (String) workItem.getParameter(JBPMConstants.CAMEL_ENDPOINT_ID_WI_PARAM);
 
         if (camelEndpointId != null && !camelEndpointId.isEmpty()) {
             if (workItemCamelEndpointId != null && !workItemCamelEndpointId.isEmpty()) {
                 logger.debug(
-                        "The Camel Endpoint ID has been set on both the WorkItemHanlder and WorkItem. The camel-endpoint-id configured on the WorkItem overrides the global configuation.");
+                        "The Camel Endpoint ID has been set on both the WorkItemHanlder and WorkItem. The '"
+                                + JBPMConstants.CAMEL_ENDPOINT_ID_WI_PARAM
+                                + "' configured on the WorkItem overrides the global configuation.");
             } else {
                 workItemCamelEndpointId = camelEndpointId;
             }
@@ -129,8 +127,9 @@ public abstract class AbstractCamelWorkItemHandler extends AbstractLogOrThrowWor
 
         if (workItemCamelEndpointId == null || workItemCamelEndpointId.isEmpty()) {
             throw new IllegalArgumentException(
-                    "No Camel Endpoint ID specified. Please configure the 'camel-endpoint-id' in either the constructor of this WorkItemHandler, or pass it via the "
-                            + CAMEL_ENDPOINT_ID_PARAM + "' WorkItem parameter.");
+                    "No Camel Endpoint ID specified. Please configure the '" + JBPMConstants.CAMEL_ENDPOINT_ID_WI_PARAM
+                            + "' in either the constructor of this WorkItemHandler, or pass it via the "
+                            + JBPMConstants.CAMEL_ENDPOINT_ID_WI_PARAM + "' WorkItem parameter.");
         }
         return workItemCamelEndpointId;
     }
diff --git a/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/DeploymentContextCamelCommand.java b/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/DeploymentContextCamelCommand.java
index e3d3fd1..009b909 100644
--- a/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/DeploymentContextCamelCommand.java
+++ b/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/DeploymentContextCamelCommand.java
@@ -22,6 +22,7 @@ import java.util.concurrent.ConcurrentHashMap;
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.ProducerTemplate;
+import org.apache.camel.component.jbpm.JBPMConstants;
 import org.jbpm.services.api.service.ServiceRegistry;
 import org.kie.api.executor.CommandContext;
 import org.slf4j.Logger;
@@ -32,8 +33,6 @@ import org.slf4j.LoggerFactory;
  */
 public class DeploymentContextCamelCommand extends AbstractCamelCommand {
 
-    private static final String RUNTIME_CAMEL_CONTEXT_SERVICE_POSTFIX = "_CamelService";
-
     private final Map<String, ProducerTemplate> templates = new ConcurrentHashMap<>();
 
     private static final Logger logger = LoggerFactory.getLogger(DeploymentContextCamelCommand.class);
@@ -48,7 +47,7 @@ public class DeploymentContextCamelCommand extends AbstractCamelCommand {
                 template = templates.get(deploymentId);
                 if (template == null) {
                     CamelContext deploymentCamelContext = (CamelContext) ServiceRegistry.get()
-                            .service(deploymentId + RUNTIME_CAMEL_CONTEXT_SERVICE_POSTFIX);
+                            .service(deploymentId + JBPMConstants.DEPLOYMENT_CAMEL_CONTEXT_SERVICE_KEY_POSTFIX);
                     template = deploymentCamelContext.createProducerTemplate();
                     templates.put(deploymentId, template);
                 }
diff --git a/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/GlobalContextCamelCommand.java b/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/GlobalContextCamelCommand.java
index 974b896..10950b3 100644
--- a/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/GlobalContextCamelCommand.java
+++ b/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/GlobalContextCamelCommand.java
@@ -19,6 +19,7 @@ package org.apache.camel.component.jbpm.workitem;
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.ProducerTemplate;
+import org.apache.camel.component.jbpm.JBPMConstants;
 import org.jbpm.services.api.service.ServiceRegistry;
 import org.kie.api.executor.CommandContext;
 import org.slf4j.Logger;
@@ -29,14 +30,12 @@ import org.slf4j.LoggerFactory;
  */
 public class GlobalContextCamelCommand extends AbstractCamelCommand {
 
-    private static final String GLOBAL_CAMEL_CONTEXT_SERVICE_KEY = "GlobalCamelService";
-    
     private final ProducerTemplate globalContextProducerTemplate;
     
     private static final Logger logger = LoggerFactory.getLogger(GlobalContextCamelCommand.class);
     
     public GlobalContextCamelCommand() {
-        CamelContext globalCamelContext = (CamelContext) ServiceRegistry.get().service(GLOBAL_CAMEL_CONTEXT_SERVICE_KEY);
+        CamelContext globalCamelContext = (CamelContext) ServiceRegistry.get().service(JBPMConstants.GLOBAL_CAMEL_CONTEXT_SERVICE_KEY);
         // TODO: Should we allow to set the maximumCacheSize on the producer?
         this.globalContextProducerTemplate = globalCamelContext.createProducerTemplate();
     }
diff --git a/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/InOnlyCamelWorkItemHandler.java b/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/InOnlyCamelWorkItemHandler.java
index 0588c02..b97b0ad 100644
--- a/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/InOnlyCamelWorkItemHandler.java
+++ b/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/InOnlyCamelWorkItemHandler.java
@@ -22,6 +22,7 @@ import org.apache.camel.ExchangePattern;
 import org.apache.camel.Message;
 import org.apache.camel.ProducerTemplate;
 import org.apache.camel.builder.ExchangeBuilder;
+import org.apache.camel.component.jbpm.JBPMConstants;
 import org.drools.core.process.instance.impl.WorkItemImpl;
 import org.jbpm.process.workitem.core.util.Wid;
 import org.jbpm.process.workitem.core.util.WidMavenDepends;
@@ -56,11 +57,11 @@ import org.kie.api.runtime.process.WorkItemManager;
         defaultHandler = "mvel: new org.apache.camel.component.jbpm.workitem.InOnlyCamelWorkitemHandler()",
         documentation = "${artifactId}/index.html",
         parameters = {
-                @WidParameter(name = "camel-endpoint-id")
+                @WidParameter(name = JBPMConstants.CAMEL_ENDPOINT_ID_WI_PARAM)
         },
         results = {
-                @WidResult(name = "response"),
-                @WidResult(name = "message") },
+                @WidResult(name = JBPMConstants.RESPONSE_WI_PARAM),
+                @WidResult(name = JBPMConstants.MESSAGE_WI_PARAM) },
         mavenDepends = {
                 @WidMavenDepends(group = "${groupId}",
                         artifact = "${artifactId}",
diff --git a/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/InOutCamelWorkItemHandler.java b/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/InOutCamelWorkItemHandler.java
index d53c882..a8482dd 100644
--- a/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/InOutCamelWorkItemHandler.java
+++ b/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/InOutCamelWorkItemHandler.java
@@ -25,6 +25,7 @@ import org.apache.camel.ExchangePattern;
 import org.apache.camel.Message;
 import org.apache.camel.ProducerTemplate;
 import org.apache.camel.builder.ExchangeBuilder;
+import org.apache.camel.component.jbpm.JBPMConstants;
 import org.drools.core.process.instance.impl.WorkItemImpl;
 import org.jbpm.process.workitem.core.util.Wid;
 import org.jbpm.process.workitem.core.util.WidMavenDepends;
@@ -58,11 +59,11 @@ import org.kie.api.runtime.process.WorkItemManager;
         defaultHandler = "mvel: new org.apache.camel.component.jbpm.workitem.InOutCamelWorkitemHandler()",
         documentation = "${artifactId}/index.html",
         parameters = {
-                @WidParameter(name = "camel-endpoint-id")
+                @WidParameter(name = JBPMConstants.CAMEL_ENDPOINT_ID_WI_PARAM)
         },
         results = {
-                @WidResult(name = "response"),
-                @WidResult(name = "message") },
+                @WidResult(name = JBPMConstants.RESPONSE_WI_PARAM),
+                @WidResult(name = JBPMConstants.MESSAGE_WI_PARAM) },
         mavenDepends = {
                 @WidMavenDepends(group = "${groupId}",
                         artifact = "${artifactId}",
@@ -74,9 +75,6 @@ import org.kie.api.runtime.process.WorkItemManager;
                 action = @WidAction(title = "Send payload to a Camel endpoint")))
 public class InOutCamelWorkItemHandler extends AbstractCamelWorkItemHandler {
 
-    private static final String RESPONSE_PARAM = "response";
-    private static final String MESSAGE_PARAM = "message";
-
     public InOutCamelWorkItemHandler() {
         super();
     }
@@ -99,8 +97,8 @@ public class InOutCamelWorkItemHandler extends AbstractCamelWorkItemHandler {
 
         Map<String, Object> result = new HashMap<>();
         Object response = outMessage.getBody();
-        result.put(RESPONSE_PARAM, response);
-        result.put(MESSAGE_PARAM, outMessage);
+        result.put(JBPMConstants.RESPONSE_WI_PARAM, response);
+        result.put(JBPMConstants.MESSAGE_WI_PARAM, outMessage);
 
         manager.completeWorkItem(workItem.getId(), result);
     }
diff --git a/components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/workitem/CamelWorkItemHandlerIntegrationTests.java b/components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/workitem/CamelWorkItemHandlerIntegrationTests.java
index 39fd861..4e594dd 100644
--- a/components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/workitem/CamelWorkItemHandlerIntegrationTests.java
+++ b/components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/workitem/CamelWorkItemHandlerIntegrationTests.java
@@ -23,6 +23,7 @@ import org.apache.camel.EndpointInject;
 import org.apache.camel.Produce;
 import org.apache.camel.ProducerTemplate;
 import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.jbpm.JBPMConstants;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.test.junit4.CamelTestSupport;
 import org.drools.core.process.instance.impl.WorkItemImpl;
@@ -50,22 +51,22 @@ public class CamelWorkItemHandlerIntegrationTests extends CamelTestSupport {
             @Override
             public void configure() throws Exception {
                 from("direct:start").routeId(routeId)
-                        .setBody(simple("${body.getParameter(\"request\")}"))
+                        .setBody(simple("${body.getParameter(\"Request\")}"))
                         .to("mock:result");
             }
         };
         context.addRoutes(builder);
         try {
             // Register the Camel Context with the jBPM ServiceRegistry.
-            ServiceRegistry.get().register("GlobalCamelService", context);
+            ServiceRegistry.get().register(JBPMConstants.GLOBAL_CAMEL_CONTEXT_SERVICE_KEY, context);
 
             // Test
             String expectedBody = "helloRequest";
             resultEndpoint.expectedBodiesReceived(expectedBody);
 
             WorkItemImpl workItem = new WorkItemImpl();
-            workItem.setParameter("camel-endpoint-id", "start");
-            workItem.setParameter("request", expectedBody);
+            workItem.setParameter(JBPMConstants.CAMEL_ENDPOINT_ID_WI_PARAM, "start");
+            workItem.setParameter("Request", expectedBody);
 
             TestWorkItemManager manager = new TestWorkItemManager();
 
@@ -90,7 +91,7 @@ public class CamelWorkItemHandlerIntegrationTests extends CamelTestSupport {
             @Override
             public void configure() throws Exception {
                 from("direct:start").routeId(routeId)
-                        .setBody(simple("${body.getParameter(\"request\")}"))
+                        .setBody(simple("${body.getParameter(\"Request\")}"))
                         .throwException(new IllegalArgumentException("Illegal contennt!"))
                         .to("mock:result");
             }
@@ -98,15 +99,15 @@ public class CamelWorkItemHandlerIntegrationTests extends CamelTestSupport {
         context.addRoutes(builder);
         try {
             // Register the Camel Context with the jBPM ServiceRegistry.
-            ServiceRegistry.get().register("GlobalCamelService", context);
+            ServiceRegistry.get().register(JBPMConstants.GLOBAL_CAMEL_CONTEXT_SERVICE_KEY, context);
 
             // Test
             String expectedBody = "helloRequest";
             resultEndpoint.expectedBodiesReceived(expectedBody);
 
             WorkItemImpl workItem = new WorkItemImpl();
-            workItem.setParameter("camel-endpoint-id", "start");
-            workItem.setParameter("request", expectedBody);
+            workItem.setParameter(JBPMConstants.CAMEL_ENDPOINT_ID_WI_PARAM, "start");
+            workItem.setParameter("Request", expectedBody);
 
             TestWorkItemManager manager = new TestWorkItemManager();
 
@@ -131,22 +132,22 @@ public class CamelWorkItemHandlerIntegrationTests extends CamelTestSupport {
             @Override
             public void configure() throws Exception {
                 from("direct:start").routeId(routeId)
-                        .setBody(simple("${body.getParameter(\"request\")}"))
+                        .setBody(simple("${body.getParameter(\"Request\")}"))
                         .to("mock:result");
             }
         };
         context.addRoutes(builder);
         try {
             // Register the Camel Context with the jBPM ServiceRegistry.
-            ServiceRegistry.get().register("GlobalCamelService", context);
+            ServiceRegistry.get().register(JBPMConstants.GLOBAL_CAMEL_CONTEXT_SERVICE_KEY, context);
 
             // Test
             String expectedBody = "helloRequest";
             resultEndpoint.expectedBodiesReceived(expectedBody);
 
             WorkItemImpl workItem = new WorkItemImpl();
-            workItem.setParameter("camel-endpoint-id", "start");
-            workItem.setParameter("request", expectedBody);
+            workItem.setParameter(JBPMConstants.CAMEL_ENDPOINT_ID_WI_PARAM, "start");
+            workItem.setParameter("Request", expectedBody);
 
             TestWorkItemManager manager = new TestWorkItemManager();
 
@@ -172,7 +173,7 @@ public class CamelWorkItemHandlerIntegrationTests extends CamelTestSupport {
             @Override
             public void configure() throws Exception {
                 from("direct:start").routeId(routeId)
-                        .setBody(simple("${body.getParameter(\"request\")}"))
+                        .setBody(simple("${body.getParameter(\"Request\")}"))
                         .throwException(new IllegalArgumentException("Illegal contennt!"))
                         .to("mock:result");
             }
@@ -180,15 +181,15 @@ public class CamelWorkItemHandlerIntegrationTests extends CamelTestSupport {
         context.addRoutes(builder);
         try {
             // Register the Camel Context with the jBPM ServiceRegistry.
-            ServiceRegistry.get().register("GlobalCamelService", context);
+            ServiceRegistry.get().register(JBPMConstants.GLOBAL_CAMEL_CONTEXT_SERVICE_KEY, context);
 
             // Test
             String expectedBody = "helloRequest";
             resultEndpoint.expectedBodiesReceived(expectedBody);
 
             WorkItemImpl workItem = new WorkItemImpl();
-            workItem.setParameter("camel-endpoint-id", "start");
-            workItem.setParameter("request", expectedBody);
+            workItem.setParameter(JBPMConstants.CAMEL_ENDPOINT_ID_WI_PARAM, "start");
+            workItem.setParameter("Request", expectedBody);
 
             TestWorkItemManager manager = new TestWorkItemManager();
 
diff --git a/components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/workitem/DeploymentContextCamelCommandTest.java b/components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/workitem/DeploymentContextCamelCommandTest.java
index b703456..e1aef21 100644
--- a/components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/workitem/DeploymentContextCamelCommandTest.java
+++ b/components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/workitem/DeploymentContextCamelCommandTest.java
@@ -25,6 +25,7 @@ import org.apache.camel.CamelContext;
 import org.apache.camel.Exchange;
 import org.apache.camel.Message;
 import org.apache.camel.ProducerTemplate;
+import org.apache.camel.component.jbpm.JBPMConstants;
 import org.drools.core.process.instance.impl.WorkItemImpl;
 import org.jbpm.services.api.service.ServiceRegistry;
 import org.junit.Test;
@@ -76,11 +77,11 @@ public class DeploymentContextCamelCommandTest {
         when(outMessage.getBody()).thenReturn(testReponse);
         
         //Register the RuntimeManager bound camelcontext.
-        ServiceRegistry.get().register(deploymentId + "_CamelService", camelContext);
+        ServiceRegistry.get().register(deploymentId + JBPMConstants.DEPLOYMENT_CAMEL_CONTEXT_SERVICE_KEY_POSTFIX, camelContext);
         
         WorkItemImpl workItem = new WorkItemImpl();
-        workItem.setParameter("camel-endpoint-id", camelEndpointId);
-        workItem.setParameter("request", "someRequest");
+        workItem.setParameter(JBPMConstants.CAMEL_ENDPOINT_ID_WI_PARAM, camelEndpointId);
+        workItem.setParameter("Request", "someRequest");
         
         when(commandContext.getData("workItem")).thenReturn(workItem);
         when(commandContext.getData("deploymentId")).thenReturn(deploymentId);
@@ -90,6 +91,6 @@ public class DeploymentContextCamelCommandTest {
         
         assertNotNull(results);
         assertEquals(2, results.getData().size());
-        assertEquals(testReponse, results.getData().get("response"));
+        assertEquals(testReponse, results.getData().get(JBPMConstants.RESPONSE_WI_PARAM));
     }
 }
diff --git a/components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/workitem/GlobalContextCamelCommandTest.java b/components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/workitem/GlobalContextCamelCommandTest.java
index ad36879..048ec72 100644
--- a/components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/workitem/GlobalContextCamelCommandTest.java
+++ b/components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/workitem/GlobalContextCamelCommandTest.java
@@ -25,6 +25,7 @@ import org.apache.camel.CamelContext;
 import org.apache.camel.Exchange;
 import org.apache.camel.Message;
 import org.apache.camel.ProducerTemplate;
+import org.apache.camel.component.jbpm.JBPMConstants;
 import org.drools.core.process.instance.impl.WorkItemImpl;
 import org.jbpm.services.api.service.ServiceRegistry;
 import org.junit.Test;
@@ -78,11 +79,11 @@ public class GlobalContextCamelCommandTest {
     	when(outMessage.getBody()).thenReturn(testReponse);
     	
     	//Register the RuntimeManager bound camelcontext.
-    	ServiceRegistry.get().register("GlobalCamelService", camelContext);
+    	ServiceRegistry.get().register(JBPMConstants.GLOBAL_CAMEL_CONTEXT_SERVICE_KEY, camelContext);
     	
         WorkItemImpl workItem = new WorkItemImpl();
-        workItem.setParameter("camel-endpoint-id", camelEndpointId);
-        workItem.setParameter("request", "someRequest");
+        workItem.setParameter(JBPMConstants.CAMEL_ENDPOINT_ID_WI_PARAM, camelEndpointId);
+        workItem.setParameter("Request", "someRequest");
         
         when(commandContext.getData(anyString())).thenReturn(workItem);
         
@@ -92,6 +93,6 @@ public class GlobalContextCamelCommandTest {
         
         assertNotNull(results);
         assertEquals(2, results.getData().size());
-        assertEquals(testReponse, results.getData().get("response"));
+        assertEquals(testReponse, results.getData().get(JBPMConstants.RESPONSE_WI_PARAM));
     }
 }
diff --git a/components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/workitem/InOnlyCamelWorkItemHandlerTest.java b/components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/workitem/InOnlyCamelWorkItemHandlerTest.java
index 1ad1bf9..a862f22 100644
--- a/components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/workitem/InOnlyCamelWorkItemHandlerTest.java
+++ b/components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/workitem/InOnlyCamelWorkItemHandlerTest.java
@@ -26,6 +26,7 @@ import org.apache.camel.CamelContext;
 import org.apache.camel.Exchange;
 import org.apache.camel.Message;
 import org.apache.camel.ProducerTemplate;
+import org.apache.camel.component.jbpm.JBPMConstants;
 import org.apache.camel.impl.DefaultHeadersMapFactory;
 import org.apache.camel.spi.HeadersMapFactory;
 import org.drools.core.process.instance.impl.WorkItemImpl;
@@ -79,8 +80,8 @@ public class InOnlyCamelWorkItemHandlerTest {
         ServiceRegistry.get().register(runtimeManagerId + "_CamelService", camelContext);
 
         WorkItemImpl workItem = new WorkItemImpl();
-        workItem.setParameter("camel-endpoint-id", camelEndpointId);
-        workItem.setParameter("request", "someRequest");
+        workItem.setParameter(JBPMConstants.CAMEL_ENDPOINT_ID_WI_PARAM, camelEndpointId);
+        workItem.setParameter("Request", "someRequest");
         workItem.setDeploymentId("testDeploymentId");
         workItem.setProcessInstanceId(1L);
         workItem.setId(1L);
diff --git a/components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/workitem/InOutCamelWorkItemHandlerTest.java b/components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/workitem/InOutCamelWorkItemHandlerTest.java
index e4bc6ba..1277f04 100644
--- a/components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/workitem/InOutCamelWorkItemHandlerTest.java
+++ b/components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/workitem/InOutCamelWorkItemHandlerTest.java
@@ -28,6 +28,7 @@ import org.apache.camel.CamelContext;
 import org.apache.camel.Exchange;
 import org.apache.camel.Message;
 import org.apache.camel.ProducerTemplate;
+import org.apache.camel.component.jbpm.JBPMConstants;
 import org.apache.camel.impl.DefaultHeadersMapFactory;
 import org.apache.camel.spi.HeadersMapFactory;
 import org.drools.core.process.instance.impl.WorkItemImpl;
@@ -80,8 +81,8 @@ public class InOutCamelWorkItemHandlerTest {
 
         TestWorkItemManager manager = new TestWorkItemManager();
         WorkItemImpl workItem = new WorkItemImpl();
-        workItem.setParameter("camel-endpoint-id", camelEndpointId);
-        workItem.setParameter("request", "someRequest");
+        workItem.setParameter("CamelEndpointId", camelEndpointId);
+        workItem.setParameter("Request", "someRequest");
         workItem.setDeploymentId("testDeploymentId");
         workItem.setProcessInstanceId(1L);
         workItem.setId(1L);
@@ -95,7 +96,7 @@ public class InOutCamelWorkItemHandlerTest {
         assertThat(manager.getResults().containsKey(workItem.getId()), is(true));
         Map<String, Object> results = manager.getResults(workItem.getId());
         assertThat(results.size(), equalTo(2));
-        assertThat(results.get("response"), equalTo(testReponse));
+        assertThat(results.get("Response"), equalTo(testReponse));
     }
 
     @Test
@@ -124,8 +125,8 @@ public class InOutCamelWorkItemHandlerTest {
         ServiceRegistry.get().register(runtimeManagerId + "_CamelService", camelContext);
 
         WorkItemImpl workItem = new WorkItemImpl();
-        workItem.setParameter("camel-endpoint-id", camelEndpointId);
-        workItem.setParameter("request", "someRequest");
+        workItem.setParameter(JBPMConstants.CAMEL_ENDPOINT_ID_WI_PARAM, camelEndpointId);
+        workItem.setParameter("Request", "someRequest");
         workItem.setDeploymentId("testDeploymentId");
         workItem.setProcessInstanceId(1L);
         workItem.setId(1L);
@@ -141,7 +142,7 @@ public class InOutCamelWorkItemHandlerTest {
         
         Map<String, Object> results = manager.getResults(workItem.getId());
         assertThat(results.size(), equalTo(2));
-        assertThat(results.get("response"), equalTo(testReponse));
+        assertThat(results.get(JBPMConstants.RESPONSE_WI_PARAM), equalTo(testReponse));
     }
    
 }


[camel] 05/05: CAMEL-12964: Fix CS

Posted by dm...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

dmvolod pushed a commit to branch camel-2.23.x
in repository https://gitbox.apache.org/repos/asf/camel.git

commit e58bb7c49ac11ab9271d2c3dfaf460f66c4109ca
Author: Dmitry Volodin <dm...@gmail.com>
AuthorDate: Fri Nov 30 13:18:23 2018 +0300

    CAMEL-12964: Fix CS
---
 .../jbpm/server/CamelKieServerExtension.java       | 29 +++++------
 .../jbpm/workitem/AbstractCamelCommand.java        | 60 ++++++++++------------
 .../workitem/AbstractCamelWorkItemHandler.java     |  1 -
 .../workitem/DeploymentContextCamelCommand.java    |  5 +-
 .../jbpm/workitem/GlobalContextCamelCommand.java   |  8 ++-
 .../jbpm/workitem/InOnlyCamelWorkItemHandler.java  |  1 -
 .../jbpm/workitem/InOutCamelWorkItemHandler.java   |  1 -
 .../jbpm/JBPMComponentIntegrationTest.java         |  1 -
 .../CamelWorkItemHandlerIntegrationTests.java      |  5 +-
 .../DeploymentContextCamelCommandTest.java         |  9 ++--
 .../workitem/GlobalContextCamelCommandTest.java    | 59 ++++++++++-----------
 .../workitem/InOnlyCamelWorkItemHandlerTest.java   | 11 ++--
 .../workitem/InOutCamelWorkItemHandlerTest.java    | 12 ++---
 13 files changed, 92 insertions(+), 110 deletions(-)

diff --git a/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/server/CamelKieServerExtension.java b/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/server/CamelKieServerExtension.java
index 659a498..1783b04 100644
--- a/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/server/CamelKieServerExtension.java
+++ b/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/server/CamelKieServerExtension.java
@@ -14,7 +14,6 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package org.apache.camel.component.jbpm.server;
 
 import java.io.InputStream;
@@ -44,7 +43,7 @@ public class CamelKieServerExtension implements KieServerExtension {
 
     private static final Boolean DISABLED = Boolean.parseBoolean(System.getProperty("org.camel.server.ext.disabled", "false"));
 
-    protected DefaultCamelContext camel;
+    protected DefaultCamelContext camelContext;
 
     protected boolean managedCamel;
 
@@ -54,14 +53,14 @@ public class CamelKieServerExtension implements KieServerExtension {
         this.managedCamel = true;
     }
 
-    public CamelKieServerExtension(DefaultCamelContext camel) {
-        this.camel = camel;
+    public CamelKieServerExtension(DefaultCamelContext camelContext) {
+        this.camelContext = camelContext;
         this.managedCamel = false;
     }
 
     @Override
     public boolean isInitialized() {
-        return camel != null;
+        return camelContext != null;
     }
 
     @Override
@@ -71,31 +70,31 @@ public class CamelKieServerExtension implements KieServerExtension {
 
     @Override
     public void init(KieServerImpl kieServer, KieServerRegistry registry) {
-        if (this.managedCamel && this.camel == null) {
-            this.camel = new DefaultCamelContext();
-            this.camel.setName("KIE Server Camel context");
+        if (this.managedCamel && this.camelContext == null) {
+            this.camelContext = new DefaultCamelContext();
+            this.camelContext.setName("KIE Server Camel context");
 
             try (InputStream is = this.getClass().getResourceAsStream("/global-camel-routes.xml")) {
                 if (is != null) {
 
-                    RoutesDefinition routes = camel.loadRoutesDefinition(is);
-                    camel.addRouteDefinitions(routes.getRoutes());
+                    RoutesDefinition routes = camelContext.loadRoutesDefinition(is);
+                    camelContext.addRouteDefinitions(routes.getRoutes());
                 }
             } catch (Exception e) {
                 LOGGER.error("Error while adding Camel context for KIE Server", e);
             }
         }
 
-        ServiceRegistry.get().register(JBPMConstants.GLOBAL_CAMEL_CONTEXT_SERVICE_KEY, this.camel);
+        ServiceRegistry.get().register(JBPMConstants.GLOBAL_CAMEL_CONTEXT_SERVICE_KEY, this.camelContext);
     }
 
     @Override
     public void destroy(KieServerImpl kieServer, KieServerRegistry registry) {
         ServiceRegistry.get().remove("GlobalCamelService");
 
-        if (this.managedCamel && this.camel != null) {
+        if (this.managedCamel && this.camelContext != null) {
             try {
-                this.camel.stop();
+                this.camelContext.stop();
             } catch (Exception e) {
                 LOGGER.error("Failed at stopping KIE Server extension {}", EXTENSION_NAME);
             }
@@ -184,9 +183,9 @@ public class CamelKieServerExtension implements KieServerExtension {
 
     @Override
     public void serverStarted() {
-        if (this.managedCamel && this.camel != null && !this.camel.isStarted()) {
+        if (this.managedCamel && this.camelContext != null && !this.camelContext.isStarted()) {
             try {
-                this.camel.start();
+                this.camelContext.start();
             } catch (Exception e) {
                 LOGGER.error("Failed at start Camel context", e);
             }
diff --git a/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/AbstractCamelCommand.java b/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/AbstractCamelCommand.java
index a26aa32..1900960 100644
--- a/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/AbstractCamelCommand.java
+++ b/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/AbstractCamelCommand.java
@@ -14,20 +14,16 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package org.apache.camel.component.jbpm.workitem;
 
-import org.apache.camel.CamelContext;
 import org.apache.camel.Exchange;
 import org.apache.camel.Message;
 import org.apache.camel.ProducerTemplate;
 import org.apache.camel.builder.ExchangeBuilder;
 import org.apache.camel.component.jbpm.JBPMConstants;
-import org.jbpm.services.api.service.ServiceRegistry;
 import org.kie.api.executor.Command;
 import org.kie.api.executor.CommandContext;
 import org.kie.api.executor.ExecutionResults;
-import org.kie.api.runtime.manager.RuntimeManager;
 import org.kie.api.runtime.process.WorkItem;
 import org.kie.internal.runtime.Cacheable;
 import org.slf4j.Logger;
@@ -45,41 +41,41 @@ import org.slf4j.LoggerFactory;
  * {@link Message} is provided via the <code>Message</code> parameter. This gives the user access to more advanced fields like message headers 
  * and attachments.
  */
-public abstract class AbstractCamelCommand implements Command,
-                                          Cacheable {
-
-    private static final Logger logger = LoggerFactory.getLogger(AbstractCamelCommand.class);
+public abstract class AbstractCamelCommand implements Command, Cacheable {
+    private static final Logger LOGGER = LoggerFactory.getLogger(AbstractCamelCommand.class);
 
-	public AbstractCamelCommand() {
-	}
-	
+    public AbstractCamelCommand() {
+    }
+    
     @Override
     public ExecutionResults execute(CommandContext ctx) throws Exception {
         
         WorkItem workItem = (WorkItem) ctx.getData("workItem");
-    	
-    	String camelEndpointId = (String) workItem.getParameter(JBPMConstants.CAMEL_ENDPOINT_ID_WI_PARAM);
-		
-		// We only support direct. We don't need to support more, as direct simply gives us the entrypoint into the actual Camel Routes.
-		String camelUri = "direct://" + camelEndpointId;
-		
-		ProducerTemplate producerTemplate = getProducerTemplate(ctx);
-		Exchange inExchange = ExchangeBuilder.anExchange(producerTemplate.getCamelContext()).withBody(workItem).build();
-		Exchange outExchange = producerTemplate.send(camelUri, inExchange);
-		// producerTemplate.send does not throw exceptions, instead they are set on the returned Exchange.
-		if (outExchange.getException() != null) {
-			throw outExchange.getException();
-		}
-		Message outMessage = outExchange.getOut();
-		
-		ExecutionResults results = new ExecutionResults();
-		Object response = outMessage.getBody();
-		results.setData(JBPMConstants.RESPONSE_WI_PARAM, response);
-		results.setData(JBPMConstants.MESSAGE_WI_PARAM, outMessage);
-    	
+      
+        String camelEndpointId = (String) workItem.getParameter(JBPMConstants.CAMEL_ENDPOINT_ID_WI_PARAM);
+
+        // We only support direct. We don't need to support more, as direct simply gives us the entrypoint into the actual Camel Routes.
+        String camelUri = "direct://" + camelEndpointId;
+        
+        ProducerTemplate producerTemplate = getProducerTemplate(ctx);
+        Exchange inExchange = ExchangeBuilder.anExchange(producerTemplate.getCamelContext()).withBody(workItem).build();
+        Exchange outExchange = producerTemplate.send(camelUri, inExchange);
+
+        // producerTemplate.send does not throw exceptions, instead they are set on the returned Exchange.
+        if (outExchange.getException() != null) {
+            throw outExchange.getException();
+        }
+
+        Message outMessage = outExchange.getOut();
+
+        ExecutionResults results = new ExecutionResults();
+        Object response = outMessage.getBody();
+        results.setData(JBPMConstants.RESPONSE_WI_PARAM, response);
+        results.setData(JBPMConstants.MESSAGE_WI_PARAM, outMessage);
+
         return results;
     }
-    
+
     protected abstract ProducerTemplate getProducerTemplate(CommandContext ctx);
 
 }
\ No newline at end of file
diff --git a/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/AbstractCamelWorkItemHandler.java b/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/AbstractCamelWorkItemHandler.java
index 23d7a35..d5ea7df 100644
--- a/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/AbstractCamelWorkItemHandler.java
+++ b/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/AbstractCamelWorkItemHandler.java
@@ -14,7 +14,6 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package org.apache.camel.component.jbpm.workitem;
 
 import org.apache.camel.CamelContext;
diff --git a/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/DeploymentContextCamelCommand.java b/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/DeploymentContextCamelCommand.java
index 009b909..69c74ad 100644
--- a/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/DeploymentContextCamelCommand.java
+++ b/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/DeploymentContextCamelCommand.java
@@ -32,11 +32,10 @@ import org.slf4j.LoggerFactory;
  * CamelCommand that uses the {@link CamelContext} registered on the {@link ServiceRegistry} for this specific deployment.
  */
 public class DeploymentContextCamelCommand extends AbstractCamelCommand {
+    private static final Logger LOGGER = LoggerFactory.getLogger(DeploymentContextCamelCommand.class);
 
     private final Map<String, ProducerTemplate> templates = new ConcurrentHashMap<>();
 
-    private static final Logger logger = LoggerFactory.getLogger(DeploymentContextCamelCommand.class);
-
     @Override
     protected ProducerTemplate getProducerTemplate(CommandContext ctx) {
         String deploymentId = (String) ctx.getData("deploymentId");
@@ -62,7 +61,7 @@ public class DeploymentContextCamelCommand extends AbstractCamelCommand {
             try {
                 nextTemplate.stop();
             } catch (Exception e) {
-                logger.warn("Error encountered while closing the Camel Producer Template.", e);
+                LOGGER.warn("Error encountered while closing the Camel Producer Template.", e);
                 // Not much we can do here, so swallowing exception.
             }
         }
diff --git a/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/GlobalContextCamelCommand.java b/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/GlobalContextCamelCommand.java
index e129a12..aa46014 100644
--- a/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/GlobalContextCamelCommand.java
+++ b/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/GlobalContextCamelCommand.java
@@ -14,7 +14,6 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package org.apache.camel.component.jbpm.workitem;
 
 import org.apache.camel.CamelContext;
@@ -29,10 +28,9 @@ import org.slf4j.LoggerFactory;
  * CamelCommand that uses the global {@link CamelContext} registered on the {@link ServiceRegistry}.
  */
 public class GlobalContextCamelCommand extends AbstractCamelCommand {
-
-    private final ProducerTemplate globalContextProducerTemplate;
+    private static final Logger LOGGER = LoggerFactory.getLogger(GlobalContextCamelCommand.class);
     
-    private static final Logger logger = LoggerFactory.getLogger(GlobalContextCamelCommand.class);
+    private final ProducerTemplate globalContextProducerTemplate;
     
     public GlobalContextCamelCommand() {
         CamelContext globalCamelContext = (CamelContext) ServiceRegistry.get().service(JBPMConstants.GLOBAL_CAMEL_CONTEXT_SERVICE_KEY);
@@ -49,7 +47,7 @@ public class GlobalContextCamelCommand extends AbstractCamelCommand {
         try {
             this.globalContextProducerTemplate.stop();
         } catch (Exception e) {
-            logger.warn("Error encountered while closing the Camel Producer Template.", e);
+            LOGGER.warn("Error encountered while closing the Camel Producer Template.", e);
             // Not much we can do here, so swallowing exception.
         }
     }
diff --git a/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/InOnlyCamelWorkItemHandler.java b/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/InOnlyCamelWorkItemHandler.java
index b97b0ad..b20bcda 100644
--- a/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/InOnlyCamelWorkItemHandler.java
+++ b/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/InOnlyCamelWorkItemHandler.java
@@ -14,7 +14,6 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package org.apache.camel.component.jbpm.workitem;
 
 import org.apache.camel.Exchange;
diff --git a/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/InOutCamelWorkItemHandler.java b/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/InOutCamelWorkItemHandler.java
index a8482dd..6b6ef5f 100644
--- a/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/InOutCamelWorkItemHandler.java
+++ b/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/InOutCamelWorkItemHandler.java
@@ -14,7 +14,6 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package org.apache.camel.component.jbpm.workitem;
 
 import java.util.HashMap;
diff --git a/components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/JBPMComponentIntegrationTest.java b/components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/JBPMComponentIntegrationTest.java
index fbab216..046b118 100644
--- a/components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/JBPMComponentIntegrationTest.java
+++ b/components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/JBPMComponentIntegrationTest.java
@@ -14,7 +14,6 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package org.apache.camel.component.jbpm;
 
 import java.util.HashMap;
diff --git a/components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/workitem/CamelWorkItemHandlerIntegrationTests.java b/components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/workitem/CamelWorkItemHandlerIntegrationTests.java
index 4e594dd..67d54fb 100644
--- a/components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/workitem/CamelWorkItemHandlerIntegrationTests.java
+++ b/components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/workitem/CamelWorkItemHandlerIntegrationTests.java
@@ -14,11 +14,8 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package org.apache.camel.component.jbpm.workitem;
 
-import static org.hamcrest.CoreMatchers.*;
-
 import org.apache.camel.EndpointInject;
 import org.apache.camel.Produce;
 import org.apache.camel.ProducerTemplate;
@@ -33,6 +30,8 @@ import org.jbpm.services.api.service.ServiceRegistry;
 import org.junit.Test;
 import org.kie.api.runtime.process.WorkItemHandler;
 
+import static org.hamcrest.CoreMatchers.*;
+
 //http://camel.apache.org/using-getin-or-getout-methods-on-exchange.html
 //http://camel.apache.org/async.html
 public class CamelWorkItemHandlerIntegrationTests extends CamelTestSupport {
diff --git a/components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/workitem/DeploymentContextCamelCommandTest.java b/components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/workitem/DeploymentContextCamelCommandTest.java
index e1aef21..b0086b9 100644
--- a/components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/workitem/DeploymentContextCamelCommandTest.java
+++ b/components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/workitem/DeploymentContextCamelCommandTest.java
@@ -14,13 +14,8 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package org.apache.camel.component.jbpm.workitem;
 
-import static org.junit.Assert.*;
-import static org.mockito.ArgumentMatchers.*;
-import static org.mockito.Mockito.*;
-
 import org.apache.camel.CamelContext;
 import org.apache.camel.Exchange;
 import org.apache.camel.Message;
@@ -37,6 +32,10 @@ import org.kie.api.runtime.manager.RuntimeManager;
 import org.mockito.Mock;
 import org.mockito.junit.MockitoJUnitRunner;
 
+import static org.junit.Assert.*;
+import static org.mockito.ArgumentMatchers.*;
+import static org.mockito.Mockito.*;
+
 @RunWith(MockitoJUnitRunner.class)
 public class DeploymentContextCamelCommandTest {
     
diff --git a/components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/workitem/GlobalContextCamelCommandTest.java b/components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/workitem/GlobalContextCamelCommandTest.java
index 048ec72..031bc69 100644
--- a/components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/workitem/GlobalContextCamelCommandTest.java
+++ b/components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/workitem/GlobalContextCamelCommandTest.java
@@ -14,13 +14,8 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package org.apache.camel.component.jbpm.workitem;
 
-import static org.junit.Assert.*;
-import static org.mockito.ArgumentMatchers.*;
-import static org.mockito.Mockito.*;
-
 import org.apache.camel.CamelContext;
 import org.apache.camel.Exchange;
 import org.apache.camel.Message;
@@ -37,10 +32,14 @@ import org.kie.api.runtime.manager.RuntimeManager;
 import org.mockito.Mock;
 import org.mockito.junit.MockitoJUnitRunner;
 
+import static org.junit.Assert.*;
+import static org.mockito.ArgumentMatchers.*;
+import static org.mockito.Mockito.*;
+
 @RunWith(MockitoJUnitRunner.class)
 public class GlobalContextCamelCommandTest {
 
-	@Mock
+    @Mock
     ProducerTemplate producerTemplate;
 
     @Mock
@@ -61,38 +60,36 @@ public class GlobalContextCamelCommandTest {
     @Test
     public void testExecuteGlobalCommand() throws Exception {
     
-    	String camelEndpointId = "testCamelRoute";
-    	String camelRouteUri = "direct://" + camelEndpointId;
-    	
-    	String testReponse = "testResponse";
-    	
-    	String runtimeManagerId = "testRuntimeManager";
-    	
-    	when(producerTemplate.send(eq(camelRouteUri), any(Exchange.class))).thenReturn(outExchange);
-    	
-    	
-    	when(producerTemplate.getCamelContext()).thenReturn(camelContext);
-    	
-    	when(camelContext.createProducerTemplate()).thenReturn(producerTemplate);
-    	
-    	when(outExchange.getOut()).thenReturn(outMessage);
-    	when(outMessage.getBody()).thenReturn(testReponse);
-    	
-    	//Register the RuntimeManager bound camelcontext.
-    	ServiceRegistry.get().register(JBPMConstants.GLOBAL_CAMEL_CONTEXT_SERVICE_KEY, camelContext);
-    	
+        String camelEndpointId = "testCamelRoute";
+        String camelRouteUri = "direct://" + camelEndpointId;
+
+        String testReponse = "testResponse";
+
+        String runtimeManagerId = "testRuntimeManager";
+
+        when(producerTemplate.send(eq(camelRouteUri), any(Exchange.class))).thenReturn(outExchange);
+
+        when(producerTemplate.getCamelContext()).thenReturn(camelContext);
+
+        when(camelContext.createProducerTemplate()).thenReturn(producerTemplate);
+
+        when(outExchange.getOut()).thenReturn(outMessage);
+        when(outMessage.getBody()).thenReturn(testReponse);
+
+        //Register the RuntimeManager bound camelContext.
+        ServiceRegistry.get().register(JBPMConstants.GLOBAL_CAMEL_CONTEXT_SERVICE_KEY, camelContext);
+
         WorkItemImpl workItem = new WorkItemImpl();
         workItem.setParameter(JBPMConstants.CAMEL_ENDPOINT_ID_WI_PARAM, camelEndpointId);
         workItem.setParameter("Request", "someRequest");
-        
+
         when(commandContext.getData(anyString())).thenReturn(workItem);
-        
+
         Command command = new GlobalContextCamelCommand();
         ExecutionResults results = command.execute(commandContext);
-        
-        
+
         assertNotNull(results);
         assertEquals(2, results.getData().size());
         assertEquals(testReponse, results.getData().get(JBPMConstants.RESPONSE_WI_PARAM));
     }
-}
+}
\ No newline at end of file
diff --git a/components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/workitem/InOnlyCamelWorkItemHandlerTest.java b/components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/workitem/InOnlyCamelWorkItemHandlerTest.java
index a862f22..b97822e 100644
--- a/components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/workitem/InOnlyCamelWorkItemHandlerTest.java
+++ b/components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/workitem/InOnlyCamelWorkItemHandlerTest.java
@@ -14,14 +14,8 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package org.apache.camel.component.jbpm.workitem;
 
-import static org.hamcrest.CoreMatchers.*;
-import static org.junit.Assert.*;
-import static org.mockito.ArgumentMatchers.*;
-import static org.mockito.Mockito.*;
-
 import org.apache.camel.CamelContext;
 import org.apache.camel.Exchange;
 import org.apache.camel.Message;
@@ -39,6 +33,11 @@ import org.mockito.ArgumentMatchers;
 import org.mockito.Mock;
 import org.mockito.junit.MockitoJUnitRunner;
 
+import static org.hamcrest.CoreMatchers.*;
+import static org.junit.Assert.*;
+import static org.mockito.ArgumentMatchers.*;
+import static org.mockito.Mockito.*;
+
 @RunWith(MockitoJUnitRunner.class)
 public class InOnlyCamelWorkItemHandlerTest {
 
diff --git a/components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/workitem/InOutCamelWorkItemHandlerTest.java b/components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/workitem/InOutCamelWorkItemHandlerTest.java
index 1277f04..578de78 100644
--- a/components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/workitem/InOutCamelWorkItemHandlerTest.java
+++ b/components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/workitem/InOutCamelWorkItemHandlerTest.java
@@ -14,14 +14,8 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package org.apache.camel.component.jbpm.workitem;
 
-import static org.hamcrest.CoreMatchers.*;
-import static org.junit.Assert.*;
-import static org.mockito.ArgumentMatchers.*;
-import static org.mockito.Mockito.*;
-
 import java.util.Map;
 
 import org.apache.camel.CamelContext;
@@ -41,6 +35,12 @@ import org.mockito.ArgumentMatchers;
 import org.mockito.Mock;
 import org.mockito.junit.MockitoJUnitRunner;
 
+import static org.hamcrest.CoreMatchers.*;
+import static org.junit.Assert.*;
+import static org.mockito.ArgumentMatchers.*;
+import static org.mockito.Mockito.*;
+
+
 @RunWith(MockitoJUnitRunner.class)
 public class InOutCamelWorkItemHandlerTest {
 


[camel] 02/05: CamelCommand splitted in a separate command for Camel DeploymentContext and GlobalContext. WorkItemHandler can now be configured with default route. WIH supports both InOut and InOnly MEPs. Added tests that use a test CamelContext and test-routes to verify behaviour on Exceptions.

Posted by dm...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

dmvolod pushed a commit to branch camel-2.23.x
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 2dace2c1724c4f2d57132f31f4c7e06c00eea194
Author: Duncan Doyle <Du...@gmail.com>
AuthorDate: Thu Nov 29 15:02:15 2018 +0100

    CamelCommand splitted in a separate command for Camel DeploymentContext and GlobalContext. WorkItemHandler can now be configured with default route. WIH supports both InOut and InOnly MEPs. Added tests that use a test CamelContext and test-routes to verify behaviour on Exceptions.
---
 ...CamelCommand.java => AbstractCamelCommand.java} |  46 +----
 .../workitem/AbstractCamelWorkItemHandler.java     | 156 ++++++++++++++++
 .../jbpm/workitem/CamelWorkItemHandler.java        | 137 --------------
 .../workitem/DeploymentContextCamelCommand.java    |  73 ++++++++
 .../jbpm/workitem/GlobalContextCamelCommand.java   |  60 ++++++
 .../jbpm/workitem/InOnlyCamelWorkItemHandler.java  | 106 +++++++++++
 .../jbpm/workitem/InOutCamelWorkItemHandler.java   | 119 ++++++++++++
 .../CamelWorkItemHandlerIntegrationTests.java      | 204 +++++++++++++++++++++
 .../jbpm/workitem/CamelWorkItemHandlerTest.java    | 137 --------------
 .../DeploymentContextCamelCommandTest.java         |  95 ++++++++++
 ...est.java => GlobalContextCamelCommandTest.java} |  65 ++-----
 .../workitem/InOnlyCamelWorkItemHandlerTest.java   |  97 ++++++++++
 .../workitem/InOutCamelWorkItemHandlerTest.java    | 147 +++++++++++++++
 13 files changed, 1078 insertions(+), 364 deletions(-)

diff --git a/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/CamelCommand.java b/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/AbstractCamelCommand.java
similarity index 68%
rename from components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/CamelCommand.java
rename to components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/AbstractCamelCommand.java
index 80c767e..3cb1ee4 100644
--- a/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/CamelCommand.java
+++ b/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/AbstractCamelCommand.java
@@ -42,48 +42,24 @@ import org.slf4j.LoggerFactory;
  * <p/>
  * The body of the result {@link Message} of the invocation is returned via the <code>response</code> parameter. Access to the raw response 
  * {@link Message} is provided via the <code>message</code> parameter. This gives the user access to more advanced fields like message headers 
- * and attachments.  
- * <p/>
- * This {@link Command} can be constructed in 2 ways. When using the default constructor, the {link Command} will try to find 
- * the global KIE {@link CamelContext} from the <code>jBPM</code> {@link ServiceRegistry}. 
- * When the {@link RuntimeManager} is passed to the constructor, the {@link Command} will retrieve and use the {@link CamelContext} bound 
- * to the {@link RuntimeManage} from the {@link ServiceRegistry}
- * 
+ * and attachments.
  */
-public class CamelCommand implements Command,
+public abstract class AbstractCamelCommand implements Command,
                                           Cacheable {
 
-	private static final String GLOBAL_CAMEL_CONTEXT_SERVICE_KEY = "GlobalCamelService";
-	private static final String RUNTIME_CAMEL_CONTEXT_SERVICE_POSTFIX = "_CamelService";
-	
 	private static final String CAMEL_ENDPOINT_ID_PARAM = "camel-endpoint-id";
 	private static final String RESPONSE_PARAM = "response";
 	private static final String MESSAGE_PARAM = "out-headers";
-
 	
-    private static final Logger logger = LoggerFactory.getLogger(CamelCommand.class);
-
-	private final ProducerTemplate producerTemplate;
+    private static final Logger logger = LoggerFactory.getLogger(AbstractCamelCommand.class);
 
-
-	public CamelCommand() {
-		CamelContext globalCamelContext = (CamelContext) ServiceRegistry.get().service(GLOBAL_CAMEL_CONTEXT_SERVICE_KEY);
-		// TODO: Should we allow to set the maximumCacheSize on the producer?
-		this.producerTemplate = globalCamelContext.createProducerTemplate();
-	}
-	
-	public CamelCommand(RuntimeManager runtimeManager) {
-		String runtimeCamelContextKey = runtimeManager.getIdentifier() + RUNTIME_CAMEL_CONTEXT_SERVICE_POSTFIX;
-		CamelContext runtimeCamelContext = (CamelContext) ServiceRegistry.get().service(runtimeCamelContextKey);
-		// TODO: Should we allow to set the maximumCacheSize on the producer?
-		this.producerTemplate = runtimeCamelContext.createProducerTemplate();
+	public AbstractCamelCommand() {
 	}
 	
-	
-	
     @Override
     public ExecutionResults execute(CommandContext ctx) throws Exception {
         
+        
     	WorkItem workItem = (WorkItem) ctx.getData("workItem");
     	
     	String camelEndpointId = (String) workItem.getParameter(CAMEL_ENDPOINT_ID_PARAM);
@@ -91,6 +67,7 @@ public class CamelCommand implements Command,
 		// We only support direct. We don't need to support more, as direct simply gives us the entrypoint into the actual Camel Routes.
 		String camelUri = "direct://" + camelEndpointId;
 		
+		ProducerTemplate producerTemplate = getProducerTemplate(ctx);
 		Exchange inExchange = ExchangeBuilder.anExchange(producerTemplate.getCamelContext()).withBody(workItem).build();
 		Exchange outExchange = producerTemplate.send(camelUri, inExchange);
 		// producerTemplate.send does not throw exceptions, instead they are set on the returned Exchange.
@@ -106,16 +83,7 @@ public class CamelCommand implements Command,
     	
         return results;
     }
-
     
-	@Override
-	public void close() {
-		try {
-			this.producerTemplate.stop();
-		} catch (Exception e) {
-			logger.warn("Error encountered while closing the Camel Producer Template.", e);
-			// Not much we can do here, so swallowing exception.
-		}
-	}
+    protected abstract ProducerTemplate getProducerTemplate(CommandContext ctx);
 
 }
\ No newline at end of file
diff --git a/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/AbstractCamelWorkItemHandler.java b/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/AbstractCamelWorkItemHandler.java
new file mode 100644
index 0000000..db88e70
--- /dev/null
+++ b/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/AbstractCamelWorkItemHandler.java
@@ -0,0 +1,156 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.camel.component.jbpm.workitem;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.ProducerTemplate;
+import org.jbpm.process.workitem.core.AbstractLogOrThrowWorkItemHandler;
+import org.jbpm.services.api.service.ServiceRegistry;
+import org.kie.api.runtime.manager.RuntimeManager;
+import org.kie.api.runtime.process.WorkItem;
+import org.kie.api.runtime.process.WorkItemHandler;
+import org.kie.api.runtime.process.WorkItemManager;
+import org.kie.internal.runtime.Cacheable;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Camel jBPM {@link WorkItemHandler} which allows to call Camel routes with a <code>direct</code> endpoint.
+ * <p/>
+ * The handler passes the {@WorkItem} to the route that has a consumer on the endpoint-id that can be passed with the
+ * <code>camel-endpoint-id</code>{@link WorkItem} parameter. E.g. when a the value "myCamelEndpoint" is passed to the {link WorkItem} via
+ * the <code>camel-endpoint-id</code> parameter, this command will send the {@link WorkItem} to the Camel URI
+ * <code>direct://myCamelEndpoint</code>.
+ * <p/>
+ * The body of the result {@link Message} of the invocation is returned via the <code>response</code> parameter. Access to the raw response
+ * {@link Message} is provided via the <code>message</code> parameter. This gives the user access to more advanced fields like message
+ * headers and attachments.
+ * <p/>
+ * This handler can be constructed in multiple ways. When you don't pass a {@link RuntimeManager} to the constructor, the handler will try
+ * to find the global KIE {@link CamelContext} from the <code>jBPM</code> {@link ServiceRegistry}. When the {@link RuntimeManager} is passed
+ * to the constructor, the handler will retrieve and use the {@link CamelContext} bound to the {@link RuntimeManage} from the
+ * {@link ServiceRegistry}. When a <code>camel-endpoint-id</code> is passed to the constructor, the handler will send all requests to the
+ * Camel route that is consuming from that endpoint, unless the endpoint is overridden by passing a the <code>camel-endpoint-id</code> in
+ * the {@link WorkItem} parameters.
+ * 
+ */
+public abstract class AbstractCamelWorkItemHandler extends AbstractLogOrThrowWorkItemHandler implements Cacheable {
+
+    private static final String GLOBAL_CAMEL_CONTEXT_SERVICE_KEY = "GlobalCamelService";
+    private static final String RUNTIME_CAMEL_CONTEXT_SERVICE_POSTFIX = "_CamelService";
+
+    private static final String CAMEL_ENDPOINT_ID_PARAM = "camel-endpoint-id";
+
+    private static Logger logger = LoggerFactory.getLogger(AbstractCamelWorkItemHandler.class);
+
+    private final ProducerTemplate producerTemplate;
+
+    private final String camelEndpointId;
+
+    /**
+     * Default Constructor. This creates a {@link ProducerTemplate} for the global {@link CamelContext}.
+     */
+    public AbstractCamelWorkItemHandler() {
+        this("");
+    }
+
+    public AbstractCamelWorkItemHandler(String camelEndointId) {
+        CamelContext globalCamelContext = (CamelContext) ServiceRegistry.get().service(GLOBAL_CAMEL_CONTEXT_SERVICE_KEY);
+        // TODO: Should we allow to set the maximumCacheSize on the producer?
+        this.producerTemplate = globalCamelContext.createProducerTemplate();
+        this.camelEndpointId = camelEndointId;
+    }
+
+    /**
+     * Constructor which accepts {@link RuntimeManager}. This causes this WorkItemHanlder to create a {@link ProducerTemplate} for the
+     * runtime specific {@link CamelContext}.
+     */
+    public AbstractCamelWorkItemHandler(RuntimeManager runtimeManager) {
+        this(runtimeManager, "");
+    }
+
+    public AbstractCamelWorkItemHandler(RuntimeManager runtimeManager, String camelEndpointId) {
+        String runtimeCamelContextKey = runtimeManager.getIdentifier() + RUNTIME_CAMEL_CONTEXT_SERVICE_POSTFIX;
+        CamelContext runtimeCamelContext = (CamelContext) ServiceRegistry.get().service(runtimeCamelContextKey);
+        // TODO: Should we allow to set the maximumCacheSize on the producer?
+        this.producerTemplate = runtimeCamelContext.createProducerTemplate();
+        this.camelEndpointId = camelEndpointId;
+    }
+
+    public void executeWorkItem(WorkItem workItem, final WorkItemManager manager) {
+
+        String workItemCamelEndpointId = getCamelEndpointId(workItem);
+
+        // We only support direct. We don't need to support more, as direct simply gives us the entrypoint into the actual Camel Routes.
+        String camelUri = "direct://" + workItemCamelEndpointId;
+
+        try {
+            Exchange requestExchange = buildExchange(producerTemplate, workItem);
+            logger.debug("Sending Camel Exchange to: " + camelUri);
+            Exchange responseExchange = producerTemplate.send(camelUri, requestExchange);
+            // producerTemplate.send does not throw exceptions, instead they are set on the returned Exchange.
+            if (responseExchange.getException() != null) {
+                throw responseExchange.getException();
+            }
+            handleResponse(responseExchange, workItem, manager);
+        } catch (Exception e) {
+            handleException(e);
+        }
+    }
+
+    private String getCamelEndpointId(WorkItem workItem) {
+        String workItemCamelEndpointId = (String) workItem.getParameter(CAMEL_ENDPOINT_ID_PARAM);
+
+        if (camelEndpointId != null && !camelEndpointId.isEmpty()) {
+            if (workItemCamelEndpointId != null && !workItemCamelEndpointId.isEmpty()) {
+                logger.debug(
+                        "The Camel Endpoint ID has been set on both the WorkItemHanlder and WorkItem. The camel-endpoint-id configured on the WorkItem overrides the global configuation.");
+            } else {
+                workItemCamelEndpointId = camelEndpointId;
+            }
+        }
+
+        if (workItemCamelEndpointId == null || workItemCamelEndpointId.isEmpty()) {
+            throw new IllegalArgumentException(
+                    "No Camel Endpoint ID specified. Please configure the 'camel-endpoint-id' in either the constructor of this WorkItemHandler, or pass it via the "
+                            + CAMEL_ENDPOINT_ID_PARAM + "' WorkItem parameter.");
+        }
+        return workItemCamelEndpointId;
+    }
+
+    protected abstract void handleResponse(Exchange responseExchange, WorkItem workItem, WorkItemManager manager);
+
+    protected abstract Exchange buildExchange(ProducerTemplate template, WorkItem workItem);
+
+    public void abortWorkItem(WorkItem workItem, WorkItemManager manager) {
+        // Do nothing, cannot be aborted
+    }
+
+    @Override
+    public void close() {
+        try {
+            this.producerTemplate.stop();
+        } catch (Exception e) {
+            logger.warn("Error encountered while closing the Camel Producer Template.", e);
+            // Not much we can do here, so swallowing exception.
+        }
+    }
+
+}
\ No newline at end of file
diff --git a/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/CamelWorkItemHandler.java b/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/CamelWorkItemHandler.java
deleted file mode 100644
index 7734dd9..0000000
--- a/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/CamelWorkItemHandler.java
+++ /dev/null
@@ -1,137 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.camel.component.jbpm.workitem;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.apache.camel.CamelContext;
-import org.apache.camel.Exchange;
-import org.apache.camel.Message;
-import org.apache.camel.ProducerTemplate;
-import org.apache.camel.builder.ExchangeBuilder;
-import org.jbpm.process.workitem.core.AbstractLogOrThrowWorkItemHandler;
-import org.jbpm.process.workitem.core.util.Wid;
-import org.jbpm.process.workitem.core.util.WidMavenDepends;
-import org.jbpm.process.workitem.core.util.WidParameter;
-import org.jbpm.process.workitem.core.util.WidResult;
-import org.jbpm.process.workitem.core.util.service.WidAction;
-import org.jbpm.process.workitem.core.util.service.WidService;
-import org.jbpm.services.api.service.ServiceRegistry;
-import org.kie.api.runtime.manager.RuntimeManager;
-import org.kie.api.runtime.process.WorkItem;
-import org.kie.api.runtime.process.WorkItemManager;
-import org.kie.internal.runtime.Cacheable;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Camel jBPM {@link WorkItemHandler} which allows to call Camel routes with a <code>direct</code> endpoint.
- * <p/>
- * The handler passes the {@WorkItem} to the route that has a consumer on the endpoint-id that can be passed with the
- * <code>camel-endpoint-id</code>{@link WorkItem} parameter. E.g. when a the value "myCamelEndpoint" is passed to the 
- * {link WorkItem} via the <code>camel-endpoint-id</code> parameter, this command will send the {@link WorkItem} to the Camel URI
- * <code>direct://myCamelEndpoint</code>.
- * <p/>
- * The body of the result {@link Message} of the invocation is returned via the <code>response</code> parameter. Access to the raw response
- * {@link Message} is provided via the <code>message</code> parameter. This gives the user access to more advanced fields like message
- * headers and attachments.
- * <p/>
- * This handler can be constructed in 2 ways. When using the default constructor, the handler will try to find the global KIE
- * {@link CamelContext} from the <code>jBPM</code> {@link ServiceRegistry}. When the {@link RuntimeManager} is passed to the constructor,
- * the handler will retrieve and use the {@link CamelContext} bound to the {@link RuntimeManage} from the {@link ServiceRegistry}
- * 
- */
-@Wid(widfile = "CamelConnector.wid", name = "CamelConnector", displayName = "CamelConnector", defaultHandler = "mvel: new org.apache.camel.component.jbpm.workitem.CamelWorkitemHandler()", documentation = "${artifactId}/index.html", parameters = {
-		@WidParameter(name = "camel-endpoint-id") }, results = { @WidResult(name = "response"),
-				@WidResult(name = "message") }, mavenDepends = {
-						@WidMavenDepends(group = "${groupId}", artifact = "${artifactId}", version = "${version}") }, serviceInfo = @WidService(category = "${name}", description = "${description}", keywords = "apache,camel,payload,route,connector", action = @WidAction(title = "Send payload to a Camel endpoint")))
-public class CamelWorkItemHandler extends AbstractLogOrThrowWorkItemHandler implements Cacheable {
-
-	private static final String GLOBAL_CAMEL_CONTEXT_SERVICE_KEY = "GlobalCamelService";
-	private static final String RUNTIME_CAMEL_CONTEXT_SERVICE_POSTFIX = "_CamelService";
-
-	private static final String CAMEL_ENDPOINT_ID_PARAM = "camel-endpoint-id";
-	private static final String RESPONSE_PARAM = "response";
-	private static final String MESSAGE_PARAM = "message";
-
-	private static Logger logger = LoggerFactory.getLogger(CamelWorkItemHandler.class);
-
-	private final ProducerTemplate producerTemplate;
-
-	/**
-	 * Default Constructor. This creates a {@link ProducerTemplate} for the global {@link CamelContext}.
-	 */
-	public CamelWorkItemHandler() {
-		CamelContext globalCamelContext = (CamelContext) ServiceRegistry.get().service(GLOBAL_CAMEL_CONTEXT_SERVICE_KEY);
-		// TODO: Should we allow to set the maximumCacheSize on the producer?
-		this.producerTemplate = globalCamelContext.createProducerTemplate();
-	}
-
-	/**
-	 * Constructor which accepts {@link RuntimeManager}. This causes this WorkItemHanlder to create a {@link ProducerTemplate} for the
-	 * runtime specific {@link CamelContext}.
-	 */
-	public CamelWorkItemHandler(RuntimeManager runtimeManager) {
-		String runtimeCamelContextKey = runtimeManager.getIdentifier() + RUNTIME_CAMEL_CONTEXT_SERVICE_POSTFIX;
-		CamelContext runtimeCamelContext = (CamelContext) ServiceRegistry.get().service(runtimeCamelContextKey);
-		// TODO: Should we allow to set the maximumCacheSize on the producer?
-		this.producerTemplate = runtimeCamelContext.createProducerTemplate();
-	}
-
-	public void executeWorkItem(WorkItem workItem, final WorkItemManager manager) {
-
-		String camelEndpointId = (String) workItem.getParameter(CAMEL_ENDPOINT_ID_PARAM);
-
-		// We only support direct. We don't need to support more, as direct simply gives us the entrypoint into the actual Camel Routes.
-		String camelUri = "direct://" + camelEndpointId;
-		try {
-			Exchange inExchange = ExchangeBuilder.anExchange(producerTemplate.getCamelContext()).withBody(workItem).build();
-			Exchange outExchange = producerTemplate.send(camelUri, inExchange);
-			// producerTemplate.send does not throw exceptions, instead they are set on the returned Exchange.
-			if (outExchange.getException() != null) {
-				throw outExchange.getException();
-			}
-			Message outMessage = outExchange.getOut();
-
-			Map<String, Object> result = new HashMap<>();
-			Object response = outMessage.getBody();
-			result.put(RESPONSE_PARAM, response);
-			result.put(MESSAGE_PARAM, outMessage);
-
-			manager.completeWorkItem(workItem.getId(), result);
-		} catch (Exception e) {
-			handleException(e);
-		}
-	}
-
-	public void abortWorkItem(WorkItem workItem, WorkItemManager manager) {
-		// Do nothing, cannot be aborted
-	}
-
-	@Override
-	public void close() {
-		try {
-			this.producerTemplate.stop();
-		} catch (Exception e) {
-			logger.warn("Error encountered while closing the Camel Producer Template.", e);
-			// Not much we can do here, so swallowing exception.
-		}
-	}
-
-}
\ No newline at end of file
diff --git a/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/DeploymentContextCamelCommand.java b/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/DeploymentContextCamelCommand.java
new file mode 100644
index 0000000..e3d3fd1
--- /dev/null
+++ b/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/DeploymentContextCamelCommand.java
@@ -0,0 +1,73 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.camel.component.jbpm.workitem;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.ProducerTemplate;
+import org.jbpm.services.api.service.ServiceRegistry;
+import org.kie.api.executor.CommandContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * CamelCommand that uses the {@link CamelContext} registered on the {@link ServiceRegistry} for this specific deployment.
+ */
+public class DeploymentContextCamelCommand extends AbstractCamelCommand {
+
+    private static final String RUNTIME_CAMEL_CONTEXT_SERVICE_POSTFIX = "_CamelService";
+
+    private final Map<String, ProducerTemplate> templates = new ConcurrentHashMap<>();
+
+    private static final Logger logger = LoggerFactory.getLogger(DeploymentContextCamelCommand.class);
+
+    @Override
+    protected ProducerTemplate getProducerTemplate(CommandContext ctx) {
+        String deploymentId = (String) ctx.getData("deploymentId");
+        ProducerTemplate template = templates.get(deploymentId);
+
+        if (template == null) {
+            synchronized (this) {
+                template = templates.get(deploymentId);
+                if (template == null) {
+                    CamelContext deploymentCamelContext = (CamelContext) ServiceRegistry.get()
+                            .service(deploymentId + RUNTIME_CAMEL_CONTEXT_SERVICE_POSTFIX);
+                    template = deploymentCamelContext.createProducerTemplate();
+                    templates.put(deploymentId, template);
+                }
+            }
+        }
+        return template;
+    }
+
+    @Override
+    public void close() {
+        for (ProducerTemplate nextTemplate : templates.values()) {
+            try {
+                nextTemplate.stop();
+            } catch (Exception e) {
+                logger.warn("Error encountered while closing the Camel Producer Template.", e);
+                // Not much we can do here, so swallowing exception.
+            }
+        }
+
+    }
+
+}
diff --git a/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/GlobalContextCamelCommand.java b/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/GlobalContextCamelCommand.java
new file mode 100644
index 0000000..974b896
--- /dev/null
+++ b/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/GlobalContextCamelCommand.java
@@ -0,0 +1,60 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.camel.component.jbpm.workitem;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.ProducerTemplate;
+import org.jbpm.services.api.service.ServiceRegistry;
+import org.kie.api.executor.CommandContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * CamelCommand that uses the global {@link CamelContext} registered on the {@link ServiceRegistry}.
+ */
+public class GlobalContextCamelCommand extends AbstractCamelCommand {
+
+    private static final String GLOBAL_CAMEL_CONTEXT_SERVICE_KEY = "GlobalCamelService";
+    
+    private final ProducerTemplate globalContextProducerTemplate;
+    
+    private static final Logger logger = LoggerFactory.getLogger(GlobalContextCamelCommand.class);
+    
+    public GlobalContextCamelCommand() {
+        CamelContext globalCamelContext = (CamelContext) ServiceRegistry.get().service(GLOBAL_CAMEL_CONTEXT_SERVICE_KEY);
+        // TODO: Should we allow to set the maximumCacheSize on the producer?
+        this.globalContextProducerTemplate = globalCamelContext.createProducerTemplate();
+    }
+    
+    @Override
+    protected ProducerTemplate getProducerTemplate(CommandContext ctx) {
+        return globalContextProducerTemplate;
+    }
+    
+    @Override
+    public void close() {
+        try {
+            this.globalContextProducerTemplate.stop();
+        } catch (Exception e) {
+            logger.warn("Error encountered while closing the Camel Producer Template.", e);
+            // Not much we can do here, so swallowing exception.
+        }
+    }
+    
+
+}
diff --git a/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/InOnlyCamelWorkItemHandler.java b/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/InOnlyCamelWorkItemHandler.java
new file mode 100644
index 0000000..0588c02
--- /dev/null
+++ b/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/InOnlyCamelWorkItemHandler.java
@@ -0,0 +1,106 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.camel.component.jbpm.workitem;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.ExchangePattern;
+import org.apache.camel.Message;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.ExchangeBuilder;
+import org.drools.core.process.instance.impl.WorkItemImpl;
+import org.jbpm.process.workitem.core.util.Wid;
+import org.jbpm.process.workitem.core.util.WidMavenDepends;
+import org.jbpm.process.workitem.core.util.WidParameter;
+import org.jbpm.process.workitem.core.util.WidResult;
+import org.jbpm.process.workitem.core.util.service.WidAction;
+import org.jbpm.process.workitem.core.util.service.WidService;
+import org.kie.api.runtime.manager.RuntimeManager;
+import org.kie.api.runtime.process.WorkItem;
+import org.kie.api.runtime.process.WorkItemHandler;
+import org.kie.api.runtime.process.WorkItemManager;
+
+/**
+ * Camel jBPM {@link WorkItemHandler} that sends {@link Exchange Exchanges} with an <code>InOnly</code> Message Exchange Pattern.
+ * <p/>
+ * This handler does <b>NOT<b/> complete the {@link WorkItem}, and will not parse any response from the Camel route, other than possible exceptions.
+ * The use-case for this handler is asynchronous, one-way, communication, where an external party is responsible for completing the
+ * {@link WorkItem} at a later point in time.
+ * <p/>
+ * The handler creates a Camel Exchange and sets the {@link WorkItem} as the body of the {@link Message}. Furthermore, the following message
+ * headers are set:
+ * <ul>
+ * <li>deploymentId</li>
+ * <li>processInstanceId</li>
+ * <li>workItemId</li>
+ * </ul>
+ */
+@Wid(
+        widfile = "InOnlyCamelConnector.wid",
+        name = "InOnlyCamelConnector",
+        displayName = "InOnlyCamelConnector",
+        defaultHandler = "mvel: new org.apache.camel.component.jbpm.workitem.InOnlyCamelWorkitemHandler()",
+        documentation = "${artifactId}/index.html",
+        parameters = {
+                @WidParameter(name = "camel-endpoint-id")
+        },
+        results = {
+                @WidResult(name = "response"),
+                @WidResult(name = "message") },
+        mavenDepends = {
+                @WidMavenDepends(group = "${groupId}",
+                        artifact = "${artifactId}",
+                        version = "${version}")
+        },
+        serviceInfo = @WidService(category = "${name}",
+                description = "${description}",
+                keywords = "apache,camel,payload,route,connector",
+                action = @WidAction(title = "Send payload to a Camel endpoint")))
+public class InOnlyCamelWorkItemHandler extends AbstractCamelWorkItemHandler {
+
+    public InOnlyCamelWorkItemHandler() {
+        super();
+    }
+
+    public InOnlyCamelWorkItemHandler(String camelEndpointId) {
+        super(camelEndpointId);
+    }
+
+    public InOnlyCamelWorkItemHandler(RuntimeManager runtimeManager) {
+        super(runtimeManager);
+    }
+
+    public InOnlyCamelWorkItemHandler(RuntimeManager runtimeManager, String camelEndpointId) {
+        super(runtimeManager, camelEndpointId);
+    }
+
+    @Override
+    protected void handleResponse(Exchange responseExchange, WorkItem workItem, WorkItemManager manager) {
+        // no-op. There is no response for InOnly, so need to handle anything
+    }
+
+    @Override
+    protected Exchange buildExchange(ProducerTemplate template, WorkItem workItem) {
+        return ExchangeBuilder.anExchange(template.getCamelContext())
+                .withPattern(ExchangePattern.InOnly)
+                .withHeader("deploymentId", ((WorkItemImpl) workItem).getDeploymentId())
+                .withHeader("processInstanceId", workItem.getProcessInstanceId())
+                .withHeader("workItemId", workItem.getId())
+                .withBody(workItem).build();
+    }
+
+}
diff --git a/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/InOutCamelWorkItemHandler.java b/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/InOutCamelWorkItemHandler.java
new file mode 100644
index 0000000..d53c882
--- /dev/null
+++ b/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/InOutCamelWorkItemHandler.java
@@ -0,0 +1,119 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.camel.component.jbpm.workitem;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.ExchangePattern;
+import org.apache.camel.Message;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.ExchangeBuilder;
+import org.drools.core.process.instance.impl.WorkItemImpl;
+import org.jbpm.process.workitem.core.util.Wid;
+import org.jbpm.process.workitem.core.util.WidMavenDepends;
+import org.jbpm.process.workitem.core.util.WidParameter;
+import org.jbpm.process.workitem.core.util.WidResult;
+import org.jbpm.process.workitem.core.util.service.WidAction;
+import org.jbpm.process.workitem.core.util.service.WidService;
+import org.kie.api.runtime.manager.RuntimeManager;
+import org.kie.api.runtime.process.WorkItem;
+import org.kie.api.runtime.process.WorkItemHandler;
+import org.kie.api.runtime.process.WorkItemManager;
+
+/**
+ * Camel jBPM {@link WorkItemHandler} that sends {@link Exchange Exchanges} with an <code>InOut</code> Message Exchange Pattern.
+ * <p/>
+ * This handler parses the response message from the given Camel route and completes the {@link WorkItem}. The use-case for this handler is
+ * synchronous, request-response style, communication.
+ * <p/>
+ * The handler creates a Camel Exchange and sets the {@link WorkItem} as the body of the {@link Message}. Furthermore, the following message
+ * headers are set:
+ * <ul>
+ * <li>deploymentId</li>
+ * <li>processInstanceId</li>
+ * <li>workItemId</li>
+ * </ul>
+ */
+@Wid(
+        widfile = "InOutCamelConnector.wid",
+        name = "InOutCamelConnector",
+        displayName = "InOutCamelConnector",
+        defaultHandler = "mvel: new org.apache.camel.component.jbpm.workitem.InOutCamelWorkitemHandler()",
+        documentation = "${artifactId}/index.html",
+        parameters = {
+                @WidParameter(name = "camel-endpoint-id")
+        },
+        results = {
+                @WidResult(name = "response"),
+                @WidResult(name = "message") },
+        mavenDepends = {
+                @WidMavenDepends(group = "${groupId}",
+                        artifact = "${artifactId}",
+                        version = "${version}")
+        },
+        serviceInfo = @WidService(category = "${name}",
+                description = "${description}",
+                keywords = "apache,camel,payload,route,connector",
+                action = @WidAction(title = "Send payload to a Camel endpoint")))
+public class InOutCamelWorkItemHandler extends AbstractCamelWorkItemHandler {
+
+    private static final String RESPONSE_PARAM = "response";
+    private static final String MESSAGE_PARAM = "message";
+
+    public InOutCamelWorkItemHandler() {
+        super();
+    }
+
+    public InOutCamelWorkItemHandler(String camelEndpointId) {
+        super(camelEndpointId);
+    }
+
+    public InOutCamelWorkItemHandler(RuntimeManager runtimeManager) {
+        super(runtimeManager);
+    }
+
+    public InOutCamelWorkItemHandler(RuntimeManager runtimeManager, String camelEndpointId) {
+        super(runtimeManager, camelEndpointId);
+    }
+
+    @Override
+    protected void handleResponse(Exchange responseExchange, WorkItem workItem, WorkItemManager manager) {
+        Message outMessage = responseExchange.getOut();
+
+        Map<String, Object> result = new HashMap<>();
+        Object response = outMessage.getBody();
+        result.put(RESPONSE_PARAM, response);
+        result.put(MESSAGE_PARAM, outMessage);
+
+        manager.completeWorkItem(workItem.getId(), result);
+    }
+
+    @Override
+    protected Exchange buildExchange(ProducerTemplate template, WorkItem workItem) {
+        return ExchangeBuilder.anExchange(template.getCamelContext())
+                .withPattern(ExchangePattern.InOut)
+                .withHeader("deploymentId", ((WorkItemImpl) workItem).getDeploymentId())
+                .withHeader("processInstanceId", workItem.getProcessInstanceId())
+                .withHeader("workItemId", workItem.getId())
+                .withBody(workItem)
+                .build();
+    }
+
+}
diff --git a/components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/workitem/CamelWorkItemHandlerIntegrationTests.java b/components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/workitem/CamelWorkItemHandlerIntegrationTests.java
new file mode 100644
index 0000000..39fd861
--- /dev/null
+++ b/components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/workitem/CamelWorkItemHandlerIntegrationTests.java
@@ -0,0 +1,204 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.camel.component.jbpm.workitem;
+
+import static org.hamcrest.CoreMatchers.*;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Produce;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.drools.core.process.instance.impl.WorkItemImpl;
+import org.jbpm.bpmn2.handler.WorkItemHandlerRuntimeException;
+import org.jbpm.process.workitem.core.TestWorkItemManager;
+import org.jbpm.services.api.service.ServiceRegistry;
+import org.junit.Test;
+import org.kie.api.runtime.process.WorkItemHandler;
+
+//http://camel.apache.org/using-getin-or-getout-methods-on-exchange.html
+//http://camel.apache.org/async.html
+public class CamelWorkItemHandlerIntegrationTests extends CamelTestSupport {
+
+    @EndpointInject(uri = "mock:result")
+    protected MockEndpoint resultEndpoint;
+
+    @Produce(uri = "direct:start")
+    protected ProducerTemplate template;
+
+    @Test
+    public void testSyncInOnly() throws Exception {
+        // Setup
+        String routeId = "testSyncInOnlyExceptionRoute";
+        RouteBuilder builder = new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start").routeId(routeId)
+                        .setBody(simple("${body.getParameter(\"request\")}"))
+                        .to("mock:result");
+            }
+        };
+        context.addRoutes(builder);
+        try {
+            // Register the Camel Context with the jBPM ServiceRegistry.
+            ServiceRegistry.get().register("GlobalCamelService", context);
+
+            // Test
+            String expectedBody = "helloRequest";
+            resultEndpoint.expectedBodiesReceived(expectedBody);
+
+            WorkItemImpl workItem = new WorkItemImpl();
+            workItem.setParameter("camel-endpoint-id", "start");
+            workItem.setParameter("request", expectedBody);
+
+            TestWorkItemManager manager = new TestWorkItemManager();
+
+            WorkItemHandler handler = new InOnlyCamelWorkItemHandler();
+
+            handler.executeWorkItem(workItem, manager);
+
+            // Assertions
+            assertThat(manager.getResults().size(), equalTo(0));
+            resultEndpoint.assertIsSatisfied();
+        } finally {
+            // Cleanup
+            context.removeRoute(routeId);
+        }
+    }
+
+    @Test(expected = WorkItemHandlerRuntimeException.class)
+    public void testSyncInOnlyException() throws Exception {
+        // Setup
+        String routeId = "testSyncInOnlyExceptionRoute";
+        RouteBuilder builder = new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start").routeId(routeId)
+                        .setBody(simple("${body.getParameter(\"request\")}"))
+                        .throwException(new IllegalArgumentException("Illegal contennt!"))
+                        .to("mock:result");
+            }
+        };
+        context.addRoutes(builder);
+        try {
+            // Register the Camel Context with the jBPM ServiceRegistry.
+            ServiceRegistry.get().register("GlobalCamelService", context);
+
+            // Test
+            String expectedBody = "helloRequest";
+            resultEndpoint.expectedBodiesReceived(expectedBody);
+
+            WorkItemImpl workItem = new WorkItemImpl();
+            workItem.setParameter("camel-endpoint-id", "start");
+            workItem.setParameter("request", expectedBody);
+
+            TestWorkItemManager manager = new TestWorkItemManager();
+
+            WorkItemHandler handler = new InOnlyCamelWorkItemHandler();
+
+            handler.executeWorkItem(workItem, manager);
+
+            // Assertions
+            assertThat(manager.getResults().size(), equalTo(0));
+            resultEndpoint.assertIsSatisfied();
+        } finally {
+            // Cleanup
+            context.removeRoute(routeId);
+        }
+    }
+
+    @Test
+    public void testSyncInOut() throws Exception {
+        // Setup
+        String routeId = "testSyncInOnlyExceptionRoute";
+        RouteBuilder builder = new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start").routeId(routeId)
+                        .setBody(simple("${body.getParameter(\"request\")}"))
+                        .to("mock:result");
+            }
+        };
+        context.addRoutes(builder);
+        try {
+            // Register the Camel Context with the jBPM ServiceRegistry.
+            ServiceRegistry.get().register("GlobalCamelService", context);
+
+            // Test
+            String expectedBody = "helloRequest";
+            resultEndpoint.expectedBodiesReceived(expectedBody);
+
+            WorkItemImpl workItem = new WorkItemImpl();
+            workItem.setParameter("camel-endpoint-id", "start");
+            workItem.setParameter("request", expectedBody);
+
+            TestWorkItemManager manager = new TestWorkItemManager();
+
+            AbstractCamelWorkItemHandler handler = new InOutCamelWorkItemHandler();
+
+            handler.executeWorkItem(workItem, manager);
+
+            // Assertions
+            assertThat(manager.getResults().size(), equalTo(1));
+            resultEndpoint.assertIsSatisfied();
+        } finally {
+            // Cleanup
+            context.removeRoute(routeId);
+        }
+
+    }
+
+    @Test(expected = WorkItemHandlerRuntimeException.class)
+    public void testSyncInOutException() throws Exception {
+        // Setup
+        String routeId = "testSyncInOutExceptionRoute";
+        RouteBuilder builder = new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start").routeId(routeId)
+                        .setBody(simple("${body.getParameter(\"request\")}"))
+                        .throwException(new IllegalArgumentException("Illegal contennt!"))
+                        .to("mock:result");
+            }
+        };
+        context.addRoutes(builder);
+        try {
+            // Register the Camel Context with the jBPM ServiceRegistry.
+            ServiceRegistry.get().register("GlobalCamelService", context);
+
+            // Test
+            String expectedBody = "helloRequest";
+            resultEndpoint.expectedBodiesReceived(expectedBody);
+
+            WorkItemImpl workItem = new WorkItemImpl();
+            workItem.setParameter("camel-endpoint-id", "start");
+            workItem.setParameter("request", expectedBody);
+
+            TestWorkItemManager manager = new TestWorkItemManager();
+
+            WorkItemHandler handler = new InOutCamelWorkItemHandler();
+
+            handler.executeWorkItem(workItem, manager);
+        } finally {
+            // Cleanup
+            context.removeRoute(routeId);
+        }
+    }
+
+}
diff --git a/components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/workitem/CamelWorkItemHandlerTest.java b/components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/workitem/CamelWorkItemHandlerTest.java
deleted file mode 100644
index 7872132..0000000
--- a/components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/workitem/CamelWorkItemHandlerTest.java
+++ /dev/null
@@ -1,137 +0,0 @@
-/*
- * Copyright 2018 Red Hat, Inc. and/or its affiliates.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.camel.component.jbpm.workitem;
-
-import static org.junit.Assert.*;
-import static org.mockito.ArgumentMatchers.*;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.*;
-
-import java.util.Map;
-
-import org.apache.camel.CamelContext;
-import org.apache.camel.Exchange;
-import org.apache.camel.Message;
-import org.apache.camel.ProducerTemplate;
-import org.drools.core.process.instance.impl.WorkItemImpl;
-import org.jbpm.process.workitem.core.TestWorkItemManager;
-import org.jbpm.services.api.service.ServiceRegistry;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.kie.api.runtime.manager.RuntimeManager;
-import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
-
-@RunWith(MockitoJUnitRunner.class)
-public class CamelWorkItemHandlerTest {
-
-    @Mock
-    ProducerTemplate producerTemplate;
-
-    @Mock
-    Exchange outExchange;
-    
-    @Mock
-    Message outMessage;
-    
-    @Mock
-    CamelContext camelContext;
-    
-    @Mock
-    RuntimeManager runtimeManager;
-
-    @Test
-    public void testExecuteGlobalCamelContext() throws Exception {
-    
-    	String camelEndpointId = "testCamelRoute";
-    	String camelRouteUri = "direct://" + camelEndpointId;
-    	
-    	String testReponse = "testResponse";
-    	
-    	when(producerTemplate.send(eq(camelRouteUri), any(Exchange.class))).thenReturn(outExchange);
-    	when(producerTemplate.getCamelContext()).thenReturn(camelContext);
-    	
-    	when(camelContext.createProducerTemplate()).thenReturn(producerTemplate);
-    	
-    	when(outExchange.getOut()).thenReturn(outMessage);
-    	when(outMessage.getBody()).thenReturn(testReponse);
-    	
-    	ServiceRegistry.get().register("GlobalCamelService", camelContext);
-    	
-    	
-        TestWorkItemManager manager = new TestWorkItemManager();
-        WorkItemImpl workItem = new WorkItemImpl();
-        workItem.setParameter("camel-endpoint-id", camelEndpointId);
-        workItem.setParameter("request", "someRequest");
-        
-        CamelWorkItemHandler handler = new CamelWorkItemHandler();
-        
-        handler.executeWorkItem(workItem,
-                                manager);
-        assertNotNull(manager.getResults());
-        assertEquals(1,
-                     manager.getResults().size());
-        assertTrue(manager.getResults().containsKey(workItem.getId()));
-        Map<String, Object> results = manager.getResults(workItem.getId());
-        assertEquals(2, results.size());
-        assertEquals(testReponse, results.get("response"));
-    }
-    
-    @Test
-    public void testExecuteLocalCamelContext() throws Exception {
-    
-    	String camelEndpointId = "testCamelRoute";
-    	String camelRouteUri = "direct://" + camelEndpointId;
-    	
-    	String testReponse = "testResponse";
-    	
-    	String runtimeManagerId = "testRuntimeManager";
-    	
-    	when(runtimeManager.getIdentifier()).thenReturn(runtimeManagerId);
-    	
-    	when(producerTemplate.send(eq(camelRouteUri), any(Exchange.class))).thenReturn(outExchange);
-       	when(producerTemplate.getCamelContext()).thenReturn(camelContext);
-    	
-    	when(camelContext.createProducerTemplate()).thenReturn(producerTemplate);
-    	
-    	when(outExchange.getOut()).thenReturn(outMessage);
-    	when(outMessage.getBody()).thenReturn(testReponse);
-    	
-    	//Register the RuntimeManager bound camelcontext.
-    	ServiceRegistry.get().register(runtimeManagerId + "_CamelService", camelContext);
-    	
-    	
-        WorkItemImpl workItem = new WorkItemImpl();
-        workItem.setParameter("camel-endpoint-id", camelEndpointId);
-        workItem.setParameter("request", "someRequest");
-        
-        CamelWorkItemHandler handler = new CamelWorkItemHandler(runtimeManager);
-        
-        TestWorkItemManager manager = new TestWorkItemManager();
-        handler.executeWorkItem(workItem,
-                                manager);
-        assertNotNull(manager.getResults());
-        assertEquals(1,
-                     manager.getResults().size());
-        assertTrue(manager.getResults().containsKey(workItem.getId()));
-        Map<String, Object> results = manager.getResults(workItem.getId());
-        assertEquals(2, results.size());
-        assertEquals(testReponse, results.get("response"));
-    }
-
-
-}
diff --git a/components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/workitem/DeploymentContextCamelCommandTest.java b/components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/workitem/DeploymentContextCamelCommandTest.java
new file mode 100644
index 0000000..b703456
--- /dev/null
+++ b/components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/workitem/DeploymentContextCamelCommandTest.java
@@ -0,0 +1,95 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.camel.component.jbpm.workitem;
+
+import static org.junit.Assert.*;
+import static org.mockito.ArgumentMatchers.*;
+import static org.mockito.Mockito.*;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.ProducerTemplate;
+import org.drools.core.process.instance.impl.WorkItemImpl;
+import org.jbpm.services.api.service.ServiceRegistry;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.kie.api.executor.Command;
+import org.kie.api.executor.CommandContext;
+import org.kie.api.executor.ExecutionResults;
+import org.kie.api.runtime.manager.RuntimeManager;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+
+@RunWith(MockitoJUnitRunner.class)
+public class DeploymentContextCamelCommandTest {
+    
+    @Mock
+    ProducerTemplate producerTemplate;
+
+    @Mock
+    Exchange outExchange;
+    
+    @Mock
+    Message outMessage;
+    
+    @Mock
+    CamelContext camelContext;
+    
+    @Mock
+    RuntimeManager runtimeManager;
+    
+    @Mock
+    CommandContext commandContext;
+
+    @Test
+    public void testExecuteCommandDeploymentCamelContext() throws Exception {
+    
+        String camelEndpointId = "testCamelRoute";
+        String camelRouteUri = "direct://" + camelEndpointId;
+        
+        String testReponse = "testResponse";
+        
+        String deploymentId = "testDeployment";
+        
+        when(producerTemplate.send(eq(camelRouteUri), any(Exchange.class))).thenReturn(outExchange);
+        when(producerTemplate.getCamelContext()).thenReturn(camelContext);
+        
+        when(camelContext.createProducerTemplate()).thenReturn(producerTemplate);
+        
+        when(outExchange.getOut()).thenReturn(outMessage);
+        when(outMessage.getBody()).thenReturn(testReponse);
+        
+        //Register the RuntimeManager bound camelcontext.
+        ServiceRegistry.get().register(deploymentId + "_CamelService", camelContext);
+        
+        WorkItemImpl workItem = new WorkItemImpl();
+        workItem.setParameter("camel-endpoint-id", camelEndpointId);
+        workItem.setParameter("request", "someRequest");
+        
+        when(commandContext.getData("workItem")).thenReturn(workItem);
+        when(commandContext.getData("deploymentId")).thenReturn(deploymentId);
+        
+        Command command = new DeploymentContextCamelCommand();
+        ExecutionResults results = command.execute(commandContext);
+        
+        assertNotNull(results);
+        assertEquals(2, results.getData().size());
+        assertEquals(testReponse, results.getData().get("response"));
+    }
+}
diff --git a/components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/workitem/CamelCommandTest.java b/components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/workitem/GlobalContextCamelCommandTest.java
similarity index 54%
rename from components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/workitem/CamelCommandTest.java
rename to components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/workitem/GlobalContextCamelCommandTest.java
index 543b833..ad36879 100644
--- a/components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/workitem/CamelCommandTest.java
+++ b/components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/workitem/GlobalContextCamelCommandTest.java
@@ -1,11 +1,12 @@
-/*
- * Copyright 2018 Red Hat, Inc. and/or its affiliates.
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
  *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
+ *      http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
@@ -13,11 +14,12 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 package org.apache.camel.component.jbpm.workitem;
 
 import static org.junit.Assert.*;
+import static org.mockito.ArgumentMatchers.*;
 import static org.mockito.Mockito.*;
-import static org.mockito.ArgumentMatchers.any;
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.Exchange;
@@ -27,6 +29,7 @@ import org.drools.core.process.instance.impl.WorkItemImpl;
 import org.jbpm.services.api.service.ServiceRegistry;
 import org.junit.Test;
 import org.junit.runner.RunWith;
+import org.kie.api.executor.Command;
 import org.kie.api.executor.CommandContext;
 import org.kie.api.executor.ExecutionResults;
 import org.kie.api.runtime.manager.RuntimeManager;
@@ -34,7 +37,7 @@ import org.mockito.Mock;
 import org.mockito.junit.MockitoJUnitRunner;
 
 @RunWith(MockitoJUnitRunner.class)
-public class CamelCommandTest {
+public class GlobalContextCamelCommandTest {
 
 	@Mock
     ProducerTemplate producerTemplate;
@@ -55,7 +58,7 @@ public class CamelCommandTest {
     CommandContext commandContext;
 
     @Test
-    public void testExecuteComamnd() throws Exception {
+    public void testExecuteGlobalCommand() throws Exception {
     
     	String camelEndpointId = "testCamelRoute";
     	String camelRouteUri = "direct://" + camelEndpointId;
@@ -83,7 +86,7 @@ public class CamelCommandTest {
         
         when(commandContext.getData(anyString())).thenReturn(workItem);
         
-        CamelCommand command = new CamelCommand();
+        Command command = new GlobalContextCamelCommand();
         ExecutionResults results = command.execute(commandContext);
         
         
@@ -91,44 +94,4 @@ public class CamelCommandTest {
         assertEquals(2, results.getData().size());
         assertEquals(testReponse, results.getData().get("response"));
     }
-    
-    
-    @Test
-    public void testExecuteCommandLocalCamelContext() throws Exception {
-    
-    	String camelEndpointId = "testCamelRoute";
-    	String camelRouteUri = "direct://" + camelEndpointId;
-    	
-    	String testReponse = "testResponse";
-    	
-    	String runtimeManagerId = "testRuntimeManager";
-    	
-    	when(runtimeManager.getIdentifier()).thenReturn(runtimeManagerId);
-    	
-    	when(producerTemplate.send(eq(camelRouteUri), any(Exchange.class))).thenReturn(outExchange);
-    	//when(producerTemplate.send(argThat(not(camelRouteUri)), any(Exchange.class))).thenThrow(new IllegalArgumentException("Unexpected route id"));
-    	when(producerTemplate.getCamelContext()).thenReturn(camelContext);
-    	
-    	when(camelContext.createProducerTemplate()).thenReturn(producerTemplate);
-    	
-    	when(outExchange.getOut()).thenReturn(outMessage);
-    	when(outMessage.getBody()).thenReturn(testReponse);
-    	
-    	//Register the RuntimeManager bound camelcontext.
-    	ServiceRegistry.get().register(runtimeManagerId + "_CamelService", camelContext);
-    	
-        WorkItemImpl workItem = new WorkItemImpl();
-        workItem.setParameter("camel-endpoint-id", camelEndpointId);
-        workItem.setParameter("request", "someRequest");
-        
-        when(commandContext.getData(anyString())).thenReturn(workItem);
-        
-        CamelCommand command = new CamelCommand(runtimeManager);
-        ExecutionResults results = command.execute(commandContext);
-        
-        assertNotNull(results);
-        assertEquals(2, results.getData().size());
-        assertEquals(testReponse, results.getData().get("response"));
-    }
-
 }
diff --git a/components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/workitem/InOnlyCamelWorkItemHandlerTest.java b/components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/workitem/InOnlyCamelWorkItemHandlerTest.java
new file mode 100644
index 0000000..1ad1bf9
--- /dev/null
+++ b/components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/workitem/InOnlyCamelWorkItemHandlerTest.java
@@ -0,0 +1,97 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.camel.component.jbpm.workitem;
+
+import static org.hamcrest.CoreMatchers.*;
+import static org.junit.Assert.*;
+import static org.mockito.ArgumentMatchers.*;
+import static org.mockito.Mockito.*;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.impl.DefaultHeadersMapFactory;
+import org.apache.camel.spi.HeadersMapFactory;
+import org.drools.core.process.instance.impl.WorkItemImpl;
+import org.jbpm.process.workitem.core.TestWorkItemManager;
+import org.jbpm.services.api.service.ServiceRegistry;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.kie.api.runtime.manager.RuntimeManager;
+import org.mockito.ArgumentMatchers;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+
+@RunWith(MockitoJUnitRunner.class)
+public class InOnlyCamelWorkItemHandlerTest {
+
+    @Mock
+    ProducerTemplate producerTemplate;
+
+    @Mock
+    Exchange outExchange;
+
+    @Mock
+    Message outMessage;
+
+    @Mock
+    CamelContext camelContext;
+
+    @Mock
+    RuntimeManager runtimeManager;
+
+    @Test
+    public void testExecuteInOnlyLocalCamelContext() throws Exception {
+
+        String camelEndpointId = "testCamelRoute";
+        String camelRouteUri = "direct://" + camelEndpointId;
+
+        String testReponse = "testResponse";
+
+        String runtimeManagerId = "testRuntimeManager";
+
+        when(runtimeManager.getIdentifier()).thenReturn(runtimeManagerId);
+
+        when(producerTemplate.send(eq(camelRouteUri), ArgumentMatchers.any(Exchange.class))).thenReturn(outExchange);
+        when(producerTemplate.getCamelContext()).thenReturn(camelContext);
+
+        when(camelContext.createProducerTemplate()).thenReturn(producerTemplate);
+        HeadersMapFactory hmf = new DefaultHeadersMapFactory();
+        when(camelContext.getHeadersMapFactory()).thenReturn(hmf);
+
+        // Register the RuntimeManager bound camelcontext.
+        ServiceRegistry.get().register(runtimeManagerId + "_CamelService", camelContext);
+
+        WorkItemImpl workItem = new WorkItemImpl();
+        workItem.setParameter("camel-endpoint-id", camelEndpointId);
+        workItem.setParameter("request", "someRequest");
+        workItem.setDeploymentId("testDeploymentId");
+        workItem.setProcessInstanceId(1L);
+        workItem.setId(1L);
+        
+        AbstractCamelWorkItemHandler handler = new InOnlyCamelWorkItemHandler(runtimeManager);
+
+        TestWorkItemManager manager = new TestWorkItemManager();
+        handler.executeWorkItem(workItem,
+                manager);
+        assertThat(manager.getResults(), is(notNullValue()));
+        //InOnly does not complete WorkItem.
+        assertThat(manager.getResults().size(), equalTo(0));
+    }
+}
diff --git a/components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/workitem/InOutCamelWorkItemHandlerTest.java b/components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/workitem/InOutCamelWorkItemHandlerTest.java
new file mode 100644
index 0000000..e4bc6ba
--- /dev/null
+++ b/components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/workitem/InOutCamelWorkItemHandlerTest.java
@@ -0,0 +1,147 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.camel.component.jbpm.workitem;
+
+import static org.hamcrest.CoreMatchers.*;
+import static org.junit.Assert.*;
+import static org.mockito.ArgumentMatchers.*;
+import static org.mockito.Mockito.*;
+
+import java.util.Map;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.impl.DefaultHeadersMapFactory;
+import org.apache.camel.spi.HeadersMapFactory;
+import org.drools.core.process.instance.impl.WorkItemImpl;
+import org.jbpm.process.workitem.core.TestWorkItemManager;
+import org.jbpm.services.api.service.ServiceRegistry;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.kie.api.runtime.manager.RuntimeManager;
+import org.mockito.ArgumentMatchers;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+
+@RunWith(MockitoJUnitRunner.class)
+public class InOutCamelWorkItemHandlerTest {
+
+    @Mock
+    ProducerTemplate producerTemplate;
+
+    @Mock
+    Exchange outExchange;
+
+    @Mock
+    Message outMessage;
+
+    @Mock
+    CamelContext camelContext;
+
+    @Mock
+    RuntimeManager runtimeManager;
+
+    @Test
+    public void testExecuteInOutGlobalCamelContext() throws Exception {
+
+        String camelEndpointId = "testCamelRoute";
+        String camelRouteUri = "direct://" + camelEndpointId;
+
+        String testReponse = "testResponse";
+
+        when(producerTemplate.send(eq(camelRouteUri), ArgumentMatchers.any(Exchange.class))).thenReturn(outExchange);
+        when(producerTemplate.getCamelContext()).thenReturn(camelContext);
+
+        when(camelContext.createProducerTemplate()).thenReturn(producerTemplate);
+        HeadersMapFactory hmf = new DefaultHeadersMapFactory();
+        when(camelContext.getHeadersMapFactory()).thenReturn(hmf);
+
+        when(outExchange.getOut()).thenReturn(outMessage);
+        when(outMessage.getBody()).thenReturn(testReponse);
+
+        ServiceRegistry.get().register("GlobalCamelService", camelContext);
+
+        TestWorkItemManager manager = new TestWorkItemManager();
+        WorkItemImpl workItem = new WorkItemImpl();
+        workItem.setParameter("camel-endpoint-id", camelEndpointId);
+        workItem.setParameter("request", "someRequest");
+        workItem.setDeploymentId("testDeploymentId");
+        workItem.setProcessInstanceId(1L);
+        workItem.setId(1L);
+
+        AbstractCamelWorkItemHandler handler = new InOutCamelWorkItemHandler();
+
+        handler.executeWorkItem(workItem,
+                manager);
+        assertThat(manager.getResults(), is(notNullValue()));
+        assertThat(manager.getResults().size(), equalTo(1));
+        assertThat(manager.getResults().containsKey(workItem.getId()), is(true));
+        Map<String, Object> results = manager.getResults(workItem.getId());
+        assertThat(results.size(), equalTo(2));
+        assertThat(results.get("response"), equalTo(testReponse));
+    }
+
+    @Test
+    public void testExecuteInOutLocalCamelContext() throws Exception {
+
+        String camelEndpointId = "testCamelRoute";
+        String camelRouteUri = "direct://" + camelEndpointId;
+
+        String testReponse = "testResponse";
+
+        String runtimeManagerId = "testRuntimeManager";
+
+        when(runtimeManager.getIdentifier()).thenReturn(runtimeManagerId);
+
+        when(producerTemplate.send(eq(camelRouteUri), ArgumentMatchers.any(Exchange.class))).thenReturn(outExchange);
+        when(producerTemplate.getCamelContext()).thenReturn(camelContext);
+
+        when(camelContext.createProducerTemplate()).thenReturn(producerTemplate);
+        HeadersMapFactory hmf = new DefaultHeadersMapFactory();
+        when(camelContext.getHeadersMapFactory()).thenReturn(hmf);
+
+        when(outExchange.getOut()).thenReturn(outMessage);
+        when(outMessage.getBody()).thenReturn(testReponse);
+
+        // Register the RuntimeManager bound camelcontext.
+        ServiceRegistry.get().register(runtimeManagerId + "_CamelService", camelContext);
+
+        WorkItemImpl workItem = new WorkItemImpl();
+        workItem.setParameter("camel-endpoint-id", camelEndpointId);
+        workItem.setParameter("request", "someRequest");
+        workItem.setDeploymentId("testDeploymentId");
+        workItem.setProcessInstanceId(1L);
+        workItem.setId(1L);
+
+        AbstractCamelWorkItemHandler handler = new InOutCamelWorkItemHandler(runtimeManager);
+
+        TestWorkItemManager manager = new TestWorkItemManager();
+        handler.executeWorkItem(workItem,
+                manager);
+        assertThat(manager.getResults(), is(notNullValue()));
+        assertThat(manager.getResults().size(), equalTo(1));
+        assertThat(manager.getResults().containsKey(workItem.getId()), is(true));
+        
+        Map<String, Object> results = manager.getResults(workItem.getId());
+        assertThat(results.size(), equalTo(2));
+        assertThat(results.get("response"), equalTo(testReponse));
+    }
+   
+}


[camel] 01/05: CAMEL-12964: Initial import of jBPM CamelWIH and Command.

Posted by dm...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

dmvolod pushed a commit to branch camel-2.23.x
in repository https://gitbox.apache.org/repos/asf/camel.git

commit a0fc18b3a67558073e7a7d3ff9db30b077c6695e
Author: Duncan Doyle <Du...@gmail.com>
AuthorDate: Wed Nov 28 13:50:22 2018 +0100

    CAMEL-12964: Initial import of jBPM CamelWIH and Command.
---
 components/camel-jbpm/pom.xml                      |  27 ++++
 .../component/jbpm/workitem/CamelCommand.java      | 121 ++++++++++++++++++
 .../jbpm/workitem/CamelWorkItemHandler.java        | 137 +++++++++++++++++++++
 .../component/jbpm/workitem/CamelCommandTest.java  | 134 ++++++++++++++++++++
 .../jbpm/workitem/CamelWorkItemHandlerTest.java    | 137 +++++++++++++++++++++
 5 files changed, 556 insertions(+)

diff --git a/components/camel-jbpm/pom.xml b/components/camel-jbpm/pom.xml
index ecbb6e9..c6c4dc9 100644
--- a/components/camel-jbpm/pom.xml
+++ b/components/camel-jbpm/pom.xml
@@ -92,6 +92,15 @@
             <optional>true</optional>
         </dependency>
         
+        <!-- jBPM WorkItems -->
+        <dependency>
+        	<groupId>org.jbpm</groupId>
+        	<artifactId>jbpm-workitems-core</artifactId>
+        	<version>${jbpm-version}</version>
+        	<scope>provided</scope>
+        	<optional>true</optional>
+        </dependency>
+        
         <dependency>
             <groupId>org.jboss.logging</groupId>
             <artifactId>jboss-logging</artifactId>
@@ -128,6 +137,24 @@
             <artifactId>camel-test</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+        	<groupId>org.mockito</groupId>
+        	<artifactId>mockito-core</artifactId>
+        	<scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.jbpm</groupId>
+            <artifactId>jbpm-workitems-core</artifactId>
+            <version>${jbpm-version}</version>
+            <type>test-jar</type>
+            <scope>test</scope>
+            <exclusions>
+               <exclusion>
+                   <groupId>xml-apis</groupId>
+                   <artifactId>xml-apis</artifactId>
+               </exclusion>
+            </exclusions>
+        </dependency>
     </dependencies>
 
 </project>
diff --git a/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/CamelCommand.java b/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/CamelCommand.java
new file mode 100644
index 0000000..80c767e
--- /dev/null
+++ b/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/CamelCommand.java
@@ -0,0 +1,121 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.camel.component.jbpm.workitem;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.ExchangeBuilder;
+import org.jbpm.services.api.service.ServiceRegistry;
+import org.kie.api.executor.Command;
+import org.kie.api.executor.CommandContext;
+import org.kie.api.executor.ExecutionResults;
+import org.kie.api.runtime.manager.RuntimeManager;
+import org.kie.api.runtime.process.WorkItem;
+import org.kie.internal.runtime.Cacheable;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Camel jBPM {@link Command} which allows to call Camel routes with a <code>direct</code> endpoint.
+ * <p/>
+ * The command passes the {@WorkItem} retrieved from the {@link CommandContext} to the route that has a consumer on the endpoint-id 
+ * that can be passed with the <code>camel-endpoint-id</code> {@link WorkItem} parameter. E.g. when a the value "myCamelEndpoint" is passed to the 
+ * {link WorkItem} via the <code>camel-endpoint-id</code> parameter, this {@link Command} will send the {@link WorkItem} to 
+ * the Camel URI <code>direct://myCamelEndpoint</code>.  
+ * <p/>
+ * The body of the result {@link Message} of the invocation is returned via the <code>response</code> parameter. Access to the raw response 
+ * {@link Message} is provided via the <code>message</code> parameter. This gives the user access to more advanced fields like message headers 
+ * and attachments.  
+ * <p/>
+ * This {@link Command} can be constructed in 2 ways. When using the default constructor, the {link Command} will try to find 
+ * the global KIE {@link CamelContext} from the <code>jBPM</code> {@link ServiceRegistry}. 
+ * When the {@link RuntimeManager} is passed to the constructor, the {@link Command} will retrieve and use the {@link CamelContext} bound 
+ * to the {@link RuntimeManage} from the {@link ServiceRegistry}
+ * 
+ */
+public class CamelCommand implements Command,
+                                          Cacheable {
+
+	private static final String GLOBAL_CAMEL_CONTEXT_SERVICE_KEY = "GlobalCamelService";
+	private static final String RUNTIME_CAMEL_CONTEXT_SERVICE_POSTFIX = "_CamelService";
+	
+	private static final String CAMEL_ENDPOINT_ID_PARAM = "camel-endpoint-id";
+	private static final String RESPONSE_PARAM = "response";
+	private static final String MESSAGE_PARAM = "out-headers";
+
+	
+    private static final Logger logger = LoggerFactory.getLogger(CamelCommand.class);
+
+	private final ProducerTemplate producerTemplate;
+
+
+	public CamelCommand() {
+		CamelContext globalCamelContext = (CamelContext) ServiceRegistry.get().service(GLOBAL_CAMEL_CONTEXT_SERVICE_KEY);
+		// TODO: Should we allow to set the maximumCacheSize on the producer?
+		this.producerTemplate = globalCamelContext.createProducerTemplate();
+	}
+	
+	public CamelCommand(RuntimeManager runtimeManager) {
+		String runtimeCamelContextKey = runtimeManager.getIdentifier() + RUNTIME_CAMEL_CONTEXT_SERVICE_POSTFIX;
+		CamelContext runtimeCamelContext = (CamelContext) ServiceRegistry.get().service(runtimeCamelContextKey);
+		// TODO: Should we allow to set the maximumCacheSize on the producer?
+		this.producerTemplate = runtimeCamelContext.createProducerTemplate();
+	}
+	
+	
+	
+    @Override
+    public ExecutionResults execute(CommandContext ctx) throws Exception {
+        
+    	WorkItem workItem = (WorkItem) ctx.getData("workItem");
+    	
+    	String camelEndpointId = (String) workItem.getParameter(CAMEL_ENDPOINT_ID_PARAM);
+		
+		// We only support direct. We don't need to support more, as direct simply gives us the entrypoint into the actual Camel Routes.
+		String camelUri = "direct://" + camelEndpointId;
+		
+		Exchange inExchange = ExchangeBuilder.anExchange(producerTemplate.getCamelContext()).withBody(workItem).build();
+		Exchange outExchange = producerTemplate.send(camelUri, inExchange);
+		// producerTemplate.send does not throw exceptions, instead they are set on the returned Exchange.
+		if (outExchange.getException() != null) {
+			throw outExchange.getException();
+		}
+		Message outMessage = outExchange.getOut();
+		
+		ExecutionResults results = new ExecutionResults();
+		Object response = outMessage.getBody();
+		results.setData(RESPONSE_PARAM, response);
+		results.setData(MESSAGE_PARAM, outMessage);
+    	
+        return results;
+    }
+
+    
+	@Override
+	public void close() {
+		try {
+			this.producerTemplate.stop();
+		} catch (Exception e) {
+			logger.warn("Error encountered while closing the Camel Producer Template.", e);
+			// Not much we can do here, so swallowing exception.
+		}
+	}
+
+}
\ No newline at end of file
diff --git a/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/CamelWorkItemHandler.java b/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/CamelWorkItemHandler.java
new file mode 100644
index 0000000..7734dd9
--- /dev/null
+++ b/components/camel-jbpm/src/main/java/org/apache/camel/component/jbpm/workitem/CamelWorkItemHandler.java
@@ -0,0 +1,137 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.camel.component.jbpm.workitem;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.ExchangeBuilder;
+import org.jbpm.process.workitem.core.AbstractLogOrThrowWorkItemHandler;
+import org.jbpm.process.workitem.core.util.Wid;
+import org.jbpm.process.workitem.core.util.WidMavenDepends;
+import org.jbpm.process.workitem.core.util.WidParameter;
+import org.jbpm.process.workitem.core.util.WidResult;
+import org.jbpm.process.workitem.core.util.service.WidAction;
+import org.jbpm.process.workitem.core.util.service.WidService;
+import org.jbpm.services.api.service.ServiceRegistry;
+import org.kie.api.runtime.manager.RuntimeManager;
+import org.kie.api.runtime.process.WorkItem;
+import org.kie.api.runtime.process.WorkItemManager;
+import org.kie.internal.runtime.Cacheable;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Camel jBPM {@link WorkItemHandler} which allows to call Camel routes with a <code>direct</code> endpoint.
+ * <p/>
+ * The handler passes the {@WorkItem} to the route that has a consumer on the endpoint-id that can be passed with the
+ * <code>camel-endpoint-id</code>{@link WorkItem} parameter. E.g. when a the value "myCamelEndpoint" is passed to the 
+ * {link WorkItem} via the <code>camel-endpoint-id</code> parameter, this command will send the {@link WorkItem} to the Camel URI
+ * <code>direct://myCamelEndpoint</code>.
+ * <p/>
+ * The body of the result {@link Message} of the invocation is returned via the <code>response</code> parameter. Access to the raw response
+ * {@link Message} is provided via the <code>message</code> parameter. This gives the user access to more advanced fields like message
+ * headers and attachments.
+ * <p/>
+ * This handler can be constructed in 2 ways. When using the default constructor, the handler will try to find the global KIE
+ * {@link CamelContext} from the <code>jBPM</code> {@link ServiceRegistry}. When the {@link RuntimeManager} is passed to the constructor,
+ * the handler will retrieve and use the {@link CamelContext} bound to the {@link RuntimeManage} from the {@link ServiceRegistry}
+ * 
+ */
+@Wid(widfile = "CamelConnector.wid", name = "CamelConnector", displayName = "CamelConnector", defaultHandler = "mvel: new org.apache.camel.component.jbpm.workitem.CamelWorkitemHandler()", documentation = "${artifactId}/index.html", parameters = {
+		@WidParameter(name = "camel-endpoint-id") }, results = { @WidResult(name = "response"),
+				@WidResult(name = "message") }, mavenDepends = {
+						@WidMavenDepends(group = "${groupId}", artifact = "${artifactId}", version = "${version}") }, serviceInfo = @WidService(category = "${name}", description = "${description}", keywords = "apache,camel,payload,route,connector", action = @WidAction(title = "Send payload to a Camel endpoint")))
+public class CamelWorkItemHandler extends AbstractLogOrThrowWorkItemHandler implements Cacheable {
+
+	private static final String GLOBAL_CAMEL_CONTEXT_SERVICE_KEY = "GlobalCamelService";
+	private static final String RUNTIME_CAMEL_CONTEXT_SERVICE_POSTFIX = "_CamelService";
+
+	private static final String CAMEL_ENDPOINT_ID_PARAM = "camel-endpoint-id";
+	private static final String RESPONSE_PARAM = "response";
+	private static final String MESSAGE_PARAM = "message";
+
+	private static Logger logger = LoggerFactory.getLogger(CamelWorkItemHandler.class);
+
+	private final ProducerTemplate producerTemplate;
+
+	/**
+	 * Default Constructor. This creates a {@link ProducerTemplate} for the global {@link CamelContext}.
+	 */
+	public CamelWorkItemHandler() {
+		CamelContext globalCamelContext = (CamelContext) ServiceRegistry.get().service(GLOBAL_CAMEL_CONTEXT_SERVICE_KEY);
+		// TODO: Should we allow to set the maximumCacheSize on the producer?
+		this.producerTemplate = globalCamelContext.createProducerTemplate();
+	}
+
+	/**
+	 * Constructor which accepts {@link RuntimeManager}. This causes this WorkItemHanlder to create a {@link ProducerTemplate} for the
+	 * runtime specific {@link CamelContext}.
+	 */
+	public CamelWorkItemHandler(RuntimeManager runtimeManager) {
+		String runtimeCamelContextKey = runtimeManager.getIdentifier() + RUNTIME_CAMEL_CONTEXT_SERVICE_POSTFIX;
+		CamelContext runtimeCamelContext = (CamelContext) ServiceRegistry.get().service(runtimeCamelContextKey);
+		// TODO: Should we allow to set the maximumCacheSize on the producer?
+		this.producerTemplate = runtimeCamelContext.createProducerTemplate();
+	}
+
+	public void executeWorkItem(WorkItem workItem, final WorkItemManager manager) {
+
+		String camelEndpointId = (String) workItem.getParameter(CAMEL_ENDPOINT_ID_PARAM);
+
+		// We only support direct. We don't need to support more, as direct simply gives us the entrypoint into the actual Camel Routes.
+		String camelUri = "direct://" + camelEndpointId;
+		try {
+			Exchange inExchange = ExchangeBuilder.anExchange(producerTemplate.getCamelContext()).withBody(workItem).build();
+			Exchange outExchange = producerTemplate.send(camelUri, inExchange);
+			// producerTemplate.send does not throw exceptions, instead they are set on the returned Exchange.
+			if (outExchange.getException() != null) {
+				throw outExchange.getException();
+			}
+			Message outMessage = outExchange.getOut();
+
+			Map<String, Object> result = new HashMap<>();
+			Object response = outMessage.getBody();
+			result.put(RESPONSE_PARAM, response);
+			result.put(MESSAGE_PARAM, outMessage);
+
+			manager.completeWorkItem(workItem.getId(), result);
+		} catch (Exception e) {
+			handleException(e);
+		}
+	}
+
+	public void abortWorkItem(WorkItem workItem, WorkItemManager manager) {
+		// Do nothing, cannot be aborted
+	}
+
+	@Override
+	public void close() {
+		try {
+			this.producerTemplate.stop();
+		} catch (Exception e) {
+			logger.warn("Error encountered while closing the Camel Producer Template.", e);
+			// Not much we can do here, so swallowing exception.
+		}
+	}
+
+}
\ No newline at end of file
diff --git a/components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/workitem/CamelCommandTest.java b/components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/workitem/CamelCommandTest.java
new file mode 100644
index 0000000..543b833
--- /dev/null
+++ b/components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/workitem/CamelCommandTest.java
@@ -0,0 +1,134 @@
+/*
+ * Copyright 2018 Red Hat, Inc. and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.jbpm.workitem;
+
+import static org.junit.Assert.*;
+import static org.mockito.Mockito.*;
+import static org.mockito.ArgumentMatchers.any;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.ProducerTemplate;
+import org.drools.core.process.instance.impl.WorkItemImpl;
+import org.jbpm.services.api.service.ServiceRegistry;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.kie.api.executor.CommandContext;
+import org.kie.api.executor.ExecutionResults;
+import org.kie.api.runtime.manager.RuntimeManager;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+
+@RunWith(MockitoJUnitRunner.class)
+public class CamelCommandTest {
+
+	@Mock
+    ProducerTemplate producerTemplate;
+
+    @Mock
+    Exchange outExchange;
+    
+    @Mock
+    Message outMessage;
+    
+    @Mock
+    CamelContext camelContext;
+    
+    @Mock
+    RuntimeManager runtimeManager;
+    
+    @Mock
+    CommandContext commandContext;
+
+    @Test
+    public void testExecuteComamnd() throws Exception {
+    
+    	String camelEndpointId = "testCamelRoute";
+    	String camelRouteUri = "direct://" + camelEndpointId;
+    	
+    	String testReponse = "testResponse";
+    	
+    	String runtimeManagerId = "testRuntimeManager";
+    	
+    	when(producerTemplate.send(eq(camelRouteUri), any(Exchange.class))).thenReturn(outExchange);
+    	
+    	
+    	when(producerTemplate.getCamelContext()).thenReturn(camelContext);
+    	
+    	when(camelContext.createProducerTemplate()).thenReturn(producerTemplate);
+    	
+    	when(outExchange.getOut()).thenReturn(outMessage);
+    	when(outMessage.getBody()).thenReturn(testReponse);
+    	
+    	//Register the RuntimeManager bound camelcontext.
+    	ServiceRegistry.get().register("GlobalCamelService", camelContext);
+    	
+        WorkItemImpl workItem = new WorkItemImpl();
+        workItem.setParameter("camel-endpoint-id", camelEndpointId);
+        workItem.setParameter("request", "someRequest");
+        
+        when(commandContext.getData(anyString())).thenReturn(workItem);
+        
+        CamelCommand command = new CamelCommand();
+        ExecutionResults results = command.execute(commandContext);
+        
+        
+        assertNotNull(results);
+        assertEquals(2, results.getData().size());
+        assertEquals(testReponse, results.getData().get("response"));
+    }
+    
+    
+    @Test
+    public void testExecuteCommandLocalCamelContext() throws Exception {
+    
+    	String camelEndpointId = "testCamelRoute";
+    	String camelRouteUri = "direct://" + camelEndpointId;
+    	
+    	String testReponse = "testResponse";
+    	
+    	String runtimeManagerId = "testRuntimeManager";
+    	
+    	when(runtimeManager.getIdentifier()).thenReturn(runtimeManagerId);
+    	
+    	when(producerTemplate.send(eq(camelRouteUri), any(Exchange.class))).thenReturn(outExchange);
+    	//when(producerTemplate.send(argThat(not(camelRouteUri)), any(Exchange.class))).thenThrow(new IllegalArgumentException("Unexpected route id"));
+    	when(producerTemplate.getCamelContext()).thenReturn(camelContext);
+    	
+    	when(camelContext.createProducerTemplate()).thenReturn(producerTemplate);
+    	
+    	when(outExchange.getOut()).thenReturn(outMessage);
+    	when(outMessage.getBody()).thenReturn(testReponse);
+    	
+    	//Register the RuntimeManager bound camelcontext.
+    	ServiceRegistry.get().register(runtimeManagerId + "_CamelService", camelContext);
+    	
+        WorkItemImpl workItem = new WorkItemImpl();
+        workItem.setParameter("camel-endpoint-id", camelEndpointId);
+        workItem.setParameter("request", "someRequest");
+        
+        when(commandContext.getData(anyString())).thenReturn(workItem);
+        
+        CamelCommand command = new CamelCommand(runtimeManager);
+        ExecutionResults results = command.execute(commandContext);
+        
+        assertNotNull(results);
+        assertEquals(2, results.getData().size());
+        assertEquals(testReponse, results.getData().get("response"));
+    }
+
+}
diff --git a/components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/workitem/CamelWorkItemHandlerTest.java b/components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/workitem/CamelWorkItemHandlerTest.java
new file mode 100644
index 0000000..7872132
--- /dev/null
+++ b/components/camel-jbpm/src/test/java/org/apache/camel/component/jbpm/workitem/CamelWorkItemHandlerTest.java
@@ -0,0 +1,137 @@
+/*
+ * Copyright 2018 Red Hat, Inc. and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.camel.component.jbpm.workitem;
+
+import static org.junit.Assert.*;
+import static org.mockito.ArgumentMatchers.*;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.*;
+
+import java.util.Map;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.ProducerTemplate;
+import org.drools.core.process.instance.impl.WorkItemImpl;
+import org.jbpm.process.workitem.core.TestWorkItemManager;
+import org.jbpm.services.api.service.ServiceRegistry;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.kie.api.runtime.manager.RuntimeManager;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+
+@RunWith(MockitoJUnitRunner.class)
+public class CamelWorkItemHandlerTest {
+
+    @Mock
+    ProducerTemplate producerTemplate;
+
+    @Mock
+    Exchange outExchange;
+    
+    @Mock
+    Message outMessage;
+    
+    @Mock
+    CamelContext camelContext;
+    
+    @Mock
+    RuntimeManager runtimeManager;
+
+    @Test
+    public void testExecuteGlobalCamelContext() throws Exception {
+    
+    	String camelEndpointId = "testCamelRoute";
+    	String camelRouteUri = "direct://" + camelEndpointId;
+    	
+    	String testReponse = "testResponse";
+    	
+    	when(producerTemplate.send(eq(camelRouteUri), any(Exchange.class))).thenReturn(outExchange);
+    	when(producerTemplate.getCamelContext()).thenReturn(camelContext);
+    	
+    	when(camelContext.createProducerTemplate()).thenReturn(producerTemplate);
+    	
+    	when(outExchange.getOut()).thenReturn(outMessage);
+    	when(outMessage.getBody()).thenReturn(testReponse);
+    	
+    	ServiceRegistry.get().register("GlobalCamelService", camelContext);
+    	
+    	
+        TestWorkItemManager manager = new TestWorkItemManager();
+        WorkItemImpl workItem = new WorkItemImpl();
+        workItem.setParameter("camel-endpoint-id", camelEndpointId);
+        workItem.setParameter("request", "someRequest");
+        
+        CamelWorkItemHandler handler = new CamelWorkItemHandler();
+        
+        handler.executeWorkItem(workItem,
+                                manager);
+        assertNotNull(manager.getResults());
+        assertEquals(1,
+                     manager.getResults().size());
+        assertTrue(manager.getResults().containsKey(workItem.getId()));
+        Map<String, Object> results = manager.getResults(workItem.getId());
+        assertEquals(2, results.size());
+        assertEquals(testReponse, results.get("response"));
+    }
+    
+    @Test
+    public void testExecuteLocalCamelContext() throws Exception {
+    
+    	String camelEndpointId = "testCamelRoute";
+    	String camelRouteUri = "direct://" + camelEndpointId;
+    	
+    	String testReponse = "testResponse";
+    	
+    	String runtimeManagerId = "testRuntimeManager";
+    	
+    	when(runtimeManager.getIdentifier()).thenReturn(runtimeManagerId);
+    	
+    	when(producerTemplate.send(eq(camelRouteUri), any(Exchange.class))).thenReturn(outExchange);
+       	when(producerTemplate.getCamelContext()).thenReturn(camelContext);
+    	
+    	when(camelContext.createProducerTemplate()).thenReturn(producerTemplate);
+    	
+    	when(outExchange.getOut()).thenReturn(outMessage);
+    	when(outMessage.getBody()).thenReturn(testReponse);
+    	
+    	//Register the RuntimeManager bound camelcontext.
+    	ServiceRegistry.get().register(runtimeManagerId + "_CamelService", camelContext);
+    	
+    	
+        WorkItemImpl workItem = new WorkItemImpl();
+        workItem.setParameter("camel-endpoint-id", camelEndpointId);
+        workItem.setParameter("request", "someRequest");
+        
+        CamelWorkItemHandler handler = new CamelWorkItemHandler(runtimeManager);
+        
+        TestWorkItemManager manager = new TestWorkItemManager();
+        handler.executeWorkItem(workItem,
+                                manager);
+        assertNotNull(manager.getResults());
+        assertEquals(1,
+                     manager.getResults().size());
+        assertTrue(manager.getResults().containsKey(workItem.getId()));
+        Map<String, Object> results = manager.getResults(workItem.getId());
+        assertEquals(2, results.size());
+        assertEquals(testReponse, results.get("response"));
+    }
+
+
+}