ws-axis-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chinth...@apache.org
Subject svn commit: r391933 - in /webservices/axis2/trunk/java/modules: core/src/org/apache/axis2/ core/src/org/apache/axis2/description/ integration/test/org/apache/axis2/engine/ integration/test/org/apache/axis2/rpc/
Date Thu, 06 Apr 2006 08:30:51 GMT
Author: chinthaka
Date: Thu Apr  6 01:30:48 2006
New Revision: 391933

URL: http://svn.apache.org/viewcvs?rev=391933&view=rev
Log:
Fixed FaultHandling in client side so that now you will get fault information as SOAPFault*
from the AxisFault. 


Modified:
    webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/AxisFault.java
    webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/OutInAxisOperation.java
    webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/FaultHandlingTest.java
    webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/rpc/MultirefTest.java

Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/AxisFault.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/AxisFault.java?rev=391933&r1=391932&r2=391933&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/AxisFault.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/AxisFault.java Thu Apr
 6 01:30:48 2006
@@ -25,6 +25,7 @@
 import org.apache.axiom.soap.SOAPFaultReason;
 import org.apache.axiom.soap.SOAPFaultRole;
 import org.apache.axiom.soap.SOAPHeader;
+import org.apache.axiom.soap.SOAPConstants;
 
 import javax.xml.namespace.QName;
 import java.lang.reflect.InvocationTargetException;
@@ -55,14 +56,14 @@
  *      a SOAP1.1 fault is created, spurious information can be discarded.
  *      Mapping
  *      <pre>
- *                                         SOAP1.2              SOAP1.1
- *                                         node                 faultactor
- *                                         reason(0).text       faultstring
- *                                         faultcode.value      faultcode
- *                                         faultcode.subcode    (discarded)
- *                                         detail               detail
- *                                         role                 (discarded)
- *                                         </pre>
+ *                                                   SOAP1.2              SOAP1.1
+ *                                                   node                 faultactor
+ *                                                   reason(0).text       faultstring
+ *                                                   faultcode.value      faultcode
+ *                                                   faultcode.subcode    (discarded)
+ *                                                   detail               detail
+ *                                                   role                 (discarded)
+ *                                                   </pre>
  */
 public class AxisFault extends RemoteException {
 
@@ -80,6 +81,10 @@
     private OMElement detail;
 
     private Map faultElements;
+
+    private String message;
+    private Throwable cause;
+
     /**
      * SOAP1.2: URI of faulting node. Null for unknown.
      * <p/>
@@ -129,10 +134,10 @@
      * @param soapFaultReason
      * @param soapFaultNode
      * @param soapFaultRole
-     * @param soap
      */
     public AxisFault(SOAPFaultCode soapFaultCode, SOAPFaultReason soapFaultReason,
                      SOAPFaultNode soapFaultNode, SOAPFaultRole soapFaultRole, SOAPFaultDetail
soapFaultDetail) {
+
         if (faultElements == null) {
             // assuming that most of the times fault code, fault string and fault details
are set
             faultElements = new HashMap(3);
@@ -143,6 +148,18 @@
         setToElementsListIfNotNull(SOAP12Constants.SOAP_FAULT_ROLE_LOCAL_NAME, soapFaultRole);
         setToElementsListIfNotNull(SOAP12Constants.SOAP_FAULT_DETAIL_LOCAL_NAME, soapFaultDetail);
 
+        if (soapFaultReason != null) {
+            message = soapFaultReason.getFirstSOAPText().getText();
+        }
+
+        if (soapFaultDetail != null) {
+            OMElement exceptionElement = soapFaultDetail.getFirstChildWithName(
+                    new QName(SOAPConstants.SOAP_FAULT_DETAIL_EXCEPTION_ENTRY));
+            if (exceptionElement != null && exceptionElement.getText() != null) {
+                cause = new Exception(exceptionElement.getText());
+            }
+        }
+
     }
 
     private void setToElementsListIfNotNull(String soapFaultElementName, OMElement soapFaultElement)
{
@@ -311,6 +328,46 @@
     }
 
     /**
+     * @return SOAPFaultCode if, user has set a {@link SOAPFaultCode} element when constructing
the
+     *         {@link #AxisFault(org.apache.axiom.soap.SOAPFaultCode, org.apache.axiom.soap.SOAPFaultReason,
org.apache.axiom.soap.SOAPFaultNode, org.apache.axiom.soap.SOAPFaultRole, org.apache.axiom.soap.SOAPFaultDetail)
AxisFault}
+     */
+    public SOAPFaultCode getFaultCodeElement() {
+        return (SOAPFaultCode) (faultElements != null ? faultElements.get(SOAP12Constants.SOAP_FAULT_CODE_LOCAL_NAME)
: null);
+    }
+
+    /**
+     * @return SOAPFaultCode if, user has set a {@link SOAPFaultReason} element when constructing
the
+     *         {@link #AxisFault(org.apache.axiom.soap.SOAPFaultCode, org.apache.axiom.soap.SOAPFaultReason,
org.apache.axiom.soap.SOAPFaultNode, org.apache.axiom.soap.SOAPFaultRole, org.apache.axiom.soap.SOAPFaultDetail)
AxisFault}
+     */
+    public SOAPFaultReason getFaultReasonElement() {
+        return (SOAPFaultReason) (faultElements != null ? faultElements.get(SOAP12Constants.SOAP_FAULT_REASON_LOCAL_NAME)
: null);
+    }
+
+    /**
+     * @return SOAPFaultCode if, user has set a {@link SOAPFaultNode} element when constructing
the
+     *         {@link #AxisFault(org.apache.axiom.soap.SOAPFaultCode, org.apache.axiom.soap.SOAPFaultReason,
org.apache.axiom.soap.SOAPFaultNode, org.apache.axiom.soap.SOAPFaultRole, org.apache.axiom.soap.SOAPFaultDetail)
AxisFault}
+     */
+    public SOAPFaultNode getFaultNodeElement() {
+        return (SOAPFaultNode) (faultElements != null ? faultElements.get(SOAP12Constants.SOAP_FAULT_NODE_LOCAL_NAME)
: null);
+    }
+
+    /**
+     * @return SOAPFaultCode if, user has set a {@link SOAPFaultRole} element when constructing
the
+     *         {@link #AxisFault(org.apache.axiom.soap.SOAPFaultCode, org.apache.axiom.soap.SOAPFaultReason,
org.apache.axiom.soap.SOAPFaultNode, org.apache.axiom.soap.SOAPFaultRole, org.apache.axiom.soap.SOAPFaultDetail)
AxisFault}
+     */
+    public SOAPFaultRole getFaultRoleElement() {
+        return (SOAPFaultRole) (faultElements != null ? faultElements.get(SOAP12Constants.SOAP_FAULT_ROLE_LOCAL_NAME)
: null);
+    }
+
+    /**
+     * @return SOAPFaultCode if, user has set a {@link SOAPFaultDetail} element when constructing
the
+     *         {@link #AxisFault(org.apache.axiom.soap.SOAPFaultCode, org.apache.axiom.soap.SOAPFaultReason,
org.apache.axiom.soap.SOAPFaultNode, org.apache.axiom.soap.SOAPFaultRole, org.apache.axiom.soap.SOAPFaultDetail)
AxisFault}
+     */
+    public SOAPFaultDetail getFaultDetailElement() {
+        return (SOAPFaultDetail) (faultElements != null ? faultElements.get(SOAP12Constants.SOAP_FAULT_DETAIL_LOCAL_NAME)
: null);
+    }
+
+    /**
      * Get the faulting node uri.
      * SOAP1.2
      *
@@ -357,6 +414,14 @@
         return faultRole;
     }
 
+    public String getMessage() {
+        return message != null ? message : super.getMessage();
+    }
+
+    public Throwable getCause() {
+        return cause != null ? cause : super.getCause();
+    }
+
     class FaultReason {
 
         /**
@@ -403,4 +468,5 @@
             this.text = text;
         }
     }
+
 }

Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/OutInAxisOperation.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/OutInAxisOperation.java?rev=391933&r1=391932&r2=391933&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/OutInAxisOperation.java
(original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/description/OutInAxisOperation.java
Thu Apr  6 01:30:48 2006
@@ -223,7 +223,7 @@
             EndpointReference toEPR = (options.getTo() != null) ? options
                     .getTo() : mc.getTo();
             transportOut = ClientUtils.inferOutTransport(cc
-                    .getAxisConfiguration(), toEPR ,mc);
+                    .getAxisConfiguration(), toEPR, mc);
         }
         mc.setTransportOut(transportOut);
 
@@ -266,30 +266,15 @@
                 // Send the SOAP Message and receive a response
                 MessageContext response = send(mc);
                 // check for a fault and return the result
-                SOAPEnvelope resenvelope = response.getEnvelope();
-                if (resenvelope.getBody().hasFault()) {
-                    SOAPFault soapFault = resenvelope.getBody().getFault();
-                    Exception ex = soapFault.getException();
+                SOAPEnvelope resEnvelope = response.getEnvelope();
+                if (resEnvelope.getBody().hasFault()) {
+                    SOAPFault soapFault = resEnvelope.getBody().getFault();
                     if (options.isExceptionToBeThrownOnSOAPFault()) {
                         // does the SOAPFault has a detail element for Excpetion
-                        if (ex != null) {
-                            throw new AxisFault(ex);
-                        } else {
-                            // if detail element not present create a new
-                            // Exception from the detail
-                            String message = "";
-                            message = (message + "Code =" + soapFault.getCode() == null)
? ""
-                                    : (soapFault.getCode().getValue() == null) ? ""
-                                    : soapFault.getCode().getValue()
-                                    .getText();
-                            message = (message + "Reason ="
-                                    + soapFault.getReason() == null) ? ""
-                                    : (soapFault.getReason().getFirstSOAPText() == null)
? ""
-                                    : soapFault.getReason()
-                                    .getFirstSOAPText().getText();
 
-                            throw new AxisFault(message);
-                        }
+                        throw new AxisFault(soapFault.getCode(), soapFault.getReason(),
+                                soapFault.getNode(), soapFault.getRole(), soapFault.getDetail());
+
                     }
                 }
                 completed = true;

Modified: webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/FaultHandlingTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/FaultHandlingTest.java?rev=391933&r1=391932&r2=391933&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/FaultHandlingTest.java
(original)
+++ webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/FaultHandlingTest.java
Thu Apr  6 01:30:48 2006
@@ -41,6 +41,7 @@
 import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.util.ArrayList;
+import java.util.Map;
 
 public class FaultHandlingTest extends TestCase implements TestConstants {
 
@@ -104,7 +105,6 @@
     }
 
 
-
     public void testRefParamsWithFaultTo() throws AxisFault, XMLStreamException {
         SOAPEnvelope soapEnvelope = getSOAPEnvelopeWithRefParamsInFaultTo();
         SOAPEnvelope resposeEnvelope = getResponse(soapEnvelope);
@@ -162,6 +162,30 @@
 
     protected void tearDown() throws Exception {
         UtilServer.stop();
+    }
+
+    public void testExceptionInformationExtractionFromAxisFault() {
+        try {
+            ConfigurationContext configContext =
+                    ConfigurationContextFactory.createConfigurationContextFromFileSystem("target/test-resources/integrationRepo",
null);
+            ServiceClient sender = new ServiceClient(configContext, null);
+
+            OMElement payload = getOMElement(FaultHandler.ERR_HANDLING_WITH_AXIS_FAULT);
+
+            // test with SOAP 1.2
+            Options options = new Options();
+            options.setTo(targetEPR);
+            options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
+            options.setExceptionToBeThrownOnSOAPFault(true);
+            options.setSoapVersionURI(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);
+            sender.setOptions(options);
+
+           sender.sendReceive(payload).toString();
+        } catch (AxisFault axisFault) {
+            assertTrue(axisFault.getFaultCodeElement().toString().indexOf(FaultHandler.M_FAULT_EXCEPTION)
> -1);
+            assertTrue(axisFault.getFaultDetailElement().toString().indexOf(FaultHandler.DETAIL_MORE_INFO)
> -1);
+            assertTrue(axisFault.getFaultReasonElement().toString().indexOf(FaultHandler.FAULT_REASON)
> -1);
+        }
     }
 
 }

Modified: webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/rpc/MultirefTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/rpc/MultirefTest.java?rev=391933&r1=391932&r2=391933&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/rpc/MultirefTest.java
(original)
+++ webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/rpc/MultirefTest.java
Thu Apr  6 01:30:48 2006
@@ -295,7 +295,7 @@
 
             fail("This should fail with : " + "org.apache.axis2.AxisFault: Invalid reference
:2");
         } catch (AxisFault axisFault) {
-            String val = axisFault.getMessage();
+            String val = axisFault.getFaultDetailElement().toString();
             int index = val.indexOf("org.apache.axis2.AxisFault: Invalid reference :2");
             if (index < 0) {
                 fail("This should fail with : " + "org.apache.axis2.AxisFault: Invalid reference
:2");



Mime
View raw message