You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by ed...@apache.org on 2009/08/17 13:14:05 UTC

svn commit: r804938 - in /tuscany/java/sca/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/provider: BPELImplementationProvider.java BPELInvoker.java

Author: edwardsmj
Date: Mon Aug 17 11:14:04 2009
New Revision: 804938

URL: http://svn.apache.org/viewvc?rev=804938&view=rev
Log:
Adding support for SCA callbacks, as described in TUSCANY 3216

Modified:
    tuscany/java/sca/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/provider/BPELImplementationProvider.java
    tuscany/java/sca/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/provider/BPELInvoker.java

Modified: tuscany/java/sca/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/provider/BPELImplementationProvider.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/provider/BPELImplementationProvider.java?rev=804938&r1=804937&r2=804938&view=diff
==============================================================================
--- tuscany/java/sca/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/provider/BPELImplementationProvider.java (original)
+++ tuscany/java/sca/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/provider/BPELImplementationProvider.java Mon Aug 17 11:14:04 2009
@@ -109,9 +109,16 @@
     public void start() {
         if(__log.isInfoEnabled()) {
             __log.info("Starting " + component.getName());
-        }
+        } // end if
+        
+    	ClassLoader tccl = Thread.currentThread().getContextClassLoader();
+    	ClassLoader bpelcl = this.getClass().getClassLoader();
 
         try {
+    		// Switch TCCL - under OSGi this causes the TCCL to be set to the Bundle
+    		// classloader - this is then used by 3rd party code from ODE and its dependencies
+    		if( bpelcl != tccl ) Thread.currentThread().setContextClassLoader(bpelcl);
+    		
             if (!odeServer.isInitialized()) {
                 // start ode server
                 odeServer.init();
@@ -142,8 +149,11 @@
             throw new RuntimeException("BPEL Component Type Implementation : Error initializing embedded ODE server " + inite.getMessage(), inite);
         } catch(Exception e) {
             throw new RuntimeException("BPEL Component Type Implementation initialization failure : " + e.getMessage(), e);
-        }
-    }
+    	} finally {
+    		// Restore the TCCL if we changed it
+    		if( bpelcl != tccl ) Thread.currentThread().setContextClassLoader(tccl);
+        } // end try
+    } // end method start()
 
     public void stop() {
         if(__log.isInfoEnabled()) {

Modified: tuscany/java/sca/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/provider/BPELInvoker.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/provider/BPELInvoker.java?rev=804938&r1=804937&r2=804938&view=diff
==============================================================================
--- tuscany/java/sca/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/provider/BPELInvoker.java (original)
+++ tuscany/java/sca/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/provider/BPELInvoker.java Mon Aug 17 11:14:04 2009
@@ -29,11 +29,14 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.ode.bpel.iapi.MessageExchange;
 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.assembly.Base;
+import org.apache.tuscany.sca.assembly.Endpoint;
+import org.apache.tuscany.sca.assembly.EndpointReference;
 import org.apache.tuscany.sca.implementation.bpel.ode.EmbeddedODEServer;
 import org.apache.tuscany.sca.interfacedef.Interface;
 import org.apache.tuscany.sca.interfacedef.Operation;
@@ -68,18 +71,27 @@
     private Part 					bpelOperationInputPart;
     private Part 					bpelOperationOutputPart;
     private RuntimeComponent 		component;
+    // Marks if this service has a callback interface
+    private Boolean					isCallback = false;
+    private EndpointReference 		callbackEPR;
 
-    public BPELInvoker(RuntimeComponent component, RuntimeComponentService service, Operation operation, EmbeddedODEServer odeServer, TransactionManager txMgr) {
+    public BPELInvoker(RuntimeComponent component, RuntimeComponentService service, Operation operation, 
+    		           EmbeddedODEServer odeServer, TransactionManager txMgr) {
         this.service = service;
         this.component = component;
         this.operation = operation;
         this.bpelOperationName = operation.getName();
         this.odeServer = odeServer;
         this.txMgr = txMgr;
+        this.isCallback = serviceHasCallback( service );
 
         initializeInvocation();
-    }
-
+    } // end method BPELInvoker
+    
+    private boolean serviceHasCallback( RuntimeComponentService service ) {
+    	if(service.getInterfaceContract().getCallbackInterface() != null) return true;
+    	return false;
+    } // end method serviceHasCallback
 
     private void initializeInvocation() {
 
@@ -90,10 +102,6 @@
             WSDLInterface wsdlInterface = null;
             wsdlInterface = (WSDLInterface) interfaze;
 
-            // The following commented out code is bogus and is replaced by what follows - Mike Edwards
-            // Service serviceDefinition = (Service) wsdlInterface.getWsdlDefinition().getDefinition().getAllServices().values().iterator().next();
-            // bpelServiceName = serviceDefinition.getQName();
-            //
             // Fetch the service name from the service object - including the componentURI guarantees a unique service name
             String componentURI = component.getURI();
             bpelServiceName = new QName( Base.SCA11_TUSCANY_NS, componentURI + service.getName() );
@@ -101,10 +109,14 @@
             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();
         }
-    }
+    } // end method initializeInvocation
 
     public Message invoke(Message msg) {
         try {
+        	if( isCallback ) {
+        		// Extract the callback endpoint metadata
+        		callbackEPR = msg.getFrom();
+        	} // end if
             Object[] args = msg.getBody();
             Object resp = doTheWork(args);
             msg.setBody(resp);
@@ -125,15 +137,23 @@
         Future<?> onhold = null;
 
         //Process the BPEL process invocation
+        Long processID = 0L;
         try {
             txMgr.begin();
             mex = odeServer.getBpelServer().getEngine().createMessageExchange(new GUID().toString(),
                                                                               bpelServiceName,
                                                                               bpelOperationName);
+            //TODO - this will not be true for OneWay operations - need to handle those
             mex.setProperty("isTwoWay", "true");
             onhold = mex.invoke(createInvocationMessage(mex, args));
-
+            
             txMgr.commit();
+            // Deal with callback cases - store the callback metadata by process instance ID
+            if( isCallback ) {
+            	processID = odeServer.getProcessIDFromMex(mex.getMessageExchangeId());
+                // Store the callback metadata for this invocation
+            	odeServer.saveCallbackMetadata( processID, service.getName(), callbackEPR );
+            } // end if
         } catch (Exception e) {
             try {
                 txMgr.rollback();
@@ -141,8 +161,7 @@
 
             }
             throw new InvocationTargetException(e, "Error invoking BPEL process : " + e.getMessage());
-        }
-
+        } // end try
 
         // Waiting until the reply is ready in case the engine needs to continue in a different thread
         if (onhold != null) {
@@ -150,8 +169,8 @@
                 onhold.get();
             } catch (Exception e) {
                 throw new InvocationTargetException(e,"Error invoking BPEL process : " + e.getMessage());
-            }
-        }
+            } // end try
+        } // end if
 
         //Process the BPEL invocation response
         try {
@@ -193,8 +212,10 @@
 
             }
             throw new InvocationTargetException(e, "Error retrieving BPEL process invocation status : " + e.getMessage());
-        }
+        } // end try
 
+        // Cleanup the ODE MessageExchange object
+        //mex.release();
 
         return response;
     }
@@ -218,6 +239,7 @@
         Element contentPart = dom.createElement(bpelOperationInputPart.getName());
         Element payload = null;
 
+        // TODO handle WSDL input messages with multiple Parts...
         //TUSCANY-2321 - Properly handling Document or Element types
         if(args[0] instanceof Document) {
             payload = (Element) ((Document) args[0]).getFirstChild();
@@ -258,6 +280,5 @@
 
     	// MJE, 12/06/2009 - changed to return the message without the PART wrapper element, since this element is not
     	// transmitted in the SOAP messages on the wire
-    	//return (Element) DOMUtils.findChildByName(response, new QName("",bpelOperationOutputPart.getName()));
-    }
-}
+    } // end method processResponse
+} // end class BPELInvoker