Author: lresende
Date: Sat Sep 15 09:55:41 2007
New Revision: 575938

URL: http://svn.apache.org/viewvc?rev=575938&view=rev
Log:
Merging updates to BPEL Implementation

Modified:
    incubator/tuscany/branches/sca-java-1.0/modules/implementation-bpel/pom.xml
    
incubator/tuscany/branches/sca-java-1.0/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/provider/BPELImplementationProvider.java
    
incubator/tuscany/branches/sca-java-1.0/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/provider/BPELInvoker.java
    
incubator/tuscany/branches/sca-java-1.0/modules/implementation-bpel/src/test/java/org/apache/tuscany/sca/implementation/bpel/BPELDocumentProcessorTestCase.java
    
incubator/tuscany/branches/sca-java-1.0/modules/implementation-bpel/src/test/java/org/apache/tuscany/sca/implementation/bpel/BPELTestCase.java
    
incubator/tuscany/branches/sca-java-1.0/modules/implementation-bpel/src/test/resources/helloworld.bpel

Modified: 
incubator/tuscany/branches/sca-java-1.0/modules/implementation-bpel/pom.xml
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-1.0/modules/implementation-bpel/pom.xml?rev=575938&r1=575937&r2=575938&view=diff
==============================================================================
--- incubator/tuscany/branches/sca-java-1.0/modules/implementation-bpel/pom.xml 
(original)
+++ incubator/tuscany/branches/sca-java-1.0/modules/implementation-bpel/pom.xml 
Sat Sep 15 09:55:41 2007
@@ -385,7 +385,7 @@
                                                
<id>generate-bpel-helloworld</id>
                                                <phase>generate-sources</phase>
                                                <configuration>
-                                                       
<schemaFile>${basedir}/src/test/resources/HelloWorld.wsdl</schemaFile>
+                                                       
<schemaFile>${basedir}/src/test/resources/helloworld.wsdl</schemaFile>
                                                        
<targetDirectory>${basedir}/target/wsdl2java-source</targetDirectory>
                                                        
<prefix>HelloWorld</prefix>
                                                        
<noNotification>true</noNotification>
@@ -407,7 +407,7 @@
                                                <configuration>
                                                        <wsdlFiles>
                                                                <wsdlFile>
-                                                                       
<fileName>${basedir}/src/test/resources/HelloWorld.wsdl</fileName>
+                                                                       
<fileName>${basedir}/src/test/resources/helloworld.wsdl</fileName>
                                                                </wsdlFile>
                                                        </wsdlFiles>
                                                </configuration>

Modified: 
incubator/tuscany/branches/sca-java-1.0/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/provider/BPELImplementationProvider.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-1.0/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/provider/BPELImplementationProvider.java?rev=575938&r1=575937&r2=575938&view=diff
==============================================================================
--- 
incubator/tuscany/branches/sca-java-1.0/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/provider/BPELImplementationProvider.java
 (original)
+++ 
incubator/tuscany/branches/sca-java-1.0/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/provider/BPELImplementationProvider.java
 Sat Sep 15 09:55:41 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/branches/sca-java-1.0/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/provider/BPELInvoker.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-1.0/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/provider/BPELInvoker.java?rev=575938&r1=575937&r2=575938&view=diff
==============================================================================
--- 
incubator/tuscany/branches/sca-java-1.0/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/provider/BPELInvoker.java
 (original)
+++ 
incubator/tuscany/branches/sca-java-1.0/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/provider/BPELInvoker.java
 Sat Sep 15 09:55:41 2007
@@ -20,16 +20,29 @@
 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.wsdl.Service;
+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
@@ -39,12 +52,37 @@
 public class BPELInvoker implements Invoker {
     private EmbeddedODEServer odeServer;
     private TransactionManager txMgr;
+    
     private Operation operation;
+    private QName bpelServiceName;
+    private String bpelOperationName;
+    private Part bpelOperationInputPart;
+    private Part bpelOperationOutputPart;
     
     public BPELInvoker(Operation operation, EmbeddedODEServer odeServer, 
TransactionManager txMgr) {
         this.operation = operation;
         this.odeServer = odeServer;
         this.txMgr = txMgr;
+
+        initializeInvocation();
+    }
+
+    
+    private void initializeInvocation() {
+
+        this.bpelOperationName = operation.getName();
+        
+        Interface interfaze = operation.getInterface();
+        if(interfaze instanceof WSDLInterface){
+            WSDLInterface wsdlInterface = null;
+            wsdlInterface = (WSDLInterface) interfaze;
+            
+            Service serviceDefinition = (Service) 
wsdlInterface.getWsdlDefinition().getDefinition().getServices().values().iterator().next();
 
+            bpelServiceName = serviceDefinition.getQName();
+                
+            bpelOperationInputPart = (Part) 
wsdlInterface.getPortType().getOperation(bpelOperationName,null,null).getInput().getMessage().getParts().values().iterator().next();
+            bpelOperationOutputPart = (Part) 
wsdlInterface.getPortType().getOperation(bpelOperationName,null,null).getOutput().getMessage().getParts().values().iterator().next();
+        }
     }
     
     public Message invoke(Message msg) {
@@ -59,11 +97,118 @@
     }
 
     public Object doTheWork(Object[] args) throws InvocationTargetException {
-        if (operation.getName().equals("invokeProcess")) {
-            return args[0];
-        } else {
-            return null;
+        Element response = null;
+        
+        if(! (operation.getInterface() instanceof WSDLInterface)) {
+            throw new InvocationTargetException(null,"Unsupported service 
contract");
+        }
+        
+        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(),
+                                                                              
bpelServiceName,
+                                                                              
bpelOperationName);
+            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) {
+        Document dom = DOMUtils.newDocument();
+        
+        Element contentMessage = dom.createElement("message");
+        Element contentPart = 
dom.createElement(bpelOperationInputPart.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;
+    }
+    
+    /**
+     * 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) {
+        return (Element) DOMUtils.findChildByName(response, new 
QName("",bpelOperationOutputPart.getName()));
+    }
 }

Modified: 
incubator/tuscany/branches/sca-java-1.0/modules/implementation-bpel/src/test/java/org/apache/tuscany/sca/implementation/bpel/BPELDocumentProcessorTestCase.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-1.0/modules/implementation-bpel/src/test/java/org/apache/tuscany/sca/implementation/bpel/BPELDocumentProcessorTestCase.java?rev=575938&r1=575937&r2=575938&view=diff
==============================================================================
--- 
incubator/tuscany/branches/sca-java-1.0/modules/implementation-bpel/src/test/java/org/apache/tuscany/sca/implementation/bpel/BPELDocumentProcessorTestCase.java
 (original)
+++ 
incubator/tuscany/branches/sca-java-1.0/modules/implementation-bpel/src/test/java/org/apache/tuscany/sca/implementation/bpel/BPELDocumentProcessorTestCase.java
 Sat Sep 15 09:55:41 2007
@@ -6,15 +6,15 @@
  * 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.    
+ * under the License.
  */
 
 package org.apache.tuscany.sca.implementation.bpel;
@@ -36,30 +36,30 @@
  * @version $Rev$ $Date$
  */
 public class BPELDocumentProcessorTestCase extends TestCase {
-    
-    protected static final String BPEL_PROCESS_FILE = "HelloWorld.bpel";
+
+    protected static final String BPEL_PROCESS_FILE = "helloworld.bpel";
 
     private ModelFactoryExtensionPoint modelFactories;
 
     @Override
     protected void setUp() throws Exception {
         super.setUp();
-       
+
         modelFactories = new DefaultModelFactoryExtensionPoint();
         modelFactories.addFactory(new DefaultAssemblyFactory());
         modelFactories.addFactory(new DefaultWSDLFactory());
-        
+
         BPELFactory bpelFactory = new DefaultBPELFactory(modelFactories);
         modelFactories.addFactory(bpelFactory);
     }
 
     public void testLoadBPELProcessDefinition() throws Exception {
         BPELDocumentProcessor bpelDocumentProcessor = new 
BPELDocumentProcessor(modelFactories);
-        
+
         URI processURI = 
getClass().getClassLoader().getResource(BPEL_PROCESS_FILE).toURI();
         URL processLocation = 
getClass().getClassLoader().getResource(BPEL_PROCESS_FILE);
         BPELProcessDefinition bpelProcessDefinition = 
bpelDocumentProcessor.read(null, processURI, processLocation);
-        
+
         assertNotNull(bpelProcessDefinition);
         assertEquals(new 
QName("http://tuscany.apache.org/implementation/bpel/example/helloworld";, 
"HelloWorld"), bpelProcessDefinition.getName());
         assertEquals(processLocation, bpelProcessDefinition.getLocation());

Modified: 
incubator/tuscany/branches/sca-java-1.0/modules/implementation-bpel/src/test/java/org/apache/tuscany/sca/implementation/bpel/BPELTestCase.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-1.0/modules/implementation-bpel/src/test/java/org/apache/tuscany/sca/implementation/bpel/BPELTestCase.java?rev=575938&r1=575937&r2=575938&view=diff
==============================================================================
--- 
incubator/tuscany/branches/sca-java-1.0/modules/implementation-bpel/src/test/java/org/apache/tuscany/sca/implementation/bpel/BPELTestCase.java
 (original)
+++ 
incubator/tuscany/branches/sca-java-1.0/modules/implementation-bpel/src/test/java/org/apache/tuscany/sca/implementation/bpel/BPELTestCase.java
 Sat Sep 15 09:55:41 2007
@@ -53,6 +53,7 @@
     }
     
     public void testInvoke() {
-        //bpelService.hello("Luciano");
+        String response = bpelService.hello("Hello");
+        assertEquals("World", response);
     }
 }

Modified: 
incubator/tuscany/branches/sca-java-1.0/modules/implementation-bpel/src/test/resources/helloworld.bpel
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-1.0/modules/implementation-bpel/src/test/resources/helloworld.bpel?rev=575938&r1=575937&r2=575938&view=diff
==============================================================================
--- 
incubator/tuscany/branches/sca-java-1.0/modules/implementation-bpel/src/test/resources/helloworld.bpel
 (original)
+++ 
incubator/tuscany/branches/sca-java-1.0/modules/implementation-bpel/src/test/resources/helloworld.bpel
 Sat Sep 15 09:55:41 2007
@@ -26,7 +26,7 @@
     queryLanguage="urn:oasis:names:tc:wsbpel:2.0:sublang:xpath2.0"
     expressionLanguage="urn:oasis:names:tc:wsbpel:2.0:sublang:xpath2.0">
 
-  <import location="HelloWorld.wsdl" 
importType="http://schemas.xmlsoap.org/wsdl/";
+  <import location="helloworld.wsdl" 
importType="http://schemas.xmlsoap.org/wsdl/";
      
namespace="file:///home/mriou/dev/projects/ode/distro-axis2/src/examples/HelloWorld2/HelloWorld2.wsdl"/>
 
    <partnerLinks>



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to