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/02/01 18:44:33 UTC

svn commit: r502299 - in /webservices/axis2/trunk/java/modules/jaxws: src/org/apache/axis2/jaxws/marshaller/impl/alt/ test/org/apache/axis2/jaxws/provider/ test/org/apache/axis2/jaxws/sample/ test/org/apache/axis2/jaxws/sample/faultsservice/

Author: scheu
Date: Thu Feb  1 09:44:32 2007
New Revision: 502299

URL: http://svn.apache.org/viewvc?view=rev&rev=502299
Log:
AXIS2-2077
Contributor: Rich Scheuerle
JAXWS SOAPFaultException unmarshalling fix.

Modified:
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/alt/MethodMarshallerUtils.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/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=502299&r1=502298&r2=502299
==============================================================================
--- 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 Feb  1 09:44:32 2007
@@ -648,94 +648,71 @@
         XMLFault xmlfault = message.getXMLFault();
         Block[] detailBlocks = xmlfault.getDetailBlocks();
         
-        // Sometimes Axis2 will flow a single detail element with the name "Exception".  
-        // "Exception" contains stack information.  This is a violation of the WSI specification; however
-        // we still need to work around it.
-        boolean isStack = false;
-        QName elementName = null;
+        // If there is only one block, get the element name of that block.
+        QName elementQName = null;
         if (detailBlocks !=null && detailBlocks.length == 1) {
-            elementName = detailBlocks[0].getQName();
-            isStack = (elementName.getNamespaceURI().length() == 0 && elementName.getLocalPart().equals("Exception"));
+            elementQName = detailBlocks[0].getQName();
         }
         
+        // Use the element name to find the matching FaultDescriptor
+        FaultDescription faultDesc = null;
+        if (elementQName != null) {
+            for(int i=0; i<operationDesc.getFaultDescriptions().length && faultDesc == null; i++) {
+                FaultDescription fd = operationDesc.getFaultDescriptions()[i];
+                QName tryQName = new QName(fd.getTargetNamespace(), fd.getName());
+                if (log.isErrorEnabled()) {
+                    log.debug("  FaultDescription qname is (" + tryQName + ") and detail element qname is (" + elementQName + ")");
+                }
+                if (elementQName.equals(tryQName)) {
+                    faultDesc = fd;
+                }
+            }
+        }
+        
+        if (faultDesc == null && isRPC && elementQName != null) {
+            // If not found and RPC, retry the search using just the local name
+            for(int i=0; i<operationDesc.getFaultDescriptions().length && faultDesc == null; i++) {
+                FaultDescription fd = operationDesc.getFaultDescriptions()[i];
+                String tryName = fd.getName();
+                if (elementQName.getLocalPart().equals(tryName)) {
+                    faultDesc = fd;
+                }
+            }
+        }
         
-        if ((operationDesc.getFaultDescriptions().length == 0) || 
-                isStack ||
-                (detailBlocks == null) || 
-                (detailBlocks.length > 1))  {
+        
+        if (faultDesc == null) {
             // This is a system exception if the method does not throw a checked exception or if 
             // the detail block is missing or contains multiple items.
             exception = createSystemException(xmlfault, message);
         } else {        
             if (log.isErrorEnabled()) {
-                log.debug("Ready to demarshal service exception.  The detail entry name is " + elementName);
+                log.debug("Ready to demarshal service exception.  The detail entry name is " + elementQName);
             }
             // Get the JAXB object from the block
             JAXBBlockContext blockContext = new JAXBBlockContext(packages);        
             
             if (isRPC) {
-                // RPC is problem ! We have a chicken and egg problem.
+                // RPC is problem ! 
                 // Since RPC is type based, JAXB needs the declared type
-                // to unmarshal the object.  But we don't know the declared
-                // type without knowing the name of the type (sigh)
-                
-                // Now search the FaultDescriptors to find the right 
-                // declared type
-                Class rpcType = null;
-                for(int i=0; i<operationDesc.getFaultDescriptions().length && rpcType == null; i++) {
-                    FaultDescription fd = operationDesc.getFaultDescriptions()[i];
-                    String tryName = fd.getName();
-                    if (elementName.getLocalPart().equals(tryName)) {
-                        rpcType = fd.getClass();
-                    }
-                }
-                // Now set it on the context
+                // to unmarshal the object.
+                Class rpcType = faultDesc.getClass();
                 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.
-            // 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)
-            //
+            // Get the jaxb block and business object
             Block jaxbBlock = factory.createFrom(detailBlocks[0], blockContext);
             Object faultBeanObject = jaxbBlock.getBusinessObject(true); 
             
             // At this point, faultBeanObject is an object that can be rendered as an
-            // element.  We want the object that represents the type.  Also get the 
-            // name of the element.
-            QName faultBeanQName = null;
+            // element.  We want the object that represents the type.
             if (faultBeanObject instanceof JAXBElement) {
-                faultBeanQName = ((JAXBElement)faultBeanObject).getName();
                 faultBeanObject = ((JAXBElement)faultBeanObject).getValue();
-            } else {
-                faultBeanQName = XMLRootElementUtil.getXmlRootElementQName(faultBeanObject);
-            }
+            } 
             
             if (log.isErrorEnabled()) {
-                log.debug("Searching for the matching FaultDescription");
-            }
-            // Using the faultBeanQName, find the matching faultDescription 
-            FaultDescription faultDesc = null;
-            for(int i=0; i<operationDesc.getFaultDescriptions().length && faultDesc == null; i++) {
-                FaultDescription fd = operationDesc.getFaultDescriptions()[i];
-                QName tryQName = new QName(fd.getTargetNamespace(), fd.getName());
-                if (log.isErrorEnabled()) {
-                    log.debug("  FaultDescription qname is (" + tryQName + ") and demarshalled bean qname is (" + faultBeanQName + ")");
-                }
-                if (faultBeanQName == null || faultBeanQName.equals(tryQName)) {
-                    faultDesc = fd;
-                    
-                }
-            }
-            if (faultDesc == null) {
-                if (log.isErrorEnabled()) {
-                    log.debug("A FaultDescription was not found");
-                }
-                throw ExceptionFactory.makeWebServiceException(Messages.getMessage("MethodMarshallerErr1", faultBeanObject.getClass().toString()));
+                log.debug("Unmarshalled the detail element into a JAXB object");
             }
             
             // Construct the JAX-WS generated exception that holds the faultBeanObject

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=502299&r1=502298&r2=502299
==============================================================================
--- 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 Feb  1 09:44:32 2007
@@ -26,6 +26,7 @@
 import javax.xml.soap.MessageFactory;
 import javax.xml.soap.Node;
 import javax.xml.soap.SOAPBody;
+import javax.xml.soap.SOAPConstants;
 import javax.xml.soap.SOAPElement;
 import javax.xml.soap.SOAPFault;
 import javax.xml.soap.SOAPMessage;
@@ -203,6 +204,7 @@
                 SOAPFault fault = e.getFault();
                 assertTrue(fault != null);
                 assertTrue(fault.getFaultString().equals("sample fault"));
+                assertTrue(fault.getFaultCodeAsQName().getNamespaceURI().equals(SOAPConstants.URI_NS_SOAP_1_1_ENVELOPE));
                 assertTrue(fault.getDetail() != null);
                 DetailEntry de = (DetailEntry) fault.getDetail().getDetailEntries().next();
                 assertTrue(de != null);

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=502299&r1=502298&r2=502299
==============================================================================
--- 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 Feb  1 09:44:32 2007
@@ -261,10 +261,8 @@
     
     /**
      * Tests that that SOAPFaultException is thrown 
-     * The AXIS2 SAAJ Fault model contains problems, which 
-     * cause the following test to fail.
      */
-    public void _testFaultsService9(){
+    public void testFaultsService9a(){
         Exception exception = null;
         try{
             FaultsServicePortType proxy = getProxy();
@@ -285,10 +283,36 @@
         SOAPFaultException sfe = (SOAPFaultException) exception;
         SOAPFault soapFault = sfe.getFault();
         assertTrue(soapFault != null);
+        assertTrue(soapFault.getFaultString().equals("hello world"));
+        assertTrue(soapFault.getFaultActor().equals("actor"));
+        assertTrue(soapFault.getDetail() == null);
+    }
+    
+    /**
+     * Tests that that SOAPFaultException is thrown 
+     */
+    public void testFaultsService9b(){
+        Exception exception = null;
+        try{
+            FaultsServicePortType proxy = getProxy();
+            
+            // the invoke will throw an exception, if the test is performed right
+            int total = proxy.throwFault(2, "SOAPFaultException2", 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 world2"));
-        QName faultCode = soapFault.getFaultCodeAsQName();
-        assertTrue(faultCode.getNamespaceURI().equals("urn://sample"));
-        assertTrue(faultCode.getLocalPart().equals("faultCode2"));
         assertTrue(soapFault.getFaultActor().equals("actor2"));
         assertTrue(soapFault.getDetail() != null);
         DetailEntry de = (DetailEntry) soapFault.getDetail().getDetailEntries().next();

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=502299&r1=502298&r2=502299
==============================================================================
--- 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 Feb  1 09:44:32 2007
@@ -106,8 +106,6 @@
             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) {}
@@ -115,8 +113,6 @@
             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"));



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