[jboss-svn-commits] JBL Code SVN: r17203 - in labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src: main/java/org/jboss/soa/esb/services/jbpm/actionhandlers and 3 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Dec 12 15:35:19 EST 2007
Author: kurt.stam at jboss.com
Date: 2007-12-12 15:35:19 -0500 (Wed, 12 Dec 2007)
New Revision: 17203
Added:
labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/cmd/CallbackCommand.java
labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/cmd/CallbackException.java
labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/actionhandlers/JBpmObjectMapperCallbackTest.java
Removed:
labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/JBpmCallbackException.java
labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/JBpmCallbackHelper.java
labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/cmd/CommandServiceImpl.java
Modified:
labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actionhandlers/EsbActionHandler.java
labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/cmd/CommandExecutor.java
labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/JBpmObjectMapperTest.java
Log:
JBESB-1301 Moving Callback into a jBPM Command.
Deleted: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/JBpmCallbackException.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/JBpmCallbackException.java 2007-12-12 16:04:22 UTC (rev 17202)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/JBpmCallbackException.java 2007-12-12 20:35:19 UTC (rev 17203)
@@ -1,60 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2006, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.soa.esb.services.jbpm;
-
-import org.jboss.soa.esb.BaseException;
-
-/**
- * Configuration Exception.
- * @author <a href="mailto:kurt.stam at jboss.com">kurt.stam at jboss.com</a>
- * @since Version 4.2
- */
-public class JBpmCallbackException extends BaseException {
-
- private static final long serialVersionUID = 1L;
-
- /**
- * Construct an exception instance.
- * @param message Exception message.
- */
- public JBpmCallbackException(String message) {
- super(message);
- }
-
- /**
- * Construct an exception instance.
- * @param message Exception message.
- * @param cause Exception cause.
- */
- public JBpmCallbackException(String message, Throwable cause) {
- super(message, cause);
- }
-
- /**
- * Construct an exception instance.
- * @param cause Exception cause.
- */
- public JBpmCallbackException(Throwable cause) {
- super(cause);
- }
-}
Deleted: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/JBpmCallbackHelper.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/JBpmCallbackHelper.java 2007-12-12 16:04:22 UTC (rev 17202)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/JBpmCallbackHelper.java 2007-12-12 20:35:19 UTC (rev 17203)
@@ -1,135 +0,0 @@
-/**
- *
- */
-package org.jboss.soa.esb.services.jbpm;
-
-import java.util.List;
-
-import org.apache.log4j.Logger;
-import org.jboss.soa.esb.addressing.EPR;
-import org.jboss.soa.esb.addressing.PortReference;
-import org.jboss.soa.esb.addressing.eprs.LogicalEPR;
-import org.jboss.soa.esb.client.ServiceInvoker;
-import org.jboss.soa.esb.services.jbpm.actions.JBpmCallback;
-import org.jboss.soa.esb.services.jbpm.cmd.CommandServiceImpl;
-import org.jbpm.command.GetProcessInstanceCommand;
-import org.jbpm.graph.exe.ExecutionContext;
-import org.jbpm.graph.exe.ProcessInstance;
-import org.jbpm.graph.exe.Token;
-
-/**
- * @author kstam
- *
- */
-public class JBpmCallbackHelper
-{
- private Logger logger = Logger.getLogger(this.getClass());
-
- /**
- * Setup the replyTo for the CallBack Service.
- *
- * Creates or increments a process-node-version-counter whose name is related to
- * the current node ID. The name of the counter is jbpmProcessNodeVersionCounter<NodeId>.
- * The counter is added to the ProcessVariable Map (global to the ProcessInstance)
- * on the jBPM side The same variable should be added to the
- * EsbMessage before it is passed onto the ESB. Other parameters added
- * are the returnVariable mapping, the nodeId and the tokenId.
- *
- * @param returnVars - XML fragment from the processdefinition.xml describing
- * the mapping of ESB Message objects to the jBPM variableMap.
- * @param executionContext of the currently invoked EsbActionHandler.
- * @return the replyTo EPR of the JBpmCallbackService.
- */
- public EPR createReplyTo(String esbToJBpmXml, Boolean globalProcessScope, ExecutionContext executionContext)
- {
- EPR replyTo = new LogicalEPR(ServiceInvoker.INTERNAL_SERVICE_CATEGORY, JBpmCallback.JBPM_CALL_BACK_SERVICE_NAME);
- PortReference portReference = replyTo.getAddr();
- portReference.addExtension(Constants.ESB_TO_BPM_VARS_TAG, esbToJBpmXml);
- if (globalProcessScope!=null) {
- portReference.addExtension(Constants.PROCESS_SCOPE_ATTR, globalProcessScope.toString());
- }
- portReference.addExtension(Constants.TOKEN_ID, String.valueOf(executionContext.getToken().getId()));
- String nodeId = "";
- if (executionContext.getNode()!=null) {
- nodeId = String.valueOf(executionContext.getNode().getId());
- portReference.addExtension(Constants.NODE_ID, nodeId);
-
- }
- portReference.addExtension(Constants.PROCESS_INSTANCE_ID, String.valueOf(executionContext.getProcessInstance().getId()));
-
- String counterName = Constants.PROCESS_NODE_VERSION_COUNTER + nodeId;
- Long counter = Long.getLong(String.valueOf(executionContext.getVariable(counterName)));
- if (counter!=null) {
- counter = counter + 1;
- } else {
- counter = 0l;
- }
- //Adding to the jBPM variableMap
- executionContext.setVariable(counterName, counter.toString());
- //Adding same value to the message
- portReference.addExtension(counterName, counter.toString());
- return replyTo;
- }
- /**
- * Checks whether the current state in jBPM is the expected state. If so it returns the tokenId
- * on which we can invoke a signal.
- *
- * @param commandService
- * @param replyTo
- * @return
- * @throws JBpmCallbackException
- */
- public long checkCurrentState(CommandServiceImpl commandService, EPR replyTo)
- throws JBpmCallbackException
- {
- long nodeId = Long.parseLong(replyTo.getAddr().getExtensionValue(Constants.NODE_ID));
- long tokenId = Long.parseLong(replyTo.getAddr().getExtensionValue(Constants.TOKEN_ID));
- long processInstanceId = Long.parseLong(replyTo.getAddr().getExtensionValue(Constants.PROCESS_INSTANCE_ID));
- String counterName = Constants.PROCESS_NODE_VERSION_COUNTER + nodeId;
- long processNodeVersion = Long.parseLong(replyTo.getAddr().getExtensionValue(counterName));
- if (logger.isDebugEnabled()) logger.debug("Expected nodeId=" + nodeId +
- ", tokenId=" + tokenId + ", processNodeVersion=" + processNodeVersion);
- //get update on current state of things.
- try {
- ProcessInstance instance = (ProcessInstance)commandService
- .execute(new GetProcessInstanceCommand(processInstanceId));
- Long currentTokenId = null;
- Long currentNodeId = null;
- List tokens = instance.findAllTokens();
- for (Object object : tokens) {
- Token token = (Token) object;
- if (token.getId()==tokenId) {
- currentTokenId = token.getId();
- currentNodeId = token.getNode().getId();
- break;
- }
- }
- //Compare current with expected
- StringBuilder unExpected = new StringBuilder();
- if (nodeId!=currentNodeId) {
- unExpected.append("A timeout occured or something else signaled the node, " + currentNodeId +
- "causing it to move away from the expected node with id= ").append(nodeId).append(". ");
- }
- if (tokenId!=currentTokenId) {
- unExpected.append("The process is at the expected Node, but the current Token (id=" + currentTokenId +
- ") is not the expected Token (").append(tokenId).append("), ");
- }
- if (logger.isDebugEnabled()) logger.debug("Current state nodeId=" + currentNodeId);
- //get the current processNode Version
- Long currentProcessNodeVersion = Long.parseLong(String.valueOf(
- instance.getContextInstance().getVariable(counterName)));
- if (logger.isDebugEnabled()) logger.debug("ProcessNodeVersion=" + currentProcessNodeVersion);
- if (processNodeVersion!=currentProcessNodeVersion) {
- unExpected.append("The current processNodeVersion (id=" + currentProcessNodeVersion +
- ") is not the expected version (version=").append(processNodeVersion).append("). ");
- }
- if (!"".equals(unExpected.toString())) {
- throw new JBpmCallbackException(unExpected.toString());
- }
- } finally {
- commandService.close();
- }
-
- return tokenId;
- }
-}
Modified: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actionhandlers/EsbActionHandler.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actionhandlers/EsbActionHandler.java 2007-12-12 16:04:22 UTC (rev 17202)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/actionhandlers/EsbActionHandler.java 2007-12-12 20:35:19 UTC (rev 17203)
@@ -26,11 +26,14 @@
import org.jboss.internal.soa.esb.util.LRUCache;
import org.jboss.soa.esb.ConfigurationException;
import org.jboss.soa.esb.addressing.EPR;
+import org.jboss.soa.esb.addressing.PortReference;
+import org.jboss.soa.esb.addressing.eprs.LogicalEPR;
import org.jboss.soa.esb.client.ServiceInvoker;
import org.jboss.soa.esb.listeners.message.MessageDeliverException;
import org.jboss.soa.esb.message.Message;
-import org.jboss.soa.esb.services.jbpm.JBpmCallbackHelper;
+import org.jboss.soa.esb.services.jbpm.Constants;
import org.jboss.soa.esb.services.jbpm.JBpmObjectMapper;
+import org.jboss.soa.esb.services.jbpm.actions.JBpmCallback;
import org.jbpm.graph.def.ActionHandler;
import org.jbpm.graph.exe.ExecutionContext;
/**
@@ -62,11 +65,11 @@
public DefaultElement bpmToEsbVars;
public DefaultElement esbToBpmVars;
+
+ public String exceptionTransition;
private transient Logger logger = Logger.getLogger(getClass());
- private transient JBpmCallbackHelper jBpmCallbackHelper = new JBpmCallbackHelper();
-
private static transient LRUCache<String, ServiceInvoker> siCache = new LRUCache<String, ServiceInvoker>(20);
public void execute (ExecutionContext executionContext) throws Exception
@@ -86,8 +89,13 @@
JBpmObjectMapper mapper = new JBpmObjectMapper();
Message message = mapper.mapFromJBpmToEsbMessage(bpmToEsbVars, globalProcessScope, executionContext);
//Set the replyTo to the JBpmCallback Service
- EPR replyTo = jBpmCallbackHelper.createReplyTo(esbToBpmVars.asXML(), globalProcessScope, executionContext);
+ EPR replyTo = createReplyTo(esbToBpmVars.asXML(), globalProcessScope, executionContext);
message.getHeader().getCall().setReplyTo(replyTo);
+ if (exceptionTransition!=null) {
+// Set the replyTo to the JBpmCallback Service
+ EPR faultTo = createReplyTo(esbToBpmVars.asXML(), globalProcessScope, executionContext);
+ message.getHeader().getCall().setFaultTo(faultTo);
+ }
//Sending the message on its way
if (logger.isDebugEnabled()) logger.debug("Created ESB message=" + message);
getServiceInvoker().deliverAsync(message);
@@ -110,6 +118,69 @@
return invoker;
}
}
+
+ /**
+ * Setup the replyTo for the CallBack Service.
+ *
+ * Creates or increments a process-node-version-counter whose name is related to
+ * the current node ID. The name of the counter is jbpmProcessNodeVersionCounter<NodeId>.
+ * The counter is added to the ProcessVariable Map (global to the ProcessInstance)
+ * on the jBPM side The same variable should be added to the
+ * EsbMessage before it is passed onto the ESB. Other parameters added
+ * are the returnVariable mapping, the nodeId and the tokenId.
+ *
+ * @param returnVars - XML fragment from the processdefinition.xml describing
+ * the mapping of ESB Message objects to the jBPM variableMap.
+ * @param executionContext of the currently invoked EsbActionHandler.
+ * @return the replyTo EPR of the JBpmCallbackService.
+ */
+ protected EPR createReplyTo(String esbToJBpmXml, Boolean globalProcessScope, ExecutionContext executionContext)
+ {
+ EPR replyTo = new LogicalEPR(ServiceInvoker.INTERNAL_SERVICE_CATEGORY, JBpmCallback.JBPM_CALL_BACK_SERVICE_NAME);
+ PortReference portReference = replyTo.getAddr();
+ portReference.addExtension(Constants.ESB_TO_BPM_VARS_TAG, esbToJBpmXml);
+ if (globalProcessScope!=null) {
+ portReference.addExtension(Constants.PROCESS_SCOPE_ATTR, globalProcessScope.toString());
+ }
+ portReference.addExtension(Constants.TOKEN_ID, String.valueOf(executionContext.getToken().getId()));
+ String nodeId = "";
+ if (executionContext.getNode()!=null) {
+ nodeId = String.valueOf(executionContext.getNode().getId());
+ portReference.addExtension(Constants.NODE_ID, nodeId);
+
+ }
+ portReference.addExtension(Constants.PROCESS_INSTANCE_ID, String.valueOf(executionContext.getProcessInstance().getId()));
+
+ String counterName = Constants.PROCESS_NODE_VERSION_COUNTER + nodeId;
+ Long counter = Long.getLong(String.valueOf(executionContext.getVariable(counterName)));
+ if (counter!=null) {
+ counter = counter + 1;
+ } else {
+ counter = 0l;
+ }
+ //Adding to the jBPM variableMap
+ executionContext.setVariable(counterName, counter.toString());
+ //Adding same value to the message
+ portReference.addExtension(counterName, counter.toString());
+ return replyTo;
+ }
+ /**
+ * Sets the faultTo EPR. This way jBPM can handle a failure in the ESB service by taking a
+ * exception (faultTo) transition.
+ * @param returnVars - XML fragment from the processdefinition.xml describing
+ * the mapping of ESB Message objects to the jBPM variableMap.
+ * @param executionContext of the currently invoked EsbActionHandler.
+ * @return the faultTo EPR of the JBpmCallbackService.
+ */
+ protected EPR createFaultTo(String esbToJBpmXml, Boolean globalProcessScope, ExecutionContext executionContext)
+ {
+ EPR faultTo = createReplyTo(esbToJBpmXml, globalProcessScope, executionContext);
+ if (!exceptionTransition.equals("condition")) {
+ PortReference portReference = faultTo.getAddr();
+ portReference.addExtension(Constants.TRANSITION_NAME, exceptionTransition);
+ }
+ return faultTo;
+ }
}
Added: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/cmd/CallbackCommand.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/cmd/CallbackCommand.java (rev 0)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/cmd/CallbackCommand.java 2007-12-12 20:35:19 UTC (rev 17203)
@@ -0,0 +1,120 @@
+/**
+ *
+ */
+package org.jboss.soa.esb.services.jbpm.cmd;
+
+import java.util.List;
+
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.addressing.EPR;
+import org.jboss.soa.esb.services.jbpm.Constants;
+import org.jbpm.JbpmContext;
+import org.jbpm.command.SignalCommand;
+import org.jbpm.graph.exe.ProcessInstance;
+import org.jbpm.graph.exe.Token;
+
+/**
+ * @author kstam
+ *
+ */
+public class CallbackCommand extends SignalCommand {
+
+ private Logger logger = Logger.getLogger(this.getClass());
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+ private EPR callbackEpr;
+
+ public CallbackCommand() {
+ super();
+ }
+
+ public CallbackCommand(long tokenId, String transitionName) {
+ super(tokenId, transitionName);
+ }
+
+ public CallbackCommand(long tokenId, String transitionName, EPR callbackEpr)
+ {
+ super(tokenId, transitionName);
+ this.callbackEpr = callbackEpr;
+ }
+
+ public EPR getCallbackEpr() {
+ return callbackEpr;
+ }
+ public void setCallbackEpr(EPR callbackEpr) {
+ this.callbackEpr = callbackEpr;
+ }
+
+ public Object execute(JbpmContext jbpmContext)
+ {
+ try {
+ long tokenId = checkCurrentState(jbpmContext, callbackEpr);
+ //if the state is ok, then goahead with the signalling the transition
+ this.setTokenId(tokenId);
+ return super.execute(jbpmContext);
+ } catch (CallbackException jbpmCe) {
+ logger.warn(jbpmCe.getMessage());
+ return null;
+ }
+ }
+
+ /**
+ * Checks whether the current state in jBPM is the expected state. If so it returns the tokenId
+ * on which we can invoke a signal.
+ *
+ * @param replyTo
+ * @return
+ * @throws CallbackException
+ */
+ protected long checkCurrentState(JbpmContext jbpmContext, EPR callbackEpr)
+ throws CallbackException
+ {
+ long nodeId = Long.parseLong(callbackEpr.getAddr().getExtensionValue(Constants.NODE_ID));
+ long tokenId = Long.parseLong(callbackEpr.getAddr().getExtensionValue(Constants.TOKEN_ID));
+ long processInstanceId = Long.parseLong(callbackEpr.getAddr().getExtensionValue(Constants.PROCESS_INSTANCE_ID));
+ String counterName = Constants.PROCESS_NODE_VERSION_COUNTER + nodeId;
+ long processNodeVersion = Long.parseLong(callbackEpr.getAddr().getExtensionValue(counterName));
+ if (logger.isDebugEnabled()) logger.debug("Expected nodeId=" + nodeId +
+ ", tokenId=" + tokenId + ", processNodeVersion=" + processNodeVersion);
+ //get update on current state of things.
+ ProcessInstance instance = jbpmContext.getProcessInstance(processInstanceId);
+ Long currentTokenId = null;
+ Long currentNodeId = null;
+ List tokens = instance.findAllTokens();
+ for (Object object : tokens) {
+ Token token = (Token) object;
+ if (token.getId()==tokenId) {
+ currentTokenId = token.getId();
+ currentNodeId = token.getNode().getId();
+ break;
+ }
+ }
+ //Compare current with expected
+ StringBuilder unExpected = new StringBuilder();
+ if (nodeId!=currentNodeId) {
+ unExpected.append("A timeout occured or something else signaled the node, " + currentNodeId +
+ "causing it to move away from the expected node with id= ").append(nodeId).append(". ");
+ }
+ if (tokenId!=currentTokenId) {
+ unExpected.append("The process is at the expected Node, but the current Token (id=" + currentTokenId +
+ ") is not the expected Token (").append(tokenId).append("), ");
+ }
+ if (logger.isDebugEnabled()) logger.debug("Current state nodeId=" + currentNodeId);
+ //get the current processNode Version
+ Long currentProcessNodeVersion = Long.parseLong(String.valueOf(
+ instance.getContextInstance().getVariable(counterName)));
+ if (logger.isDebugEnabled()) logger.debug("ProcessNodeVersion=" + currentProcessNodeVersion);
+ if (processNodeVersion!=currentProcessNodeVersion) {
+ unExpected.append("The current processNodeVersion (id=" + currentProcessNodeVersion +
+ ") is not the expected version (version=").append(processNodeVersion).append("). ");
+ }
+ if (!"".equals(unExpected.toString())) {
+ throw new CallbackException(unExpected.toString());
+ }
+ return tokenId;
+ }
+
+
+}
Property changes on: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/cmd/CallbackCommand.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/cmd/CallbackException.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/cmd/CallbackException.java (rev 0)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/cmd/CallbackException.java 2007-12-12 20:35:19 UTC (rev 17203)
@@ -0,0 +1,60 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.soa.esb.services.jbpm.cmd;
+
+import org.jboss.soa.esb.BaseException;
+
+/**
+ * Configuration Exception.
+ * @author <a href="mailto:kurt.stam at jboss.com">kurt.stam at jboss.com</a>
+ * @since Version 4.2
+ */
+public class CallbackException extends BaseException {
+
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Construct an exception instance.
+ * @param message Exception message.
+ */
+ public CallbackException(String message) {
+ super(message);
+ }
+
+ /**
+ * Construct an exception instance.
+ * @param message Exception message.
+ * @param cause Exception cause.
+ */
+ public CallbackException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ /**
+ * Construct an exception instance.
+ * @param cause Exception cause.
+ */
+ public CallbackException(Throwable cause) {
+ super(cause);
+ }
+}
Property changes on: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/cmd/CallbackException.java
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/cmd/CommandExecutor.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/cmd/CommandExecutor.java 2007-12-12 16:04:22 UTC (rev 17202)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/cmd/CommandExecutor.java 2007-12-12 20:35:19 UTC (rev 17203)
@@ -32,17 +32,17 @@
import org.jboss.soa.esb.message.mapping.ObjectMapper;
import org.jboss.soa.esb.message.mapping.ObjectMappingException;
import org.jboss.soa.esb.services.jbpm.Constants;
-import org.jboss.soa.esb.services.jbpm.JBpmCallbackException;
-import org.jboss.soa.esb.services.jbpm.JBpmCallbackHelper;
import org.jboss.soa.esb.services.jbpm.JBpmObjectMapper;
import org.jbpm.JbpmConfiguration;
import org.jbpm.JbpmContext;
import org.jbpm.JbpmException;
import org.jbpm.command.CancelProcessInstanceCommand;
+import org.jbpm.command.CommandService;
import org.jbpm.command.GetProcessInstanceCommand;
import org.jbpm.command.NewProcessInstanceCommand;
import org.jbpm.command.SignalCommand;
import org.jbpm.command.StartProcessInstanceCommand;
+import org.jbpm.command.impl.CommandServiceImpl;
import org.jbpm.graph.def.ProcessDefinition;
import org.jbpm.graph.exe.ProcessInstance;
@@ -59,7 +59,7 @@
private static Logger logger = Logger.getLogger(CommandExecutor.class);
private static JbpmConfiguration jbpmConfig;
- private static CommandServiceImpl jbpmService;
+ private static CommandService jbpmService;
public static CommandExecutor getInstance()
{
@@ -155,27 +155,26 @@
{
public void execute(Message message) throws JbpmException
{
- SignalCommand command = new SignalCommand();
- EPR toEPR = message.getHeader().getCall().getTo();
- JBpmCallbackHelper jBpmCallbackHelper = new JBpmCallbackHelper();
+ CallbackCommand command = new CallbackCommand();
+ EPR toEpr = message.getHeader().getCall().getTo();
try {
- long tokenId = jBpmCallbackHelper.checkCurrentState(getJbpmCommandService(), toEPR);
- command.setTokenId(tokenId);
-
-// Map the variables
- String esbToBpmXml = toEPR.getAddr().getExtensionValue(Constants.ESB_TO_BPM_VARS_TAG);
+ command.setCallbackEpr(toEpr);
+ //Map the variables
+ String esbToBpmXml = toEpr.getAddr().getExtensionValue(Constants.ESB_TO_BPM_VARS_TAG);
JBpmObjectMapper mapper = new JBpmObjectMapper();
//Obtaining the VariableMap that is going to be set callback command
Map<String,Object> variableMap = mapper.mapFromEsbMessageToJBpmMap(message, esbToBpmXml);
if (null!=variableMap) command.setVariables(variableMap);
- //By default we will not include a named transtion, so it will use the default transition
- //However this can be overriden if needed, by setting the following variable.
- String transition = MessageHelper.getStringValue(message, Constants.TRANSITION_NAME);
+ String transition = (toEpr.getAddr().getExtensionValue(Constants.TRANSITION_NAME));
+ //The transition can be overriden if needed, by setting the following variable.
+ String overriddenTransition = MessageHelper.getStringValue(message, Constants.TRANSITION_NAME);
+ if (overriddenTransition!=null) {
+ if (transition!=null) logger.debug("Overriding the transition to " + overriddenTransition);
+ transition = overriddenTransition;
+ }
if (null!=transition) command.setTransitionName(transition);
- logger.debug("Signaling Process with TokenId=" + tokenId + ", Transition=" + transition + ", VariableMap=" + variableMap);
+ logger.debug("Signaling Process with Transition=" + transition + ", VariableMap=" + variableMap);
executeJbpmCommand(command);
- } catch (JBpmCallbackException jbce) {
- throw new JbpmException(jbce.getMessage(), jbce);
} catch (ConfigurationException ce) {
throw new JbpmException(ce.getMessage(), ce);
}
@@ -257,18 +256,14 @@
if (logger.isDebugEnabled()) {
logger.debug(command);
}
- try {
- getJbpmCommandService().execute(command);
- } finally {
- jbpmService.close();
- }
+ getJbpmCommandService().execute(command);
}
/**
* Encapsulate obtention of jBPM CommandService.
* @return CommandService
*/
- public static CommandServiceImpl getJbpmCommandService()
+ public static CommandService getJbpmCommandService()
{
if (null== jbpmService) {
jbpmConfig = JbpmConfiguration.getInstance();
Deleted: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/cmd/CommandServiceImpl.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/cmd/CommandServiceImpl.java 2007-12-12 16:04:22 UTC (rev 17202)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/main/java/org/jboss/soa/esb/services/jbpm/cmd/CommandServiceImpl.java 2007-12-12 20:35:19 UTC (rev 17203)
@@ -1,91 +0,0 @@
-/**
- *
- */
-package org.jboss.soa.esb.services.jbpm.cmd;
-
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-import java.io.Serializable;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.jbpm.JbpmConfiguration;
-import org.jbpm.JbpmContext;
-import org.jbpm.JbpmException;
-import org.jbpm.command.Command;
-import org.jbpm.command.CommandService;
-
-/**
- * Provide services for accessing the jBPM engine. Access is currently provided
- * through a set of {@link org.jbpm.command.Command} derived operations.
- *
- * @author Jim Rigsbee, Tom Baeyens
- */
-public class CommandServiceImpl implements CommandService, Serializable {
-
- private static final long serialVersionUID = 1L;
-
- protected JbpmConfiguration jbpmConfiguration = null;
- JbpmContext jbpmContext = null;
-
- /**
- * Establish an instance of the command service with a particular jBPM
- * configuration which provides connectivity to the jBPM engine and its
- * related services including the persistence manager.
- *
- * @param jbpmConfiguration
- * jBPM Configuration
- */
- public CommandServiceImpl(JbpmConfiguration jbpmConfiguration) {
- this.jbpmConfiguration = jbpmConfiguration;
- }
-
- /**
- * Executes command based on its current context. Each command contains the
- * appropriate context information such as token, process instance, etc. to
- * insure that the operation is carried out on the proper graph object.
- *
- * @param command
- * jBPM engine command to execute
- */
- public Object execute(Command command) {
- Object result = null;
- if (jbpmContext==null) {
- jbpmContext = jbpmConfiguration.createJbpmContext();
- }
- try {
- log.debug("executing " + command);
- result = command.execute(jbpmContext);
- } catch (Exception e) {
- throw new JbpmException("couldn't execute "+command, e);
- }
- return result;
- }
-
- public void close(){
- jbpmContext.close();
- jbpmContext=null;
- }
-
- private static final Log log = LogFactory.getLog(CommandServiceImpl.class);
-}
-
Modified: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/JBpmObjectMapperTest.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/JBpmObjectMapperTest.java 2007-12-12 16:04:22 UTC (rev 17202)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/JBpmObjectMapperTest.java 2007-12-12 20:35:19 UTC (rev 17203)
@@ -27,8 +27,6 @@
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
-import java.util.Map;
-
import junit.framework.JUnit4TestAdapter;
import org.apache.log4j.Logger;
@@ -36,7 +34,6 @@
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import org.dom4j.tree.DefaultElement;
-import org.jboss.soa.esb.addressing.EPR;
import org.jboss.soa.esb.message.Message;
import org.jbpm.graph.def.Node;
import org.jbpm.graph.def.ProcessDefinition;
@@ -204,43 +201,6 @@
assertEquals(String.valueOf(String.valueOf(message.getBody().get("piVersion"))), String.valueOf(processInstance.getVersion()));
logger.info("Message=" + message);
}
- /**
- * Tests if the variableMapping can go roundtrip (via the callbackService code)
- *
- * @throws Exception
- */
- @Test
- public void esbToJBpmAndBack() throws Exception
- {
- SAXReader reader = new SAXReader();
- Document document = reader.read(this.getClass().getResourceAsStream("/" + PROCESS_DEF_XML));
- Element element = document.getRootElement();
- DefaultElement bpmToEsbVars = (DefaultElement) element.element("start-state").element("transition").element("action").element("bpmToEsbVars");
- DefaultElement esbToBpmVars = (DefaultElement) element.element("start-state").element("transition").element("action").element("esbToBpmVars");
-
- String helloWorldTokenScope = "Hello world token scope";
- String helloWorldGlobalScope = "Hello world process-instance scope";
-
- Token token = processInstance.getRootToken();
- processInstance.getContextInstance().createVariable("v1", helloWorldTokenScope, token);
- processInstance.getContextInstance().createVariable("g2", helloWorldGlobalScope);
- ExecutionContext executionContext = new ExecutionContext(token);
-
- JBpmObjectMapper mapper = new JBpmObjectMapper();
- Message message = mapper.mapFromJBpmToEsbMessage(bpmToEsbVars, Boolean.FALSE, executionContext);
-
- //Setting up return mapping for the callback service.
- JBpmCallbackHelper callbackHelper = new JBpmCallbackHelper();
- EPR epr = callbackHelper.createReplyTo(esbToBpmVars.asXML(), Boolean.FALSE, executionContext);
- String esbToBpmXml = epr.getAddr().getExtensionValue(Constants.ESB_TO_BPM_VARS_TAG);
-
- //Obtaining the VariableMap that is going to be set callback command
- Map<String,Object> variableMap = mapper.mapFromEsbMessageToJBpmMap(message, esbToBpmXml);
- logger.info(variableMap);
- //Let's make sure that what we put in is going to make it roundtrip.
- assertEquals(helloWorldTokenScope, variableMap.get("x1"));
- assertEquals(helloWorldGlobalScope,variableMap.get("x2"));
- }
public static junit.framework.Test suite(){
return new JUnit4TestAdapter(JBpmObjectMapperTest.class);
Added: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/actionhandlers/JBpmObjectMapperCallbackTest.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/actionhandlers/JBpmObjectMapperCallbackTest.java (rev 0)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/actionhandlers/JBpmObjectMapperCallbackTest.java 2007-12-12 20:35:19 UTC (rev 17203)
@@ -0,0 +1,118 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.soa.esb.services.jbpm.actionhandlers;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Map;
+
+import junit.framework.JUnit4TestAdapter;
+
+import org.apache.log4j.Logger;
+import org.dom4j.Document;
+import org.dom4j.Element;
+import org.dom4j.io.SAXReader;
+import org.dom4j.tree.DefaultElement;
+import org.jboss.soa.esb.addressing.EPR;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.services.jbpm.Constants;
+import org.jboss.soa.esb.services.jbpm.JBpmObjectMapper;
+import org.jboss.soa.esb.services.jbpm.actionhandlers.EsbActionHandler;
+import org.jbpm.graph.def.ProcessDefinition;
+import org.jbpm.graph.exe.ExecutionContext;
+import org.jbpm.graph.exe.ProcessInstance;
+import org.jbpm.graph.exe.Token;
+import org.junit.BeforeClass;
+import org.junit.Test;
+/**
+ * Tests the capabilities of the JBpmObjectMapper.
+ *
+ * @author kstam
+ *
+ */
+public class JBpmObjectMapperCallbackTest
+{
+ private static String PROCESS_DEF_XML = "JBpmObjectMapperTestProcessDefinition.xml";
+ private static Logger logger = Logger.getLogger(JBpmObjectMapperCallbackTest.class);
+ private static ProcessInstance processInstance = null;
+
+ @BeforeClass
+ public static void setup()
+ {
+ logger.info("Setting up jBPM");
+ //Extract a process definition from the processdefinition.xml file.
+ ProcessDefinition processDefinition
+ = ProcessDefinition.parseXmlResource(PROCESS_DEF_XML);
+ assertNotNull(processDefinition);
+ //Create an instance of the process definition.
+ processInstance = new ProcessInstance(processDefinition);
+ assertTrue(
+ "Instance is in start state",
+ "start".equals(processInstance.getRootToken().getNode().getName()));
+ }
+
+ /**
+ * Tests if the variableMapping can go roundtrip (via the callbackService code)
+ *
+ * @throws Exception
+ */
+ @Test
+ public void esbToJBpmAndBack() throws Exception
+ {
+ SAXReader reader = new SAXReader();
+ Document document = reader.read(this.getClass().getResourceAsStream("/" + PROCESS_DEF_XML));
+ Element element = document.getRootElement();
+ DefaultElement bpmToEsbVars = (DefaultElement) element.element("start-state").element("transition").element("action").element("bpmToEsbVars");
+ DefaultElement esbToBpmVars = (DefaultElement) element.element("start-state").element("transition").element("action").element("esbToBpmVars");
+
+ String helloWorldTokenScope = "Hello world token scope";
+ String helloWorldGlobalScope = "Hello world process-instance scope";
+
+ Token token = processInstance.getRootToken();
+ processInstance.getContextInstance().createVariable("v1", helloWorldTokenScope, token);
+ processInstance.getContextInstance().createVariable("g2", helloWorldGlobalScope);
+ ExecutionContext executionContext = new ExecutionContext(token);
+
+ JBpmObjectMapper mapper = new JBpmObjectMapper();
+ Message message = mapper.mapFromJBpmToEsbMessage(bpmToEsbVars, Boolean.FALSE, executionContext);
+
+ //Setting up return mapping for the callback service.
+ EsbActionHandler esbActionHandler = new EsbActionHandler();
+ EPR epr = esbActionHandler.createReplyTo(esbToBpmVars.asXML(), Boolean.FALSE, executionContext);
+ String esbToBpmXml = epr.getAddr().getExtensionValue(Constants.ESB_TO_BPM_VARS_TAG);
+
+ //Obtaining the VariableMap that is going to be set callback command
+ Map<String,Object> variableMap = mapper.mapFromEsbMessageToJBpmMap(message, esbToBpmXml);
+ logger.info(variableMap);
+ //Let's make sure that what we put in is going to make it roundtrip.
+ assertEquals(helloWorldTokenScope, variableMap.get("x1"));
+ assertEquals(helloWorldGlobalScope,variableMap.get("x2"));
+ }
+
+ public static junit.framework.Test suite(){
+ return new JUnit4TestAdapter(JBpmObjectMapperCallbackTest.class);
+ }
+
+}
Property changes on: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/services/jbpm/src/test/java/org/jboss/soa/esb/services/jbpm/actionhandlers/JBpmObjectMapperCallbackTest.java
___________________________________________________________________
Name: svn:eol-style
+ native
More information about the jboss-svn-commits
mailing list