You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ws.apache.org by ve...@apache.org on 2012/07/04 19:43:02 UTC

svn commit: r1357344 - in /webservices/commons/trunk/modules/axiom/modules: axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/ axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/soap11/ axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/so...

Author: veithen
Date: Wed Jul  4 17:43:01 2012
New Revision: 1357344

URL: http://svn.apache.org/viewvc?rev=1357344&view=rev
Log:
Don't attempt to cache the result of SOAPFault#hasFault() if we are unable to keep the cached value up to date.

Added:
    webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/body/TestHasFaultAfterReplace.java   (with props)
Modified:
    webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/SOAPBodyImpl.java
    webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/soap11/SOAP11BodyImpl.java
    webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/soap12/SOAP12BodyImpl.java
    webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/soap/impl/dom/SOAPImplementationTest.java
    webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/soap/impl/llom/SOAPBodyImpl.java
    webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/SOAPTestSuiteBuilder.java
    webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/body/TestAddFault2.java

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/SOAPBodyImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/SOAPBodyImpl.java?rev=1357344&r1=1357343&r2=1357344&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/SOAPBodyImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/SOAPBodyImpl.java Wed Jul  4 17:43:01 2012
@@ -37,10 +37,6 @@ import org.apache.axiom.soap.SOAPProcess
 
 public abstract class SOAPBodyImpl extends SOAPElement implements SOAPBody,
         OMConstants {
-
-    /** Field hasSOAPFault */
-    protected boolean hasSOAPFault = false;
-
     /** @param envelope  */
     public SOAPBodyImpl(SOAPEnvelope envelope, SOAPFactory factory)
             throws SOAPProcessingException {
@@ -71,24 +67,15 @@ public abstract class SOAPBodyImpl exten
      *         <code>SOAPBody</code> object; <code>false</code> otherwise
      */
     public boolean hasFault() {
-        if (hasSOAPFault) {
-            return true;
+        OMElement element = getFirstElement();
+        if (element != null
+                && SOAPConstants.SOAPFAULT_LOCAL_NAME.equals(element.getLocalName())) {
+            OMNamespace ns = element.getNamespace();
+            return ns != null &&
+                    (SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(ns.getNamespaceURI()) ||
+                     SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(ns.getNamespaceURI()));
         } else {
-            OMElement element = getFirstElement();
-            if (element != null
-                    && SOAPConstants.SOAPFAULT_LOCAL_NAME.equals(element.getLocalName())) {
-                OMNamespace ns = element.getNamespace();
-                if (ns != null &&
-                        (SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(ns.getNamespaceURI()) ||
-                         SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(ns.getNamespaceURI()))) {
-                    hasSOAPFault = true;
-                    return true;
-                } else {
-                    return false;
-                }
-            } else {
-                return false;
-            }
+            return false;
         }
     }
 
@@ -99,15 +86,12 @@ public abstract class SOAPBodyImpl exten
      */
     public SOAPFault getFault() {
         OMElement element = getFirstElement();
-        if (hasSOAPFault) {
-            return (SOAPFault) element;
-        } else if (element != null
+        if (element != null
                 && SOAPConstants.SOAPFAULT_LOCAL_NAME.equals(element.getLocalName())) {
             OMNamespace ns = element.getNamespace();
             if (ns != null &&
                     (SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(ns.getNamespaceURI()) ||
                      SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(ns.getNamespaceURI()))) {
-                hasSOAPFault = true;
                 return (SOAPFault) element;
             } else {
                 return null;
@@ -124,13 +108,12 @@ public abstract class SOAPBodyImpl exten
      * @throws OMException
      */
     public void addFault(SOAPFault soapFault) throws OMException {
-        if (hasSOAPFault) {
+        if (hasFault()) {
             throw new OMException(
                     "SOAP Body already has a SOAP Fault and there can not be " +
                             "more than one SOAP fault");
         }
         addChild(soapFault);
-        hasSOAPFault = true;
     }
 
     protected void checkParent(OMElement parent) throws SOAPProcessingException {

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/soap11/SOAP11BodyImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/soap11/SOAP11BodyImpl.java?rev=1357344&r1=1357343&r2=1357344&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/soap11/SOAP11BodyImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/soap11/SOAP11BodyImpl.java Wed Jul  4 17:43:01 2012
@@ -45,9 +45,7 @@ public class SOAP11BodyImpl extends SOAP
     }
 
     public SOAPFault addFault(Exception e) throws OMException {
-        SOAPFault soapFault = new SOAP11FaultImpl(this, e, (SOAPFactory) this.factory);
-        this.hasSOAPFault = true;
-        return soapFault;
+        return new SOAP11FaultImpl(this, e, (SOAPFactory) this.factory);
     }
 
     protected OMElement createClone(OMCloneOptions options, ParentNode targetParent, boolean generateNSDecl) {

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/soap12/SOAP12BodyImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/soap12/SOAP12BodyImpl.java?rev=1357344&r1=1357343&r2=1357344&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/soap12/SOAP12BodyImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/soap12/SOAP12BodyImpl.java Wed Jul  4 17:43:01 2012
@@ -45,10 +45,7 @@ public class SOAP12BodyImpl extends SOAP
     }
 
     public SOAPFault addFault(Exception e) throws OMException {
-        SOAPFault soapFault = new SOAP12FaultImpl(this, e,
-                                                  (SOAPFactory) this.factory);
-        this.hasSOAPFault = true;
-        return soapFault;
+        return new SOAP12FaultImpl(this, e, (SOAPFactory) this.factory);
     }
 
     protected OMElement createClone(OMCloneOptions options, ParentNode targetParent, boolean generateNSDecl) {

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/soap/impl/dom/SOAPImplementationTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/soap/impl/dom/SOAPImplementationTest.java?rev=1357344&r1=1357343&r2=1357344&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/soap/impl/dom/SOAPImplementationTest.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/soap/impl/dom/SOAPImplementationTest.java Wed Jul  4 17:43:01 2012
@@ -23,6 +23,7 @@ import junit.framework.TestSuite;
 
 import org.apache.axiom.om.impl.dom.factory.OMDOMMetaFactory;
 import org.apache.axiom.ts.soap.SOAPTestSuiteBuilder;
+import org.apache.axiom.ts.soap.body.TestHasFaultAfterReplace;
 import org.apache.axiom.ts.soap.factory.TestGetDefaultFaultEnvelope;
 import org.apache.axiom.ts.soap.faultdetail.TestWSCommons202;
 import org.apache.axiom.ts.soap.faulttext.TestSetLang;
@@ -33,7 +34,10 @@ public class SOAPImplementationTest exte
     public static TestSuite suite() {
         SOAPTestSuiteBuilder builder = new SOAPTestSuiteBuilder(new OMDOMMetaFactory(), false, false);
         builder.exclude(TestWSCommons202.class);
-        builder.exclude(TestGetDefaultFaultEnvelope.class);
+        
+        // TODO: getDefaultFaultEnvelope is broken
+        builder.exclude(TestGetDefaultFaultEnvelope.class, "(spec=soap11)");
+        builder.exclude(TestHasFaultAfterReplace.class, "(spec=soap11)");
         
         // TODO: not sure if this is an issue in DOOM or if the test case is wrong
         builder.exclude(TestMoreChildrenAddition.class);

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/soap/impl/llom/SOAPBodyImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/soap/impl/llom/SOAPBodyImpl.java?rev=1357344&r1=1357343&r2=1357344&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/soap/impl/llom/SOAPBodyImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/soap/impl/llom/SOAPBodyImpl.java Wed Jul  4 17:43:01 2012
@@ -42,9 +42,6 @@ import javax.xml.stream.XMLStreamConstan
 /** Class SOAPBodyImpl */
 public abstract class SOAPBodyImpl extends SOAPElement
         implements SOAPBody, OMConstants {
-    /** Field hasSOAPFault */
-    private boolean hasSOAPFault = false;
-    
     private boolean enableLookAhead = true;
     private boolean lookAheadAttempted = false;
     private boolean lookAheadSuccessful = false;
@@ -94,24 +91,14 @@ public abstract class SOAPBodyImpl exten
      *         <code>SOAPBody</code> object; <code>false</code> otherwise
      */
     public boolean hasFault() {
-        if (hasSOAPFault) {
-            return true;
+        // Set hasSOAPFault if it matches the name matches a SOAP Fault
+        if (hasLookahead()) {
+            return SOAPConstants.SOAPFAULT_LOCAL_NAME.equals(lookAheadLocalName)
+                    && lookAheadNS != null
+                    && (SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(lookAheadNS.getNamespaceURI()) ||
+                        SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(lookAheadNS.getNamespaceURI()));
         } else {
-            // Set hasSOAPFault if it matches the name matches a SOAP Fault
-            if (hasLookahead()) {
-                if (SOAPConstants.SOAPFAULT_LOCAL_NAME.equals(lookAheadLocalName)) {
-                    if (lookAheadNS != null &&
-                        (SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(lookAheadNS.getNamespaceURI()) ||
-                         SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(lookAheadNS.getNamespaceURI()))) {
-                        hasSOAPFault = true;
-                    }                                                             
-                }
-            } else {
-                if (getFirstElement() instanceof SOAPFault) {
-                    hasSOAPFault = true;
-                }
-            }
-            return hasSOAPFault;
+            return getFirstElement() instanceof SOAPFault;
         }
     }
 
@@ -122,15 +109,12 @@ public abstract class SOAPBodyImpl exten
      */
     public SOAPFault getFault() {
         OMElement element = getFirstElement();
-        if (hasSOAPFault) {
-            return (SOAPFault) element;
-        } else if (element != null
+        if (element != null
                 && SOAPConstants.SOAPFAULT_LOCAL_NAME.equals(element.getLocalName())) {
             OMNamespace ns = element.getNamespace();
             if (ns != null &&
                     (SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(ns.getNamespaceURI()) ||
                      SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(ns.getNamespaceURI()))) {
-                hasSOAPFault = true;
                 return (SOAPFault) element;
             } else {
                 return null;
@@ -147,12 +131,11 @@ public abstract class SOAPBodyImpl exten
      * @throws OMException
      */
     public void addFault(SOAPFault soapFault) throws OMException {
-        if (hasSOAPFault) {
+        if (hasFault()) {
             throw new OMException(
                     "SOAP Body already has a SOAP Fault and there can not be more than one SOAP fault");
         }
         addChild(soapFault);
-        hasSOAPFault = true;
     }
 
     protected void checkParent(OMElement parent) throws SOAPProcessingException {

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/SOAPTestSuiteBuilder.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/SOAPTestSuiteBuilder.java?rev=1357344&r1=1357343&r2=1357344&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/SOAPTestSuiteBuilder.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/SOAPTestSuiteBuilder.java Wed Jul  4 17:43:01 2012
@@ -94,6 +94,7 @@ public class SOAPTestSuiteBuilder extend
         addTest(new org.apache.axiom.ts.soap.body.TestGetFirstElementLocalNameEmptyBody(metaFactory, spec));
         addTest(new org.apache.axiom.ts.soap.body.TestGetFirstElementNSEmptyBody(metaFactory, spec));
         addTest(new org.apache.axiom.ts.soap.body.TestHasFault(metaFactory, spec));
+        addTest(new org.apache.axiom.ts.soap.body.TestHasFaultAfterReplace(metaFactory, spec));
         if (supportsOMSourcedElement) {
             addTest(new org.apache.axiom.ts.soap.body.TestHasFaultWithOMSEUnknownName(metaFactory, spec));
         }

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/body/TestAddFault2.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/body/TestAddFault2.java?rev=1357344&r1=1357343&r2=1357344&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/body/TestAddFault2.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/body/TestAddFault2.java Wed Jul  4 17:43:01 2012
@@ -32,7 +32,7 @@ public class TestAddFault2 extends SOAPT
     protected void runTest() throws Throwable {
         SOAPEnvelope envelope = soapFactory.createSOAPEnvelope();
         SOAPBody body = soapFactory.createSOAPBody(envelope);
-        body.addFault(soapFactory.createSOAPFault(body));
+        body.addFault(soapFactory.createSOAPFault());
         assertTrue(
                 "Body Test:- After calling addFault method, SOAP body has no fault",
                 body.hasFault());

Added: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/body/TestHasFaultAfterReplace.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/body/TestHasFaultAfterReplace.java?rev=1357344&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/body/TestHasFaultAfterReplace.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/body/TestHasFaultAfterReplace.java Wed Jul  4 17:43:01 2012
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.axiom.ts.soap.body;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.soap.SOAPBody;
+import org.apache.axiom.ts.soap.SOAPSpec;
+import org.apache.axiom.ts.soap.SOAPTestCase;
+
+/**
+ * Tests that {@link SOAPBody#hasFault()} returns the correct value after a {@link SOAPFault} child
+ * has been replaced by an {@link OMElement} that is not a {@link SOAPFault}. Earlier versions of
+ * Axiom attempted to cache the result of {@link SOAPBody#hasFault()}, but this cached value was not
+ * updated correctly in all situations. This is a regression test for this issue.
+ */
+public class TestHasFaultAfterReplace extends SOAPTestCase {
+    public TestHasFaultAfterReplace(OMMetaFactory metaFactory, SOAPSpec spec) {
+        super(metaFactory, spec);
+    }
+
+    protected void runTest() throws Throwable {
+        SOAPBody body = soapFactory.getDefaultFaultEnvelope().getBody();
+        assertTrue(body.hasFault());
+        body.getFault().detach();
+        soapFactory.createOMElement("echo", soapFactory.createOMNamespace("urn:test", "echo"));
+        assertFalse(body.hasFault());
+    }
+}

Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/body/TestHasFaultAfterReplace.java
------------------------------------------------------------------------------
    svn:eol-style = native