You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ode.apache.org by ms...@apache.org on 2007/01/09 22:02:01 UTC

svn commit: r494571 - in /incubator/ode/trunk/jbi/src/main/java/org/apache/ode/jbi: OdeConsumer.java msgmap/DocLitMapper.java msgmap/JbiWsdl11WrapperMapper.java msgmap/Mapper.java msgmap/ServiceMixMapper.java

Author: mszefler
Date: Tue Jan  9 13:02:00 2007
New Revision: 494571

URL: http://svn.apache.org/viewvc?view=rev&rev=494571
Log:
JBI Fault handling.

Modified:
    incubator/ode/trunk/jbi/src/main/java/org/apache/ode/jbi/OdeConsumer.java
    incubator/ode/trunk/jbi/src/main/java/org/apache/ode/jbi/msgmap/DocLitMapper.java
    incubator/ode/trunk/jbi/src/main/java/org/apache/ode/jbi/msgmap/JbiWsdl11WrapperMapper.java
    incubator/ode/trunk/jbi/src/main/java/org/apache/ode/jbi/msgmap/Mapper.java
    incubator/ode/trunk/jbi/src/main/java/org/apache/ode/jbi/msgmap/ServiceMixMapper.java

Modified: incubator/ode/trunk/jbi/src/main/java/org/apache/ode/jbi/OdeConsumer.java
URL: http://svn.apache.org/viewvc/incubator/ode/trunk/jbi/src/main/java/org/apache/ode/jbi/OdeConsumer.java?view=diff&rev=494571&r1=494570&r2=494571
==============================================================================
--- incubator/ode/trunk/jbi/src/main/java/org/apache/ode/jbi/OdeConsumer.java (original)
+++ incubator/ode/trunk/jbi/src/main/java/org/apache/ode/jbi/OdeConsumer.java Tue Jan  9 13:02:00 2007
@@ -186,6 +186,7 @@
 
     try {
       _ode._scheduler.execTransaction(new Callable<Boolean>() {
+        @SuppressWarnings("unchecked")
         public Boolean call() throws Exception {
           PartnerRoleMessageExchange pmex = (PartnerRoleMessageExchange) _ode._server
               .getEngine().getMessageExchange(mexref);
@@ -206,9 +207,20 @@
             try {
               Fault jbiFlt = jbiMex.getFault();
               if (jbiFlt != null) {
-
-                // TODO: How are we supposed to figure out the fault type exactly?
-                throw new AssertionError("todo");
+                javax.wsdl.Fault wsdlFlt = mapper.toFaultType(jbiFlt,pmex.getOperation().getFaults().values());
+                if (wsdlFlt == null) {
+                    pmex.replyWithFailure(FailureType.FORMAT_ERROR, "Unrecognized fault message.", null);
+                } else {
+                    if (wsdlFlt.getMessage() != null) {
+                        Message faultResponse = pmex.createMessage(wsdlFlt.getMessage().getQName());
+                        mapper.toODE(faultResponse,jbiFlt,wsdlFlt.getMessage());
+                        pmex.replyWithFault(wsdlFlt.getName(), faultResponse);
+                    } else {
+                        // Can this even happen?
+                        __log.fatal("Internal Error: fault found without a message type: " + wsdlFlt); 
+                        pmex.replyWithFailure(FailureType.FORMAT_ERROR, "Fault has no message: " + wsdlFlt.getName(), null);;
+                    }
+                }                    
               } else {
                 Message response = pmex.createMessage(pmex.getOperation().getOutput().getMessage().getQName());
                 mapper.toODE(response,jbiMex.getOutMessage(),pmex.getOperation().getOutput().getMessage());

Modified: incubator/ode/trunk/jbi/src/main/java/org/apache/ode/jbi/msgmap/DocLitMapper.java
URL: http://svn.apache.org/viewvc/incubator/ode/trunk/jbi/src/main/java/org/apache/ode/jbi/msgmap/DocLitMapper.java?view=diff&rev=494571&r1=494570&r2=494571
==============================================================================
--- incubator/ode/trunk/jbi/src/main/java/org/apache/ode/jbi/msgmap/DocLitMapper.java (original)
+++ incubator/ode/trunk/jbi/src/main/java/org/apache/ode/jbi/msgmap/DocLitMapper.java Tue Jan  9 13:02:00 2007
@@ -19,8 +19,11 @@
 
 package org.apache.ode.jbi.msgmap;
 
+import java.util.Collection;
+
 import javax.jbi.messaging.MessagingException;
 import javax.jbi.messaging.NormalizedMessage;
+import javax.wsdl.Fault;
 import javax.wsdl.Message;
 import javax.wsdl.Operation;
 import javax.wsdl.Part;
@@ -125,6 +128,23 @@
     pel.appendChild(doc.importNode(el,true));
     odeMsg.setMessage(msgel);
     
+  }
+
+
+  public Fault toFaultType(javax.jbi.messaging.Fault jbiFlt, Collection<Fault> faults) throws MessageTranslationException {
+      Element el = parse(jbiFlt.getContent());
+      QName elQname = new QName(el.getNamespaceURI(),el.getLocalName());
+      for (Fault f : faults) {
+          if (f.getMessage() == null || f.getMessage().getParts().size() != 1)
+              continue;
+          javax.wsdl.Part pdef = (Part) f.getMessage().getParts().values().iterator().next();
+          if (pdef.getElementName() == null)
+              continue;
+          if (pdef.getElementName().equals(elQName))
+              return f;
+      }
+      
+      return null;
   }
 
   /**

Modified: incubator/ode/trunk/jbi/src/main/java/org/apache/ode/jbi/msgmap/JbiWsdl11WrapperMapper.java
URL: http://svn.apache.org/viewvc/incubator/ode/trunk/jbi/src/main/java/org/apache/ode/jbi/msgmap/JbiWsdl11WrapperMapper.java?view=diff&rev=494571&r1=494570&r2=494571
==============================================================================
--- incubator/ode/trunk/jbi/src/main/java/org/apache/ode/jbi/msgmap/JbiWsdl11WrapperMapper.java (original)
+++ incubator/ode/trunk/jbi/src/main/java/org/apache/ode/jbi/msgmap/JbiWsdl11WrapperMapper.java Tue Jan  9 13:02:00 2007
@@ -19,134 +19,201 @@
 
 package org.apache.ode.jbi.msgmap;
 
+import java.util.Collection;
+import java.util.LinkedList;
 import java.util.List;
-import javax.jbi.messaging.*;
+
+import javax.jbi.messaging.MessagingException;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.wsdl.Fault;
 import javax.wsdl.Operation;
 import javax.wsdl.Part;
 import javax.xml.namespace.QName;
 import javax.xml.transform.dom.DOMSource;
 
+import org.apache.ode.bpel.iapi.Message;
+import org.apache.ode.utils.DOMUtils;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
 
-import org.apache.ode.bpel.iapi.Message;
-import org.apache.ode.utils.DOMUtils;
-
 /**
  * Mapper for converting ODE messages to NMS messages using the WSDL 11 wrapper
  * format.
  */
 public class JbiWsdl11WrapperMapper extends BaseXmlMapper implements Mapper {
 
-  public static final String URI_WSDL11_WRAPPER = "http://java.sun.com/xml/ns/jbi/wsdl-11-wrapper";
+    public static final String URI_WSDL11_WRAPPER = "http://java.sun.com/xml/ns/jbi/wsdl-11-wrapper";
 
-  public static final QName WSDL11_W_MESSAGE = new QName(URI_WSDL11_WRAPPER,
-      "message");
+    public static final QName WSDL11_W_MESSAGE = new QName(URI_WSDL11_WRAPPER, "message");
 
+    public JbiWsdl11WrapperMapper() {
+    }
 
-  public JbiWsdl11WrapperMapper() {
-  }
+    public Recognized isRecognized(NormalizedMessage nmsMsg, Operation op) {
+        Element srcel;
+        try {
+            srcel = parse(nmsMsg.getContent());
+        } catch (MessageTranslationException e) {
+            // Well, maybe it is not XML.
+            if (__log.isDebugEnabled())
+                __log.debug("Exception parsing NMS message.", e);
+            return Recognized.FALSE;
+        }
 
-  public Recognized isRecognized(NormalizedMessage nmsMsg,
-      Operation op) {
-    Element srcel;
-    try {
-      srcel = parse(nmsMsg.getContent());
-    } catch (MessageTranslationException e) {
-      // Well, maybe it is not XML.
-      if (__log.isDebugEnabled())
-        __log.debug("Exception parsing NMS message.", e);
-      return Recognized.FALSE;
+        QName srcName = new QName(srcel.getNamespaceURI(), srcel.getLocalName());
+        return WSDL11_W_MESSAGE.equals(srcName) ? Recognized.TRUE : Recognized.FALSE;
     }
 
-    QName srcName = new QName(srcel.getNamespaceURI(), srcel.getLocalName());
-    return WSDL11_W_MESSAGE.equals(srcName) ? Recognized.TRUE : Recognized.FALSE;
-  }
-
- 
-  /**
-   * 
-   * Convert ODE normalized message to JBI normalized "WSDL 1.1 Wrapper" format.
-   */
-  public void toNMS(NormalizedMessage nmsMsg, Message odeMsg,
-      javax.wsdl.Message msgdef) throws MessagingException {
-    if (msgdef == null)
-      throw new NullPointerException("Null MessageDef");
-    if (odeMsg == null)
-      throw new NullPointerException("Null src.");
-
-    if (__log.isTraceEnabled())
-      __log.trace("toNMS(odeMsg=" + odeMsg + ")");
-
-    Element srcMsgEl = odeMsg.getMessage();
-    Document doc = newDocument();
-    Element dstMsgEl = doc.createElementNS(URI_WSDL11_WRAPPER, "message");
-    doc.appendChild(dstMsgEl);
-
-    // The JBI NMS required attributes.
-    dstMsgEl.setAttributeNS(DOMUtils.NS_URI_XMLNS, "xmlns:msgns", odeMsg
-        .getType().getNamespaceURI());
-    dstMsgEl.setAttribute("version", "1.0");
-    dstMsgEl.setAttribute("type", "msgns:" + odeMsg.getType().getLocalPart());
-
-    // The parts (hopefully they are in order, as NMS does not identify them!)
-    Element srcPartEl = DOMUtils.getFirstChildElement(srcMsgEl);
-    while (srcPartEl != null) {
-      Element dstPartEl = doc.createElementNS(URI_WSDL11_WRAPPER, "part");
-      dstMsgEl.appendChild(dstPartEl);
-      Node srccontent = srcPartEl.getFirstChild();
-      while (srccontent != null) {
-        dstPartEl.appendChild(doc.importNode(srccontent, true));
-        srccontent = srccontent.getNextSibling();
-      }
-      srcPartEl = DOMUtils.getNextSiblingElement(srcPartEl);
+    /**
+     * 
+     * Convert ODE normalized message to JBI normalized "WSDL 1.1 Wrapper"
+     * format.
+     */
+    public void toNMS(NormalizedMessage nmsMsg, Message odeMsg, javax.wsdl.Message msgdef) throws MessagingException {
+        if (msgdef == null)
+            throw new NullPointerException("Null MessageDef");
+        if (odeMsg == null)
+            throw new NullPointerException("Null src.");
+
+        if (__log.isTraceEnabled())
+            __log.trace("toNMS(odeMsg=" + odeMsg + ")");
+
+        Element srcMsgEl = odeMsg.getMessage();
+        Document doc = newDocument();
+        Element dstMsgEl = doc.createElementNS(URI_WSDL11_WRAPPER, "message");
+        doc.appendChild(dstMsgEl);
+
+        // The JBI NMS required attributes.
+        dstMsgEl.setAttributeNS(DOMUtils.NS_URI_XMLNS, "xmlns:msgns", odeMsg.getType().getNamespaceURI());
+        dstMsgEl.setAttribute("version", "1.0");
+        dstMsgEl.setAttribute("type", "msgns:" + odeMsg.getType().getLocalPart());
+
+        // The parts (hopefully they are in order, as NMS does not identify
+        // them!)
+        Element srcPartEl = DOMUtils.getFirstChildElement(srcMsgEl);
+        while (srcPartEl != null) {
+            Element dstPartEl = doc.createElementNS(URI_WSDL11_WRAPPER, "part");
+            dstMsgEl.appendChild(dstPartEl);
+            Node srccontent = srcPartEl.getFirstChild();
+            while (srccontent != null) {
+                dstPartEl.appendChild(doc.importNode(srccontent, true));
+                srccontent = srccontent.getNextSibling();
+            }
+            srcPartEl = DOMUtils.getNextSiblingElement(srcPartEl);
+        }
+
+        nmsMsg.setContent(new DOMSource(doc));
+
     }
 
-    nmsMsg.setContent(new DOMSource(doc));
+    @SuppressWarnings("unchecked")
+    public void toODE(Message dest, NormalizedMessage src, javax.wsdl.Message msgdef)
+            throws MessageTranslationException {
+        if (msgdef == null)
+            throw new NullPointerException("Null MessageDef");
+        if (dest == null)
+            throw new NullPointerException("Null dest.");
+        if (src == null)
+            throw new NullPointerException("Null src.");
+
+        if (__log.isTraceEnabled())
+            __log.trace("convertMessage<toODE>(dest=" + dest + ",src=" + src);
+
+        Element srcel = parse(src.getContent());
+
+        Document odemsgdoc = newDocument();
+        Element odemsg = odemsgdoc.createElement("message");
+        odemsgdoc.appendChild(odemsg);
+
+        List<Part> expectedParts = msgdef.getOrderedParts(null);
+
+        Element srcpart = DOMUtils.getFirstChildElement(srcel);
+        for (int i = 0; i < expectedParts.size(); ++i) {
+            Part pdef = expectedParts.get(i);
+            Element p = odemsgdoc.createElement(pdef.getName());
+            odemsg.appendChild(p);
+            if (srcpart != null) {
+                NodeList nl = srcpart.getChildNodes();
+                for (int j = 0; j < nl.getLength(); ++j)
+                    p.appendChild(odemsgdoc.importNode(nl.item(j), true));
+                srcpart = DOMUtils.getNextSiblingElement(srcpart);
+            } else {
+                __log.error("Improperly formatted message, missing part: " + pdef.getName());
+            }
+        }
 
-  }
+        dest.setMessage(odemsg);
 
-  @SuppressWarnings("unchecked")
-  public void toODE(Message dest, NormalizedMessage src,
-      javax.wsdl.Message msgdef) throws MessageTranslationException {
-    if (msgdef == null)
-      throw new NullPointerException("Null MessageDef");
-    if (dest == null)
-      throw new NullPointerException("Null dest.");
-    if (src == null)
-      throw new NullPointerException("Null src.");
-
-    if (__log.isTraceEnabled())
-      __log.trace("convertMessage<toODE>(dest=" + dest + ",src=" + src);
-
-    Element srcel = parse(src.getContent());
-
-    Document odemsgdoc = newDocument();
-    Element odemsg = odemsgdoc.createElement("message");
-    odemsgdoc.appendChild(odemsg);
-
-    List<Part> expectedParts = msgdef.getOrderedParts(null);
-
-    Element srcpart = DOMUtils.getFirstChildElement(srcel);
-    for (int i = 0; i < expectedParts.size(); ++i) {
-      Part pdef = expectedParts.get(i);
-      Element p = odemsgdoc.createElement(pdef.getName());
-      odemsg.appendChild(p);
-      if (srcpart != null) {
-        NodeList nl = srcpart.getChildNodes();
-        for (int j = 0; j < nl.getLength(); ++j)
-          p.appendChild(odemsgdoc.importNode(nl.item(j), true));
-        srcpart = DOMUtils.getNextSiblingElement(srcpart);
-      } else {
-        __log.error("Improperly formatted message, missing part: "
-            + pdef.getName());
-      }
     }
 
-    dest.setMessage(odemsg);
-
-  }
+    @SuppressWarnings("unchecked")
+    public Fault toFaultType(javax.jbi.messaging.Fault jbiFlt, Collection<Fault> faults) throws MessageTranslationException {
+        if (jbiFlt == null)
+            throw new NullPointerException("Null jbiFlt.");
+        if (faults == null)
+            throw new NullPointerException("Null faults.");
+
+        if (__log.isTraceEnabled())
+            __log.trace("toFaultType(jbiFlt=" + jbiFlt + ")");
+
+        
+        final QName partElName = new QName(URI_WSDL11_WRAPPER, "part");
+        List<QName> eltypes = new LinkedList<QName>();
+        
+        // Figure out what we have in the message we just got.
+        Element srcel = parse(jbiFlt.getContent()); 
+        Node n = srcel.getFirstChild();
+        while (n != null) {
+            if (n.getNodeType() == Node.ELEMENT_NODE) {
+                QName elName = new QName(n.getNamespaceURI(),n.getLocalName());
+                if (!elName.equals(partElName)) {
+                    String err = "Invalid NMS message format, expected " + partElName + " but found " + elName;
+                    __log.error(err);
+                    throw new MessageTranslationException(err);
+                }
+                Element pdata = DOMUtils.getFirstChildElement((Element) n);
+                if (pdata == null)
+                    eltypes.add(null);
+                else
+                    eltypes.add(new QName(pdata.getNamespaceURI(),pdata.getLocalName()));
+            }
+            n = n.getNextSibling();
+        }
+
+        // See if it matches what we expect the faults to look like (first one wins!)
+        fltiter:for (Fault f : faults) {
+            if (f.getMessage() == null && eltypes.isEmpty())
+                return f;
+            
+            if (f.getMessage().getParts().size() != eltypes.size())
+                continue;
+            
+            List<Part> expectedParts = f.getMessage().getOrderedParts(null);
+
+            int i = 0;
+            for (Part p : expectedParts) {
+                if (eltypes.size() <= i)
+                    continue fltiter;
+                QName etype = eltypes.get(i++);
+                
+                if ((p.getElementName() == null) ^ (etype == null))
+                    continue fltiter;
+                
+                if (etype == null && p.getElementName() == null)
+                    continue;
+
+                if (etype.equals(p.getElementName()))
+                    continue;
+            }
+            
+            return f;
+            
+        }
+        
+        // None of the faults has been recognized. 
+        return null;
+    }
 
 }

Modified: incubator/ode/trunk/jbi/src/main/java/org/apache/ode/jbi/msgmap/Mapper.java
URL: http://svn.apache.org/viewvc/incubator/ode/trunk/jbi/src/main/java/org/apache/ode/jbi/msgmap/Mapper.java?view=diff&rev=494571&r1=494570&r2=494571
==============================================================================
--- incubator/ode/trunk/jbi/src/main/java/org/apache/ode/jbi/msgmap/Mapper.java (original)
+++ incubator/ode/trunk/jbi/src/main/java/org/apache/ode/jbi/msgmap/Mapper.java Tue Jan  9 13:02:00 2007
@@ -19,59 +19,68 @@
 
 package org.apache.ode.jbi.msgmap;
 
+import java.util.Collection;
+import java.util.Map;
+
 import javax.jbi.messaging.MessagingException;
 import javax.jbi.messaging.NormalizedMessage;
+import javax.wsdl.Fault;
 import javax.wsdl.Operation;
 
 import org.apache.ode.bpel.iapi.Message;
 
-
-
 /**
- * Interface implemented by message format converters. 
- * TODO: Perhaps we should move this into the engine and make it pluggable?
+ * Interface implemented by message format converters. TODO: Perhaps we should
+ * move this into the engine and make it pluggable?
  */
 public interface Mapper {
-  
-  
-  /**
-   * Determine if this mapper recognizes the format of the NMS message.
-   * 
-   * @param nmsMsg
-   * @return
-   */
-  Recognized isRecognized(NormalizedMessage nmsMsg, Operation op);
-
-  /**
-   * Convert a ODE message to NMS format. This call must only be called
-   * if {@link #isRecognized(NormalizedMessage, Operation)} returned,
-   * <code>true</code>.
-   * @param nmsMsg
-   * @param odeMsg
-   * @param msgdef
-   * @throws MessagingException
-   * @throws MessageTranslationException
-   */
-  void toNMS(NormalizedMessage nmsMsg, Message odeMsg, javax.wsdl.Message msgdef)
-      throws MessagingException, MessageTranslationException;
-
-  /**
-   * Convert an NMS message to ODE format. This call must only be called
-   * if {@link #isRecognized(NormalizedMessage, Operation)} returned,
-   * <code>true</code>.
-   * @param odeMsg
-   * @param nmsMsg
-   * @param msgdef
-   * @throws MessageTranslationException
-   */
-  void toODE(Message odeMsg, NormalizedMessage nmsMsg, javax.wsdl.Message msgdef)
-      throws MessageTranslationException;
-
-  
-
-  enum Recognized {
-    TRUE,
-    FALSE,
-    UNSURE
-  }
+
+    /**
+     * Determine if this mapper recognizes the format of the NMS message.
+     * 
+     * @param nmsMsg
+     * @return
+     */
+    Recognized isRecognized(NormalizedMessage nmsMsg, Operation op);
+
+    /**
+     * Convert a ODE message to NMS format. This call must only be called if
+     * {@link #isRecognized(NormalizedMessage, Operation)} returned,
+     * <code>true</code>.
+     * 
+     * @param nmsMsg
+     * @param odeMsg
+     * @param msgdef
+     * @throws MessagingException
+     * @throws MessageTranslationException
+     */
+    void toNMS(NormalizedMessage nmsMsg, Message odeMsg, javax.wsdl.Message msgdef) throws MessagingException,
+            MessageTranslationException;
+
+    /**
+     * Convert an NMS message to ODE format. This call must only be called if
+     * {@link #isRecognized(NormalizedMessage, Operation)} returned,
+     * <code>true</code>.
+     * 
+     * @param odeMsg
+     * @param nmsMsg
+     * @param msgdef
+     * @throws MessageTranslationException
+     */
+    void toODE(Message odeMsg, NormalizedMessage nmsMsg, javax.wsdl.Message msgdef) throws MessageTranslationException;
+
+    /** 
+     * Infer the fault type based on the message.
+     * @param jbiFlt JBI fault message
+     * @param faults collection of possible faults
+     * @return matching fault, or null if no match
+     * @throws MessageTranslationException 
+     */
+    Fault toFaultType(javax.jbi.messaging.Fault jbiFlt, Collection<Fault> faults) throws MessageTranslationException;
+    
+    enum Recognized {
+        TRUE, FALSE, UNSURE
+    }
+
+   
 }

Modified: incubator/ode/trunk/jbi/src/main/java/org/apache/ode/jbi/msgmap/ServiceMixMapper.java
URL: http://svn.apache.org/viewvc/incubator/ode/trunk/jbi/src/main/java/org/apache/ode/jbi/msgmap/ServiceMixMapper.java?view=diff&rev=494571&r1=494570&r2=494571
==============================================================================
--- incubator/ode/trunk/jbi/src/main/java/org/apache/ode/jbi/msgmap/ServiceMixMapper.java (original)
+++ incubator/ode/trunk/jbi/src/main/java/org/apache/ode/jbi/msgmap/ServiceMixMapper.java Tue Jan  9 13:02:00 2007
@@ -19,10 +19,12 @@
 
 package org.apache.ode.jbi.msgmap;
 
+import java.util.Collection;
 import java.util.Set;
 
 import javax.jbi.messaging.MessagingException;
 import javax.jbi.messaging.NormalizedMessage;
+import javax.wsdl.Fault;
 import javax.wsdl.Operation;
 import javax.wsdl.Part;
 import javax.xml.namespace.QName;
@@ -170,6 +172,13 @@
     }
   }
 
+  public Fault toFaultType(javax.jbi.messaging.Fault jbiFlt, Collection<Fault> faults) throws MessageTranslationException {
+      if (faults.isEmpty())
+          return null;
+      
+      // anynone's guess really
+      return faults.iterator().next();
+  }
   private String prettyPrint( Element el ) {
       try {
           return DOMUtils.prettyPrint( el );
@@ -177,4 +186,6 @@
           return ioe.getMessage();
       }
   }
+
+
 }