axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r552618 - in /webservices/axis2/trunk/java/modules/saaj: src/org/apache/axis2/saaj/SOAPBodyImpl.java src/org/apache/axis2/saaj/SOAPFaultImpl.java test/org/apache/axis2/saaj/SOAPFaultTest.java
Date Mon, 02 Jul 2007 22:45:07 GMT
Author: gawor
Date: Mon Jul  2 15:45:06 2007
New Revision: 552618

URL: http://svn.apache.org/viewvc?view=rev&rev=552618
Log:
handle fault defaults better and remove some code duplication

Modified:
    webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPBodyImpl.java
    webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPFaultImpl.java
    webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/SOAPFaultTest.java

Modified: webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPBodyImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPBodyImpl.java?view=diff&rev=552618&r1=552617&r2=552618
==============================================================================
--- webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPBodyImpl.java
(original)
+++ webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPBodyImpl.java
Mon Jul  2 15:45:06 2007
@@ -24,8 +24,6 @@
 import org.apache.axiom.om.impl.dom.ElementImpl;
 import org.apache.axiom.om.impl.dom.NamespaceImpl;
 import org.apache.axiom.om.impl.dom.NodeImpl;
-import org.apache.axiom.soap.SOAP11Constants;
-import org.apache.axiom.soap.SOAP12Constants;
 import org.apache.axiom.soap.SOAPFactory;
 import org.apache.axiom.soap.impl.dom.soap11.SOAP11Factory;
 import org.apache.axiom.soap.impl.dom.soap11.SOAP11FaultImpl;
@@ -181,19 +179,14 @@
             SOAP11FaultImpl fault =
                     new SOAP11FaultImpl(omSOAPBody, (SOAPFactory)this.element.getOMFactory());
             saajSOAPFault = new SOAPFaultImpl(fault);
-            //set a default fault code here.
-            saajSOAPFault.setFaultCode(SOAP11Constants.QNAME_SENDER_FAULTCODE);
-            //set a default fault string here
-            saajSOAPFault.setFaultString("Fault string, and possibly fault code, not set");
         } else if (this.element.getOMFactory() instanceof SOAP12Factory) {
             SOAP12FaultImpl fault =
                     new SOAP12FaultImpl(omSOAPBody, (SOAPFactory)this.element.getOMFactory());
             saajSOAPFault = new SOAPFaultImpl(fault);
-            //set a default fault code here.
-            saajSOAPFault.setFaultCode(SOAP12Constants.QNAME_SENDER_FAULTCODE);
-            //set a default fault string here
-            saajSOAPFault.addFaultReasonText("Fault string, and possibly fault code, not
set", Locale.getDefault());
         }
+        // set default fault code and string
+        saajSOAPFault.setDefaults();
+        
         ((NodeImpl)omSOAPBody.getFault()).setUserData(SAAJ_NODE, saajSOAPFault, null);
         return saajSOAPFault;
     }

Modified: webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPFaultImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPFaultImpl.java?view=diff&rev=552618&r1=552617&r2=552618
==============================================================================
--- webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPFaultImpl.java
(original)
+++ webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPFaultImpl.java
Mon Jul  2 15:45:06 2007
@@ -25,6 +25,7 @@
 import org.apache.axiom.om.impl.dom.ElementImpl;
 import org.apache.axiom.om.impl.dom.NodeImpl;
 import org.apache.axiom.soap.SOAP11Constants;
+import org.apache.axiom.soap.SOAP12Constants;
 import org.apache.axiom.soap.SOAPFactory;
 import org.apache.axiom.soap.SOAPFaultCode;
 import org.apache.axiom.soap.SOAPFaultDetail;
@@ -65,6 +66,7 @@
     private boolean isDetailAdded;
     private Name faultCodeName;
     private Locale faultReasonLocale;
+    private boolean defaultsSet;
 
     /** @param fault  */
     public SOAPFaultImpl(org.apache.axiom.soap.SOAPFault fault) {
@@ -72,6 +74,26 @@
         this.fault = fault;
     }
 
+    void setDefaults() throws SOAPException {
+        if (this.element.getOMFactory() instanceof SOAP11Factory) {
+            setFaultCode(SOAP11Constants.QNAME_SENDER_FAULTCODE);
+        } else {
+            setFaultCode(SOAP12Constants.QNAME_SENDER_FAULTCODE);
+        }
+        setFaultString("Fault string, and possibly fault code, not set");
+        defaultsSet = true;
+    }
+    
+    void removeDefaults() {
+        if (defaultsSet) {
+            SOAPFaultReason reason = this.fault.getReason();
+            if (reason != null) {
+                reason.detach();
+            }
+            defaultsSet = false;
+        }
+    }
+    
     /**
      * Sets this <CODE>SOAPFault</CODE> object with the given fault code.
      * <p/>
@@ -192,36 +214,10 @@
      * @see #getFaultString() getFaultString()
      */
     public void setFaultString(String faultString) throws SOAPException {
-
-        boolean isSoap11 = this.element.getNamespace().getNamespaceURI()
-                .equals(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);
-
-        if (this.fault.getReason() != null) {
-            SOAPFaultReason reason = this.fault.getReason();
-            if (isSoap11) {
-                reason.setText(faultString);
-            } else {
-                if (reason.getFirstSOAPText() != null) {
-                    reason.getFirstSOAPText().getFirstOMChild().detach();
-                    reason.getFirstSOAPText().setText(faultString);
-                } else {
-                    SOAPFaultText text = new SOAP12FaultTextImpl(reason,
-                                                                 (SOAPFactory)this.element
-                                                                         .getOMFactory());
-                    text.setText(faultString);
-                    reason.addSOAPText(text);
-                }
-            }
-        } else {
-            org.apache.axiom.soap.SOAPFactory soapFactory =
-                    (SOAPFactory)this.element.getOMFactory();
-            SOAPFaultReason faultReason = soapFactory.createSOAPFaultReason(fault);
-            if (isSoap11) {
-                faultReason.setText(faultString);
-            } else {
-                SOAPFaultText faultText = soapFactory.createSOAPFaultText(faultReason);
-                faultText.setText(faultString);
-            }
+        if (this.element.getOMFactory() instanceof SOAP11Factory) {
+            setFaultString(faultString, null);
+        } else if (this.element.getOMFactory() instanceof SOAP12Factory) {
+            setFaultString(faultString, Locale.getDefault());
         }
     }
 
@@ -325,12 +321,7 @@
             if (this.element.getOMFactory() instanceof SOAP11Factory) {
                 reason.setText(faultString);
             } else if (this.element.getOMFactory() instanceof SOAP12Factory) {
-                if (reason.getFirstSOAPText() != null) {
-                    reason.getFirstSOAPText().setText(faultString);
-                    reason.getFirstSOAPText().setLang(locale.toString());
-                } else {
-                    addFaultReasonText(faultString, locale);
-                }
+                addFaultReasonText(faultString, locale);
             }
         } else {
             if (this.element.getOMFactory() instanceof SOAP11Factory) {
@@ -396,6 +387,8 @@
         if (this.element.getOMFactory() instanceof SOAP11Factory) {
             throw new UnsupportedOperationException("Not supported in SOAP 1.1");
         } else if (this.element.getOMFactory() instanceof SOAP12Factory) {
+            removeDefaults();
+            
             String existingReasonText = getFaultReasonText(locale);
             if (existingReasonText == null) {
                 org.apache.axiom.soap.SOAPFactory soapFactory = null;
@@ -574,7 +567,7 @@
             throw new UnsupportedOperationException("Message does not support the " +
                     "SOAP 1.2 concept of Fault Reason");
         } else {
-            Iterator soapTextsItr = new ArrayList().iterator();
+            Iterator soapTextsItr = null;
             SOAPFaultReason soapFaultReason = this.fault.getReason();
             if (soapFaultReason != null) {
                 List soapTexts = soapFaultReason.getAllSoapTexts();

Modified: webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/SOAPFaultTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/SOAPFaultTest.java?view=diff&rev=552618&r1=552617&r2=552618
==============================================================================
--- webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/SOAPFaultTest.java
(original)
+++ webservices/axis2/trunk/java/modules/saaj/test/org/apache/axis2/saaj/SOAPFaultTest.java
Mon Jul  2 15:45:06 2007
@@ -445,9 +445,11 @@
 
             SOAPEnvelope envelope = soapPart.getEnvelope();
             SOAPBody body = envelope.getBody();
-            SOAPFault sf = body.addFault(SOAPConstants.SOAP_RECEIVER_FAULT, "Its my fault",
Locale.ENGLISH);
+            SOAPFault sf = body.addFault();
+            
             String expected = "Its my fault again";
             boolean found = false;
+            sf.addFaultReasonText("Its my fault", Locale.ENGLISH);
             sf.addFaultReasonText(expected, Locale.ENGLISH);
             Iterator i = sf.getFaultReasonTexts();
             int j = 0;
@@ -484,14 +486,14 @@
         SOAPPart soapPart = soapMessage.getSOAPPart();
         SOAPEnvelope envelope = soapPart.getEnvelope();
         SOAPBody body = envelope.getBody();
-
+        SOAPFault sf = body.addFault();
+        
         String expected1 = "Its my fault";
         String expected2 = "Its my fault again";
 
-        SOAPFault sf = body.addFault(SOAPConstants.SOAP_RECEIVER_FAULT, expected1, Locale.UK);
-
         boolean found1 = false;
         boolean found2 = false;
+        sf.addFaultReasonText(expected1, Locale.UK);
         sf.addFaultReasonText(expected2, Locale.ENGLISH);
         Iterator i = sf.getFaultReasonTexts();
         int j = 0;
@@ -648,7 +650,8 @@
             SOAPPart soapPart = soapMessage.getSOAPPart();
             SOAPEnvelope envelope = soapPart.getEnvelope();
             SOAPBody body = envelope.getBody();
-
+            SOAPFault sf = body.addFault();
+            
             Locale expected1 = Locale.ENGLISH;
             Locale expected2 = Locale.UK;
             Locale expected3 = Locale.GERMAN;
@@ -656,9 +659,8 @@
             boolean found2 = false;
             boolean found3 = false;
 
-            SOAPFault sf = body.addFault(SOAPConstants.SOAP_RECEIVER_FAULT, "Its my fault1",
expected1);
-
             System.out.println("Adding FaultReasonText to SOAPFault");
+            sf.addFaultReasonText("Its my fault1", expected1);
             sf.addFaultReasonText("Its my fault2", expected2);
             sf.addFaultReasonText("Its my fault3", expected3);
             System.out.println("Getting FaultReasonLocales from SOAPFault");



---------------------------------------------------------------------
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