You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ode.apache.org by mr...@apache.org on 2007/10/09 19:42:32 UTC

svn commit: r583235 - in /ode/trunk: axis2/src/main/java/org/apache/ode/axis2/ axis2/src/main/java/org/apache/ode/axis2/hooks/ axis2/src/main/java/org/apache/ode/axis2/util/ utils/src/main/java/org/apache/ode/utils/

Author: mriou
Date: Tue Oct  9 10:42:31 2007
New Revision: 583235

URL: http://svn.apache.org/viewvc?rev=583235&view=rev
Log:
ODE-194 Soap faults extravaganza, made sure we got them properly, transmit them properly and return them properly. Should comply a bit more with the profile as well.

Modified:
    ode/trunk/axis2/src/main/java/org/apache/ode/axis2/ExternalService.java
    ode/trunk/axis2/src/main/java/org/apache/ode/axis2/ODEService.java
    ode/trunk/axis2/src/main/java/org/apache/ode/axis2/hooks/ODEMessageReceiver.java
    ode/trunk/axis2/src/main/java/org/apache/ode/axis2/util/SoapMessageConverter.java
    ode/trunk/utils/src/main/java/org/apache/ode/utils/Namespaces.java

Modified: ode/trunk/axis2/src/main/java/org/apache/ode/axis2/ExternalService.java
URL: http://svn.apache.org/viewvc/ode/trunk/axis2/src/main/java/org/apache/ode/axis2/ExternalService.java?rev=583235&r1=583234&r2=583235&view=diff
==============================================================================
--- ode/trunk/axis2/src/main/java/org/apache/ode/axis2/ExternalService.java (original)
+++ ode/trunk/axis2/src/main/java/org/apache/ode/axis2/ExternalService.java Tue Oct  9 10:42:31 2007
@@ -115,6 +115,7 @@
             options.setAction(mctx.getSoapAction());
             options.setTo(axisEPR);
             options.setTimeOutInMilliSeconds(60000);
+            options.setExceptionToBeThrownOnSOAPFault(false);
 
             CachedServiceClient cached = _cachedClients.get();
             long now = System.currentTimeMillis();
@@ -139,10 +140,13 @@
                     operationClient.execute(true);
                     MessageContext response = operationClient.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
                     MessageContext flt = operationClient.getMessageContext(WSDLConstants.MESSAGE_LABEL_FAULT_VALUE);
+                    if (response != null && __log.isDebugEnabled())
+                        __log.debug("Got service response: " + response.getEnvelope().toString());
+                    
                     if (flt != null) {
                         reply(mexId, operation, flt, true);
                     } else {
-                        reply(mexId, operation, response, false);
+                        reply(mexId, operation, response, response.isFault());
                     }
                 } catch (Throwable t) {
                     String errmsg = "Error sending message to Axis2 for ODE mex " + odeMex;
@@ -269,19 +273,23 @@
         try {
             if (fault) {
                 faultType = _converter.parseSoapFault(odeMsgEl, reply.getEnvelope(), operation);
+                if (__log.isDebugEnabled()) __log.debug("Reply is a fault, found type: " + faultType);
             } else {
                 faultType = null;
                 _converter.parseSoapResponse(odeMsgEl, reply.getEnvelope(), operation);
             }
         } catch (AxisFault af) {
+            __log.warn("Message format error, failing.", af);
             replyWithFailure(odeMexId, FailureType.FORMAT_ERROR, af.getMessage(), null);
             return;
         }
 
         try {
             PartnerRoleMessageExchange odeMex = (PartnerRoleMessageExchange) _server.getMessageExchange(odeMexId);
-            Message response = fault ? odeMex.createMessage(odeMex.getOperation().getFault(faultType.getLocalPart()).getMessage()
-                    .getQName()) : odeMex.createMessage(odeMex.getOperation().getOutput().getMessage().getQName());
+            QName nonNullFT = faultType != null ? faultType : new QName(Namespaces.ODE_EXTENSION_NS, "unknownFault");
+            Message response = fault ? odeMex.createMessage(odeMex.getOperation()
+                    .getFault(nonNullFT.getLocalPart()).getMessage().getQName()) : odeMex
+                    .createMessage(odeMex.getOperation().getOutput().getMessage().getQName());
             try {
                 if (__log.isDebugEnabled()) {
                     __log.debug("Received response for MEX " + odeMex);

Modified: ode/trunk/axis2/src/main/java/org/apache/ode/axis2/ODEService.java
URL: http://svn.apache.org/viewvc/ode/trunk/axis2/src/main/java/org/apache/ode/axis2/ODEService.java?rev=583235&r1=583234&r2=583235&view=diff
==============================================================================
--- ode/trunk/axis2/src/main/java/org/apache/ode/axis2/ODEService.java (original)
+++ ode/trunk/axis2/src/main/java/org/apache/ode/axis2/ODEService.java Tue Oct  9 10:42:31 2007
@@ -27,8 +27,7 @@
 import javax.xml.namespace.QName;
 
 import org.apache.axiom.om.OMElement;
-import org.apache.axiom.soap.SOAPEnvelope;
-import org.apache.axiom.soap.SOAPFactory;
+import org.apache.axiom.soap.*;
 import org.apache.axis2.AxisFault;
 import org.apache.axis2.context.MessageContext;
 import org.apache.axis2.description.AxisService;
@@ -128,7 +127,6 @@
                 __log.debug("Handling response for MEX " + odeMex);
                 onResponse(odeMex, outMsgContext);
             }
-
         } catch (Exception e) {
             String errmsg = "Call to " + _serviceName + "." + odeMex.getOperationName() + " caused an exception.";
             __log.error(errmsg, e);
@@ -156,9 +154,12 @@
             case FAULT:
                 if (__log.isDebugEnabled())
                     __log.debug("Fault response message: " + mex.getFault());
-                OMElement detail = _converter.createSoapFault(mex.getFaultResponse().getMessage(), mex.getFault(), mex.getOperation());
-                String reason = mex.getFault()+" "+mex.getFaultExplanation();
-                throw new AxisFault(mex.getFault(), reason, null, null, detail);
+                SOAPFault fault = _converter.createSoapFault(mex.getFaultResponse().getMessage(), mex.getFault(), mex.getOperation());
+                msgContext.getEnvelope().getBody().addFault(fault);
+
+                if (__log.isDebugEnabled())
+                    __log.debug("Returning fault: " + msgContext.getEnvelope().toString());
+                break;
             case ONEWAY:
             case RESPONSE:
                 _converter.createSoapResponse(msgContext, mex.getResponse().getMessage(), mex.getOperation());

Modified: ode/trunk/axis2/src/main/java/org/apache/ode/axis2/hooks/ODEMessageReceiver.java
URL: http://svn.apache.org/viewvc/ode/trunk/axis2/src/main/java/org/apache/ode/axis2/hooks/ODEMessageReceiver.java?rev=583235&r1=583234&r2=583235&view=diff
==============================================================================
--- ode/trunk/axis2/src/main/java/org/apache/ode/axis2/hooks/ODEMessageReceiver.java (original)
+++ ode/trunk/axis2/src/main/java/org/apache/ode/axis2/hooks/ODEMessageReceiver.java Tue Oct  9 10:42:31 2007
@@ -35,56 +35,57 @@
  */
 public class ODEMessageReceiver extends AbstractMessageReceiver {
 
-  private static final Log __log = LogFactory.getLog(ODEMessageReceiver.class);
+    private static final Log __log = LogFactory.getLog(ODEMessageReceiver.class);
 
-  private ODEService _service;
+    private ODEService _service;
 
-  public final void invokeBusinessLogic(final MessageContext msgContext) throws AxisFault {
-    if (hasResponse(msgContext.getAxisOperation())) {
+    public final void invokeBusinessLogic(final MessageContext msgContext) throws AxisFault {
+        if (hasResponse(msgContext.getAxisOperation())) {
             if (__log.isDebugEnabled())
                 __log.debug("Received request message for " + msgContext.getAxisService().getName() + "."
                         + msgContext.getAxisOperation().getName());
-      // Client is expecting a response, running in the same thread
-      MessageContext outMsgContext = Utils.createOutMessageContext(msgContext);
-      outMsgContext.getOperationContext().addMessageContext(outMsgContext);
-      invokeBusinessLogic(msgContext, outMsgContext);
-      if (__log.isDebugEnabled()) {
+            // Client is expecting a response, running in the same thread
+            MessageContext outMsgContext = Utils.createOutMessageContext(msgContext);
+            outMsgContext.getOperationContext().addMessageContext(outMsgContext);
+            invokeBusinessLogic(msgContext, outMsgContext);
+            if (__log.isDebugEnabled()) {
                 __log.debug("Reply for " + msgContext.getAxisService().getName() + "."
                         + msgContext.getAxisOperation().getName());
-        __log.debug("Reply message " + outMsgContext.getEnvelope());
-      }
+                __log.debug("Reply message " + outMsgContext.getEnvelope());
+            }
             AxisEngine engine = new AxisEngine(msgContext.getOperationContext().getServiceContext()
                     .getConfigurationContext());
-      engine.send(outMsgContext);
-    } else {
+            engine.send(outMsgContext);
+        } else {
             if (__log.isDebugEnabled())
                 __log.debug("Received one-way message for " + msgContext.getAxisService().getName() + "."
                         + msgContext.getAxisOperation().getName());
             invokeBusinessLogic(msgContext, null);
+        }
     }
-  }
 
-  private void invokeBusinessLogic(MessageContext msgContext, MessageContext outMsgContext)
-          throws AxisFault {
-    _service.onAxisMessageExchange(msgContext, outMsgContext, getSOAPFactory(msgContext));
-  }
-
-  public void setService(ODEService service) {
-    _service = service;
-  }
+    private void invokeBusinessLogic(MessageContext msgContext, MessageContext outMsgContext)
+            throws AxisFault {
+        _service.onAxisMessageExchange(msgContext, outMsgContext, getSOAPFactory(msgContext));
 
-  private boolean hasResponse(AxisOperation op) {
+    }
+
+    public void setService(ODEService service) {
+        _service = service;
+    }
+
+    private boolean hasResponse(AxisOperation op) {
         switch (op.getAxisSpecificMEPConstant()) {
-        case WSDLConstants.MEP_CONSTANT_IN_OUT:
-            return true;
-        case WSDLConstants.MEP_CONSTANT_OUT_ONLY:
-            return true;
-        case WSDLConstants.MEP_CONSTANT_OUT_OPTIONAL_IN:
-            return true;
-        case WSDLConstants.MEP_CONSTANT_ROBUST_OUT_ONLY:
-            return true;
-        default:
-            return false;
+            case WSDLConstants.MEP_CONSTANT_IN_OUT:
+                return true;
+            case WSDLConstants.MEP_CONSTANT_OUT_ONLY:
+                return true;
+            case WSDLConstants.MEP_CONSTANT_OUT_OPTIONAL_IN:
+                return true;
+            case WSDLConstants.MEP_CONSTANT_ROBUST_OUT_ONLY:
+                return true;
+            default:
+                return false;
+        }
     }
-  }
 }

Modified: ode/trunk/axis2/src/main/java/org/apache/ode/axis2/util/SoapMessageConverter.java
URL: http://svn.apache.org/viewvc/ode/trunk/axis2/src/main/java/org/apache/ode/axis2/util/SoapMessageConverter.java?rev=583235&r1=583234&r2=583235&view=diff
==============================================================================
--- ode/trunk/axis2/src/main/java/org/apache/ode/axis2/util/SoapMessageConverter.java (original)
+++ ode/trunk/axis2/src/main/java/org/apache/ode/axis2/util/SoapMessageConverter.java Tue Oct  9 10:42:31 2007
@@ -22,10 +22,7 @@
 import org.apache.axiom.om.OMAbstractFactory;
 import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.OMNode;
-import org.apache.axiom.soap.SOAPEnvelope;
-import org.apache.axiom.soap.SOAPFactory;
-import org.apache.axiom.soap.SOAPFault;
-import org.apache.axiom.soap.SOAPFaultDetail;
+import org.apache.axiom.soap.*;
 import org.apache.axis2.AxisFault;
 import org.apache.axis2.context.MessageContext;
 import org.apache.axis2.namespace.Constants;
@@ -258,7 +255,20 @@
 
     }
 
-    public OMElement createSoapFault(Element message, QName faultName, Operation op) throws AxisFault {
+    public SOAPFault createSoapFault(Element message, QName faultName, Operation op) throws AxisFault {
+        OMElement detail = buildSoapDetail(message, faultName, op);
+
+        SOAPFault fault = _soapFactory.createSOAPFault();
+        SOAPFaultCode code = _soapFactory.createSOAPFaultCode(fault);
+        code.setText(new QName(Namespaces.SOAP_ENV_NS, "Server"));
+        SOAPFaultReason reason = _soapFactory.createSOAPFaultReason(fault);
+        reason.setText(faultName);
+        SOAPFaultDetail soapDetail = _soapFactory.createSOAPFaultDetail(fault);
+        soapDetail.addDetailEntry(detail.getFirstElement());
+        return fault;
+    }
+
+    private OMElement buildSoapDetail(Element message, QName faultName, Operation op) throws AxisFault {
         if (faultName.getNamespaceURI() == null || !faultName.getNamespaceURI().equals(_def.getTargetNamespace()))
             return toFaultDetail(faultName, message);
         Fault f = op.getFault(faultName.getLocalPart());
@@ -519,7 +529,8 @@
         if (flt.getDetail() == null)
             return null;
 
-        QName elName = flt.getDetail().getQName();
+        // The detail is a dummy <detail> node containing the interesting fault element
+        QName elName = flt.getDetail().getFirstElement().getQName();
         for (Fault f : (Collection<Fault>)operation.getFaults().values()) {
             if (f.getMessage() == null)
                 continue;  // should have checked in ctor
@@ -533,7 +544,6 @@
 
             if (p.getElementName().equals(elName))
                 return f;
-
         }
 
         return null;

Modified: ode/trunk/utils/src/main/java/org/apache/ode/utils/Namespaces.java
URL: http://svn.apache.org/viewvc/ode/trunk/utils/src/main/java/org/apache/ode/utils/Namespaces.java?rev=583235&r1=583234&r2=583235&view=diff
==============================================================================
--- ode/trunk/utils/src/main/java/org/apache/ode/utils/Namespaces.java (original)
+++ ode/trunk/utils/src/main/java/org/apache/ode/utils/Namespaces.java Tue Oct  9 10:42:31 2007
@@ -44,6 +44,7 @@
     public static final String WS_ADDRESSING_WSDL_NS = "http://www.w3.org/2006/05/addressing/wsdl";
     public static final String WS_ADDRESSING_ANON_URI = "http://www.w3.org/2005/08/addressing/anonymous";
     public static final String SOAP_NS = "http://schemas.xmlsoap.org/wsdl/soap/";
+    public static final String SOAP_ENV_NS = "http://schemas.xmlsoap.org/soap/envelope/";    
     public static final String WSDL_11 = "http://schemas.xmlsoap.org/wsdl/";
     public static final String WSDL_20 = "http://www.w3.org/2006/01/wsdl";
     public static final String XML_SCHEMA = "http://www.w3.org/2001/XMLSchema";