You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ode.apache.org by bo...@apache.org on 2006/07/19 03:19:59 UTC

svn commit: r423323 - in /incubator/ode/scratch/pxe-iapi/jbi/src/main/java/com/fs/pxe/jbi: ./ msgmap/

Author: boisvert
Date: Tue Jul 18 18:19:58 2006
New Revision: 423323

URL: http://svn.apache.org/viewvc?rev=423323&view=rev
Log:
Revamp JBI integration layer and improve ServiceMix interoperability

Modified:
    incubator/ode/scratch/pxe-iapi/jbi/src/main/java/com/fs/pxe/jbi/EndpointReferenceContextImpl.java
    incubator/ode/scratch/pxe-iapi/jbi/src/main/java/com/fs/pxe/jbi/JbiMessageExchangeEventRouter.java
    incubator/ode/scratch/pxe-iapi/jbi/src/main/java/com/fs/pxe/jbi/MyEndpointReference.java
    incubator/ode/scratch/pxe-iapi/jbi/src/main/java/com/fs/pxe/jbi/PxeBootstrap.java
    incubator/ode/scratch/pxe-iapi/jbi/src/main/java/com/fs/pxe/jbi/PxeConsumer.java
    incubator/ode/scratch/pxe-iapi/jbi/src/main/java/com/fs/pxe/jbi/PxeContext.java
    incubator/ode/scratch/pxe-iapi/jbi/src/main/java/com/fs/pxe/jbi/PxeLifeCycle.java
    incubator/ode/scratch/pxe-iapi/jbi/src/main/java/com/fs/pxe/jbi/PxeService.java
    incubator/ode/scratch/pxe-iapi/jbi/src/main/java/com/fs/pxe/jbi/msgmap/ServiceMixMapper.java

Modified: incubator/ode/scratch/pxe-iapi/jbi/src/main/java/com/fs/pxe/jbi/EndpointReferenceContextImpl.java
URL: http://svn.apache.org/viewvc/incubator/ode/scratch/pxe-iapi/jbi/src/main/java/com/fs/pxe/jbi/EndpointReferenceContextImpl.java?rev=423323&r1=423322&r2=423323&view=diff
==============================================================================
--- incubator/ode/scratch/pxe-iapi/jbi/src/main/java/com/fs/pxe/jbi/EndpointReferenceContextImpl.java (original)
+++ incubator/ode/scratch/pxe-iapi/jbi/src/main/java/com/fs/pxe/jbi/EndpointReferenceContextImpl.java Tue Jul 18 18:19:58 2006
@@ -5,11 +5,7 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.w3c.dom.Document;
-import org.w3c.dom.DocumentFragment;
 import org.w3c.dom.Element;
-import org.w3c.dom.NodeList;
-
 import com.fs.pxe.bpel.iapi.ContextException;
 import com.fs.pxe.bpel.iapi.EndpointReference;
 import com.fs.pxe.bpel.iapi.EndpointReferenceContext;
@@ -32,6 +28,8 @@
   private static final Log __log = LogFactory.getLog(EndpointReferenceContextImpl.class);
 
   private final PxeContext _pxe;
+
+  static final QName JBI_EPR = new QName("http://java.sun.com/jbi/end-point-reference", "end-point-reference");
   
   public EndpointReferenceContextImpl(PxeContext pxe) {
     _pxe = pxe;
@@ -40,7 +38,31 @@
   public EndpointReference resolveEndpointReference(Element epr) {
     QName elname = new QName(epr.getNamespaceURI(),epr.getLocalName());
     
-    // We always expect the EPR to be wrapped in a BPEL service-ref element.
+    if (__log.isDebugEnabled()) {
+      __log.debug( "resolveEndpointReference:\n" + prettyPrint( epr ) );
+    }
+    if (elname.equals(EndpointReference.SERVICE_REF_QNAME)) {
+        epr = DOMUtils.getFirstChildElement(epr);
+        elname = new QName(epr.getNamespaceURI(),epr.getLocalName());
+    }
+    // resolve JBI end-point-references directly
+    if (epr != null && elname.equals(JBI_EPR)) {
+      String serviceName = epr.getAttribute("service-name");
+      QName serviceQName = convertClarkQName( serviceName );
+      String endpointName = epr.getAttribute("end-point-name");
+      ServiceEndpoint se = _pxe.getContext().getEndpoint(serviceQName, endpointName);
+      if (se == null) {
+        __log.warn( "Unable to resolve JBI endpoint reference:\n" + prettyPrint( epr ) );
+        return null;
+      }
+      if (__log.isDebugEnabled()) {
+        __log.debug( "Resolved JBI endpoint reference: " + se );
+      }
+      return new JbiEndpointReference(se);
+    }
+    
+    // Otherwise, we expect the EPR to be wrapped in a BPEL service-ref element.
+    /*
     if (!elname.equals(EndpointReference.SERVICE_REF_QNAME))
       throw new IllegalArgumentException("EPR root element "
           + elname + " should be " + EndpointReference.SERVICE_REF_QNAME);
@@ -54,8 +76,11 @@
     if (se == null)
       return null;
     return new JbiEndpointReference(se);
+    */
+  __log.warn( "Unsupported endpoint reference:\n" + prettyPrint( epr ) );
+    return null;
   }
-
+  
   public EndpointReference activateEndpoint(QName pid, QName serviceId, Element externalEpr) {
     try {
       return _pxe.activateEndpoint(pid,serviceId,externalEpr);
@@ -80,9 +105,30 @@
     }
   }
 
-  public EndpointReference convertEndpoint(QName qName, Element element) {
-    EndpointReference endpoint = EndpointFactory.convert(qName, element);
+  public EndpointReference convertEndpoint(QName eprType, Element element) {
+    EndpointReference endpoint = EndpointFactory.convert(eprType, element);
+ 
+    __log.warn( "ALEX convertEndpoint: " + eprType + " " + prettyPrint( element ) );
+    
     // Forcing JBI lookup
     return resolveEndpointReference(endpoint.toXML().getDocumentElement());
+  }
+  
+  public static QName convertClarkQName(String name) {
+    int pos = name.indexOf('}');
+    if ( name.startsWith("{") && pos > 0 ) {
+      String ns = name.substring(1,pos);
+      String lname = name.substring(pos+1, name.length());
+      return new QName( ns, lname );
+    }
+    return new QName( name );
+  }
+ 
+  private String prettyPrint( Element el ) {
+      try {
+          return DOMUtils.prettyPrint( el );
+      } catch ( java.io.IOException ioe ) {
+          return ioe.getMessage();
+      }
   }
 }

Modified: incubator/ode/scratch/pxe-iapi/jbi/src/main/java/com/fs/pxe/jbi/JbiMessageExchangeEventRouter.java
URL: http://svn.apache.org/viewvc/incubator/ode/scratch/pxe-iapi/jbi/src/main/java/com/fs/pxe/jbi/JbiMessageExchangeEventRouter.java?rev=423323&r1=423322&r2=423323&view=diff
==============================================================================
--- incubator/ode/scratch/pxe-iapi/jbi/src/main/java/com/fs/pxe/jbi/JbiMessageExchangeEventRouter.java (original)
+++ incubator/ode/scratch/pxe-iapi/jbi/src/main/java/com/fs/pxe/jbi/JbiMessageExchangeEventRouter.java Tue Jul 18 18:19:58 2006
@@ -19,7 +19,7 @@
     if (mex.getRole().equals(javax.jbi.messaging.MessageExchange.Role.CONSUMER)) {
       _pxe._consumer.onJbiMessageExchange(mex);
     } else if (mex.getRole().equals(javax.jbi.messaging.MessageExchange.Role.PROVIDER)) {
-      PxeService svc = _pxe.getService(mex.getEndpoint().getServiceName());
+      PxeService svc = _pxe.getServiceByServiceName(mex.getEndpoint().getServiceName());
       if (svc == null)  {
         __log.error("Received message exchange for unknown service: " + mex.getEndpoint().getServiceName());
         return;

Modified: incubator/ode/scratch/pxe-iapi/jbi/src/main/java/com/fs/pxe/jbi/MyEndpointReference.java
URL: http://svn.apache.org/viewvc/incubator/ode/scratch/pxe-iapi/jbi/src/main/java/com/fs/pxe/jbi/MyEndpointReference.java?rev=423323&r1=423322&r2=423323&view=diff
==============================================================================
--- incubator/ode/scratch/pxe-iapi/jbi/src/main/java/com/fs/pxe/jbi/MyEndpointReference.java (original)
+++ incubator/ode/scratch/pxe-iapi/jbi/src/main/java/com/fs/pxe/jbi/MyEndpointReference.java Tue Jul 18 18:19:58 2006
@@ -1,8 +1,6 @@
 package com.fs.pxe.jbi;
 
 import javax.jbi.servicedesc.ServiceEndpoint;
-import javax.xml.namespace.QName;
-
 import org.w3c.dom.Document;
 import org.w3c.dom.DocumentFragment;
 import org.w3c.dom.Element;

Modified: incubator/ode/scratch/pxe-iapi/jbi/src/main/java/com/fs/pxe/jbi/PxeBootstrap.java
URL: http://svn.apache.org/viewvc/incubator/ode/scratch/pxe-iapi/jbi/src/main/java/com/fs/pxe/jbi/PxeBootstrap.java?rev=423323&r1=423322&r2=423323&view=diff
==============================================================================
--- incubator/ode/scratch/pxe-iapi/jbi/src/main/java/com/fs/pxe/jbi/PxeBootstrap.java (original)
+++ incubator/ode/scratch/pxe-iapi/jbi/src/main/java/com/fs/pxe/jbi/PxeBootstrap.java Tue Jul 18 18:19:58 2006
@@ -13,6 +13,7 @@
  */
 public class PxeBootstrap implements Bootstrap {
   
+  @SuppressWarnings("unused")
   private InstallationContext _installContext;
 
 	/**

Modified: incubator/ode/scratch/pxe-iapi/jbi/src/main/java/com/fs/pxe/jbi/PxeConsumer.java
URL: http://svn.apache.org/viewvc/incubator/ode/scratch/pxe-iapi/jbi/src/main/java/com/fs/pxe/jbi/PxeConsumer.java?rev=423323&r1=423322&r2=423323&view=diff
==============================================================================
--- incubator/ode/scratch/pxe-iapi/jbi/src/main/java/com/fs/pxe/jbi/PxeConsumer.java (original)
+++ incubator/ode/scratch/pxe-iapi/jbi/src/main/java/com/fs/pxe/jbi/PxeConsumer.java Tue Jul 18 18:19:58 2006
@@ -19,8 +19,6 @@
 import javax.jbi.messaging.*;
 import javax.jbi.servicedesc.ServiceEndpoint;
 import javax.xml.namespace.QName;
-import javax.xml.transform.dom.DOMSource;
-
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -90,6 +88,7 @@
         mapper.toNMS(nmsg,pxeMex.getRequest(), pxeMex.getOperation().getInput().getMessage());
         inonly.setInMessage(nmsg);
         _pxe.getChannel().send(inonly);
+        pxeMex.replyOneWayOk();
       } else {
         InOut inout = (InOut) jbiMex;
         NormalizedMessage nmsg = inout.createMessage();
@@ -98,6 +97,7 @@
         _pxe.getChannel().send(inout);
         _outstandingExchanges.put(inout.getExchangeId(), pxeMex
             .getMessageExchangeId());
+        pxeMex.replyAsync();
       }
     } catch (MessagingException me) {
       String errmsg = "Error sending message to JBI for PXE mex " + pxeMex;

Modified: incubator/ode/scratch/pxe-iapi/jbi/src/main/java/com/fs/pxe/jbi/PxeContext.java
URL: http://svn.apache.org/viewvc/incubator/ode/scratch/pxe-iapi/jbi/src/main/java/com/fs/pxe/jbi/PxeContext.java?rev=423323&r1=423322&r2=423323&view=diff
==============================================================================
--- incubator/ode/scratch/pxe-iapi/jbi/src/main/java/com/fs/pxe/jbi/PxeContext.java (original)
+++ incubator/ode/scratch/pxe-iapi/jbi/src/main/java/com/fs/pxe/jbi/PxeContext.java Tue Jul 18 18:19:58 2006
@@ -27,12 +27,9 @@
 import com.fs.pxe.bpel.dao.BpelDAOConnectionFactory;
 import com.fs.pxe.bpel.engine.BpelServerImpl;
 import com.fs.pxe.bpel.iapi.EndpointReference;
-import com.fs.pxe.bpel.iapi.MyRoleMessageExchange;
 import com.fs.pxe.bpel.scheduler.quartz.QuartzSchedulerImpl;
-import com.fs.pxe.jbi.msgmap.DocLitMapper;
-import com.fs.pxe.jbi.msgmap.JbiWsdl11WrapperMapper;
 import com.fs.pxe.jbi.msgmap.Mapper;
-import com.fs.pxe.jbi.msgmap.ServiceMixMapper;
+import com.fs.utils.DOMUtils;
 
 /**
  * Encapsulation of all the junk needed to get the BPEL engine running.
@@ -76,7 +73,11 @@
 
   public DataSource _dataSource;
 
-  private Map<QName, PxeService> _activeServices = new ConcurrentHashMap<QName, PxeService>();
+  /** Mapping of PxeServiceId to PxeService */
+  private Map<QName, PxeService> _activePxeServices = new ConcurrentHashMap<QName, PxeService>();
+
+  /** Mapping of JbiServiceName to PxeService */
+  private Map<QName, PxeService> _activeJbiServices = new ConcurrentHashMap<QName, PxeService>();
 
 
   public PxeContext() {
@@ -150,25 +151,57 @@
     return (TransactionManager) getContext().getTransactionManager();
   }
 
-  public MyEndpointReference activateEndpoint(QName pid, QName serviceId,
+  public MyEndpointReference activateEndpoint(QName pid, QName pxeServiceId,
       Element externalEpr) throws Exception {
-    PxeService service = new PxeService(this, serviceId, "pxe");
+    QName jbiServiceName;
+    String jbiEndpointName;
+
+    if ( __log.isDebugEnabled() ) {
+      __log.debug( "Activate endpoint: " + prettyPrint( externalEpr ) );
+    }
+
+    QName elname = new QName(externalEpr.getNamespaceURI(),externalEpr.getLocalName());
+    if (elname.equals(EndpointReference.SERVICE_REF_QNAME)) {
+        externalEpr = DOMUtils.getFirstChildElement(externalEpr);
+        if ( externalEpr == null ) {
+            throw new IllegalArgumentException( "Unsupported EPR: " + prettyPrint(externalEpr) );
+        }
+        elname = new QName(externalEpr.getNamespaceURI(),externalEpr.getLocalName());
+    }
+    
+    // extract serviceName and endpointName from JBI EPR 
+    if (elname.equals(EndpointReferenceContextImpl.JBI_EPR)) {
+      String serviceName = externalEpr.getAttribute("service-name");
+      jbiServiceName = EndpointReferenceContextImpl.convertClarkQName( serviceName );
+      jbiEndpointName = externalEpr.getAttribute("end-point-name");
+    } else {
+      throw new IllegalArgumentException( "Unsupported EPR: " + prettyPrint(externalEpr) );
+    }
+    
+    PxeService service = new PxeService(this, pxeServiceId, jbiServiceName, jbiEndpointName);
     MyEndpointReference myepr = new MyEndpointReference(service);
     service.activate();
-    _activeServices.put(serviceId, service);
+    _activePxeServices.put(pxeServiceId, service);
+    _activeJbiServices.put(jbiServiceName, service);
     return myepr;
 
   }
 
   public void deactivateEndpoint(MyEndpointReference epr) throws Exception {
-    PxeService svc = _activeServices.remove(epr.getService().getServiceName());
-    if (svc != null)
+    PxeService svc = _activePxeServices.remove(epr.getService().getPxeServiceId());
+    _activeJbiServices.remove(epr.getService().getJbiServiceName());
+    if (svc != null) {
       svc.deactivate();
+    }
   }
 
-  public PxeService getService(QName serviceName) {
-    return _activeServices.get(serviceName);
-  }
+  public PxeService getService(QName pxeServiceId) {
+	    return _activePxeServices.get(pxeServiceId);
+	  }
+
+  public PxeService getServiceByServiceName(QName jbiServiceName) {
+	    return _activeJbiServices.get(jbiServiceName);
+	  }
 
   public Mapper findMapper(NormalizedMessage nmsMsg, Operation op) {
     ArrayList<Mapper> maybe = new ArrayList<Mapper>();
@@ -208,4 +241,13 @@
   public Mapper getDefaultMapper() {
     return _mappers.get(0);
   }
+
+  private String prettyPrint( Element el ) {
+      try {
+          return DOMUtils.prettyPrint( el );
+      } catch ( java.io.IOException ioe ) {
+          return ioe.getMessage();
+      }
+  }
+  
 }

Modified: incubator/ode/scratch/pxe-iapi/jbi/src/main/java/com/fs/pxe/jbi/PxeLifeCycle.java
URL: http://svn.apache.org/viewvc/incubator/ode/scratch/pxe-iapi/jbi/src/main/java/com/fs/pxe/jbi/PxeLifeCycle.java?rev=423323&r1=423322&r2=423323&view=diff
==============================================================================
--- incubator/ode/scratch/pxe-iapi/jbi/src/main/java/com/fs/pxe/jbi/PxeLifeCycle.java (original)
+++ incubator/ode/scratch/pxe-iapi/jbi/src/main/java/com/fs/pxe/jbi/PxeLifeCycle.java Tue Jul 18 18:19:58 2006
@@ -10,6 +10,15 @@
 import java.util.Properties;
 import java.util.concurrent.Executors;
 
+import javax.jbi.JBIException;
+import javax.jbi.component.ComponentContext;
+import javax.jbi.component.ComponentLifeCycle;
+import javax.jbi.component.ServiceUnitManager;
+import javax.management.ObjectName;
+import javax.naming.InitialContext;
+import javax.sql.DataSource;
+import javax.transaction.TransactionManager;
+
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.derby.jdbc.EmbeddedDriver;
@@ -19,24 +28,13 @@
 import org.opentools.minerva.MinervaPool;
 import org.opentools.minerva.MinervaPool.PoolType;
 
-import javax.jbi.JBIException;
-import javax.jbi.component.ComponentContext;
-import javax.jbi.component.ComponentLifeCycle;
-import javax.jbi.component.ServiceUnitManager;
-import javax.management.*;
-import javax.naming.InitialContext;
-import javax.sql.DataSource;
-import javax.transaction.TransactionManager;
-
 import com.fs.pxe.bpel.engine.BpelServerImpl;
 import com.fs.pxe.bpel.scheduler.quartz.QuartzSchedulerImpl;
 import com.fs.pxe.daohib.DataSourceConnectionProvider;
 import com.fs.pxe.daohib.HibernateTransactionManagerLookup;
 import com.fs.pxe.daohib.SessionManager;
 import com.fs.pxe.daohib.bpel.BpelDAOConnectionFactoryImpl;
-import com.fs.pxe.jbi.msgmap.JbiWsdl11WrapperMapper;
 import com.fs.pxe.jbi.msgmap.Mapper;
-
 import com.fs.utils.fs.TempFileManager;
 
 /**
@@ -445,7 +443,7 @@
         if (mapper != null) {
           dialect = mapper.getDialectClass(dbMajorVer);
         } else {
-          Dialect hbDialect = hbDialect = DialectFactory.determineDialect(
+          Dialect hbDialect = DialectFactory.determineDialect(
               dbProductName, dbMajorVer);
           if (hbDialect != null)
             dialect = hbDialect.getClass().getName();

Modified: incubator/ode/scratch/pxe-iapi/jbi/src/main/java/com/fs/pxe/jbi/PxeService.java
URL: http://svn.apache.org/viewvc/incubator/ode/scratch/pxe-iapi/jbi/src/main/java/com/fs/pxe/jbi/PxeService.java?rev=423323&r1=423322&r2=423323&view=diff
==============================================================================
--- incubator/ode/scratch/pxe-iapi/jbi/src/main/java/com/fs/pxe/jbi/PxeService.java (original)
+++ incubator/ode/scratch/pxe-iapi/jbi/src/main/java/com/fs/pxe/jbi/PxeService.java Tue Jul 18 18:19:58 2006
@@ -19,8 +19,6 @@
 import javax.jbi.messaging.*;
 import javax.jbi.servicedesc.ServiceEndpoint;
 import javax.xml.namespace.QName;
-import javax.xml.transform.dom.DOMSource;
-
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.w3c.dom.Element;
@@ -43,18 +41,21 @@
 
   private PxeContext  _pxe;
 
-  private QName _serviceName;
+  private QName _pxeServiceId;
+
+  private QName _jbiServiceName;
 
-  private String _portName;
+  private String _jbiPortName;
 
   private Element _serviceref;
   
   
-  public PxeService(PxeContext pxeContext, QName serviceName, String portName)
+  public PxeService(PxeContext pxeContext, QName pxeServiceId, QName jbiServiceName, String jbiPortName)
       throws Exception {
     _pxe = pxeContext;
-    _serviceName = serviceName;
-    _portName = portName;
+    _pxeServiceId = pxeServiceId;
+    _jbiServiceName = jbiServiceName;
+    _jbiPortName = jbiPortName;
   }
 
   /**
@@ -64,16 +65,16 @@
    */
   public void activate() throws JBIException {
     if (_serviceref ==  null) {
-      ServiceEndpoint[] candidates = _pxe.getContext().getExternalEndpointsForService(_serviceName);
+      ServiceEndpoint[] candidates = _pxe.getContext().getExternalEndpointsForService(_jbiServiceName);
       if (candidates.length != 0) {
         _external = candidates[0];
       }
     }
-    
-    _internal = _pxe.getContext().activateEndpoint(_serviceName, _portName);
+    _internal = _pxe.getContext().activateEndpoint(_jbiServiceName, _jbiPortName);
+    if (__log.isDebugEnabled()) {
+      __log.debug("Activated service " + _jbiServiceName + " on port " +  _jbiPortName);
+    }
     // TODO: Is there a race situation here?
-    
-    __log.debug("Activated service " + _serviceName + " with port " +  _portName);
   }
 
   /**
@@ -81,7 +82,7 @@
    */
   public void deactivate() throws JBIException {
     _pxe.getContext().deactivateEndpoint(_internal);
-    __log.debug("Dectivated service " + _serviceName + " with port " +  _portName);
+    __log.debug("Dectivated service " + _jbiServiceName + " with port " +  _jbiPortName);
   }
 
   public ServiceEndpoint getInternalServiceEndpoint() {
@@ -194,11 +195,15 @@
     boolean success = false;
     MyRoleMessageExchange pxeMex = null;
     try {
-       pxeMex = _pxe._server.getEngine().createMessageExchange(
-          jbiMex.getExchangeId(),
-          serviceName,
-          null,
-          jbiMex.getOperation().getLocalPart());
+      if (__log.isDebugEnabled()) {
+      __log.debug("invokePxe() JBI exchangeId=" + jbiMex.getExchangeId() + " serviceName=" + serviceName + " operation=" + jbiMex.getOperation().getLocalPart() );
+      __log.debug("invokePxe() PXE servideId=" + _pxeServiceId + " serviceName=" + _jbiServiceName + " port=" + _jbiPortName + " internal=" + _internal );
+      }
+      pxeMex = _pxe._server.getEngine().createMessageExchange(
+        jbiMex.getExchangeId(),
+        _pxeServiceId,
+        null,
+        jbiMex.getOperation().getLocalPart());
 
       if (pxeMex.getOperation() != null) {
         javax.wsdl.Message msgdef = pxeMex.getOperation().getInput().getMessage();
@@ -316,8 +321,13 @@
     }
   }
 
-  public QName getServiceName() {
-    return _serviceName;
+  public QName getJbiServiceName() {
+    return _jbiServiceName;
+  }
+
+  
+  public QName getPxeServiceId() {
+    return _jbiServiceName;
   }
 
   

Modified: incubator/ode/scratch/pxe-iapi/jbi/src/main/java/com/fs/pxe/jbi/msgmap/ServiceMixMapper.java
URL: http://svn.apache.org/viewvc/incubator/ode/scratch/pxe-iapi/jbi/src/main/java/com/fs/pxe/jbi/msgmap/ServiceMixMapper.java?rev=423323&r1=423322&r2=423323&view=diff
==============================================================================
--- incubator/ode/scratch/pxe-iapi/jbi/src/main/java/com/fs/pxe/jbi/msgmap/ServiceMixMapper.java (original)
+++ incubator/ode/scratch/pxe-iapi/jbi/src/main/java/com/fs/pxe/jbi/msgmap/ServiceMixMapper.java Tue Jul 18 18:19:58 2006
@@ -1,5 +1,6 @@
 package com.fs.pxe.jbi.msgmap;
 
+import java.util.List;
 import java.util.Set;
 
 import javax.jbi.messaging.MessagingException;
@@ -9,7 +10,9 @@
 import javax.xml.namespace.QName;
 import javax.xml.transform.dom.DOMSource;
 
+import org.w3c.dom.Document;
 import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
 
 import com.fs.pxe.bpel.iapi.Message;
 import com.fs.utils.DOMUtils;
@@ -29,13 +32,19 @@
   public Recognized isRecognized(NormalizedMessage nmsMsg, Operation op) {
     // First of all, if we are not in ServiceMix, we exclude this 
     // as a possibility.
-    if (nmsMsg.getClass().getName().indexOf("servicemix") == -1)
+    if (nmsMsg.getClass().getName().indexOf("servicemix") == -1) {
+      __log.debug( "Unrecognized message class: " + nmsMsg.getClass() );
       return Recognized.FALSE;
+    }
     
     Element msg;
     try {
       msg = parse(nmsMsg.getContent());
+      if ( __log.isDebugEnabled() ) {
+    	__log.debug("isRecognized() message: " + prettyPrint(msg));
+      }
     } catch (MessageTranslationException e) {
+      __log.debug( "Unable to parse message: ", e);
       return Recognized.FALSE;
     }
     
@@ -56,7 +65,17 @@
     
     for (String pname : ((Set<String>)op.getInput().getMessage().getParts().keySet())) {
       Part part = op.getInput().getMessage().getPart(pname);
-      Element pdata = DOMUtils.findChildByName(msg,new QName(null,part.getName()));
+      Element pdata = null;
+      // servicemix-http has a (bad) habit of placing the SOAP body content directly in the normalized message
+      QName elementName = part.getElementName();
+      if ( elementName != null && elementName.getLocalPart().equals( msg.getLocalName())
+    		  && elementName.getNamespaceURI().equals(msg.getNamespaceURI()) ) {
+        pdata = msg;
+      }
+      if (pdata == null) {
+        // with RPC semantic the body is wrapped by a partName which is same as bodyElementName
+        pdata = DOMUtils.findChildByName(msg,new QName(null,part.getName()));
+      }
       if (pdata == null) {
         __log.debug("no part data for " + part.getName() + " -- unrecognized.");
         return Recognized.FALSE;
@@ -82,14 +101,64 @@
 
     // Simple, just pass along the message.
     Element pxe = pxeMsg.getMessage();
-    nmsMsg.setContent(new DOMSource(pxe));
+    if ( __log.isDebugEnabled() ) {
+      __log.debug("toNMS() pxe message:\n" + prettyPrint(pxe));
+    }
+    Element part = DOMUtils.getFirstChildElement( pxe ); 
+    Element content = DOMUtils.getFirstChildElement( part ); 
+    if ( __log.isDebugEnabled() ) {
+      __log.debug("toNMS() normalized message:\n" + prettyPrint(content));
+    }
+    nmsMsg.setContent(new DOMSource(content));
   }
 
   public void toPXE(Message pxeMsg, NormalizedMessage nmsMsg,
-      javax.wsdl.Message msgdef) throws MessageTranslationException {
-    // Simple, just pass along the message
+      javax.wsdl.Message msgdef) throws MessageTranslationException
+  {
     Element nms = parse(nmsMsg.getContent());
-    pxeMsg.setMessage(nms);
+    boolean docLit = false;
+    
+    if ( __log.isDebugEnabled() ) {
+      __log.debug("toPXE() normalized message:\n" + prettyPrint(nms));
+    }
+    
+    for (String pname : ((Set<String>)msgdef.getParts().keySet())) {
+      Part part = msgdef.getPart(pname);
+      // servicemix-http has a (bad) habit of placing the SOAP body content directly in the normalized message
+      QName elementName = part.getElementName();
+      if ( elementName != null && elementName.getLocalPart().equals( nms.getLocalName())
+    		  && elementName.getNamespaceURI().equals(nms.getNamespaceURI()) ) {
+        docLit = true;
+        break;
+      }
+    }
+    if ( docLit ) {
+      // Simple, just pass along the message
+      __log.debug("toPXE() use doc-lit conversion");
+        
+      Document doc = newDocument();
+      Element message = doc.createElement("message");
+      doc.appendChild(message);
+    
+      Part firstPart = (Part) msgdef.getOrderedParts(null).get(0);
+      Element p = doc.createElement(firstPart.getName());
+      message.appendChild(p);
+      p.appendChild(doc.importNode(nms, true));
+      pxeMsg.setMessage(message);
+    } else {
+      // Simple, just pass along the message
+      if ( __log.isDebugEnabled() ) {
+	    __log.debug("toPXE() pxe message:\n" + prettyPrint(nms));
+	  }
+      pxeMsg.setMessage(nms);
+    }
   }
 
+  private String prettyPrint( Element el ) {
+      try {
+          return DOMUtils.prettyPrint( el );
+      } catch ( java.io.IOException ioe ) {
+          return ioe.getMessage();
+      }
+  }
 }