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/02/27 08:57:26 UTC

svn commit: r512167 - in /incubator/ode/trunk/jbi/src/main/java/org/apache/ode/jbi: EndpointReferenceContextImpl.java.2.tmp EndpointReferenceContextImpl.java.tmp OdeService.java msgmap/BaseXmlMapper.java msgmap/ServiceMixMapper.java

Author: mszefler
Date: Mon Feb 26 23:57:25 2007
New Revision: 512167

URL: http://svn.apache.org/viewvc?view=rev&rev=512167
Log:
Some more better error handling logic: unmapped faults now cause proper JBI errors to be sent. 

Added:
    incubator/ode/trunk/jbi/src/main/java/org/apache/ode/jbi/EndpointReferenceContextImpl.java.2.tmp
    incubator/ode/trunk/jbi/src/main/java/org/apache/ode/jbi/EndpointReferenceContextImpl.java.tmp
Modified:
    incubator/ode/trunk/jbi/src/main/java/org/apache/ode/jbi/OdeService.java
    incubator/ode/trunk/jbi/src/main/java/org/apache/ode/jbi/msgmap/BaseXmlMapper.java
    incubator/ode/trunk/jbi/src/main/java/org/apache/ode/jbi/msgmap/ServiceMixMapper.java

Added: incubator/ode/trunk/jbi/src/main/java/org/apache/ode/jbi/EndpointReferenceContextImpl.java.2.tmp
URL: http://svn.apache.org/viewvc/incubator/ode/trunk/jbi/src/main/java/org/apache/ode/jbi/EndpointReferenceContextImpl.java.2.tmp?view=auto&rev=512167
==============================================================================
    (empty)

Added: incubator/ode/trunk/jbi/src/main/java/org/apache/ode/jbi/EndpointReferenceContextImpl.java.tmp
URL: http://svn.apache.org/viewvc/incubator/ode/trunk/jbi/src/main/java/org/apache/ode/jbi/EndpointReferenceContextImpl.java.tmp?view=auto&rev=512167
==============================================================================
    (empty)

Modified: incubator/ode/trunk/jbi/src/main/java/org/apache/ode/jbi/OdeService.java
URL: http://svn.apache.org/viewvc/incubator/ode/trunk/jbi/src/main/java/org/apache/ode/jbi/OdeService.java?view=diff&rev=512167&r1=512166&r2=512167
==============================================================================
--- incubator/ode/trunk/jbi/src/main/java/org/apache/ode/jbi/OdeService.java (original)
+++ incubator/ode/trunk/jbi/src/main/java/org/apache/ode/jbi/OdeService.java Mon Feb 26 23:57:25 2007
@@ -317,9 +317,13 @@
 
             QName fault = mex.getFault();
             javax.wsdl.Fault wsdlFault = mex.getOperation().getFault(fault.getLocalPart());
-            mapper.toNMS(flt, mex.getFaultResponse(), wsdlFault != null ? wsdlFault.getMessage() : null, fault);
-            inout.setFault(flt);
-            _ode.getChannel().send(inout);
+            if (wsdlFault == null) {
+               sendError(jbiMex, new MessageTranslationException("Unmapped Fault : " + fault + ": " + mex.getFaultExplanation()));
+            } else {
+                mapper.toNMS(flt, mex.getFaultResponse(), wsdlFault.getMessage(), fault);
+                inout.setFault(flt);
+                _ode.getChannel().send(inout);
+            }
         } catch (MessagingException e) {
             __log.error("Error bridging ODE fault response: ", e);
             sendError(jbiMex, e);
@@ -332,6 +336,7 @@
     private void sendError(javax.jbi.messaging.MessageExchange jbiMex, Exception error) {
         try {
             jbiMex.setError(error);
+            jbiMex.setStatus(ExchangeStatus.ERROR);
             _ode.getChannel().send(jbiMex);
         } catch (Exception e) {
             __log.error("Error sending ERROR status: ", e);

Modified: incubator/ode/trunk/jbi/src/main/java/org/apache/ode/jbi/msgmap/BaseXmlMapper.java
URL: http://svn.apache.org/viewvc/incubator/ode/trunk/jbi/src/main/java/org/apache/ode/jbi/msgmap/BaseXmlMapper.java?view=diff&rev=512167&r1=512166&r2=512167
==============================================================================
--- incubator/ode/trunk/jbi/src/main/java/org/apache/ode/jbi/msgmap/BaseXmlMapper.java (original)
+++ incubator/ode/trunk/jbi/src/main/java/org/apache/ode/jbi/msgmap/BaseXmlMapper.java Mon Feb 26 23:57:25 2007
@@ -34,15 +34,17 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.ode.utils.DOMUtils;
+import org.apache.ode.utils.DOMUtilsTest;
 import org.apache.ode.utils.XMLParserUtils;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
+import com.sun.org.apache.xerces.internal.util.DOMUtil;
+
 public abstract class BaseXmlMapper {
     protected Log __log = LogFactory.getLog(getClass());
 
-    private DocumentBuilderFactory _dbf;
-
     private TransformerFactory _transformerFactory;
 
     /** Cache of the parsed messages. */
@@ -50,7 +52,6 @@
 
     protected BaseXmlMapper() {
         _transformerFactory = TransformerFactory.newInstance();
-        _dbf = XMLParserUtils.getDocumentBuilderFactory();  // we don't trust system provided parser!
     }
 
     protected Element parse(Source content) throws MessageTranslationException {
@@ -83,13 +84,7 @@
     }
 
     protected Document newDocument() {
-        try {
-            return _dbf.newDocumentBuilder().newDocument();
-        } catch (ParserConfigurationException e) {
-            String errmsg = "Parser configuration error!";
-            __log.fatal(errmsg, e);
-            throw new Error(errmsg, e);
-        }
+        return DOMUtils.newDocument();
     }
 
 }

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=512167&r1=512166&r2=512167
==============================================================================
--- 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 Mon Feb 26 23:57:25 2007
@@ -30,162 +30,192 @@
 import javax.xml.namespace.QName;
 import javax.xml.transform.dom.DOMSource;
 
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-
 import org.apache.ode.bpel.iapi.Message;
 import org.apache.ode.utils.DOMUtils;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
 
 /**
- * Message mapper for dealing with the degenerate messages that servicemix
- * components such as servicemix-http provide. These messages are not normalized
- * and hence do not conform to the JBI specification. They are in fact whatever
- * the SOAP body element happens to be.  This mapper will make a reasonable
- * attempt to handle these messages, which means don't count on it working.
- *
+ * Message mapper for dealing with the degenerate messages that servicemix components such as servicemix-http provide. These
+ * messages are not normalized and hence do not conform to the JBI specification. They are in fact whatever the SOAP body element
+ * happens to be. This mapper will make a reasonable attempt to handle these messages, which means don't count on it working.
+ * 
  */
 public class ServiceMixMapper extends BaseXmlMapper implements Mapper {
 
-  @SuppressWarnings("unchecked")
-  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) {
-      __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;
-    }
-    
-    if (op.getInput() == null) {
-      __log.debug("no input def - unrecognized");
-      return Recognized.FALSE;
-    }
-    
-    if (op.getInput().getMessage() == null) {
-      __log.debug("no message def - unrecognized");
-      return Recognized.FALSE;
-    }
-    
-    if (op.getInput().getMessage().getParts().size() == 0) {
-      __log.debug("no message parts def - unsure");
-      return Recognized.UNSURE;
-    }
-    
-    for (String pname : ((Set<String>)op.getInput().getMessage().getParts().keySet())) {
-      Part part = op.getInput().getMessage().getPart(pname);
-      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;
-      }
-      if (part.getElementName() != null) { 
-        Element child = DOMUtils.getFirstChildElement(pdata);
-        if (child == null) {
-          __log.debug("element part " + part.getName() +
-              " does not contain element "  + part.getElementName() + " -- unrecognized");
-          return Recognized.FALSE;
+    @SuppressWarnings("unchecked")
+    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) {
+            __log.debug("Unrecognized message class: " + nmsMsg.getClass());
+            return Recognized.FALSE;
         }
-        
-      }
-    }
-    
-    return Recognized.TRUE;
-    
-  }
-
-  public void toNMS(NormalizedMessage nmsMsg, Message odeMsg,
-      javax.wsdl.Message msgdef, QName fault) throws MessagingException,
-      MessageTranslationException {
-
-    // Simple, just pass along the message.
-    Element ode = odeMsg.getMessage();
-    if ( __log.isDebugEnabled() ) {
-      __log.debug("toNMS() ode message:\n" + prettyPrint(ode));
-    }
-    Element part = DOMUtils.getFirstChildElement( ode ); 
-    Element content = DOMUtils.getFirstChildElement( part ); 
-    if ( __log.isDebugEnabled() ) {
-      __log.debug("toNMS() normalized message:\n" + prettyPrint(content));
-    }
-    nmsMsg.setContent(new DOMSource(content));
-  }
 
-  public void toODE(Message odeMsg, NormalizedMessage nmsMsg,
-      javax.wsdl.Message msgdef) throws MessageTranslationException
-  {
-    Element nms = parse(nmsMsg.getContent());
-    boolean docLit = false;
-    
-    if ( __log.isDebugEnabled() ) {
-      __log.debug("toODE() normalized message:\n" + prettyPrint(nms));
+        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;
+        }
+
+        if (op.getInput() == null) {
+            __log.debug("no input def - unrecognized");
+            return Recognized.FALSE;
+        }
+
+        if (op.getInput().getMessage() == null) {
+            __log.debug("no message def - unrecognized");
+            return Recognized.FALSE;
+        }
+
+        if (op.getInput().getMessage().getParts().size() == 0) {
+            __log.debug("no message parts def - unsure");
+            return Recognized.UNSURE;
+        }
+
+        for (String pname : ((Set<String>) op.getInput().getMessage().getParts().keySet())) {
+            Part part = op.getInput().getMessage().getPart(pname);
+            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;
+            }
+            if (part.getElementName() != null) {
+                Element child = DOMUtils.getFirstChildElement(pdata);
+                if (child == null) {
+                    __log.debug("element part " + part.getName() + " does not contain element " + part.getElementName()
+                            + " -- unrecognized");
+                    return Recognized.FALSE;
+                }
+
+            }
+        }
+
+        return Recognized.TRUE;
+
     }
-    
-    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;
-      }
+
+    public void toNMS(NormalizedMessage nmsMsg, Message odeMsg, javax.wsdl.Message msgdef, QName fault) throws MessagingException,
+            MessageTranslationException {
+        if (msgdef == null)
+            throw new NullPointerException("msdef must not be null.");
+        Element ode = odeMsg == null ? null : odeMsg.getMessage();
+        Element part = ode == null ? null : DOMUtils.getFirstChildElement(ode);
+        Element firstPartEl = part == null ? null : DOMUtils.getFirstChildElement(part);
+
+        if (fault != null) {
+            // We treat faults seperately as there are some assumption we can make, mainly that there is
+            // a single part and it is an element part.
+
+            if (msgdef.getParts().size() != 1)
+                throw new MessageTranslationException("Message for fault \"" + fault + "\" does not contain exactly one part! Cannot map!");
+
+            Part partDef = (Part) msgdef.getParts().values().iterator().next();
+            if (partDef.getElementName() == null)
+                throw new MessageTranslationException("Message for fault \"" + fault + "\" does not contain an element part.");
+
+            if (firstPartEl == null) {
+                // Oooops, our assumption did not pan out; we'll do our best i.e. create empty content. 
+                __log.warn("Proceessing fault \"" + fault + "\" with empty content (check your BPEL).");
+
+                Document doc = newDocument();
+                Element content = doc.createElementNS(partDef.getElementName().getNamespaceURI(), partDef.getElementName().getLocalPart());
+                doc.appendChild(content);
+                if (__log.isDebugEnabled())
+                    __log.debug("toNMS() ode message (fault, BS): " + prettyPrint(content));
+                nmsMsg.setContent(new DOMSource(doc));
+            } else {
+                if (__log.isDebugEnabled())
+                    __log.debug("toNMS() ode message (fault): " + prettyPrint(firstPartEl));
+                nmsMsg.setContent(new DOMSource(firstPartEl));
+            }
+            return;
+        }
+
+        if (msgdef.getParts().size() > 1 || ((Part) msgdef.getParts().values().iterator().next()).getElementName() == null) {
+            // If we have more than one part, or a single non-element part, then we can't use the standard
+            // NMS doc-lit like convention. Instead we place the entire message on the bus and hope for the
+            // best.
+            if (__log.isDebugEnabled())
+                __log.debug("toNMS() ode message (rpc-like): " + prettyPrint(ode));
+            nmsMsg.setContent(new DOMSource(ode));
+            return;
+        }
+
+        if (__log.isDebugEnabled())
+            __log.debug("toNMS() normalized message (doc-like):" + prettyPrint(firstPartEl));
+        nmsMsg.setContent(new DOMSource(firstPartEl));
     }
-    if ( docLit ) {
-      // Simple, just pass along the message
-      __log.debug("toODE() 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));
-      odeMsg.setMessage(message);
-    } else {
-      // Simple, just pass along the message
-      if ( __log.isDebugEnabled() ) {
-	    __log.debug("toODE() ode message:\n" + prettyPrint(nms));
-	  }
-      odeMsg.setMessage(nms);
+
+    public void toODE(Message odeMsg, NormalizedMessage nmsMsg, javax.wsdl.Message msgdef) throws MessageTranslationException {
+        Element nms = parse(nmsMsg.getContent());
+        boolean docLit = false;
+
+        if (__log.isDebugEnabled()) {
+            __log.debug("toODE() 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) {
+            __log.debug("toODE() doc-like message ");
+
+            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));
+            odeMsg.setMessage(message);
+        } else {
+            __log.debug("toODE() rpc-like message ");
+            // Simple, just pass along the message
+            if (__log.isDebugEnabled()) {
+                __log.debug("toODE() ode message:\n" + prettyPrint(nms));
+            }
+            odeMsg.setMessage(nms);
+        }
     }
-  }
 
-  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 );
-      } catch ( java.io.IOException ioe ) {
-          return ioe.getMessage();
-      }
-  }
+    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);
+        } catch (java.io.IOException ioe) {
+            return ioe.getMessage();
+        }
+    }
 
 }