axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sc...@apache.org
Subject svn commit: r499795 - in /webservices/axis2/trunk/java/modules/jaxws: src/org/apache/axis2/jaxws/marshaller/impl/alt/ src/org/apache/axis2/jaxws/message/ src/org/apache/axis2/jaxws/message/util/ src/org/apache/axis2/jaxws/server/dispatcher/ test/org/ap...
Date Thu, 25 Jan 2007 13:52:05 GMT
Author: scheu
Date: Thu Jan 25 05:52:04 2007
New Revision: 499795

URL: http://svn.apache.org/viewvc?view=rev&rev=499795
Log:
AXIS2-1984
Contributor:Rich Scheuerle
SOAPFaultException Detail marshalling/demarshalling, SOAPFaultException w/ WebService Provider support, tests etc.

Modified:
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/alt/MethodMarshallerUtils.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/XMLFaultCode.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/util/XMLFaultUtils.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/dispatcher/ProviderDispatcher.java
    webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/provider/SoapMessageProviderTests.java
    webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/provider/soapmsg/SoapMessageProvider.java
    webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/FaultsServiceTests.java
    webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/faultsservice/FaultsServiceSoapBindingImpl.java

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/alt/MethodMarshallerUtils.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/alt/MethodMarshallerUtils.java?view=diff&rev=499795&r1=499794&r2=499795
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/alt/MethodMarshallerUtils.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/alt/MethodMarshallerUtils.java Thu Jan 25 05:52:04 2007
@@ -424,14 +424,12 @@
      * @param packages Packages needed to marshal the object
      * @param message Message
      * @param isRPC
-     * @throws WebServiceException
-     * @throws NoSuchMethodException
-     * @throws InvocationTargetException
-     * @throws IllegalAccessException
      */
-    static void marshalFaultResponse(Throwable throwable, OperationDescription operationDesc,  Set<String> packages, Message message, boolean isRPC)
-     throws WebServiceException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
-        
+    static void marshalFaultResponse(Throwable throwable, 
+            OperationDescription operationDesc,  
+            Set<String> packages, 
+            Message message, 
+            boolean isRPC) {
         // Get the root cause of the throwable object
         Throwable t = ClassUtils.getRootCause(throwable);
         if (log.isDebugEnabled()) {
@@ -439,120 +437,172 @@
             log.debug("  rootCause =" + t.getClass().getName());
             log.debug("  exception=" + t.toString());
         }
-
+        
         XMLFault xmlfault = null;
-      
-        // There are 5 different categories of exceptions.  Each category has a little different marshaling code.
-        // A) Service Exception that matches the JAX-WS specification (chapter 2.5 of the spec)
-        // B) Service Exception that matches the JAX-WS "legacy" exception (chapter 3.7 of the spec)
-        // C) SOAPFaultException
-        // D) WebServiceException
-        // E) Other runtime exceptions (i.e. NullPointerException)
         
-        // Get the FaultDescriptor matching this Exception.
-        // If FaultDescriptor is found, this is a JAX-B Service Exception.
-        // If not found, this is a System Exception
-        FaultDescription fd = operationDesc.resolveFaultByExceptionName(t.getClass().getCanonicalName());
-
-        if (t instanceof SOAPFaultException) {
-            if (log.isErrorEnabled()) {
-                log.debug("Marshal SOAPFaultException");
-            }
-            // Category C: SOAPFaultException 
-            // Construct the xmlFault from the SOAPFaultException's Fault
-            SOAPFaultException sfe = (SOAPFaultException) t;
-            SOAPFault soapFault = sfe.getFault();
-            if (soapFault == null) {
-                // No fault ?  I will treat this like category E
-                xmlfault = new XMLFault(null,       // Use the default XMLFaultCode
-                        new XMLFaultReason(t.toString()));  // Assumes text is the language supported by the current Locale
-            } else {
-                xmlfault = XMLFaultUtils.createXMLFault(soapFault);
+        try {
+             
+            // There are 5 different categories of exceptions.  Each category has a little different marshaling code.
+            // A) Service Exception that matches the JAX-WS specification (chapter 2.5 of the spec)
+            // B) Service Exception that matches the JAX-WS "legacy" exception (chapter 3.7 of the spec)
+            // C) SOAPFaultException
+            // D) WebServiceException
+            // E) Other runtime exceptions (i.e. NullPointerException)
+            
+            // Get the FaultDescriptor matching this Exception.
+            // If FaultDescriptor is found, this is a JAX-B Service Exception.
+            // If not found, this is a System Exception
+            FaultDescription fd = operationDesc.resolveFaultByExceptionName(t.getClass().getCanonicalName());
+            
+            if (fd != null) {
+                if (log.isErrorEnabled()) {
+                    log.debug("Marshal as a Service Exception");
+                }
+                // The exception is a Service Exception.  It may be (A) JAX-WS compliant exception or (B) JAX-WS legacy exception
+                
+                // The faultBeanObject is a JAXB object that represents the data of the exception.  It is marshalled in the detail
+                // section of the soap fault.  The faultBeanObject is obtained direction from the exception (A) or via 
+                // the legacy exception rules (B).
+                Object faultBeanObject = null;
+                
+                if (LegacyExceptionUtil.isLegacyException(t.getClass())) {
+                    // Legacy Exception case
+                    faultBeanObject = LegacyExceptionUtil.createFaultBean(t, fd);
+                } else {
+                    // Normal case
+                    // Get the fault bean object.  
+                    Method getFaultInfo = t.getClass().getMethod("getFaultInfo", null);
+                    faultBeanObject = getFaultInfo.invoke(t, null);
+                }
+                
+                if (log.isErrorEnabled()) {
+                    log.debug("The faultBean type is" + faultBeanObject.getClass().getName());
+                }
+                // Make sure the faultBeanObject can be marshalled as an element
+                if (!XMLRootElementUtil.isElementEnabled(faultBeanObject.getClass())) {
+                    faultBeanObject = XMLRootElementUtil.getElementEnabledObject(fd.getTargetNamespace(), fd.getName(), 
+                            faultBeanObject.getClass(), faultBeanObject);
+                }
+                
+                
+                // Create the JAXBBlockContext
+                // RPC uses type marshalling, so recored the rpcType
+                JAXBBlockContext context = new JAXBBlockContext(packages);
+                if (isRPC) {
+                    context.setRPCType(faultBeanObject.getClass());
+                }
+                
+                // Create a detailblock representing the faultBeanObject
+                Block[] detailBlocks = new Block[1];
+                detailBlocks[0] = factory.createFrom(faultBeanObject,context,null);
+                
+                if (log.isErrorEnabled()) {
+                    log.debug("Create the xmlFault for the Service Exception");
+                }
+                // Get the fault text using algorithm defined in JAX-WS 10.2.2.3
+                String text = t.getMessage();
+                if (text == null || text.length() == 0) {
+                    text = t.toString();
+                }
+                // Now make a XMLFault containing the detailblock
+                xmlfault = new XMLFault(null, new XMLFaultReason(text), detailBlocks);
+            }  else {
+                xmlfault = createXMLFaultFromSystemException(t);
+            }
+        } catch (Throwable e) {
+            // If an exception occurs while demarshalling an exception, then rinse and repeat with a system exception
+            if (log.isDebugEnabled()) {
+                log.debug("An exception (" + e + ") occurred while marshalling exception (" + t + ")");
             }
+            WebServiceException wse = ExceptionFactory.makeWebServiceException(e);
+            xmlfault = createXMLFaultFromSystemException(wse);
+        }
             
-        } else if (fd != null) {
-            if (log.isErrorEnabled()) {
-                log.debug("Marshal as a Service Exception");
-            }
-            // The exception is a Service Exception.  It may be (A) JAX-WS compliant exception or (B) JAX-WS legacy exception
-            
-            // The faultBeanObject is a JAXB object that represents the data of the exception.  It is marshalled in the detail
-            // section of the soap fault.  The faultBeanObject is obtained direction from the exception (A) or via 
-            // the legacy exception rules (B).
-            Object faultBeanObject = null;
-       
-            if (LegacyExceptionUtil.isLegacyException(t.getClass())) {
-                // Legacy Exception case
-                faultBeanObject = LegacyExceptionUtil.createFaultBean(t, fd);
+        // Add the fault to the message
+        message.setXMLFault(xmlfault);
+    }
+    
+    /**
+     * This method is used by WebService Impl and Provider to create
+     * an XMLFault (for marshalling) from an exception that is a non-service exception
+     * @param t Throwable that represents a Service Exception
+     * @return XMLFault
+     */
+    public static XMLFault createXMLFaultFromSystemException(Throwable t) {
+        
+        try {
+            XMLFault xmlfault = null;
+            if (t instanceof SOAPFaultException) {
+                if (log.isErrorEnabled()) {
+                    log.debug("Marshal SOAPFaultException");
+                }
+                // Category C: SOAPFaultException 
+                // Construct the xmlFault from the SOAPFaultException's Fault
+                SOAPFaultException sfe = (SOAPFaultException) t;
+                SOAPFault soapFault = sfe.getFault();
+                if (soapFault == null) {
+                    // No fault ?  I will treat this like category E
+                    xmlfault = new XMLFault(null,       // Use the default XMLFaultCode
+                            new XMLFaultReason(t.toString()));  // Assumes text is the language supported by the current Locale
+                } else {
+                    xmlfault = XMLFaultUtils.createXMLFault(soapFault);
+                }
+                
+            } else if (t instanceof WebServiceException) {
+                if (log.isErrorEnabled()) {
+                    log.debug("Marshal as a WebServiceException");
+                }
+                // Category D: WebServiceException
+                // The reason is constructed with the getMessage of the exception.  
+                // There is no detail
+                WebServiceException wse = (WebServiceException) t;
+                
+                // Get the fault text using algorithm defined in JAX-WS 10.2.2.3
+                String text = wse.getMessage();
+                if (text == null || text.length() == 0) {
+                    text = wse.toString();
+                }
+                xmlfault = new XMLFault(null,       // Use the default XMLFaultCode
+                        new XMLFaultReason(text));  // Assumes text is the language supported by the current Locale
             } else {
-                // Normal case
-                // Get the fault bean object.  
-                Method getFaultInfo = t.getClass().getMethod("getFaultInfo", null);
-                faultBeanObject = getFaultInfo.invoke(t, null);
-            }
-            
-            if (log.isErrorEnabled()) {
-                log.debug("The faultBean type is" + faultBeanObject.getClass().getName());
-            }
-            // Make sure the faultBeanObject can be marshalled as an element
-            if (!XMLRootElementUtil.isElementEnabled(faultBeanObject.getClass())) {
-                faultBeanObject = XMLRootElementUtil.getElementEnabledObject(fd.getTargetNamespace(), fd.getName(), 
-                        faultBeanObject.getClass(), faultBeanObject);
-            }
-            
-            
-            // Create the JAXBBlockContext
-            // RPC uses type marshalling, so recored the rpcType
-            JAXBBlockContext context = new JAXBBlockContext(packages);
-            if (isRPC) {
-                context.setRPCType(faultBeanObject.getClass());
-            }
-            
-            // Create a detailblock representing the faultBeanObject
-            Block[] detailBlocks = new Block[1];
-            detailBlocks[0] = factory.createFrom(faultBeanObject,context,null);
-            
-            if (log.isErrorEnabled()) {
-                log.debug("Create the xmlFault for the Service Exception");
-            }
-            // Now make a XMLFault containing the detailblock
-            xmlfault = new XMLFault(null, new XMLFaultReason(t.getMessage()), detailBlocks);
-        } else if (t instanceof WebServiceException) {
-            if (log.isErrorEnabled()) {
-                log.debug("Marshal as a WebServiceException");
-            }
-            // Category D: WebServiceException
-            // The reason is constructed with the getMessage of the exception.  
-            // There is no detail
-            WebServiceException wse = (WebServiceException) t;
-            
-            // Get the fault text using algorithm defined in JAX-WS 10.2.2.3
-            String text = wse.getMessage();
-            if (text == null || text.length() == 0) {
-                text = wse.toString();
-            }
-            xmlfault = new XMLFault(null,       // Use the default XMLFaultCode
-                    new XMLFaultReason(text));  // Assumes text is the language supported by the current Locale
-        } else {
-            if (log.isErrorEnabled()) {
-                log.debug("Marshal as a unchecked System Exception");
+                if (log.isErrorEnabled()) {
+                    log.debug("Marshal as a unchecked System Exception");
+                }
+                // Category E: Other System Exception
+                // The reason is constructed with the toString of the exception.  
+                // This places the class name of the exception in the reason
+                // There is no detail.
+                // Get the fault text using algorithm defined in JAX-WS 10.2.2.3
+                String text = t.getMessage();
+                if (text == null || text.length() == 0) {
+                    text = t.toString();
+                }
+                xmlfault = new XMLFault(null,       // Use the default XMLFaultCode
+                        new XMLFaultReason(text));  // Assumes text is the language supported by the current Locale
             }
-            // Category E: Other System Exception
-            // The reason is constructed with the toString of the exception.  
-            // This places the class name of the exception in the reason
-            // There is no detail.
-            // Get the fault text using algorithm defined in JAX-WS 10.2.2.3
-            String text = t.getMessage();
-            if (text == null || text.length() == 0) {
-                text = t.toString();
+            return xmlfault;
+        } catch (Throwable e) {
+            try {
+                // If an exception occurs while demarshalling an exception, then rinse and repeat with a webservice exception
+                if (log.isDebugEnabled()) {
+                    log.debug("An exception (" + e + ") occurred while marshalling exception (" + t + ")");
+                }
+                // Get the fault text using algorithm defined in JAX-WS 10.2.2.3
+                String text = e.getMessage();
+                if (text == null || text.length() == 0) {
+                    text = e.toString();
+                }
+                WebServiceException wse = ExceptionFactory.makeWebServiceException(e);
+                
+                return new XMLFault(null,       // Use the default XMLFaultCode
+                        new XMLFaultReason(text));  // Assumes text is the language supported by the current Locale
+            } catch (Exception e2) {
+                // Exception while creating Exception for Exception
+                throw ExceptionFactory.makeWebServiceException(e2);
             }
-            xmlfault = new XMLFault(null,       // Use the default XMLFaultCode
-                    new XMLFaultReason(text));  // Assumes text is the language supported by the current Locale
         }
-        // Add the fault to the message
-        message.setXMLFault(xmlfault);
     }
-    
+            
     /**
      * Unmarshal the service/system exception from a Message.
      * This is used by all of the marshallers

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/XMLFaultCode.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/XMLFaultCode.java?view=diff&rev=499795&r1=499794&r2=499795
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/XMLFaultCode.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/XMLFaultCode.java Thu Jan 25 05:52:04 2007
@@ -91,6 +91,10 @@
      * @return corresponding XMLPart
      */
     public static XMLFaultCode fromQName(QName qName) {
+        if (qName == null) {
+            // Spec indicates that the default is receiver
+            return RECEIVER;
+        }
         String namespace = qName.getNamespaceURI();
         String localPart = qName.getLocalPart();
         XMLFaultCode xmlFaultCode= RECEIVER;

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/util/XMLFaultUtils.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/util/XMLFaultUtils.java?view=diff&rev=499795&r1=499794&r2=499795
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/util/XMLFaultUtils.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/util/XMLFaultUtils.java Thu Jan 25 05:52:04 2007
@@ -23,8 +23,10 @@
 
 import javax.xml.namespace.QName;
 import javax.xml.soap.Detail;
+import javax.xml.soap.DetailEntry;
 import javax.xml.soap.SOAPConstants;
 import javax.xml.soap.SOAPException;
+import javax.xml.stream.XMLStreamException;
 import javax.xml.ws.WebServiceException;
 
 import org.apache.axiom.om.OMElement;
@@ -235,8 +237,7 @@
         // </env:Envelope>
         
         
-        // Get the code
-        // TODO what if this fails ?  Log a message and treat like a RECEIVER fault ?
+        // Get the code or default code
         QName codeQName = soapFault.getFaultCodeAsQName();
         XMLFaultCode code = XMLFaultCode.fromQName(codeQName);
         
@@ -251,79 +252,68 @@
         XMLFault xmlFault = new XMLFault(code, reason, detailBlocks);
         
         
+        boolean isSOAP12 = soapFault.getNamespaceURI().equals(SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE);
         
         // Add the secondary fault information
  
         // Get the SubCodes
-        /* REVIEW The following needs to be added
-         
-        SOAPFaultSubCode soapSubCode = soapCode.getSubCode();
-        if (soapSubCode != null) {
+        if (isSOAP12) {
+            Iterator it = soapFault.getFaultSubcodes();
             List<QName> list = new ArrayList<QName>();
-            
-            // Walk the nested sub codes and collect the qnames
-            while (soapSubCode != null) {
-                SOAPFaultValue soapSubCodeValue = soapSubCode.getValue();
-                QName qName = soapSubCodeValue.getTextAsQName();
-                list.add(qName);
-                soapSubCode = soapSubCode.getSubCode();
+            while (it.hasNext()) {
+                QName qName = (QName) it.next();
+            }
+            if (list.size() > 0) {
+                QName[] subCodes = new QName[list.size()];
+                subCodes = list.toArray(subCodes);
+                xmlFault.setSubCodes(subCodes);
             }
-            
-            // Put the collected sub code qnames onto the xmlFault
-            QName[] qNames = new QName[list.size()];
-            xmlFault.setSubCodes(list.toArray(qNames));
         }
         
+        
         // Get the secondary Reasons...the first reason was already saved as the primary reason
-        if (soapTexts.size() > 1) {
-            XMLFaultReason[] secondaryReasons = new XMLFaultReason[soapTexts.size() - 1];
-            for (int i= 1; i<soapTexts.size(); i++) {
-                SOAPFaultText soapReasonText = (SOAPFaultText) soapTexts.get(i);
-                secondaryReasons[i-1] = new XMLFaultReason(soapReasonText.getText(), 
-                                                           soapReasonText.getLang());
+        if (isSOAP12) {
+            try {
+                Iterator it = soapFault.getFaultReasonLocales();
+                boolean first = true;
+                List<XMLFaultReason> list = new ArrayList<XMLFaultReason>();
+                while (it.hasNext()) {
+                    locale = (Locale) it.next();
+                    if (first) {
+                        first = false;
+                    } else {
+                        text = soapFault.getFaultReasonText(locale);
+                        lang = locale.getLanguage();
+                        list.add(new XMLFaultReason(text, lang));
+                    }
+                }
+                if (list.size() > 0) {
+                    XMLFaultReason[] secondaryReasons = new XMLFaultReason[list.size()];
+                    secondaryReasons = list.toArray(secondaryReasons);
+                    xmlFault.setSecondaryReasons(secondaryReasons);
+                }
+            } catch (SOAPException se) {
+                throw ExceptionFactory.makeWebServiceException(se);
             }
-            xmlFault.setSecondaryReasons(secondaryReasons);
         }
         
         // Get the Node
-        SOAPFaultNode soapNode = soapFault.getNode();
-        if (soapNode != null) {
-            xmlFault.setNode(soapNode.getText());
+        if (isSOAP12) {
+            String soapNode = soapFault.getFaultNode();
+            if (soapNode != null) {
+                xmlFault.setNode(soapNode);
+            }
         }
         
         // Get the Role
-        SOAPFaultRole soapRole = soapFault.getRole();
+        String soapRole = soapFault.getFaultActor();  // getFaultActor works for both SOAP 1.1 and SOAP 1.2 per spec
         if (soapRole != null) {
-            xmlFault.setRole(soapRole.getText());
+            xmlFault.setRole(soapRole);
         }
-        */
-        return xmlFault;         
-    }
-    /**
-     * Create an XMLFault object from a SOAPFault and detail Blocks
-     * @param soapFault
-     * @param detailBlocks
-     * @return
-     */
-    /*
-    public static XMLFault createXMLFault(javax.xml.soap.SOAPFault soapFault) throws WebServiceException {
         
-       // Convert the SOAPFault into an OM SOAPFault.  OMSOAP Fault already supports SOAP 1.2, so this makes the code easier to migrate
-       
-       SAAJConverterFactory converterFactory = 
-           (SAAJConverterFactory) FactoryRegistry.getFactory(SAAJConverterFactory.class);
-       SAAJConverter converter = converterFactory.getSAAJConverter();
-       
-       javax.xml.soap.SOAPBody body = (javax.xml.soap.SOAPBody) soapFault.getParentElement();
-       javax.xml.soap.SOAPEnvelope env = (javax.xml.soap.SOAPEnvelope) body.getParentElement();
-       SOAPEnvelope omSOAPEnv = converter.toOM(env);
-       SOAPFault omSOAPFault = omSOAPEnv.getBody().getFault();
-       Block[] detailBlocks = getDetailBlocks(omSOAPFault);
-       XMLFault xmlFault = createXMLFault(omSOAPFault, detailBlocks);
-      
-       return xmlFault;
+        return xmlFault;         
     }
-    */
+    
     
     private static Block[] getDetailBlocks(SOAPFault soapFault) throws WebServiceException {
         try {
@@ -339,6 +329,7 @@
                     Block b = bf.createFrom(om, null,om.getQName()); 
                     list.add(b);
                 }
+                blocks = new Block[list.size()];
                 blocks = list.toArray(blocks);
             }
             return blocks;
@@ -352,15 +343,21 @@
             Block[] blocks = null;
             Detail detail = soapFault.getDetail();
             if (detail != null) {
+                // Get a SAAJ->OM converter
+                SAAJConverterFactory converterFactory = (SAAJConverterFactory) FactoryRegistry.getFactory(SAAJConverterFactory.class);
+                SAAJConverter converter = converterFactory.getSAAJConverter();
+                
                 // Create a block for each element
                 OMBlockFactory bf = (OMBlockFactory) FactoryRegistry.getFactory(OMBlockFactory.class);
                 ArrayList<Block> list = new ArrayList<Block>();
                 Iterator it = detail.getChildElements();
                 while (it.hasNext()) {
-                    OMElement om = (OMElement) it.next();
+                    DetailEntry de = (DetailEntry) it.next();
+                    OMElement om = converter.toOM(de);
                     Block b = bf.createFrom(om, null,om.getQName()); 
                     list.add(b);
                 }
+                blocks = new Block[list.size()];
                 blocks = list.toArray(blocks);
             }
             return blocks;
@@ -473,12 +470,14 @@
         if (xmlFault.getRole() != null) {
             SOAPFaultRole soapRole = factory.createSOAPFaultRole();
             soapRole.setText(xmlFault.getRole());
+            soapFault.setRole(soapRole);
         }
         
         // Set the Node
         if (xmlFault.getNode() != null) {
             SOAPFaultNode soapNode = factory.createSOAPFaultNode();
             soapNode.setText(xmlFault.getNode());
+            soapFault.setNode(soapNode);
         }
            
         return soapFault;
@@ -540,60 +539,57 @@
                     Locale.getDefault();
         soapFault.setFaultString(reasonText, locale);
         
-        /*
+        
         // Set the Detail and contents of Detail
         Block[] blocks = xmlFault.getDetailBlocks();
         if (blocks != null && blocks.length > 0) {
-            SOAPFaultDetail detail = factory.createSOAPFaultDetail(soapFault);
-            if (!ignoreDetailBlocks) {
-                for (int i=0; i<blocks.length; i++) {
-                    // A Block implements OMDataSource.  So create OMSourcedElements
-                    // for each of the Blocks.
-                    OMSourcedElementImpl element = 
-                        new OMSourcedElementImpl(blocks[i].getQName(), factory, blocks[i]);
-                    detail.addChild(element);
+            Detail detail = soapFault.addDetail();
+            // Get a OM->SAAJ converter
+            SAAJConverterFactory converterFactory = (SAAJConverterFactory) FactoryRegistry.getFactory(SAAJConverterFactory.class);
+            SAAJConverter converter = converterFactory.getSAAJConverter();
+            for (int i=0; i<blocks.length; i++) {
+                try {
+                    converter.toSAAJ(blocks[i].getOMElement(), detail);
+                } catch (XMLStreamException xse) {
+                    ExceptionFactory.makeWebServiceException(xse);
                 }
             }
+            
         }
         
+        
         // Now set all of the secondary fault information
         // Set the SubCodes
         QName[] subCodes = xmlFault.getSubCodes();
-        if (subCodes != null && subCodes.length > 0) {
-           OMElement curr = soapCode;
-           for (int i=0; i<subCodes.length; i++) {
-               SOAPFaultSubCode subCode = (i==0) ?
-                       factory.createSOAPFaultSubCode((SOAPFaultCode)    curr) :
-                       factory.createSOAPFaultSubCode((SOAPFaultSubCode) curr);
-               SOAPFaultValue soapSubCodeValue = factory.createSOAPFaultValue(subCode);
-               soapSubCodeValue.setText(subCodes[i]);
-               curr = subCode;
+        if (subCodes != null && subCodes.length > 0 && protocolNS.equals(SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE)) {
+            for (int i=0; i<subCodes.length; i++) {
+               soapFault.appendFaultSubcode(subCodes[i]);
            }
         }
         
         // Set the secondary reasons and languages
         XMLFaultReason reasons[] = xmlFault.getSecondaryReasons();
-        if (reasons != null && reasons.length > 0) {
+        if (reasons != null && reasons.length > 0 && protocolNS.equals(SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE)) {
             for (int i=0; i<reasons.length; i++) {
-                SOAPFaultText soapReasonText = factory.createSOAPFaultText(soapReason);
-                soapReasonText.setText(reasons[i].getText());
-                soapReasonText.setLang(reasons[i].getLang());
+                if (reasons[i].getLang() == null || reasons[i].getLang().length() == 0) {
+                    locale = Locale.getDefault();
+                } else {
+                    locale = new Locale(reasons[i].getLang());
+                }
+                soapFault.addFaultReasonText(reasons[i].getText(), locale);
             }
         }
         
         // Set the Role
         if (xmlFault.getRole() != null) {
-            SOAPFaultRole soapRole = factory.createSOAPFaultRole();
-            soapRole.setText(xmlFault.getRole());
+            soapFault.setFaultActor(xmlFault.getRole());  // Use Fault actor because it is applicable for SOAP 1.1 and SOAP 1.2
         }
         
-        // Set the Node
-        if (xmlFault.getNode() != null) {
-            SOAPFaultNode soapNode = factory.createSOAPFaultNode();
-            soapNode.setText(xmlFault.getNode());
+        // Set the Node...only applicable for SOAP 1.2
+        if (xmlFault.getNode() != null && protocolNS.equals(SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE)) {
+            soapFault.setFaultRole(xmlFault.getNode());
         }
            
-           */
         return soapFault;
             
     }

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/dispatcher/ProviderDispatcher.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/dispatcher/ProviderDispatcher.java?view=diff&rev=499795&r1=499794&r2=499795
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/dispatcher/ProviderDispatcher.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/dispatcher/ProviderDispatcher.java Thu Jan 25 05:52:04 2007
@@ -37,6 +37,7 @@
 import org.apache.axis2.jaxws.core.util.MessageContextUtils;
 import org.apache.axis2.jaxws.description.EndpointDescription;
 import org.apache.axis2.jaxws.i18n.Messages;
+import org.apache.axis2.jaxws.marshaller.impl.alt.MethodMarshallerUtils;
 import org.apache.axis2.jaxws.message.Block;
 import org.apache.axis2.jaxws.message.Message;
 import org.apache.axis2.jaxws.message.Protocol;
@@ -49,6 +50,7 @@
 import org.apache.axis2.jaxws.message.factory.SourceBlockFactory;
 import org.apache.axis2.jaxws.message.factory.XMLStringBlockFactory;
 import org.apache.axis2.jaxws.registry.FactoryRegistry;
+import org.apache.axis2.jaxws.util.ClassUtils;
 import org.apache.axis2.wsdl.WSDLConstants.WSDL20_2004Constants;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -177,9 +179,13 @@
             	}
             });
         } catch (Exception e) {
-            e.printStackTrace();
-            //throw ExceptionFactory.makeWebServiceException(e);
-            responseParamValue = new XMLFault(XMLFaultCode.RECEIVER, new XMLFaultReason(e.toString()));
+            Throwable t = ClassUtils.getRootCause(e);
+            if (log.isDebugEnabled()) {
+                log.debug("Marshal Throwable =" + e.getClass().getName());
+                log.debug("  rootCause =" + t.getClass().getName());
+                log.debug("  exception=" + t.toString());
+            }
+            responseParamValue =MethodMarshallerUtils.createXMLFaultFromSystemException(t);
         }
 
         // If we have a one-way operation, then we cannot create a MessageContext 

Modified: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/provider/SoapMessageProviderTests.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/provider/SoapMessageProviderTests.java?view=diff&rev=499795&r1=499794&r2=499795
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/provider/SoapMessageProviderTests.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/provider/SoapMessageProviderTests.java Thu Jan 25 05:52:04 2007
@@ -22,16 +22,19 @@
 
 import javax.xml.namespace.QName;
 import javax.xml.soap.AttachmentPart;
+import javax.xml.soap.DetailEntry;
 import javax.xml.soap.MessageFactory;
 import javax.xml.soap.Node;
 import javax.xml.soap.SOAPBody;
 import javax.xml.soap.SOAPElement;
+import javax.xml.soap.SOAPFault;
 import javax.xml.soap.SOAPMessage;
 import javax.xml.transform.stream.StreamSource;
 import javax.xml.ws.Binding;
 import javax.xml.ws.Dispatch;
 import javax.xml.ws.Service;
 import javax.xml.ws.soap.SOAPBinding;
+import javax.xml.ws.soap.SOAPFaultException;
 
 import org.apache.axis2.jaxws.provider.soapmsg.SoapMessageProvider;
 
@@ -54,6 +57,9 @@
     private String XML_INVOKE = "<ns2:invoke xmlns:ns2=\"http://org.test.soapmessage\"><invoke_str>" + 
         SoapMessageProvider.XML_REQUEST +
         "</invoke_str></ns2:invoke>";
+    private String EMPTYBODY_INVOKE = "<ns2:invoke xmlns:ns2=\"http://org.test.soapmessage\"><invoke_str>" + 
+        SoapMessageProvider.XML_EMPTYBODY_REQUEST +
+        "</invoke_str></ns2:invoke>";
     private String ATTACHMENT_INVOKE = "<ns2:invoke xmlns:ns2=\"http://org.test.soapmessage\"><invoke_str>" + 
         SoapMessageProvider.XML_ATTACHMENT_REQUEST +
         "</invoke_str></ns2:invoke>";
@@ -70,6 +76,9 @@
     private String XML_FAULT_INVOKE = "<ns2:invoke xmlns:ns2=\"http://org.test.soapmessage\"><invoke_str>" + 
     SoapMessageProvider.XML_FAULT_REQUEST +
     "</invoke_str></ns2:invoke>";
+    private String XML_WSE_INVOKE = "<ns2:invoke xmlns:ns2=\"http://org.test.soapmessage\"><invoke_str>" + 
+    SoapMessageProvider.XML_WSE_REQUEST +
+    "</invoke_str></ns2:invoke>";
                 
     
     protected void setUp() throws Exception {
@@ -127,11 +136,51 @@
     }
     
     /**
+     * Sends an SOAPMessage containing only xml data to the web service.  
+     * Receives a response containing an empty body
+     */
+    public void testProviderSourceXMLEmptyBody(){
+        try{       
+            // Create the dispatch
+            Dispatch<SOAPMessage> dispatch = createDispatch();
+            
+            // Create the SOAPMessage
+            String msg = reqMsgStart + EMPTYBODY_INVOKE + reqMsgEnd;
+            MessageFactory factory = MessageFactory.newInstance();
+            SOAPMessage request = factory.createMessage(null, 
+                    new ByteArrayInputStream(msg.getBytes()));
+            
+            // Test the transport headers by sending a content description
+            request.setContentDescription(SoapMessageProvider.XML_EMPTYBODY_REQUEST);
+            
+            // Dispatch
+            System.out.println(">> Invoking SourceMessageProviderDispatch");
+            SOAPMessage response = dispatch.invoke(request);
+            
+            // Check assertions
+            assertTrue(response !=null);
+            assertTrue(response.getSOAPBody() != null);
+            assertTrue(response.getSOAPBody().getFirstChild() == null);  // There should be nothing in the body
+            
+            assertTrue(countAttachments(response) == 0);
+            
+            // Print out the response
+            System.out.println(">> Response [" + response.toString() + "]");
+            response.writeTo(System.out);
+            
+        }catch(Exception e){
+            e.printStackTrace();
+            fail("Caught exception " + e);
+        }
+        
+    }
+    
+    /**
      * Sends an SOAPMessage containing only xml data 
      * Provider will throw a Fault
      */
-    public void testProviderSOAPFault(){
-        try{       
+    public void testProviderSOAPFault() throws Exception {
+             
             // Create the dispatch
             Dispatch<SOAPMessage> dispatch = createDispatch();
             
@@ -149,17 +198,49 @@
                 System.out.println(">> Invoking SourceMessageProviderDispatch");
                 SOAPMessage response = dispatch.invoke(request);
                 assertTrue("Expected failure", false);
-            } catch (Exception e) {
-                
-            }
-
-           
+            } catch (SOAPFaultException e) {
+                // Okay
+                SOAPFault fault = e.getFault();
+                assertTrue(fault != null);
+                assertTrue(fault.getFaultString().equals("sample fault"));
+                assertTrue(fault.getDetail() != null);
+                DetailEntry de = (DetailEntry) fault.getDetail().getDetailEntries().next();
+                assertTrue(de != null);
+                assertTrue(de.getLocalName().equals("detailEntry"));
+                assertTrue(de.getValue().equals("sample detail"));
+                assertTrue(fault.getFaultActor().equals("sample actor"));
+            }    
+    }
+    
+    /**
+     * Sends an SOAPMessage containing only xml data 
+     * Provider will throw a generic WebServicesException
+     */
+    public void testProviderWebServiceException() throws Exception {
+             
+            // Create the dispatch
+            Dispatch<SOAPMessage> dispatch = createDispatch();
             
-        }catch(Exception e){
-            e.printStackTrace();
-            fail("Caught exception " + e);
-        }
-        
+            // Create the SOAPMessage
+            String msg = reqMsgStart + XML_WSE_INVOKE + reqMsgEnd;
+            MessageFactory factory = MessageFactory.newInstance();
+            SOAPMessage request = factory.createMessage(null, 
+                    new ByteArrayInputStream(msg.getBytes()));
+            
+            // Test the transport headers by sending a content description
+            request.setContentDescription(SoapMessageProvider.XML_WSE_REQUEST);
+            
+            try {
+                // Dispatch
+                System.out.println(">> Invoking SourceMessageProviderDispatch");
+                SOAPMessage response = dispatch.invoke(request);
+                assertTrue("Expected failure", false);
+            } catch (SOAPFaultException e) {
+                // Okay...SOAPFaultException should be thrown
+                SOAPFault fault = e.getFault();
+                assertTrue(fault != null);
+                assertTrue(fault.getFaultString().equals("A WSE was thrown"));
+            }    
     }
     
     /**

Modified: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/provider/soapmsg/SoapMessageProvider.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/provider/soapmsg/SoapMessageProvider.java?view=diff&rev=499795&r1=499794&r2=499795
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/provider/soapmsg/SoapMessageProvider.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/provider/soapmsg/SoapMessageProvider.java Thu Jan 25 05:52:04 2007
@@ -41,6 +41,7 @@
 import javax.xml.ws.Provider;
 import javax.xml.ws.Service;
 import javax.xml.ws.ServiceMode;
+import javax.xml.ws.WebServiceException;
 import javax.xml.ws.WebServiceProvider;
 import javax.xml.ws.soap.SOAPBinding;
 import javax.xml.ws.soap.SOAPFaultException;
@@ -62,6 +63,7 @@
     
     public static String XML_REQUEST              = "xml request";
     public static String XML_RESPONSE             = "xml response";
+    public static String XML_EMPTYBODY_REQUEST    = "xml empty body request";
     public static String XML_ATTACHMENT_REQUEST   = "xml and attachment request";
     public static String XML_ATTACHMENT_RESPONSE  = "xml and attachment response";
     public static String XML_MTOM_REQUEST         = "xml and mtom request";
@@ -69,6 +71,7 @@
     public static String XML_SWAREF_REQUEST       = "xml and swaref request";
     public static String XML_SWAREF_RESPONSE      = "xml and swaref response";
     public static String XML_FAULT_REQUEST        = "xml fault";
+    public static String XML_WSE_REQUEST        = "xml wse fault";
     
     private String XML_RETURN = "<ns2:ReturnType xmlns:ns2=\"http://test\"><return_str>" + 
         SoapMessageProvider.XML_RESPONSE +
@@ -118,6 +121,8 @@
             String text = discElement.getValue();
             if (XML_REQUEST.equals(text)) {
                 response = getXMLResponse(soapMessage, discElement);
+            } else if (XML_EMPTYBODY_REQUEST.equals(text)) {
+                response = getXMLEmptyBodyResponse(soapMessage, discElement);
             } else if (XML_ATTACHMENT_REQUEST.equals(text)) {
                 response = getXMLAttachmentResponse(soapMessage, discElement);
             } else if (XML_MTOM_REQUEST.equals(text)) {
@@ -126,6 +131,8 @@
                 response = getXMLSWARefResponse(soapMessage, discElement);
             } else if (XML_FAULT_REQUEST.equals(text)) {
                 throwSOAPFaultException();
+            } else if (XML_WSE_REQUEST.equals(text)) {
+                throwWebServiceException();
             } else {
                 // We should not get here
                 System.out.println("Unknown Type of Message");
@@ -137,8 +144,8 @@
             //response.writeTo(System.out);
             //System.out.println("\n");
             return response;
-    	} catch (SOAPFaultException sfe) {
-    	    throw sfe;
+    	} catch (WebServiceException wse) {
+    	    throw wse;
         } catch(Exception e){
             System.out.println("***ERROR: In SoapMessageProvider.invoke: Caught exception " + e);
     		e.printStackTrace();
@@ -199,6 +206,26 @@
     }
     
     /**
+     * Get the response for an XML only request
+     * @param request
+     * @param dataElement
+     * @return SOAPMessage
+     */
+    private SOAPMessage getXMLEmptyBodyResponse(SOAPMessage request, SOAPElement dataElement) throws Exception {
+        SOAPMessage response;
+       
+
+        // Additional assertion checks
+        assert(countAttachments(request) == 0);
+        
+        // Build the Response
+        MessageFactory factory = MessageFactory.newInstance();
+        response = factory.createMessage();
+     
+        return response;
+    }
+    
+    /**
      * Get the response for an XML and an Attachment request
      * @param request
      * @param dataElement
@@ -303,6 +330,7 @@
             Name deName = sf.createName("detailEntry");
             SOAPElement detailEntry = detail.addDetailEntry(deName);
             detailEntry.addTextNode("sample detail");
+            fault.setFaultActor("sample actor");
             
             SOAPFaultException sfe = new SOAPFaultException(fault);
             throw sfe;
@@ -311,6 +339,10 @@
         } catch (Exception e) {
             throw new RuntimeException(e);
         }
+    }
+    
+    private void throwWebServiceException() throws WebServiceException {
+        throw new WebServiceException("A WSE was thrown");
     }
     /**
      * Count Attachments

Modified: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/FaultsServiceTests.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/FaultsServiceTests.java?view=diff&rev=499795&r1=499794&r2=499795
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/FaultsServiceTests.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/FaultsServiceTests.java Thu Jan 25 05:52:04 2007
@@ -4,6 +4,7 @@
 package org.apache.axis2.jaxws.sample;
 
 import javax.xml.namespace.QName;
+import javax.xml.soap.DetailEntry;
 import javax.xml.soap.SOAPFault;
 import javax.xml.ws.BindingProvider;
 import javax.xml.ws.soap.SOAPFaultException;
@@ -284,11 +285,17 @@
         SOAPFaultException sfe = (SOAPFaultException) exception;
         SOAPFault soapFault = sfe.getFault();
         assertTrue(soapFault != null);
-        assertTrue(soapFault.getFaultString().equals("hello world"));
+        assertTrue(soapFault.getFaultString().equals("hello world2"));
         QName faultCode = soapFault.getFaultCodeAsQName();
         assertTrue(faultCode.getNamespaceURI().equals("urn://sample"));
-        assertTrue(faultCode.getLocalPart().equals("faultCode"));
-        assertTrue(soapFault.getFaultActor().equals("actor"));
+        assertTrue(faultCode.getLocalPart().equals("faultCode2"));
+        assertTrue(soapFault.getFaultActor().equals("actor2"));
+        assertTrue(soapFault.getDetail() != null);
+        DetailEntry de = (DetailEntry) soapFault.getDetail().getDetailEntries().next();
+        assertTrue(de != null);
+        assertTrue(de.getNamespaceURI().equals("urn://sample"));
+        assertTrue(de.getLocalName().equals("detailEntry"));
+        assertTrue(de.getValue().equals("Texas"));
     }
     
     /**
@@ -315,7 +322,34 @@
         SOAPFaultException sfe = (SOAPFaultException) exception;
         SOAPFault soapFault = sfe.getFault();
         assertTrue(soapFault != null);
-        assertTrue(soapFault.getFaultString().contains("NullPointerException"));
+        assertTrue(soapFault.getFaultString().equals("java.lang.NullPointerException"));
+    }
+    
+    /**
+     * Tests that that SOAPFaultException (NPE) is thrown 
+     */
+    public void testFaultsService10a(){
+        Exception exception = null;
+        try{
+            FaultsServicePortType proxy = getProxy();
+            
+            // the invoke will throw an exception, if the test is performed right
+            int total = proxy.throwFault(2, "NPE2", 2);  // "NPE" will cause service to throw NPE System Exception
+            
+        }catch(SOAPFaultException e){
+            // Okay
+            exception = e;
+        } catch (Exception e) {
+            fail("Did not get a SOAPFaultException");
+        }
+        
+        System.out.println("----------------------------------");
+        
+        assertNotNull(exception);
+        SOAPFaultException sfe = (SOAPFaultException) exception;
+        SOAPFault soapFault = sfe.getFault();
+        assertTrue(soapFault != null);
+        assertTrue(soapFault.getFaultString().equals("Null Pointer Exception occurred"));
     }
     
     /**

Modified: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/faultsservice/FaultsServiceSoapBindingImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/faultsservice/FaultsServiceSoapBindingImpl.java?view=diff&rev=499795&r1=499794&r2=499795
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/faultsservice/FaultsServiceSoapBindingImpl.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/faultsservice/FaultsServiceSoapBindingImpl.java Thu Jan 25 05:52:04 2007
@@ -15,6 +15,8 @@
 
 import javax.jws.WebService;
 import javax.xml.namespace.QName;
+import javax.xml.soap.Detail;
+import javax.xml.soap.DetailEntry;
 import javax.xml.soap.SOAPBody;
 import javax.xml.soap.SOAPException;
 import javax.xml.soap.SOAPFactory;
@@ -109,8 +111,23 @@
                 soapFault.setFaultActor("actor");
                 throw new SOAPFaultException(soapFault);
             } catch (SOAPException se) {}
+        } else if (b.equals("SOAPFaultException2")) {
+            try {
+                SOAPFault soapFault = createSOAPFault();
+                soapFault.setFaultString("hello world2");
+                QName faultCode = new QName("urn://sample", "faultCode2");
+                soapFault.setFaultCode(faultCode);
+                soapFault.setFaultActor("actor2");
+                Detail detail = soapFault.addDetail();
+                DetailEntry de = detail.addDetailEntry(new QName("urn://sample", "detailEntry"));
+                de.setValue("Texas");
+                throw new SOAPFaultException(soapFault);
+            } catch (SOAPException se) {}
         } else if (b.equals("NPE")) {
             throw new NullPointerException();
+        } else if (b.equals("NPE2")) {
+            // Throw NPE with a message
+            throw new NullPointerException("Null Pointer Exception occurred");
         } else if (b.equals("WSE")) {
             WebServiceException wsf = new WebServiceException("This is a WebServiceException");
             throw wsf;



---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org


Mime
View raw message