You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by sc...@apache.org on 2007/01/16 17:45:31 UTC

svn commit: r496755 - in /webservices/axis2/trunk/java/modules: jaxws/src/org/apache/axis2/jaxws/client/ jaxws/src/org/apache/axis2/jaxws/marshaller/impl/alt/ jaxws/src/org/apache/axis2/jaxws/message/util/ jaxws/src/org/apache/axis2/jaxws/message/util/...

Author: scheu
Date: Tue Jan 16 08:45:30 2007
New Revision: 496755

URL: http://svn.apache.org/viewvc?view=rev&rev=496755
Log:
AXIS2-1984
Contributor: Rich Scheuerle
SOAPFaultException processing

Modified:
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/BaseDispatch.java
    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/util/XMLFaultUtils.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/util/impl/SAAJConverterImpl.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
    webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/util/SAAJFactory.java

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/BaseDispatch.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/BaseDispatch.java?view=diff&rev=496755&r1=496754&r2=496755
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/BaseDispatch.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/BaseDispatch.java Tue Jan 16 08:45:30 2007
@@ -24,6 +24,7 @@
 import javax.xml.transform.dom.DOMSource;
 import javax.xml.ws.AsyncHandler;
 import javax.xml.ws.Binding;
+import javax.xml.ws.ProtocolException;
 import javax.xml.ws.Response;
 import javax.xml.ws.Service.Mode;
 import javax.xml.ws.WebServiceException;
@@ -40,6 +41,7 @@
 import org.apache.axis2.jaxws.core.controller.AxisInvocationController;
 import org.apache.axis2.jaxws.core.controller.InvocationController;
 import org.apache.axis2.jaxws.description.EndpointDescription;
+import org.apache.axis2.jaxws.marshaller.impl.alt.MethodMarshallerUtils;
 import org.apache.axis2.jaxws.message.Message;
 import org.apache.axis2.jaxws.message.MessageException;
 import org.apache.axis2.jaxws.message.XMLFault;
@@ -129,7 +131,8 @@
                 if (responseMsg.isFault()) {
                     XMLFault fault = responseMsg.getXMLFault();
                     // 4.3.2 conformance bullet 1 requires a ProtocolException here
-                    throw ExceptionFactory.makeProtocolException(fault.getReason().getText(), null);
+                    ProtocolException pe = MethodMarshallerUtils.createSystemException(responseMsg.getXMLFault(), responseMsg);
+                    throw  pe;
                 }
                 else if (responseMsgCtx.getLocalException() != null) {
                     // use the factory, it'll throw the right thing:

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=496755&r1=496754&r2=496755
==============================================================================
--- 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 Tue Jan 16 08:45:30 2007
@@ -29,10 +29,13 @@
 import javax.jws.soap.SOAPBinding.Style;
 import javax.xml.bind.JAXBElement;
 import javax.xml.namespace.QName;
+import javax.xml.soap.SOAPBody;
+import javax.xml.soap.SOAPEnvelope;
 import javax.xml.soap.SOAPFault;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.ws.AsyncHandler;
 import javax.xml.ws.Holder;
+import javax.xml.ws.ProtocolException;
 import javax.xml.ws.WebServiceException;
 import javax.xml.ws.soap.SOAPFaultException;
 
@@ -44,6 +47,7 @@
 import org.apache.axis2.jaxws.message.Block;
 import org.apache.axis2.jaxws.message.Message;
 import org.apache.axis2.jaxws.message.MessageException;
+import org.apache.axis2.jaxws.message.Protocol;
 import org.apache.axis2.jaxws.message.XMLFault;
 import org.apache.axis2.jaxws.message.XMLFaultReason;
 import org.apache.axis2.jaxws.message.databinding.JAXBBlockContext;
@@ -59,7 +63,7 @@
 /**
  * Static Utilty Classes used by the MethodMarshaller implementations in the alt package.
  */
-class MethodMarshallerUtils  {
+public class MethodMarshallerUtils  {
 
     private static Log log = LogFactory.getLog(MethodMarshallerUtils.class);
     
@@ -534,19 +538,13 @@
         Block[] detailBlocks = xmlfault.getDetailBlocks();
         
         
-        if ((operationDesc.getFaultDescriptions().length == 0) || (detailBlocks == null))  {
+        if ((operationDesc.getFaultDescriptions().length == 0) || 
+                (detailBlocks == null) || 
+                (detailBlocks.length > 1))  {
             // This is a system exception if the method does not throw a checked exception or if 
-            // there is nothing in the detail element.
-            // Shouldn't this create 
-            
-            // Create SystemException
-            // TODO shouldn't the exception capture the contents of the detail blocks
-            exception = createSystemException(xmlfault.getReason().getText());
-        } else {
-            
-            // TODO what if there are multiple blocks in the detail ?
-            // We should create a generic fault with the appropriate detail
-            
+            // the detail block is missing or contains multiple items.
+            exception = createSystemException(xmlfault, message);
+        } else {            
             // Get the JAXB object from the block
             JAXBBlockContext blockContext = new JAXBBlockContext(packages);        
             
@@ -573,6 +571,14 @@
                 blockContext.setRPCType(rpcType);
                 
             }
+            
+            // TODO This code assumes that the block can be demarshalled as a 
+            // known JAXB object.  But what if a detail is flowed that we don't know how to handle.
+            // for example, what if the detail is a stack trace.  To be on the safe side, we should
+            // probably make a copy of the OMBlock and then throw create a SystemException if
+            // with the original detail if JAXB unmarshalling fails.
+            // (I agree that this would not be performant, but we are on an exception path)
+            //
             Block jaxbBlock = factory.createFrom(detailBlocks[0], blockContext);
             Object faultBeanObject = jaxbBlock.getBusinessObject(true); 
             
@@ -693,8 +699,44 @@
      * @param message
      * @return
      */
-    private static Exception createSystemException(String message) {
-        return ExceptionFactory.makeWebServiceException(message);
+    public static ProtocolException createSystemException(XMLFault xmlFault, Message message) {
+        ProtocolException e = null;
+        Protocol protocol = message.getProtocol();
+        String text = xmlFault.getReason().getText();
+        if (protocol == Protocol.soap11 || protocol == Protocol.soap12) {
+            // Throw a SOAPFaultException
+            if (log.isDebugEnabled()) {
+                log.debug("Constructing SOAPFaultException for " + text);
+            }
+            try {
+                // The following set of instructions is used to avoid 
+                // some unimplemented methods in the Axis2 SAAJ implementation
+                SOAPEnvelope env = message.getAsSOAPEnvelope();
+                SOAPBody body = env.getBody();
+                SOAPFault soapFault = XMLFaultUtils.createSAAJFault(xmlFault, body);
+                e = new SOAPFaultException(soapFault);
+            } catch (Exception ex) {
+                // Exception occurred during exception processing.
+                // TODO Probably should do something better here
+                if (log.isDebugEnabled()) {
+                    log.debug("Exception occurred during fault processing:", ex);
+                }
+                e = ExceptionFactory.makeProtocolException(text, null);
+            }
+        } else if (protocol == Protocol.rest) {
+            if (log.isDebugEnabled()) {
+                log.debug("Constructing ProtocolException for " + text);
+            }
+            // TODO Is there an explicit exception for REST
+            e = ExceptionFactory.makeProtocolException(text, null);
+        } else if (protocol == Protocol.unknown) {
+            // REVIEW What should happen if there is no protocol
+            if (log.isDebugEnabled()) {
+                log.debug("Constructing ProtocolException for " + text);
+            }
+            e = ExceptionFactory.makeProtocolException(text, null);
+        }
+        return e;
     }
     
     

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=496755&r1=496754&r2=496755
==============================================================================
--- 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 Tue Jan 16 08:45:30 2007
@@ -19,8 +19,11 @@
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Locale;
 
 import javax.xml.namespace.QName;
+import javax.xml.soap.Detail;
+import javax.xml.soap.SOAPConstants;
 import javax.xml.soap.SOAPException;
 
 import org.apache.axiom.om.OMElement;
@@ -41,11 +44,14 @@
 import org.apache.axis2.jaxws.ExceptionFactory;
 import org.apache.axis2.jaxws.message.Block;
 import org.apache.axis2.jaxws.message.MessageException;
+import org.apache.axis2.jaxws.message.Protocol;
 import org.apache.axis2.jaxws.message.XMLFault;
 import org.apache.axis2.jaxws.message.XMLFaultCode;
 import org.apache.axis2.jaxws.message.XMLFaultReason;
 import org.apache.axis2.jaxws.message.factory.OMBlockFactory;
+import org.apache.axis2.jaxws.message.factory.SAAJConverterFactory;
 import org.apache.axis2.jaxws.registry.FactoryRegistry;
+import org.apache.axis2.jaxws.util.SAAJFactory;
 
 /**
  * Collection of utilities used by the Message implementation to 
@@ -183,20 +189,141 @@
 	}
     
     /**
+     * Create XMLFault
+     * @param soapFault
+     * @return xmlFault
+     * @throws MessageException
+     */
+    public static XMLFault createXMLFault(javax.xml.soap.SOAPFault soapFault) throws MessageException {
+        Block[] detailBlocks = getDetailBlocks(soapFault);
+        return createXMLFault(soapFault, detailBlocks);
+    }
+    
+    /**
+     * Create an XMLFault object from a SOAPFault and detail Blocks
+     * @param soapFault
+     * @param detailBlocks
+     * @return
+     */
+    public static XMLFault createXMLFault(javax.xml.soap.SOAPFault soapFault, Block[] detailBlocks) throws MessageException {
+        
+        // The SOAPFault structure is modeled after SOAP 1.2.  
+        // Here is a sample comprehensive SOAP 1.2 fault which will help you understand the
+        // structure.
+        // <env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope"
+        //               xmlns:m="http://www.example.org/timeouts"
+        //               xmlns:xml="http://www.w3.org/XML/1998/namespace">
+        //   <env:Body>
+        //      <env:Fault>
+        //        <env:Code>
+        //          <env:Value>env:Sender</env:Value>
+        //          <env:Subcode>
+        //            <env:Value>m:MessageTimeout</env:Value>
+        //          </env:Subcode>
+        //        </env:Code>
+        //        <env:Reason>
+        //          <env:Text xml:lang="en">Sender Timeout</env:Text>
+        //          <env:Text xml:lang="de">Sender Timeout</env:Text>
+        //        </env:Reason>
+        //        <env:Node>http://my.example.org/Node</env:Node>
+        //        <env:Role>http://my.example.org/Role</env:Role>
+        //        <env:Detail>
+        //          <m:MaxTime>P5M</m:MaxTime>
+        //        </env:Detail>    
+        //      </env:Fault>
+        //   </env:Body>
+        // </env:Envelope>
+        
+        
+        // Get the code
+        // TODO what if this fails ?  Log a message and treat like a RECEIVER fault ?
+        QName codeQName = soapFault.getFaultCodeAsQName();
+        XMLFaultCode code = XMLFaultCode.fromQName(codeQName);
+        
+        // Get the primary reason text
+        // TODO what if this fails
+        String text = soapFault.getFaultString();
+        Locale locale = soapFault.getFaultStringLocale();
+        String lang = (locale == null) ? Locale.getDefault().getLanguage() : locale.getLanguage();
+        XMLFaultReason reason = new XMLFaultReason(text, lang);
+
+        // Construct the XMLFault from the required information (code, reason, detail blocks)
+        XMLFault xmlFault = new XMLFault(code, reason, detailBlocks);
+        
+        
+        
+        // Add the secondary fault information
+ 
+        // Get the SubCodes
+        /* REVIEW The following needs to be added
+         
+        SOAPFaultSubCode soapSubCode = soapCode.getSubCode();
+        if (soapSubCode != null) {
+            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();
+            }
+            
+            // 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());
+            }
+            xmlFault.setSecondaryReasons(secondaryReasons);
+        }
+        
+        // Get the Node
+        SOAPFaultNode soapNode = soapFault.getNode();
+        if (soapNode != null) {
+            xmlFault.setNode(soapNode.getText());
+        }
+        
+        // Get the Role
+        SOAPFaultRole soapRole = soapFault.getRole();
+        if (soapRole != null) {
+            xmlFault.setRole(soapRole.getText());
+        }
+        */
+        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 MessageException {
+        
        // Convert the SOAPFault into an OM SOAPFault.  OMSOAP Fault already supports SOAP 1.2, so this makes the code easier to migrate
-       SAAJConverter converter = 
-           (SAAJConverter) FactoryRegistry.getFactory(SAAJConverter.class);
-       SOAPFault omSOAPFault = (SOAPFault) converter.toOM(soapFault);
+       
+       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;
     }
+    */
     
     private static Block[] getDetailBlocks(SOAPFault soapFault) throws MessageException {
         try {
@@ -219,6 +346,28 @@
             throw ExceptionFactory.makeMessageException(e);
         }
     }
+    
+    private static Block[] getDetailBlocks(javax.xml.soap.SOAPFault soapFault) throws MessageException {
+        try {
+            Block[] blocks = null;
+            Detail detail = soapFault.getDetail();
+            if (detail != null) {
+                // 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();
+                    Block b = bf.createFrom(om, null,om.getQName()); 
+                    list.add(b);
+                }
+                blocks = list.toArray(blocks);
+            }
+            return blocks;
+        } catch (Exception e) {
+            throw ExceptionFactory.makeMessageException(e);
+        }
+    }
         
     /**
      * Create a SOAPFault representing the XMLFault and attach it to body.
@@ -332,6 +481,119 @@
             soapNode.setText(xmlFault.getNode());
         }
            
+        return soapFault;
+            
+    }
+    
+    
+    /**
+     * Create a SOAPFault representing the XMLFault.
+     * If there are 1 or more detail Blocks on the XMLFault, a SOAPFaultDetail is attached.
+     * @param xmlFault
+     * @param body
+     * @return SOAPFault (which is attached to body)
+     */
+    public static javax.xml.soap.SOAPFault createSAAJFault(XMLFault xmlFault, 
+                javax.xml.soap.SOAPBody body) throws SOAPException, MessageException {
+        
+        // Get the factory and create the soapFault
+        String protocolNS = body.getNamespaceURI();
+            
+        javax.xml.soap.SOAPFault soapFault = body.addFault();
+        
+        // The SOAPFault structure is modeled after SOAP 1.2.  
+        // Here is a sample comprehensive SOAP 1.2 fault which will help you understand the
+        // structure.
+        // <env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope"
+        //               xmlns:m="http://www.example.org/timeouts"
+        //               xmlns:xml="http://www.w3.org/XML/1998/namespace">
+        //   <env:Body>
+        //      <env:Fault>
+        //        <env:Code>
+        //          <env:Value>env:Sender</env:Value>
+        //          <env:Subcode>
+        //            <env:Value>m:MessageTimeout</env:Value>
+        //          </env:Subcode>
+        //        </env:Code>
+        //        <env:Reason>
+        //          <env:Text xml:lang="en">Sender Timeout</env:Text>
+        //          <env:Text xml:lang="de">Sender Timeout</env:Text>
+        //        </env:Reason>
+        //        <env:Node>http://my.example.org/Node</env:Node>
+        //        <env:Role>http://my.example.org/Role</env:Role>
+        //        <env:Detail>
+        //          <m:MaxTime>P5M</m:MaxTime>
+        //        </env:Detail>    
+        //      </env:Fault>
+        //   </env:Body>
+        // </env:Envelope>
+        
+        // Set the primary Code Value
+        QName soapValueQName = xmlFault.getCode().toQName(protocolNS);
+        soapFault.setFaultCode(soapValueQName);
+        
+        // Set the primary Reason Text
+        String reasonText = xmlFault.getReason().getText();
+        String reasonLang = xmlFault.getReason().getText();
+        Locale locale = (reasonLang != null && reasonLang.length() > 0) ?
+                new Locale(reasonLang) :
+                    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);
+                }
+            }
+        }
+        
+        // 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;
+           }
+        }
+        
+        // Set the secondary reasons and languages
+        XMLFaultReason reasons[] = xmlFault.getSecondaryReasons();
+        if (reasons != null && reasons.length > 0) {
+            for (int i=0; i<reasons.length; i++) {
+                SOAPFaultText soapReasonText = factory.createSOAPFaultText(soapReason);
+                soapReasonText.setText(reasons[i].getText());
+                soapReasonText.setLang(reasons[i].getLang());
+            }
+        }
+        
+        // Set the Role
+        if (xmlFault.getRole() != null) {
+            SOAPFaultRole soapRole = factory.createSOAPFaultRole();
+            soapRole.setText(xmlFault.getRole());
+        }
+        
+        // Set the Node
+        if (xmlFault.getNode() != null) {
+            SOAPFaultNode soapNode = factory.createSOAPFaultNode();
+            soapNode.setText(xmlFault.getNode());
+        }
+           
+           */
         return soapFault;
             
     }

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/util/impl/SAAJConverterImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/util/impl/SAAJConverterImpl.java?view=diff&rev=496755&r1=496754&r2=496755
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/util/impl/SAAJConverterImpl.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/util/impl/SAAJConverterImpl.java Tue Jan 16 08:45:30 2007
@@ -121,9 +121,9 @@
 	public OMElement toOM(SOAPElement soapElement) throws MessageException {
 		// Get a XMLStreamReader backed by a SOAPElement tree
 		XMLStreamReader reader = new SOAPElementReader(soapElement);
-		// Get a OM Builder.  Passing null causes the version to be automatically triggered
-		StAXOMBuilder builder = new StAXOMBuilder(reader);  
-		// Create and return the OM Envelope
+		// Get a OM Builder.  
+        StAXOMBuilder builder = new StAXOMBuilder(reader);  
+		// Create and return the Element
 		OMElement om = builder.getDocumentElement();
 		return om;
 	}

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=496755&r1=496754&r2=496755
==============================================================================
--- 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 Tue Jan 16 08:45:30 2007
@@ -3,7 +3,10 @@
  */
 package org.apache.axis2.jaxws.sample;
 
+import javax.xml.namespace.QName;
+import javax.xml.soap.SOAPFault;
 import javax.xml.ws.BindingProvider;
+import javax.xml.ws.soap.SOAPFaultException;
 
 import junit.framework.TestCase;
 import org.apache.axis2.jaxws.sample.faultsservice.BaseFault_Exception;
@@ -253,5 +256,65 @@
         } catch (Exception e) {
             fail("Wrong exception thrown.  Expected DerivedFault1_Exception but received " + e.getClass());
         }
+    }
+    
+    /**
+     * Tests that that SOAPFaultException is thrown 
+     * The AXIS2 SAAJ Fault model contains problems, which 
+     * cause the following test to fail.
+     */
+    public void _testFaultsService9(){
+        Exception exception = null;
+        try{
+            FaultsServicePortType proxy = getProxy();
+            
+            // the invoke will throw an exception, if the test is performed right
+            int total = proxy.throwFault(2, "SOAPFaultException", 2);  // "SOAPFaultException" will cause service to throw SOAPFaultException
+            
+        }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("hello world"));
+        QName faultCode = soapFault.getFaultCodeAsQName();
+        assertTrue(faultCode.getNamespaceURI().equals("urn://sample"));
+        assertTrue(faultCode.getLocalPart().equals("faultCode"));
+        assertTrue(soapFault.getFaultActor().equals("actor"));
+    }
+    
+    /**
+     * Tests that that SOAPFaultException (NPE) is thrown 
+     */
+    public void testFaultsService10(){
+        Exception exception = null;
+        try{
+            FaultsServicePortType proxy = getProxy();
+            
+            // the invoke will throw an exception, if the test is performed right
+            int total = proxy.throwFault(2, "NPE", 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().contains("NullPointerException"));
     }
 }

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=496755&r1=496754&r2=496755
==============================================================================
--- 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 Tue Jan 16 08:45:30 2007
@@ -14,8 +14,16 @@
 package org.apache.axis2.jaxws.sample.faultsservice;
 
 import javax.jws.WebService;
+import javax.xml.namespace.QName;
+import javax.xml.soap.SOAPBody;
+import javax.xml.soap.SOAPException;
+import javax.xml.soap.SOAPFactory;
+import javax.xml.soap.SOAPFault;
 import javax.xml.ws.Holder;
+import javax.xml.ws.soap.SOAPFaultException;
 
+import org.apache.axiom.om.impl.dom.DOOMAbstractFactory;
+import org.apache.axis2.saaj.SOAPEnvelopeImpl;
 import org.test.polymorphicfaults.BaseFault;
 import org.test.polymorphicfaults.ComplexFault;
 import org.test.polymorphicfaults.DerivedFault1;
@@ -91,11 +99,21 @@
             df.setB(b); 
             df.setC(c); 
             throw new BaseFault_Exception("Server throws BaseFault_Exception", df);
+        } else if (b.equals("SOAPFaultException")) {
+            try {
+                SOAPFault soapFault = createSOAPFault();
+                soapFault.setFaultString("hello world");
+                QName faultCode = new QName("urn://sample", "faultCode");
+                soapFault.setFaultCode(faultCode);
+                soapFault.setFaultActor("actor");
+                throw new SOAPFaultException(soapFault);
+            } catch (SOAPException se) {}
+        } else if (b.equals("NPE")) {
+            throw new NullPointerException();
         }
         return 0;
     }
 
-
     /**
      * Returns a fault bean or throws a wrapper exception
      */
@@ -117,5 +135,22 @@
         df.setA(a + 1); 
         df.setB("Server: " + b); 
         throw new EqualFault("Server throws EqualFault", df);
+    }
+    
+    SOAPFault createSOAPFault() throws SOAPException {
+        SOAPFault soapFault = null;
+    
+        // REVIEW: The following does not work due to Axis2 SAAJ problems.
+        //
+        // SOAPFactory soapFactory = SOAPFactory.newInstance();
+        // SOAPFault soapFault = soapFactory.createFault();
+        
+        // Alternate Approach
+        org.apache.axiom.soap.SOAPFactory asf = DOOMAbstractFactory.getSOAP11Factory();
+        org.apache.axiom.soap.impl.dom.SOAPEnvelopeImpl axiomEnv = (org.apache.axiom.soap.impl.dom.SOAPEnvelopeImpl) asf.createSOAPEnvelope();
+        javax.xml.soap.SOAPEnvelope env = new SOAPEnvelopeImpl(axiomEnv);
+        SOAPBody body = env.addBody();
+        soapFault = body.addFault();
+        return soapFault;
     }
 }

Modified: webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/util/SAAJFactory.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/util/SAAJFactory.java?view=diff&rev=496755&r1=496754&r2=496755
==============================================================================
--- webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/util/SAAJFactory.java (original)
+++ webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/util/SAAJFactory.java Tue Jan 16 08:45:30 2007
@@ -130,7 +130,7 @@
     private static Method getSOAPFactoryNewInstanceProtocolMethod() {
         if (soapFactoryNewInstanceProtocolMethod == null) {
             try {
-                soapFactoryNewInstanceProtocolMethod = MessageFactory.class.getMethod("newInstance", new Class[] {String.class});
+                soapFactoryNewInstanceProtocolMethod = SOAPFactory.class.getMethod("newInstance", new Class[] {String.class});
             } catch (Exception e) {
                 // TODO Might want to log this.
                 // Flow to here indicates that the installed SAAJ model does not support version 1.3



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