Author: mriou
Date: Tue Jul 11 17:25:34 2006
New Revision: 421052

URL: http://svn.apache.org/viewvc?rev=421052&view=rev
Log:
Implemented support of message-style web services in Axis2 provider. A bit more 
testing is necessary but the "essence" is here.

Added:
    
incubator/ode/scratch/pxe-iapi/axis/src/main/java/com/fs/pxe/axis/ExternalService.java
Modified:
    
incubator/ode/scratch/pxe-iapi/axis/src/main/java/com/fs/pxe/axis/AxisInvoker.java
    
incubator/ode/scratch/pxe-iapi/axis/src/main/java/com/fs/pxe/axis/DeploymentUnit.java
    
incubator/ode/scratch/pxe-iapi/axis/src/main/java/com/fs/pxe/axis/DocumentRegistry.java
    
incubator/ode/scratch/pxe-iapi/axis/src/main/java/com/fs/pxe/axis/MessageExchangeContextImpl.java
    
incubator/ode/scratch/pxe-iapi/axis/src/main/java/com/fs/pxe/axis/Messages.java
    
incubator/ode/scratch/pxe-iapi/axis/src/main/java/com/fs/pxe/axis/PXEServer.java
    
incubator/ode/scratch/pxe-iapi/axis/src/main/java/com/fs/pxe/axis/PXEService.java
    
incubator/ode/scratch/pxe-iapi/axis/src/main/java/com/fs/pxe/axis/SOAPUtils.java
    
incubator/ode/scratch/pxe-iapi/axis/src/main/java/com/fs/pxe/axis/hooks/PXEMessageReceiver.java
    
incubator/ode/scratch/pxe-iapi/bpel-api/src/main/java/com/fs/pxe/bpel/epr/WSDL11Endpoint.java
    
incubator/ode/scratch/pxe-iapi/bpel-runtime/src/main/java/com/fs/pxe/bpel/engine/BpelProcess.java
    
incubator/ode/scratch/pxe-iapi/bpel-runtime/src/main/java/com/fs/pxe/bpel/engine/BpelRuntimeContextImpl.java
    
incubator/ode/scratch/pxe-iapi/bpel-runtime/src/main/java/com/fs/pxe/bpel/runtime/PropertyAliasEvaluationContext.java

Modified: 
incubator/ode/scratch/pxe-iapi/axis/src/main/java/com/fs/pxe/axis/AxisInvoker.java
URL: 
http://svn.apache.org/viewvc/incubator/ode/scratch/pxe-iapi/axis/src/main/java/com/fs/pxe/axis/AxisInvoker.java?rev=421052&r1=421051&r2=421052&view=diff
==============================================================================
--- 
incubator/ode/scratch/pxe-iapi/axis/src/main/java/com/fs/pxe/axis/AxisInvoker.java
 (original)
+++ 
incubator/ode/scratch/pxe-iapi/axis/src/main/java/com/fs/pxe/axis/AxisInvoker.java
 Tue Jul 11 17:25:34 2006
@@ -40,6 +40,7 @@
             
com.fs.pxe.bpel.iapi.MessageExchange.MessageExchangePattern.REQUEST_RESPONSE;
     try {
       Document doc = DOMUtils.newDocument();
+      // TODO handle message style
       Element op = doc.createElement(pxeMex.getOperationName());
       
op.appendChild(doc.importNode(DOMUtils.getFirstChildElement(pxeMex.getRequest().getMessage()),
 true));
 

Modified: 
incubator/ode/scratch/pxe-iapi/axis/src/main/java/com/fs/pxe/axis/DeploymentUnit.java
URL: 
http://svn.apache.org/viewvc/incubator/ode/scratch/pxe-iapi/axis/src/main/java/com/fs/pxe/axis/DeploymentUnit.java?rev=421052&r1=421051&r2=421052&view=diff
==============================================================================
--- 
incubator/ode/scratch/pxe-iapi/axis/src/main/java/com/fs/pxe/axis/DeploymentUnit.java
 (original)
+++ 
incubator/ode/scratch/pxe-iapi/axis/src/main/java/com/fs/pxe/axis/DeploymentUnit.java
 Tue Jul 11 17:25:34 2006
@@ -3,6 +3,7 @@
 import com.fs.pxe.axis.dd.DeployDocument;
 import com.fs.pxe.axis.dd.TDeployment;
 import com.fs.pxe.axis.dd.TProvide;
+import com.fs.pxe.axis.dd.TInvoke;
 import com.fs.pxe.bom.wsdl.Definition4BPEL;
 import com.fs.pxe.bom.wsdl.WSDLFactory4BPEL;
 import com.fs.pxe.bom.wsdl.WSDLFactoryBPEL20;
@@ -96,6 +97,11 @@
                   provide.getService().getName().getNamespaceURI());
           _pxeServer.createService(def, provide.getService().getName(), 
provide.getService().getPort());
         }
+        for (TInvoke invoke : processDD.getInvokeList()) {
+          Definition4BPEL def = _docRegistry.getDefinition(
+                  invoke.getService().getName().getNamespaceURI());
+          _pxeServer.createExternalService(def, invoke.getService().getName(), 
invoke.getService().getPort());
+        }
       } catch (AxisFault axisFault) {
         throw new DeploymentException("Service deployment in Axis2 failed!", 
axisFault);
       } catch (IOException e) {
@@ -117,7 +123,6 @@
       _pxeServer.getBpelServer().undeploy(processDD.getName());
     }
   }
-
 
   /**
    * Load the parsed and compiled BPEL process definition.

Modified: 
incubator/ode/scratch/pxe-iapi/axis/src/main/java/com/fs/pxe/axis/DocumentRegistry.java
URL: 
http://svn.apache.org/viewvc/incubator/ode/scratch/pxe-iapi/axis/src/main/java/com/fs/pxe/axis/DocumentRegistry.java?rev=421052&r1=421051&r2=421052&view=diff
==============================================================================
--- 
incubator/ode/scratch/pxe-iapi/axis/src/main/java/com/fs/pxe/axis/DocumentRegistry.java
 (original)
+++ 
incubator/ode/scratch/pxe-iapi/axis/src/main/java/com/fs/pxe/axis/DocumentRegistry.java
 Tue Jul 11 17:25:34 2006
@@ -138,7 +138,7 @@
         // If there are several imports in the same WSDL all importing the 
same namespace
         // that is a sure sign of programmer error.
         if (imported.contains(im.getNamespaceURI())) {
-          throw new 
DeploymentException(__msgs.errDuplicateWSDLImport(im.getNamespaceURI(), 
im.getLocationURI()));
+          throw new 
DeploymentException(__msgs.msgDuplicateWSDLImport(im.getNamespaceURI(), 
im.getLocationURI()));
 
         }
 
@@ -150,7 +150,7 @@
         // error.
         if (importDef == null) {
           throw new DeploymentException(
-                  __msgs.errWsdlImportNotFound(im.getNamespaceURI(), 
im.getLocationURI()));
+                  __msgs.msgWsdlImportNotFound(im.getNamespaceURI(), 
im.getLocationURI()));
         }
 
         imported.add(im.getNamespaceURI());

Added: 
incubator/ode/scratch/pxe-iapi/axis/src/main/java/com/fs/pxe/axis/ExternalService.java
URL: 
http://svn.apache.org/viewvc/incubator/ode/scratch/pxe-iapi/axis/src/main/java/com/fs/pxe/axis/ExternalService.java?rev=421052&view=auto
==============================================================================
--- 
incubator/ode/scratch/pxe-iapi/axis/src/main/java/com/fs/pxe/axis/ExternalService.java
 (added)
+++ 
incubator/ode/scratch/pxe-iapi/axis/src/main/java/com/fs/pxe/axis/ExternalService.java
 Tue Jul 11 17:25:34 2006
@@ -0,0 +1,98 @@
+package com.fs.pxe.axis;
+
+import com.fs.pxe.bpel.iapi.PartnerRoleMessageExchange;
+import com.fs.pxe.bpel.iapi.MessageExchange;
+import com.fs.pxe.bpel.iapi.Message;
+import com.fs.pxe.bpel.epr.MutableEndpoint;
+import com.fs.utils.DOMUtils;
+
+import javax.wsdl.Definition;
+import javax.xml.namespace.QName;
+
+import org.w3c.dom.Element;
+import org.apache.axiom.om.OMElement;
+import org.apache.axis2.client.Options;
+import org.apache.axis2.client.ServiceClient;
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.axis2.AxisFault;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.util.concurrent.Future;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutorService;
+
+/**
+ * Acts as a service not provided by PXE. Used mainly for invocation as a way 
to
+ * maintain the WSDL decription of used services.
+ */
+public class ExternalService {
+
+  private static final Log __log = LogFactory.getLog(ExternalService.class);
+
+  private ExecutorService _executorService;
+
+  private Definition _definition;
+  private QName _serviceName;
+  private String _portName;
+
+  public ExternalService(Definition definition, QName serviceName,
+                         String portName, ExecutorService executorService) {
+    _definition = definition;
+    _serviceName = serviceName;
+    _portName = portName;
+    _executorService = executorService;
+  }
+
+  public void invoke(final PartnerRoleMessageExchange pxeMex) {
+    boolean isTwoWay = pxeMex.getMessageExchangePattern() ==
+            
com.fs.pxe.bpel.iapi.MessageExchange.MessageExchangePattern.REQUEST_RESPONSE;
+    try {
+      Element msgContent = SOAPUtils.wrap(pxeMex.getRequest().getMessage(), 
_definition, _serviceName,
+              pxeMex.getOperation(), 
pxeMex.getOperation().getInput().getMessage());
+
+      final OMElement payload = OMUtils.toOM(msgContent);
+
+      Options options = new Options();
+      EndpointReference axisEPR = new 
EndpointReference(((MutableEndpoint)pxeMex.getEndpointReference()).getUrl());
+      __log.debug("Axis2 sending message to " + axisEPR.getAddress() + " using 
MEX " + pxeMex);
+      __log.debug("Message: " + payload);
+      options.setTo(axisEPR);
+
+      final ServiceClient serviceClient = new ServiceClient();
+      serviceClient.setOptions(options);
+
+      if (isTwoWay) {
+        // Invoking in a separate thread even though we're supposed to wait 
for a synchronous reply
+        // to force clear transaction separation.
+        Future<OMElement> freply = _executorService.submit(new 
Callable<OMElement>() {
+          public OMElement call() throws Exception {
+            return serviceClient.sendReceive(payload);
+          }
+        });
+        OMElement reply = null;
+        try {
+          reply = freply.get();
+        } catch (Exception e) {
+          __log.error("We've been interrupted while waiting for reply to MEX " 
+ pxeMex + "!!!");
+          String errmsg = "Error sending message to Axis2 for PXE mex " + 
pxeMex;
+          __log.error(errmsg, e);
+          
pxeMex.replyWithFailure(MessageExchange.FailureType.COMMUNICATION_ERROR, 
errmsg, null);
+        }
+
+        final Message response = 
pxeMex.createMessage(pxeMex.getOperation().getOutput().getMessage().getQName());
+        Element responseElmt = OMUtils.toDOM(reply);
+        __log.debug("Received synchronous response for MEX " + pxeMex);
+        __log.debug("Message: " + DOMUtils.domToString(responseElmt));
+        response.setMessage(OMUtils.toDOM(reply));
+        pxeMex.reply(response);
+      } else
+        serviceClient.sendRobust(payload);
+    } catch (AxisFault axisFault) {
+      String errmsg = "Error sending message to Axis2 for PXE mex " + pxeMex;
+      __log.error(errmsg, axisFault);
+      pxeMex.replyWithFailure(MessageExchange.FailureType.COMMUNICATION_ERROR, 
errmsg, null);
+    }
+
+  }
+}

Modified: 
incubator/ode/scratch/pxe-iapi/axis/src/main/java/com/fs/pxe/axis/MessageExchangeContextImpl.java
URL: 
http://svn.apache.org/viewvc/incubator/ode/scratch/pxe-iapi/axis/src/main/java/com/fs/pxe/axis/MessageExchangeContextImpl.java?rev=421052&r1=421051&r2=421052&view=diff
==============================================================================
--- 
incubator/ode/scratch/pxe-iapi/axis/src/main/java/com/fs/pxe/axis/MessageExchangeContextImpl.java
 (original)
+++ 
incubator/ode/scratch/pxe-iapi/axis/src/main/java/com/fs/pxe/axis/MessageExchangeContextImpl.java
 Tue Jul 11 17:25:34 2006
@@ -5,9 +5,15 @@
 import com.fs.pxe.bpel.iapi.MessageExchangeContext;
 import com.fs.pxe.bpel.iapi.MyRoleMessageExchange;
 import com.fs.pxe.bpel.iapi.PartnerRoleMessageExchange;
+import com.fs.pxe.bpel.iapi.EndpointReference;
+import com.fs.pxe.bpel.epr.WSDL11Endpoint;
+import com.fs.pxe.bpel.epr.EndpointFactory;
+import com.fs.utils.Namespaces;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
+import javax.xml.namespace.QName;
+
 /**
  * Implementation of the PXE [EMAIL PROTECTED] 
com.fs.pxe.bpel.iapi.MessageExchangeContext}
  * interface. This class is used by the PXE engine to make invocation of 
external
@@ -28,7 +34,14 @@
   public void invokePartner(PartnerRoleMessageExchange 
partnerRoleMessageExchange) throws ContextException {
     if (__log.isDebugEnabled())
       __log.debug("Invoking a partner operation: " + 
partnerRoleMessageExchange.getOperationName());
-    _invoker.invokePartner(partnerRoleMessageExchange);
+
+    EndpointReference epr = partnerRoleMessageExchange.getEndpointReference();
+    // We only invoke with WSDL 1.1 service elements, that makes our life 
easier
+    if (!(epr instanceof WSDL11Endpoint))
+      epr = EndpointFactory.convert(new QName(Namespaces.WSDL_11, "service"), 
epr.toXML().getDocumentElement());
+    // It's now safe to cast
+    ExternalService service = 
_server.getExternalService(((WSDL11Endpoint)epr).getServiceName());
+    service.invoke(partnerRoleMessageExchange);
   }
 
   public void onAsyncReply(MyRoleMessageExchange myRoleMessageExchange) throws 
BpelEngineException {

Modified: 
incubator/ode/scratch/pxe-iapi/axis/src/main/java/com/fs/pxe/axis/Messages.java
URL: 
http://svn.apache.org/viewvc/incubator/ode/scratch/pxe-iapi/axis/src/main/java/com/fs/pxe/axis/Messages.java?rev=421052&r1=421051&r2=421052&view=diff
==============================================================================
--- 
incubator/ode/scratch/pxe-iapi/axis/src/main/java/com/fs/pxe/axis/Messages.java 
(original)
+++ 
incubator/ode/scratch/pxe-iapi/axis/src/main/java/com/fs/pxe/axis/Messages.java 
Tue Jul 11 17:25:34 2006
@@ -8,14 +8,12 @@
 public class Messages extends MessageBundle {
 
   public String msgPxeInstallErrorCfgNotFound(File configFile) {
-    return format("Error installing PXE component: config file {0} not found!",
-        configFile);
+    return format("Error installing PXE component: config file {0} not 
found!", configFile);
   }
 
   public String msgPxeInstallErrorCfgReadError(File configFile) {
     return format(
-        "Error installing PXE component: config file {0} could not be read!",
-        configFile);
+        "Error installing PXE component: config file {0} could not be read!", 
configFile);
   }
 
   public String msgPxeInstalled(String dir) {
@@ -31,14 +29,12 @@
   }
 
   public String msgPxeInitExternalDbFailed(String dbDataSource) {
-    return format("Failed to resolved external DataSource at \"{0}\".",
-        dbDataSource);
+    return format("Failed to resolved external DataSource at \"{0}\".", 
dbDataSource);
   }
 
   public String msgPxeInitHibernateErrorReadingHibernateProperties(
       File hibernatePropFile) {
-    return format("Error reading Hibernate properties file \"{0}\".",
-        hibernatePropFile);
+    return format("Error reading Hibernate properties file \"{0}\".", 
hibernatePropFile);
   }
 
   public String msgPxeStarting() {
@@ -76,8 +72,7 @@
   }
 
   public String msgPxeProcessUndeploymentFailed(QName pid) {
-    return format(
-        "Error undeploying process \"{0}\".",pid);
+    return format("Error undeploying process \"{0}\".",pid);
   }
 
   public String msgServiceUnitDeployFailed(String serviceUnitID) {
@@ -85,17 +80,14 @@
   }
 
   public String msgServiceUnitInitFailed(String serviceUnitID) {
-
     return format("Error initializing service unit \"{0}\".", serviceUnitID);
   }
 
   public String msgServiceUnitStartFailed(String serviceUnitID) {
-
     return format("Error starting service unit \"{0}\".", serviceUnitID);
   }
 
   public String msgServiceUnitStopFailed(String serviceUnitID) {
-
     return format("Error stopping service unit \"{0}\".", serviceUnitID);
   }
 
@@ -103,23 +95,31 @@
     return format("Error shutting down service unit \"{0}\".", serviceUnitID);
   }
 
+  /** Port {0} is missing <wsdl:binding> or <soapbind:binding> */
+  public String msgNoBindingForService(QName sericeName) {
+    return format("Couldn't find any port in service {0} having <wsdl:binding> 
and <soapbind:binding>", sericeName);
+  }
+
+  /** Port {0} has multiple <soapbind:binding> elements! */
+  public String msgMultipleSoapBindingsForPort(String portName) {
+    return format("Port {0} has multiple <soapbind:binding> elements!", 
portName);
+  }
+
   /**
    * Attempted to import WSDL for namespace {0} from multiple locations:
    * definitions from {1} will be ignored!
    */
-  public String errDuplicateWSDLImport(String tns, String location) {
+  public String msgDuplicateWSDLImport(String tns, String location) {
     return format("Attempted to import WSDL for namespace {0} from"
         + " multiple locations: definitions from {1} will be ignored!", tns, 
location);
   }
 
   /** The WSDL for namespace "{0}" could not be found in "{1}". */
-  public String errWsdlImportNotFound(String wsdlUri, String location) {
+  public String msgWsdlImportNotFound(String wsdlUri, String location) {
     return format("The WSDL for namespace \"{0}\" could not be found in 
\"{1}\".", wsdlUri, location);
   }
 
-  /**
-   * Error in schema processing: {0}
-   */
+  /** Error in schema processing: {0} **/
   public String errSchemaError(String detailMessage) {
     return format("Error in schema processing: {0}", detailMessage);
   }

Modified: 
incubator/ode/scratch/pxe-iapi/axis/src/main/java/com/fs/pxe/axis/PXEServer.java
URL: 
http://svn.apache.org/viewvc/incubator/ode/scratch/pxe-iapi/axis/src/main/java/com/fs/pxe/axis/PXEServer.java?rev=421052&r1=421051&r2=421052&view=diff
==============================================================================
--- 
incubator/ode/scratch/pxe-iapi/axis/src/main/java/com/fs/pxe/axis/PXEServer.java
 (original)
+++ 
incubator/ode/scratch/pxe-iapi/axis/src/main/java/com/fs/pxe/axis/PXEServer.java
 Tue Jul 11 17:25:34 2006
@@ -68,6 +68,7 @@
   private DeploymentPoller _poller;
 
   private HashMap<QName,PXEService> _services = new 
HashMap<QName,PXEService>();
+  private HashMap<QName,ExternalService> _externalServices = new 
HashMap<QName,ExternalService>();
 
   public void init(ServletConfig config, AxisConfiguration axisConf)  throws 
ServletException {
     _axisConfig = axisConf;
@@ -153,11 +154,13 @@
       if (_axisConfig.getService(serviceName.getLocalPart()) != null) return;
     } catch (AxisFault axisFault) {
       // For some reason Axis throws an exception if we're requesting an 
inactive service
+      return;
     }
     try {
       AxisService axisService = PXEAxisService.createService(_axisConfig,
               def, serviceName, portName);
-      PXEService pxeService = new PXEService(axisService, _server, 
_jotm.getTransactionManager());
+      PXEService pxeService = new PXEService(axisService, def, serviceName,
+              _server, _jotm.getTransactionManager());
       _services.put(serviceName, pxeService);
 
       // Setting our new service on the receiver, the same receiver handles all
@@ -174,6 +177,13 @@
     }
   }
 
+  public void createExternalService(Definition4BPEL def, QName serviceName, 
String portName) {
+    if (_externalServices.get(serviceName) != null) return;
+
+    ExternalService extService = new ExternalService(def, serviceName, 
portName, _executorService);
+    _externalServices.put(serviceName, extService);
+  }
+
   public void destroyService(QName serviceName) {
     try {
       _axisConfig.removeService(serviceName.getLocalPart());
@@ -186,6 +196,10 @@
 
   public PXEService getService(QName serviceName) {
     return _services.get(serviceName);
+  }
+
+  public ExternalService getExternalService(QName serviceName) {
+    return _externalServices.get(serviceName);
   }
 
   public AxisInvoker createInvoker() {

Modified: 
incubator/ode/scratch/pxe-iapi/axis/src/main/java/com/fs/pxe/axis/PXEService.java
URL: 
http://svn.apache.org/viewvc/incubator/ode/scratch/pxe-iapi/axis/src/main/java/com/fs/pxe/axis/PXEService.java?rev=421052&r1=421051&r2=421052&view=diff
==============================================================================
--- 
incubator/ode/scratch/pxe-iapi/axis/src/main/java/com/fs/pxe/axis/PXEService.java
 (original)
+++ 
incubator/ode/scratch/pxe-iapi/axis/src/main/java/com/fs/pxe/axis/PXEService.java
 Tue Jul 11 17:25:34 2006
@@ -4,6 +4,7 @@
 import com.fs.pxe.bpel.iapi.Message;
 import com.fs.pxe.bpel.iapi.MyRoleMessageExchange;
 import com.fs.pxe.bpel.iapi.MessageExchange;
+import com.fs.pxe.bom.wsdl.Definition4BPEL;
 import com.fs.utils.DOMUtils;
 import org.apache.axiom.om.OMElement;
 import org.apache.axiom.soap.SOAPEnvelope;
@@ -19,6 +20,7 @@
 
 import javax.transaction.TransactionManager;
 import javax.wsdl.Part;
+import javax.wsdl.Definition;
 import javax.xml.namespace.QName;
 import java.util.Collections;
 import java.util.HashMap;
@@ -37,12 +39,17 @@
   private AxisService _axisService;
   private BpelServerImpl _server;
   private TransactionManager _txManager;
+  private Definition _wsdlDef;
+  private QName _serviceName;
   private Map<String,ResponseCallback> _waitingCallbacks;
 
-  public PXEService(AxisService axisService, BpelServerImpl server, 
TransactionManager txManager) {
+  public PXEService(AxisService axisService, Definition4BPEL def, QName 
serviceName,
+                    BpelServerImpl server, TransactionManager txManager) {
     _axisService = axisService;
     _server = server;
     _txManager = txManager;
+    _wsdlDef = def;
+    _serviceName = serviceName;
     _waitingCallbacks = Collections.synchronizedMap(new HashMap<String, 
ResponseCallback>());
   }
 
@@ -55,13 +62,14 @@
 
       pxeMex = _server.getEngine().createMessageExchange(
               msgContext.getMessageID(),
-              new QName(msgContext.getAxisService().getTargetNamespace(), 
msgContext.getAxisService().getName()),
-              null,
+              new QName(msgContext.getAxisService().getTargetNamespace(),
+              msgContext.getAxisService().getName()), null,
               msgContext.getAxisOperation().getName().getLocalPart());
       if (pxeMex.getOperation() != null) {
-        javax.wsdl.Message msgdef = 
pxeMex.getOperation().getInput().getMessage();
         Message pxeRequest = 
pxeMex.createMessage(pxeMex.getOperation().getInput().getMessage().getQName());
-        convertMessage(msgdef, pxeRequest, 
msgContext.getEnvelope().getBody().getFirstElement());
+        Element msgContent = 
SOAPUtils.unwrap(OMUtils.toDOM(msgContext.getEnvelope().getBody().getFirstElement()),
+                _wsdlDef, pxeMex.getOperation().getInput().getMessage(), 
_serviceName);
+        pxeRequest.setMessage(msgContent);
 
         // Preparing a callback just in case we would need one.
         ResponseCallback callback = null;
@@ -70,8 +78,10 @@
           _waitingCallbacks.put(pxeMex.getMessageExchangeId(), callback);
         }
 
-        if (__log.isDebugEnabled())
+        if (__log.isDebugEnabled()) {
           __log.debug("Invoking PXE using MEX " + pxeMex);
+          __log.debug("Message content:  " + 
DOMUtils.domToString(pxeRequest.getMessage()));
+        }
         pxeMex.invoke(pxeRequest);
 
         boolean timeout = false;
@@ -135,7 +145,9 @@
       case FAULT:
         throw new AxisFault(null, mex.getFault(), null, null, 
OMUtils.toOM(mex.getFaultResponse().getMessage()));
       case RESPONSE:
-        fillEnvelope(mex, envelope);
+        Element response = SOAPUtils.wrap(mex.getResponse().getMessage(), 
_wsdlDef, _serviceName,
+                mex.getOperation(), 
mex.getOperation().getOutput().getMessage());
+        envelope.getBody().addChild(OMUtils.toOM(response));
         break;
       case FAILURE:
         // TODO: get failure codes out of the message.
@@ -145,6 +157,7 @@
     }
   }
 
+  // TODO Handle messages style
   private void convertMessage(javax.wsdl.Message msgdef, Message dest, 
OMElement body) throws AxisFault {
     Element srcel = OMUtils.toDOM(body);
 

Modified: 
incubator/ode/scratch/pxe-iapi/axis/src/main/java/com/fs/pxe/axis/SOAPUtils.java
URL: 
http://svn.apache.org/viewvc/incubator/ode/scratch/pxe-iapi/axis/src/main/java/com/fs/pxe/axis/SOAPUtils.java?rev=421052&r1=421051&r2=421052&view=diff
==============================================================================
--- 
incubator/ode/scratch/pxe-iapi/axis/src/main/java/com/fs/pxe/axis/SOAPUtils.java
 (original)
+++ 
incubator/ode/scratch/pxe-iapi/axis/src/main/java/com/fs/pxe/axis/SOAPUtils.java
 Tue Jul 11 17:25:34 2006
@@ -1,13 +1,26 @@
 package com.fs.pxe.axis;
 
 import com.fs.utils.stl.CollectionsX;
+import com.fs.utils.DOMUtils;
 
 import javax.wsdl.Binding;
 import javax.wsdl.Port;
+import javax.wsdl.Definition;
+import javax.wsdl.Service;
+import javax.wsdl.Part;
+import javax.wsdl.Operation;
+import javax.wsdl.Message;
 import javax.wsdl.extensions.soap.SOAPBinding;
+import javax.xml.namespace.QName;
 import java.util.Collection;
+import java.util.List;
 
+import org.apache.axis2.AxisFault;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.w3c.dom.Element;
+import org.w3c.dom.Document;
+import org.w3c.dom.NodeList;
 
 /**
  * Utility class to handle SOAP messages wrapping/unwrapping depending
@@ -15,36 +28,93 @@
  */
 public class SOAPUtils {
 
-//  public void wrap(Element msg, Port port) {
-//
-//  }
-//
-//  private boolean isRPC(Port wsdlPort) {
-//    if (wsdlPort == null)
-//      throw new NullPointerException("null wsdlPort");
-//
-//    Binding binding = wsdlPort.getBinding();
-//
-//    if (binding == null)
-//      throw new SoapBindingException(wsdlPort + " is missing <wsdl:binding>",
-//              "port", wsdlPort.getName(),
-//              __msgs.msgNoBindingForPort());
-//
-//    Collection soapBindings = 
CollectionsX.filter(binding.getExtensibilityElements(), SOAPBinding.class);
-//    if (soapBindings.isEmpty()) {
-//      throw new SoapBindingException(wsdlPort + " is missing 
<soapbind:binding>",
-//              "port", wsdlPort.getName(),
-//              __msgs.msgNoSoapBindingForPort());
-//    }
-//
-//    else if (soapBindings.size() > 1) {
-//      throw new SoapBindingException(wsdlPort + " has multiple 
<soapbind:binding> elements!",
-//              "port", wsdlPort.getName(),
-//              __msgs.msgMultipleSoapBindingsForPort());
-//    }
-//
-//    SOAPBinding soapBinding = (SOAPBinding) soapBindings.iterator().next();
-//    String style  = soapBinding.getStyle();
-//    return style != null && style.equals("rpc");
-//  }
+  private static final Messages __msgs = Messages.getMessages(Messages.class);
+
+  private static final Log __log = LogFactory.getLog(SOAPUtils.class);
+
+  public static Element wrap(Element message, Definition def, QName 
serviceName, Operation op, Message msgDef) throws AxisFault {
+    Service serviceDef = def.getService(serviceName);
+    boolean isRPC = isRPC(serviceDef);
+    Document doc = DOMUtils.newDocument();
+    if (isRPC) {
+      Element responseRoot = doc.createElementNS(null, op.getName());
+      doc.appendChild(responseRoot);
+
+      Element srcPartEl = DOMUtils.getFirstChildElement(message);
+      while (srcPartEl != null) {
+        responseRoot.appendChild(doc.importNode(srcPartEl, true));
+        srcPartEl = DOMUtils.getNextSiblingElement(srcPartEl);
+      }
+    } else {
+      // Extracting element name: parts can't be a type as per WS-BP
+      QName elmtName = ((Part)msgDef.getParts().get(0)).getElementName();
+      Element responseRoot = doc.createElementNS(elmtName.getNamespaceURI(), 
elmtName.getLocalPart());
+      // Message style has only one part, directly included in the body.
+      doc.appendChild(responseRoot);
+    }
+    return doc.getDocumentElement();
+  }
+
+  public static Element unwrap(Element bodyElmt, Definition def, Message 
msgDef, QName serviceName) throws AxisFault {
+    Service serviceDef = def.getService(serviceName);
+    boolean isRPC = isRPC(serviceDef);
+    if (isRPC) {
+      // In RPC the body element is the operation name, wrapping parts. Just 
checking
+      // the parts are alright.
+      Document doc = DOMUtils.newDocument();
+      Element msgElmt = doc.createElement("message");
+      doc.appendChild(msgElmt);
+      copyParts(bodyElmt, msgElmt, msgDef);
+      return msgElmt;
+    } else {
+      // In document style the body element is the unique part. Wrapping is 
necessary.
+      Document doc = DOMUtils.newDocument();
+      Element msgElmt = doc.createElement("message");
+      doc.appendChild(msgElmt);
+      // Just making sure the part has no namespace
+      Element destPart = doc.createElement(bodyElmt.getLocalName());
+      msgElmt.appendChild(destPart);
+      
destPart.appendChild(doc.importNode(DOMUtils.getFirstChildElement(bodyElmt), 
true));
+      return msgElmt;
+    }
+  }
+
+  private static void copyParts(Element source, Element target, 
javax.wsdl.Message msgdef) {
+    List<Part> expectedParts = msgdef.getOrderedParts(null);
+
+    Element srcpart = DOMUtils.getFirstChildElement(source);
+    for (Part pdef : expectedParts) {
+      Element p = target.getOwnerDocument().createElement(pdef.getName());
+      target.appendChild(p);
+      if (srcpart != null) {
+        NodeList nl = srcpart.getChildNodes();
+        for (int j = 0; j < nl.getLength(); ++j)
+          p.appendChild(target.getOwnerDocument().importNode(nl.item(j), 
true));
+        srcpart = DOMUtils.getNextSiblingElement(srcpart);
+      } else {
+        __log.error("Improperly formatted message, missing part: " + 
pdef.getName());
+      }
+    }
+
+  }
+
+  private static boolean isRPC(Service serviceDef) throws AxisFault {
+    for (Object oport : serviceDef.getPorts().values()) {
+      Port wsdlPort = (Port)oport;
+      Binding binding = wsdlPort.getBinding();
+
+      if (binding == null) continue;
+
+      Collection soapBindings = 
CollectionsX.filter(binding.getExtensibilityElements(), SOAPBinding.class);
+      if (soapBindings.isEmpty()) continue;
+      else if (soapBindings.size() > 1) {
+        throw new 
AxisFault(__msgs.msgMultipleSoapBindingsForPort(wsdlPort.getName()));
+      }
+
+      SOAPBinding soapBinding = (SOAPBinding) soapBindings.iterator().next();
+      String style  = soapBinding.getStyle();
+      return style != null && style.equals("rpc");
+    }
+    throw new AxisFault(__msgs.msgNoBindingForService(serviceDef.getQName()));
+  }
 }

Modified: 
incubator/ode/scratch/pxe-iapi/axis/src/main/java/com/fs/pxe/axis/hooks/PXEMessageReceiver.java
URL: 
http://svn.apache.org/viewvc/incubator/ode/scratch/pxe-iapi/axis/src/main/java/com/fs/pxe/axis/hooks/PXEMessageReceiver.java?rev=421052&r1=421051&r2=421052&view=diff
==============================================================================
--- 
incubator/ode/scratch/pxe-iapi/axis/src/main/java/com/fs/pxe/axis/hooks/PXEMessageReceiver.java
 (original)
+++ 
incubator/ode/scratch/pxe-iapi/axis/src/main/java/com/fs/pxe/axis/hooks/PXEMessageReceiver.java
 Tue Jul 11 17:25:34 2006
@@ -27,7 +27,7 @@
       __log.debug("Received message for " + 
msgContext.getAxisService().getName() +
               "." + msgContext.getAxisOperation().getName());
     if (hasResponse(msgContext.getAxisOperation())) {
-      // Expecting a response, running in the same thread
+      // Client is expecting a response, running in the same thread
       MessageContext outMsgContext = Utils.createOutMessageContext(msgContext);
       outMsgContext.getOperationContext().addMessageContext(outMsgContext);
       invokeBusinessLogic(msgContext, outMsgContext);

Modified: 
incubator/ode/scratch/pxe-iapi/bpel-api/src/main/java/com/fs/pxe/bpel/epr/WSDL11Endpoint.java
URL: 
http://svn.apache.org/viewvc/incubator/ode/scratch/pxe-iapi/bpel-api/src/main/java/com/fs/pxe/bpel/epr/WSDL11Endpoint.java?rev=421052&r1=421051&r2=421052&view=diff
==============================================================================
--- 
incubator/ode/scratch/pxe-iapi/bpel-api/src/main/java/com/fs/pxe/bpel/epr/WSDL11Endpoint.java
 (original)
+++ 
incubator/ode/scratch/pxe-iapi/bpel-api/src/main/java/com/fs/pxe/bpel/epr/WSDL11Endpoint.java
 Tue Jul 11 17:25:34 2006
@@ -26,6 +26,10 @@
     return address.getAttribute("location");
   }
 
+  public QName getServiceName() {
+    return new QName(_serviceElmt.getAttribute("targetNamespace"), 
_serviceElmt.getAttribute("name"));
+  }
+
   public boolean accept(Node node) {
     if (node.getNodeType() == Node.ELEMENT_NODE) {
       Element elmt = (Element) node;
@@ -56,7 +60,7 @@
   public Map toMap() {
     HashMap<String,Object> result = new HashMap<String,Object>(1);
     result.put(ADDRESS, getUrl());
-    result.put(SERVICE_QNAME, new QName(_serviceElmt.getNamespaceURI(), 
_serviceElmt.getAttribute("name")));
+    result.put(SERVICE_QNAME, new 
QName(_serviceElmt.getAttribute("targetNamespace"), 
_serviceElmt.getAttribute("name")));
     Element port = DOMUtils.getFirstChildElement(_serviceElmt);
     result.put(PORT_NAME, port.getAttribute("name"));
     // TODO binding
@@ -72,7 +76,7 @@
     if (eprMap.get(SERVICE_QNAME) != null) {
       QName serviceQName = ((QName) eprMap.get(SERVICE_QNAME));
       _serviceElmt.setAttribute("name", serviceQName.getLocalPart());
-      _serviceElmt.setAttribute("xmlns", serviceQName.getNamespaceURI());
+      _serviceElmt.setAttribute("targetNamespace", 
serviceQName.getNamespaceURI());
     }
     Element port = doc.createElementNS(Namespaces.WSDL_11, "port");
     if (eprMap.get(PORT_NAME) != null) {
@@ -83,8 +87,7 @@
     if (eprMap.get(ADDRESS) != null) address.setAttribute("location", (String) 
eprMap.get(ADDRESS));
 
     _serviceElmt.appendChild(port);
-    _serviceElmt.appendChild(address);
-    doc.appendChild(_serviceElmt);
+    port.appendChild(address);
   }
 
 }

Modified: 
incubator/ode/scratch/pxe-iapi/bpel-runtime/src/main/java/com/fs/pxe/bpel/engine/BpelProcess.java
URL: 
http://svn.apache.org/viewvc/incubator/ode/scratch/pxe-iapi/bpel-runtime/src/main/java/com/fs/pxe/bpel/engine/BpelProcess.java?rev=421052&r1=421051&r2=421052&view=diff
==============================================================================
--- 
incubator/ode/scratch/pxe-iapi/bpel-runtime/src/main/java/com/fs/pxe/bpel/engine/BpelProcess.java
 (original)
+++ 
incubator/ode/scratch/pxe-iapi/bpel-runtime/src/main/java/com/fs/pxe/bpel/engine/BpelProcess.java
 Tue Jul 11 17:25:34 2006
@@ -176,6 +176,9 @@
         msgData, alias);
     Node lValue = ectx.getRootNode();
 
+
+    System.out.println("####### Evaluating property alias " + alias + " on " + 
DOMUtils.domToString(msgData));
+
     if (alias.location != null)
       try {
         lValue = _expLangRuntimeRegistry.evaluateNode(alias.location, ectx);

Modified: 
incubator/ode/scratch/pxe-iapi/bpel-runtime/src/main/java/com/fs/pxe/bpel/engine/BpelRuntimeContextImpl.java
URL: 
http://svn.apache.org/viewvc/incubator/ode/scratch/pxe-iapi/bpel-runtime/src/main/java/com/fs/pxe/bpel/engine/BpelRuntimeContextImpl.java?rev=421052&r1=421051&r2=421052&view=diff
==============================================================================
--- 
incubator/ode/scratch/pxe-iapi/bpel-runtime/src/main/java/com/fs/pxe/bpel/engine/BpelRuntimeContextImpl.java
 (original)
+++ 
incubator/ode/scratch/pxe-iapi/bpel-runtime/src/main/java/com/fs/pxe/bpel/engine/BpelRuntimeContextImpl.java
 Tue Jul 11 17:25:34 2006
@@ -42,6 +42,8 @@
 import com.fs.pxe.bpel.runtime.channels.InvokeResponseChannel;
 import com.fs.pxe.bpel.runtime.channels.PickResponseChannel;
 import com.fs.pxe.bpel.runtime.channels.TimerResponseChannel;
+import com.fs.pxe.bpel.epr.MutableEndpoint;
+import com.fs.pxe.bpel.epr.WSDL11Endpoint;
 import com.fs.utils.DOMUtils;
 import com.fs.utils.ObjectPrinter;
 import com.fs.utils.Namespaces;
@@ -53,6 +55,8 @@
 import java.util.Date;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
+import java.util.HashMap;
 
 import javax.wsdl.Operation;
 import javax.xml.namespace.QName;
@@ -400,23 +404,30 @@
 
   public Element fetchEndpointReferenceData(PartnerLinkInstance pLink,
                                             boolean isMyEPR) throws 
FaultException {
+    PartnerLinkDAO pl = fetchEndpointReference(pLink, isMyEPR);
+    Element epr = (isMyEPR ? pl.getMyEPR() : pl.getPartnerEPR());
+
+    if (epr == null) {
+      throw new FaultException(
+          _bpelProcess._oprocess.constants.qnUninitializedPartnerRole);
+    } else
+      return epr;
+  }
+
+  private PartnerLinkDAO fetchEndpointReference(PartnerLinkInstance pLink,
+                                            boolean isMyEPR) throws 
FaultException {
     ScopeDAO scopeDAO = _dao.getScope(pLink.scopeInstanceId);
     PartnerLinkDAO spl = scopeDAO.getPartnerLink(pLink.partnerLink.getId());
     PartnerLinkDAO ppl = scopeDAO.getProcessInstance().getProcess()
         .getDeployedEndpointReference(pLink.partnerLink.getId());
 
-    Element epr;
+    PartnerLinkDAO rightpl;
     if (isMyEPR)
-      epr = spl.getMyEPR() != null ? spl.getMyEPR() : ppl.getMyEPR();
+      rightpl = spl.getMyEPR() != null ? spl : ppl;
     else
-      epr = spl.getPartnerEPR() != null ? spl.getPartnerEPR() : ppl
-          .getPartnerEPR();
+      rightpl = spl.getPartnerEPR() != null ? spl : ppl;
 
-    if (epr == null) {
-      throw new FaultException(
-          _bpelProcess._oprocess.constants.qnUninitializedPartnerRole);
-    } else
-      return epr;
+    return rightpl;
   }
 
   /**
@@ -460,19 +471,36 @@
 
   public Element writeEndpointReference(PartnerLinkInstance variable,
                                         Element data) throws FaultException {
-    if (__log.isDebugEnabled())
+    fetchEndpointReferenceData(variable, false);
+    PartnerLinkDAO eprDAO = fetchEndpointReference(variable, false);
+    Element originalEprElmt = eprDAO.getPartnerEPR();
+
+    if (__log.isDebugEnabled()) {
       __log.debug("Writing endpoint reference " + 
variable.partnerLink.getName() +
               " with value " + DOMUtils.domToString(data));
-    ScopeDAO scopeDAO = _dao.getScope(variable.scopeInstanceId);
-    PartnerLinkDAO eprDAO = scopeDAO.getPartnerLink(variable.partnerLink
-        .getId());
-    eprDAO.setPartnerEPR(data);
+    }
+
+    // Merging target endpoint with original endpoint and converting 
everything to
+    // a WSDL 1.1 service.
+    Map conversionMap = new HashMap();
+    if (originalEprElmt != null) {
+      MutableEndpoint originalEpr =
+              (MutableEndpoint) 
_bpelProcess._engine._contexts.eprContext.resolveEndpointReference(originalEprElmt);
+      conversionMap = originalEpr.toMap();
+    }
+    MutableEndpoint targetEpr =
+            (MutableEndpoint) 
_bpelProcess._engine._contexts.eprContext.resolveEndpointReference(data);
+    conversionMap.putAll(targetEpr.toMap());
+    WSDL11Endpoint mergedEpr = new WSDL11Endpoint();
+    mergedEpr.fromMap(conversionMap);
+
+    eprDAO.setPartnerEPR(mergedEpr.toXML().getDocumentElement());
     return data;
   }
 
   public String fetchEndpointSessionId(PartnerLinkInstance pLink,
                                        boolean isMyEPR) throws FaultException {
-    Element eprElmt = (Element) fetchEndpointReferenceData(pLink, isMyEPR);
+    Element eprElmt = fetchEndpointReferenceData(pLink, isMyEPR);
     // This is rather ugly as we're assuming that the session identifier is
     // always a direct
     // child of the epr element. However I rather that than adding a specific

Modified: 
incubator/ode/scratch/pxe-iapi/bpel-runtime/src/main/java/com/fs/pxe/bpel/runtime/PropertyAliasEvaluationContext.java
URL: 
http://svn.apache.org/viewvc/incubator/ode/scratch/pxe-iapi/bpel-runtime/src/main/java/com/fs/pxe/bpel/runtime/PropertyAliasEvaluationContext.java?rev=421052&r1=421051&r2=421052&view=diff
==============================================================================
--- 
incubator/ode/scratch/pxe-iapi/bpel-runtime/src/main/java/com/fs/pxe/bpel/runtime/PropertyAliasEvaluationContext.java
 (original)
+++ 
incubator/ode/scratch/pxe-iapi/bpel-runtime/src/main/java/com/fs/pxe/bpel/runtime/PropertyAliasEvaluationContext.java
 Tue Jul 11 17:25:34 2006
@@ -30,9 +30,12 @@
        _root  = msgData;
          } else {
        Element part = DOMUtils.findChildByName(msgData,new QName(null, 
alias.part.name),false);
-       if (part != null && alias.part.type instanceof OElementVarType)
+      System.out.println("Applying alias evaluation on " 
+DOMUtils.domToString(msgData));
+      System.out.println("Check child " + alias.part.name + " => " + part);
+      if (part != null && alias.part.type instanceof OElementVarType) {
                _root = DOMUtils.findChildByName(part, 
((OElementVarType)alias.part.type).elementType);
-       else
+        System.out.println("Check child " + 
((OElementVarType)alias.part.type).elementType + " => " + part);
+      } else
                _root = part;
          }
     


Reply via email to