Author: lresende
Date: Fri Sep 14 18:43:08 2007
New Revision: 575846
URL: http://svn.apache.org/viewvc?rev=575846&view=rev
Log:
Cleaning up BPEL process invocation mechanism
Modified:
incubator/tuscany/java/sca/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/provider/BPELImplementationProvider.java
incubator/tuscany/java/sca/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/provider/BPELInvoker.java
incubator/tuscany/java/sca/modules/implementation-bpel/src/test/java/org/apache/tuscany/sca/implementation/bpel/BPELTestCase.java
Modified:
incubator/tuscany/java/sca/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/provider/BPELImplementationProvider.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/provider/BPELImplementationProvider.java?rev=575846&r1=575845&r2=575846&view=diff
==============================================================================
---
incubator/tuscany/java/sca/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/provider/BPELImplementationProvider.java
(original)
+++
incubator/tuscany/java/sca/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/provider/BPELImplementationProvider.java
Fri Sep 14 18:43:08 2007
@@ -26,6 +26,7 @@
import org.apache.tuscany.sca.implementation.bpel.BPELImplementation;
import org.apache.tuscany.sca.implementation.bpel.ode.EmbeddedODEServer;
import org.apache.tuscany.sca.implementation.bpel.ode.ODEDeployment;
+import
org.apache.tuscany.sca.implementation.bpel.ode.ODEInitializationException;
import org.apache.tuscany.sca.interfacedef.Operation;
import org.apache.tuscany.sca.invocation.Invoker;
import org.apache.tuscany.sca.provider.ImplementationProvider;
@@ -44,12 +45,14 @@
public class BPELImplementationProvider implements ImplementationProvider {
private RuntimeComponent component;
- private BPELImplementation implementation;
+
private EmbeddedODEServer odeServer;
private TransactionManager txMgr;
+ private BPELImplementation implementation;
+
/**
- * Constructs a new CRUD implementation.
+ * Constructs a new BPEL Implementation.
*/
public BPELImplementationProvider(RuntimeComponent component,
BPELImplementation implementation,
@@ -75,9 +78,10 @@
System.out.println("Starting " + component.getName() + " " +
component.getClass().getName());
try {
- if (!odeServer.isInitialized())
+ if (!odeServer.isInitialized()) {
// start ode server
odeServer.init();
+ }
URL deployURL =
getClass().getClassLoader().getResource("deploy.xml");
File deploymentDir = new
File(deployURL.toURI().getPath()).getParentFile();
@@ -96,8 +100,10 @@
}
}
+ } catch (ODEInitializationException inite) {
+ throw new RuntimeException("BPEL Component Type Implementation :
Error initializing embedded ODE server " + inite.getMessage(), inite);
} catch(Exception e) {
- e.printStackTrace();
+ throw new RuntimeException("BPEl Component Type Implementation
initialization failure : " + e.getMessage(), e);
}
// FIXME:lresende
Modified:
incubator/tuscany/java/sca/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/provider/BPELInvoker.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/provider/BPELInvoker.java?rev=575846&r1=575845&r2=575846&view=diff
==============================================================================
---
incubator/tuscany/java/sca/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/provider/BPELInvoker.java
(original)
+++
incubator/tuscany/java/sca/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/provider/BPELInvoker.java
Fri Sep 14 18:43:08 2007
@@ -20,16 +20,28 @@
package org.apache.tuscany.sca.implementation.bpel.provider;
import java.lang.reflect.InvocationTargetException;
+import java.util.concurrent.Future;
+import javax.transaction.SystemException;
import javax.transaction.TransactionManager;
+import javax.wsdl.Part;
+import javax.xml.namespace.QName;
+import org.apache.ode.bpel.iapi.MyRoleMessageExchange;
+import org.apache.ode.bpel.iapi.MessageExchange.Status;
+import org.apache.ode.utils.DOMUtils;
+import org.apache.ode.utils.GUID;
import org.apache.tuscany.sca.implementation.bpel.ode.EmbeddedODEServer;
+import org.apache.tuscany.sca.interfacedef.Interface;
import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterface;
import org.apache.tuscany.sca.invocation.Invoker;
import org.apache.tuscany.sca.invocation.Message;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
/**
- * Implements a target invoker for CRUD component implementations.
+ * Implements a target invoker for BPEL component implementations.
*
* The target invoker is responsible for dispatching invocations to the
particular
* component implementation logic. In this example we are simply delegating the
@@ -59,11 +71,133 @@
}
public Object doTheWork(Object[] args) throws InvocationTargetException {
- if (operation.getName().equals("invokeProcess")) {
- return args[0];
- } else {
- return null;
+ Element response = null;
+
+ org.apache.ode.bpel.iapi.MyRoleMessageExchange mex = null;
+ Future onhold = null;
+
+ //Process the BPEL process invocation
+ try {
+ txMgr.begin();
+ mex =
odeServer.getBpelServer().getEngine().createMessageExchange(new
GUID().toString(),
+ new
QName("http://tuscany.apache.org/implementation/bpel/example/helloworld.wsdl",
"HelloService"), "hello");
+
+ onhold = mex.invoke(createInvocationMessage(mex, args));
+
+ txMgr.commit();
+ } catch (Exception e) {
+ try {
+ txMgr.rollback();
+ } catch (SystemException se) {
+
+ }
+ throw new InvocationTargetException(e, "Error invoking BPEL
process : " + e.getMessage());
+ }
+
+
+ // Waiting until the reply is ready in case the engine needs to
continue in a different thread
+ if (onhold != null) {
+ try {
+ onhold.get();
+ } catch (Exception e) {
+ throw new InvocationTargetException(e,"Error invoking BPEL
process : " + e.getMessage());
+ }
+ }
+
+ //Process the BPEL invocation response
+ try {
+ txMgr.begin();
+ // Reloading the mex in the current transaction, otherwise we can't
+ // be sure we have the "freshest" one.
+ mex =
(MyRoleMessageExchange)odeServer.getBpelServer().getEngine().getMessageExchange(mex.getMessageExchangeId());
+
+ Status status = mex.getStatus();
+ System.out.println("Status: " + status.name());
+ Element invocationResponse = mex.getResponse().getMessage();
+ System.out.println("Response: " +
DOMUtils.domToString(invocationResponse));
+
+ //process the method invocation result
+ response = processResponse(invocationResponse);
+
+ txMgr.commit();
+ // end of transaction two
+ } catch (Exception e) {
+ try {
+ txMgr.rollback();
+ } catch (SystemException se) {
+
+ }
+ throw new InvocationTargetException(e, "Error retrieving BPEL
process invocation status : " + e
+ .getMessage());
}
+
+
+ return response;
}
+ /**
+ * Create BPEL Invocation message
+ *
+ * BPEL invocation message like :
+ * <message>
+ * <TestPart>
+ * <hello
xmlns="http://tuscany.apache.org/implementation/bpel/example/helloworld.wsdl">Hello</hello>
+ * </TestPart>
+ * </message>
+ * @param args
+ * @return
+ */
+ private org.apache.ode.bpel.iapi.Message
createInvocationMessage(org.apache.ode.bpel.iapi.MyRoleMessageExchange mex,
Object[] args) {
+ Interface interfaze = operation.getInterface();
+ if(interfaze instanceof WSDLInterface){
+ WSDLInterface wsdlInterface = null;
+ wsdlInterface = (WSDLInterface) interfaze;
+
+ Part operationPart = (Part)
wsdlInterface.getPortType().getOperation(operation.getName(),null,null).getInput().getMessage().getParts().values().iterator().next();
+
+ Document dom = DOMUtils.newDocument();
+
+ Element contentMessage = dom.createElement("message");
+ Element contentPart = dom.createElement(operationPart.getName());
+ Element contentInvocation = (Element) args[0];
+
+ contentPart.appendChild(dom.importNode(contentInvocation, false));
+ contentMessage.appendChild(contentPart);
+ dom.appendChild(contentMessage);
+
+ System.out.println("::message:: " +
DOMUtils.domToString(dom.getDocumentElement()));
+
+ org.apache.ode.bpel.iapi.Message request = mex.createMessage(new
QName("", ""));
+ request.setMessage(dom.getDocumentElement());
+
+ return request;
+ }
+ return null;
+ }
+
+ /**
+ * Process BPEL response
+ *
+ * <message>
+ * <TestPart>
+ * <hello
xmlns="http://tuscany.apache.org/implementation/bpel/example/helloworld.wsdl">World</hello>
+ * </TestPart>
+ * </message>
+ *
+ * @param response
+ * @return
+ */
+ private Element processResponse(Element response) {
+ Interface interfaze = operation.getInterface();
+ if(interfaze instanceof WSDLInterface){
+ WSDLInterface wsdlInterface = null;
+ wsdlInterface = (WSDLInterface) interfaze;
+
+ Part operationPart = (Part)
wsdlInterface.getPortType().getOperation(operation.getName(),null,null).getOutput().getMessage().getParts().values().iterator().next();
+
+ return (Element) DOMUtils.findChildByName(response, new
QName("",operationPart.getName())).getFirstChild();
+ }
+
+ return null;
+ }
}
Modified:
incubator/tuscany/java/sca/modules/implementation-bpel/src/test/java/org/apache/tuscany/sca/implementation/bpel/BPELTestCase.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-bpel/src/test/java/org/apache/tuscany/sca/implementation/bpel/BPELTestCase.java?rev=575846&r1=575845&r2=575846&view=diff
==============================================================================
---
incubator/tuscany/java/sca/modules/implementation-bpel/src/test/java/org/apache/tuscany/sca/implementation/bpel/BPELTestCase.java
(original)
+++
incubator/tuscany/java/sca/modules/implementation-bpel/src/test/java/org/apache/tuscany/sca/implementation/bpel/BPELTestCase.java
Fri Sep 14 18:43:08 2007
@@ -53,6 +53,7 @@
}
public void testInvoke() {
- //bpelService.hello("Luciano");
+ //String response = bpelService.hello("Hello");
+ //assertEquals("World", response);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]