[jboss-svn-commits] JBL Code SVN: r14087 - labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actionhandlers.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Tue Aug 7 15:21:59 EDT 2007
Author: mark.little at jboss.com
Date: 2007-08-07 15:21:59 -0400 (Tue, 07 Aug 2007)
New Revision: 14087
Modified:
labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actionhandlers/EsbActionHandler.java
Log:
http://jira.jboss.com/jira/browse/JBESB-747
Modified: labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actionhandlers/EsbActionHandler.java
===================================================================
--- labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actionhandlers/EsbActionHandler.java 2007-08-07 19:21:46 UTC (rev 14086)
+++ labs/jbossesb/trunk/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actionhandlers/EsbActionHandler.java 2007-08-07 19:21:59 UTC (rev 14087)
@@ -49,216 +49,238 @@
/**
*
- * Send messages to ESB services from jBPM applications, and optionally wait for response.
- * <li/>esbCategoryName - for ESB registry lookup
- * <li/>esbServiceName - for ESB registry lookup
- * <li>millisToWaitForResponse - if a value > 0 is supplied, a response will be expected from the ESB service
- * and maximum wait time will be set accordingly. If response is not received, a CourierTimeoutException will
- * be thrown
- * </li>
+ * Send messages to ESB services from jBPM applications, and optionally wait for
+ * response. <li/>esbCategoryName - for ESB registry lookup <li/>esbServiceName
+ * - for ESB registry lookup
+ * <li>millisToWaitForResponse - if a value > 0 is supplied, a response will be
+ * expected from the ESB service and maximum wait time will be set accordingly.
+ * If response is not received, a CourierTimeoutException will be thrown </li>
*
- * @author <a href="mailto:schifest at heuristica.com.ar">Esteban</a>
- *
+ * @author <a href="mailto:schifest at heuristica.com.ar">Esteban</a>
+ *
*/
-public class EsbActionHandler implements ActionHandler
+public class EsbActionHandler implements ActionHandler
{
- public static final String OUTGOING_VARS_TAG = "jbpmToEsbVars";
- public static final String RETURN_VARS_TAG = "returnVars";
- public static final String MAPPING_TAG = "mapping";
- public static final String JBPM_NAME_ATTR = "jbpm-name";
- public static final String ESB_NAME_ATTR = "esb-name";
- public static final String PROCESS_SCOPE_ATTR = "process-scope";
-
- private static final long serialVersionUID = 1L;
-
- public String esbCategoryName;
- public String esbServiceName;
- public Integer millisToWaitForResponse;
- public Boolean globalProcessScope;
- public DefaultElement jbpmToEsbVars;
- public DefaultElement returnVars;
-
- protected Logger _logger = Logger.getLogger(getClass());
-
- protected Map<String, String>_outVarMapping;
- protected Map<String, String>_retVarMapping;
- protected transient Token _token;
-
- public void execute(ExecutionContext executionContext) throws Exception
+ public static final String OUTGOING_VARS_TAG = "jbpmToEsbVars";
+
+ public static final String RETURN_VARS_TAG = "returnVars";
+
+ public static final String MAPPING_TAG = "mapping";
+
+ public static final String JBPM_NAME_ATTR = "jbpm-name";
+
+ public static final String ESB_NAME_ATTR = "esb-name";
+
+ public static final String PROCESS_SCOPE_ATTR = "process-scope";
+
+ private static final long serialVersionUID = 1L;
+
+ public String esbCategoryName;
+
+ public String esbServiceName;
+
+ public Integer millisToWaitForResponse;
+
+ public Boolean globalProcessScope;
+
+ public DefaultElement jbpmToEsbVars;
+
+ public DefaultElement returnVars;
+
+ protected Logger _logger = Logger.getLogger(getClass());
+
+ protected Map<String, String> _outVarMapping;
+
+ protected Map<String, String> _retVarMapping;
+
+ protected transient Token _token;
+
+ public void execute (ExecutionContext executionContext) throws Exception
+ {
+ _token = executionContext.getToken();
+
+ Message request = getMessageTemplate();
+ varsToRequest(request);
+ if (null == millisToWaitForResponse || millisToWaitForResponse < 1)
{
- _token = executionContext.getToken();
-
- Message request = getMessageTemplate();
- varsToRequest(request);
- if (null==millisToWaitForResponse || millisToWaitForResponse < 1)
+ ServiceInvoker invoker = new ServiceInvoker(esbCategoryName,
+ esbServiceName);
+ invoker.deliverAsync(request);
+ return;
+ }
+
+ Message response = null;
+ if ("MOCK_CATEGORY".equals(esbCategoryName)
+ && "MOCK_SERVICE".equals(esbServiceName))
+ {
+ response = request;
+ }
+ else
+ {
+ ServiceInvoker invoker = new ServiceInvoker(esbCategoryName,
+ esbServiceName);
+ response = invoker.deliverSync(request, millisToWaitForResponse);
+ }
+ if (null != response)
+ varsFromResponse(response);
+ } // ________________________________
+
+ protected void varsToRequest (Message request) throws Exception
+ {
+ ContextInstance ctxInstance = _token.getProcessInstance()
+ .getContextInstance();
+ Body body = request.getBody();
+ boolean gblPrcScope = (null == globalProcessScope) ? false
+ : globalProcessScope;
+ if (null == jbpmToEsbVars)
+ {
+ Map map = (gblPrcScope) ? ctxInstance.getVariables() : ctxInstance
+ .getVariables(_token);
+ if (null != map)
+ for (Iterator iter = map.entrySet().iterator(); iter.hasNext();)
{
- ServiceInvoker invoker = new ServiceInvoker(esbCategoryName, esbServiceName);
- invoker.deliverAsync(request);
- return;
+ Map.Entry curr = (Map.Entry) iter.next();
+ body.add(curr.getKey().toString(), curr.getValue());
}
-
- Message response = null;
- if ("MOCK_CATEGORY".equals(esbCategoryName)
- && "MOCK_SERVICE".equals(esbServiceName)) {
- response = request;
- } else {
- ServiceInvoker invoker = new ServiceInvoker(esbCategoryName, esbServiceName);
- invoker.deliverSync(request, millisToWaitForResponse);
- }
- if (null!=response)
- varsFromResponse(response);
- } //________________________________
+ return;
+ }
+ List list = jbpmToEsbVars.elements(MAPPING_TAG);
+ // do nothing if empty list
+ if (list.size() < 1)
+ return;
- protected void varsToRequest(Message request)
- throws Exception
+ for (Object iter : list)
{
- ContextInstance ctxInstance = _token.getProcessInstance().getContextInstance();
- Body body = request.getBody();
- boolean gblPrcScope = (null==globalProcessScope)
- ? false : globalProcessScope;
- if (null==jbpmToEsbVars)
+ Element curr = (Element) iter;
+ String jbpmKey = curr.attributeValue(JBPM_NAME_ATTR);
+ String esbKey = curr.attributeValue(ESB_NAME_ATTR);
+ String processScope = curr.attributeValue(PROCESS_SCOPE_ATTR);
+ boolean isPrcScope = (null == processScope) ? gblPrcScope : Boolean
+ .parseBoolean(processScope);
+ Object obj = (isPrcScope) ? ctxInstance.getVariable(jbpmKey)
+ : ctxInstance.getVariable(jbpmKey, _token);
+ if (null != obj)
+ {
+ if (Constants.BODY_CONTENT_VARIABLE_NAME.equals(esbKey))
{
- Map map = (gblPrcScope)? ctxInstance.getVariables()
- : ctxInstance.getVariables(_token);
- if (null!=map)
- for (Iterator iter=map.entrySet().iterator(); iter.hasNext();)
- {
- Map.Entry curr = (Map.Entry)iter.next();
- body.add(curr.getKey().toString(), curr.getValue());
- }
- return;
+ if (obj instanceof byte[])
+ body.setByteArray((byte[]) obj);
+ else
+ body.setByteArray(obj.toString().getBytes());
}
- List list = jbpmToEsbVars.elements(MAPPING_TAG);
- // do nothing if empty list
- if (list.size()<1 )
- return;
-
- for (Object iter: list)
+ else
+ body.add(esbKey, obj);
+ }
+ }
+ } // ________________________________
+
+ protected void varsFromResponse (Message response) throws Exception
+ {
+ ContextInstance ctxInstance = _token.getProcessInstance()
+ .getContextInstance();
+ Body body = response.getBody();
+ boolean gblPrcScope = (null == globalProcessScope) ? false
+ : globalProcessScope;
+ if (null == returnVars)
+ {
+ Map map = (gblPrcScope) ? ctxInstance.getVariables() : ctxInstance
+ .getVariables(_token);
+ if (null != map)
+ for (Iterator iter = map.keySet().iterator(); iter.hasNext();)
{
- Element curr = (Element)iter;
- String jbpmKey = curr.attributeValue(JBPM_NAME_ATTR);
- String esbKey = curr.attributeValue(ESB_NAME_ATTR);
- String processScope = curr.attributeValue(PROCESS_SCOPE_ATTR);
- boolean isPrcScope = (null==processScope) ? gblPrcScope
- : Boolean.parseBoolean(processScope);
- Object obj = (isPrcScope)
- ? ctxInstance.getVariable(jbpmKey)
- : ctxInstance.getVariable(jbpmKey, _token);
- if (null!=obj)
- {
- if(Constants.BODY_CONTENT_VARIABLE_NAME.equals(esbKey))
- {
- if (obj instanceof byte[])
- body.setByteArray((byte[])obj);
- else
- body.setByteArray(obj.toString().getBytes());
- }
- else
- body.add(esbKey, obj);
- }
+ String key = iter.next().toString();
+ Object obj = body.get(key);
+ if (null != obj)
+ {
+ if (gblPrcScope)
+ ctxInstance.setVariable(key, obj);
+ else
+ ctxInstance.setVariable(key, obj, _token);
+ }
}
- } //________________________________
+ return;
+ }
+ List list = returnVars.elements(MAPPING_TAG);
+ // do nothing if empty list
+ if (list.size() < 1)
+ return;
- protected void varsFromResponse(Message response) throws Exception
+ for (Object iter : list)
{
- ContextInstance ctxInstance = _token.getProcessInstance().getContextInstance();
- Body body = response.getBody();
- boolean gblPrcScope = (null==globalProcessScope)
- ? false : globalProcessScope;
- if (null==returnVars)
+ Element curr = (Element) iter;
+ String jbpmVar = curr.attributeValue(JBPM_NAME_ATTR);
+ String esbVar = curr.attributeValue(ESB_NAME_ATTR);
+ String processScope = curr.attributeValue(PROCESS_SCOPE_ATTR);
+ boolean isPrcScope = (null == processScope) ? gblPrcScope : Boolean
+ .parseBoolean(processScope);
+ Object obj = (Constants.BODY_CONTENT_VARIABLE_NAME.equals(esbVar)) ? body
+ .getByteArray()
+ : body.get(esbVar);
+ Object oldVal = (isPrcScope) ? ctxInstance.getVariable(jbpmVar)
+ : ctxInstance.getVariable(jbpmVar, _token);
+ if (null == oldVal)
+ {
+ if (null != obj)
{
- Map map = (gblPrcScope)? ctxInstance.getVariables()
- : ctxInstance.getVariables(_token);
- if (null!=map)
- for (Iterator iter=map.keySet().iterator(); iter.hasNext();)
- {
- String key = iter.next().toString();
- Object obj = body.get(key);
- if (null!=obj)
- {
- if (gblPrcScope)
- ctxInstance.setVariable(key, obj);
- else
- ctxInstance.setVariable(key, obj, _token);
- }
- }
- return;
+ if (isPrcScope)
+ ctxInstance.createVariable(jbpmVar, obj);
+ else
+ ctxInstance.createVariable(jbpmVar, obj, _token);
}
- List list = returnVars.elements(MAPPING_TAG);
- // do nothing if empty list
- if (list.size()<1 )
- return;
-
- for (Object iter: list)
+ }
+ else
+ {
+ if (null == obj)
{
- Element curr = (Element)iter;
- String jbpmVar = curr.attributeValue(JBPM_NAME_ATTR);
- String esbVar = curr.attributeValue(ESB_NAME_ATTR);
- String processScope = curr.attributeValue(PROCESS_SCOPE_ATTR);
- boolean isPrcScope = (null==processScope) ? gblPrcScope
- : Boolean.parseBoolean(processScope);
- Object obj = (Constants.BODY_CONTENT_VARIABLE_NAME.equals(esbVar))
- ?body.getByteArray()
- :body.get(esbVar);
- Object oldVal = (isPrcScope) ? ctxInstance.getVariable(jbpmVar)
- : ctxInstance.getVariable(jbpmVar,_token);
- if (null==oldVal)
- {
- if (null!=obj)
- {
- if (isPrcScope)
- ctxInstance.createVariable(jbpmVar, obj);
- else
- ctxInstance.createVariable(jbpmVar, obj, _token);
- }
- }
- else
- {
- if (null==obj)
- {
- if (isPrcScope)
- ctxInstance.deleteVariable(jbpmVar);
- else
- ctxInstance.deleteVariable(jbpmVar, _token);
- }
- else
- {
- if (isPrcScope)
- ctxInstance.setVariable(jbpmVar,obj);
- else
- ctxInstance.setVariable(jbpmVar,obj,_token);
- }
- }
+ if (isPrcScope)
+ ctxInstance.deleteVariable(jbpmVar);
+ else
+ ctxInstance.deleteVariable(jbpmVar, _token);
}
- } //________________________________
+ else
+ {
+ if (isPrcScope)
+ ctxInstance.setVariable(jbpmVar, obj);
+ else
+ ctxInstance.setVariable(jbpmVar, obj, _token);
+ }
+ }
+ }
+ } // ________________________________
- protected Message getMessageTemplate() throws Exception
- {
- if (null==esbCategoryName)
- throw new ConfigurationException("Service category (esbCategoryName element) must not be null");
- if (null==esbServiceName)
- throw new ConfigurationException("Service name (esbServiceName element) must not be null");
-
- Message template = MessageFactory.getInstance().getMessage();
- Call call = template.getHeader().getCall();
- call.setMessageID(new URI(UUID.randomUUID().toString()));
-
- Helper.setLongValue (template,Constants.TOKEN_ID,_token.getId());
- Node node = _token.getNode();
- if (null!=node)
- Helper.setStringValue(template, Constants.CURRENT_NODE_NAME, node.getName());
+ protected Message getMessageTemplate () throws Exception
+ {
+ if (null == esbCategoryName)
+ throw new ConfigurationException(
+ "Service category (esbCategoryName element) must not be null");
+ if (null == esbServiceName)
+ throw new ConfigurationException(
+ "Service name (esbServiceName element) must not be null");
- ProcessInstance instance = _token.getProcessInstance();
- Helper.setLongValue(template,Constants.PROCESS_INSTANCE_ID,instance.getId());
-
- ProcessDefinition process = instance.getProcessDefinition();
- Helper.setObjectValue(template ,Constants.PROCESS_DEFINITION_NAME, process.getName());
- Helper.setIntValue (template ,Constants.PROCESS_DEFINITION_VERSION, process.getVersion());
- Helper.setLongValue (template ,Constants.PROCESS_DEFINITION_ID, process.getId());
-
-
- return template;
- } //________________________________
+ Message template = MessageFactory.getInstance().getMessage();
+ Call call = template.getHeader().getCall();
+ call.setMessageID(new URI(UUID.randomUUID().toString()));
+ Helper.setLongValue(template, Constants.TOKEN_ID, _token.getId());
+ Node node = _token.getNode();
+ if (null != node)
+ Helper.setStringValue(template, Constants.CURRENT_NODE_NAME, node
+ .getName());
+
+ ProcessInstance instance = _token.getProcessInstance();
+ Helper.setLongValue(template, Constants.PROCESS_INSTANCE_ID, instance
+ .getId());
+
+ ProcessDefinition process = instance.getProcessDefinition();
+ Helper.setObjectValue(template, Constants.PROCESS_DEFINITION_NAME,
+ process.getName());
+ Helper.setIntValue(template, Constants.PROCESS_DEFINITION_VERSION,
+ process.getVersion());
+ Helper.setLongValue(template, Constants.PROCESS_DEFINITION_ID, process
+ .getId());
+
+ return template;
+ } // ________________________________
+
}
More information about the jboss-svn-commits
mailing list