You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ode.apache.org by mr...@apache.org on 2008/07/23 17:46:12 UTC

svn commit: r679114 - in /ode/branches/APACHE_ODE_1.X/axis2/src/main/java/org/apache/ode/axis2: ODEServer.java hooks/ODEAxisService.java

Author: mriou
Date: Wed Jul 23 08:46:12 2008
New Revision: 679114

URL: http://svn.apache.org/viewvc?rev=679114&view=rev
Log:
ODE-345 Allow BPEL Processes To Be Provided Over JMS (including topics).

Modified:
    ode/branches/APACHE_ODE_1.X/axis2/src/main/java/org/apache/ode/axis2/ODEServer.java
    ode/branches/APACHE_ODE_1.X/axis2/src/main/java/org/apache/ode/axis2/hooks/ODEAxisService.java

Modified: ode/branches/APACHE_ODE_1.X/axis2/src/main/java/org/apache/ode/axis2/ODEServer.java
URL: http://svn.apache.org/viewvc/ode/branches/APACHE_ODE_1.X/axis2/src/main/java/org/apache/ode/axis2/ODEServer.java?rev=679114&r1=679113&r2=679114&view=diff
==============================================================================
--- ode/branches/APACHE_ODE_1.X/axis2/src/main/java/org/apache/ode/axis2/ODEServer.java (original)
+++ ode/branches/APACHE_ODE_1.X/axis2/src/main/java/org/apache/ode/axis2/ODEServer.java Wed Jul 23 08:46:12 2008
@@ -59,7 +59,15 @@
 import javax.servlet.ServletConfig;
 import javax.servlet.ServletException;
 import javax.sql.DataSource;
-import javax.transaction.*;
+import javax.transaction.HeuristicMixedException;
+import javax.transaction.HeuristicRollbackException;
+import javax.transaction.InvalidTransactionException;
+import javax.transaction.NotSupportedException;
+import javax.transaction.RollbackException;
+import javax.transaction.Synchronization;
+import javax.transaction.SystemException;
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
 import javax.transaction.xa.XAResource;
 import javax.wsdl.Definition;
 import javax.xml.namespace.QName;
@@ -313,15 +321,24 @@
     }
 
     public ODEService createService(ProcessConf pconf, QName serviceName, String portName) throws AxisFault {
-        destroyService(serviceName, portName);
-        AxisService axisService = ODEAxisService.createService(_axisConfig, pconf, serviceName, portName);
+        Definition wsdlDefinition = pconf.getDefinitionForService(serviceName);
+
+        // Since multiple processes may provide services at the same (JMS) endpoint, qualify
+        // the (JMS) endpoint-specific NCName with a process-relative URI, if necessary.
+        QName uniqueServiceName = new QName(serviceName.getNamespaceURI(),
+                ODEAxisService.extractServiceName(wsdlDefinition, serviceName, portName,
+                        ODEAxisService.deriveBaseServiceUri(pconf)));
+
+        destroyService(uniqueServiceName, portName);
+
+        AxisService axisService = ODEAxisService.createService(
+                _axisConfig, pconf, serviceName, portName, uniqueServiceName.getLocalPart());
         ODEService odeService = new ODEService(axisService, pconf, serviceName, portName, _server, _txMgr);
 
-        _services.put(serviceName, portName, odeService);
+        _services.put(uniqueServiceName, portName, odeService);
 
         // Setting our new service on the receiver, the same receiver handles
-        // all
-        // operations so the first one should fit them all
+        // all operations so the first one should fit them all
         AxisOperation firstOp = (AxisOperation) axisService.getOperations().next();
         ((ODEMessageReceiver) firstOp.getMessageReceiver()).setService(odeService);
 

Modified: ode/branches/APACHE_ODE_1.X/axis2/src/main/java/org/apache/ode/axis2/hooks/ODEAxisService.java
URL: http://svn.apache.org/viewvc/ode/branches/APACHE_ODE_1.X/axis2/src/main/java/org/apache/ode/axis2/hooks/ODEAxisService.java?rev=679114&r1=679113&r2=679114&view=diff
==============================================================================
--- ode/branches/APACHE_ODE_1.X/axis2/src/main/java/org/apache/ode/axis2/hooks/ODEAxisService.java (original)
+++ ode/branches/APACHE_ODE_1.X/axis2/src/main/java/org/apache/ode/axis2/hooks/ODEAxisService.java Wed Jul 23 08:46:12 2008
@@ -38,9 +38,11 @@
 import org.apache.axis2.deployment.ServiceBuilder;
 import org.apache.axis2.description.AxisOperation;
 import org.apache.axis2.description.AxisService;
+import org.apache.axis2.description.Parameter;
 import org.apache.axis2.description.WSDL11ToAxisServiceBuilder;
 import org.apache.axis2.engine.AxisConfiguration;
 import org.apache.axis2.engine.MessageReceiver;
+import org.apache.axis2.transport.jms.JMSConstants;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.ode.axis2.OdeFault;
@@ -60,9 +62,8 @@
     private static final Log LOG = LogFactory.getLog(ODEAxisService.class);
 
     public static AxisService createService(AxisConfiguration axisConfig, ProcessConf pconf, QName wsdlServiceName,
-                                            String portName) throws AxisFault {
+                                            String portName, String axisServiceName) throws AxisFault {
         Definition wsdlDefinition = pconf.getDefinitionForService(wsdlServiceName);
-        String serviceName = extractServiceName(wsdlDefinition, wsdlServiceName, portName);
 
         if (LOG.isDebugEnabled()) {
             LOG.debug("Create AxisService:"+" service="+wsdlServiceName+" port="+portName
@@ -79,7 +80,7 @@
             serviceBuilder.setServerSide(true);
 
             AxisService axisService = serviceBuilder.populateService();
-            axisService.setName(serviceName);
+            axisService.setName(axisServiceName);
             axisService.setWsdlFound(true);
             axisService.setCustomWsdl(true);
             axisService.setClassLoader(axisConfig.getServiceClassLoader());
@@ -110,7 +111,7 @@
 
             // In doc/lit we need to declare a mapping between operations and message element names
             // to be able to route properly.
-            declarePartsElements(wsdlDefinition, wsdlServiceName, serviceName, portName);
+            declarePartsElements(wsdlDefinition, wsdlServiceName, axisServiceName, portName);
 
             Iterator operations = axisService.getOperations();
             ODEMessageReceiver msgReceiver = new ODEMessageReceiver();
@@ -120,13 +121,36 @@
                     operation.setMessageReceiver(msgReceiver);
                 }
             }
+            
+            // Set the JMS destination name on the Axis Service (used only if endpoint is JMS)  
+            axisService.addParameter(new Parameter(JMSConstants.DEST_PARAM, extractJMSDestinationName(axisServiceName)));
+
             return axisService;
         } catch (Exception e) {
             throw AxisFault.makeFault(e);
         }
     }
 
-    public static AxisService createService(AxisConfiguration axisConfig, QName serviceQName, String port,
+    /**
+     * Extract the JMS destination name that is embedded in the Axis service name.
+     * @param serviceName the name of the axis service
+     * @return the corresponding JMS destination name
+     */
+    private static String extractJMSDestinationName(String serviceName) {
+    	String destinationPrefix = "dynamicQueues/";
+        int index = serviceName.indexOf(destinationPrefix);
+        if (index == -1) {
+        	destinationPrefix = "dynamicTopics/";
+        	index = serviceName.indexOf(destinationPrefix);
+        }
+        if (index != -1) {
+            return serviceName.substring(index);
+        }
+    	
+		return null;
+	}
+
+	public static AxisService createService(AxisConfiguration axisConfig, QName serviceQName, String port,
                                             String axisName, Definition wsdlDef, MessageReceiver receiver) throws AxisFault {
 
         WSDL11ToAxisServiceBuilder serviceBuilder = new WSDL11ToAxisServiceBuilder(wsdlDef, serviceQName, port);
@@ -144,7 +168,7 @@
         return axisService;
     }
 
-    private static String extractServiceName(Definition wsdlDefinition, QName wsdlServiceName, String portName)
+    public static String extractServiceName(Definition wsdlDefinition, QName wsdlServiceName, String portName, String baseUri)
             throws AxisFault {
         String url = null;
         Service service = wsdlDefinition.getService(wsdlServiceName);
@@ -164,7 +188,7 @@
             throw new OdeFault("Could not extract any soap:address from service WSDL definition " + wsdlServiceName
                     + " (necessary to establish the process target address)!");
         }
-        String serviceName = parseURLForService(url);
+        String serviceName = parseURLForService(url, baseUri);
         if (serviceName == null) {
             throw new OdeFault("The soap:address used for service WSDL definition " + wsdlServiceName + " and port "
                     + portName + " should be of the form http://hostname:port/ode/processes/myProcessEndpointName");
@@ -176,12 +200,18 @@
      * Obtain the service name from the request URL. The request URL is expected to use the path "/processes/" under
      * which all processes and their services are listed. Returns null if the path does not contain this part.
      */
-    protected static String parseURLForService(String path) {
-        int index = path.indexOf("/processes/");
+    protected static String parseURLForService(String path, String baseUri) {
+    	// Assume that path is HTTP-based, by default
+    	String servicePrefix = "/processes/";
+    	// Don't assume JMS-based paths start the same way 
+    	if (path.startsWith("jms")) {
+    		servicePrefix = "jms:/";
+    	}
+        int index = path.indexOf(servicePrefix);
         if (-1 != index) {
             String service;
 
-            int serviceStart = index + "/processes/".length();
+            int serviceStart = index + servicePrefix.length();
             if (path.length() > serviceStart + 1) {
                 service = path.substring(serviceStart);
                 // Path may contain query string, not interesting for us.
@@ -189,6 +219,10 @@
                 if (queryIndex > 0) {
                     service = service.substring(0, queryIndex);
                 }
+                // Qualify shared JMS names with unique baseUri
+                if (path.startsWith("jms")) {
+                	service = baseUri + "/" + service;
+                }
                 return service;
             }
         }
@@ -241,4 +275,35 @@
         }
     }
 
+    /*
+     * Generates a URI of the following form:
+     *     ${deploy_bundleNcName}/${diagram_relativeURL}/${process_relativeURL}
+     * When a service name (local part only) is qualified (prefixed) with the above,
+     * it results in a unique identifier that may be used as that service's name.  
+     */
+	public static String deriveBaseServiceUri(ProcessConf pconf) {
+		if (pconf != null) {
+			StringBuffer baseServiceUri = new StringBuffer();
+			String bundleName = pconf.getPackage();
+			if (bundleName != null) {
+				baseServiceUri.append(bundleName).append("/");
+				if (pconf.getBpelDocument() != null) {
+					String diagramName = pconf.getBpelDocument();
+					if (diagramName.indexOf(".") > 0) {
+						diagramName = diagramName.substring(0, diagramName.indexOf(".") - 1);
+					}
+					baseServiceUri.append(diagramName).append("/");
+					String processName = pconf.getType() != null 
+						? pconf.getType().getLocalPart() : null;
+					if (processName != null) {
+						baseServiceUri.append(processName);
+						return baseServiceUri.toString();
+					}
+				}
+			}
+			
+		}
+		return null;
+	}
+
 }