Author: scheu
Date: Tue Feb 12 13:25:17 2008
New Revision: 627116
URL: http://svn.apache.org/viewvc?rev=627116&view=rev
Log:
WSCOMMONS-302
Contributor:Rich Scheuerle
Detect when an Axiom caller adds a raw OMElement child to a SOAPHeader.
In such situations, debug trace will be logged, and processing will continue.
Since we have existing tests in Axis2 that depend on this ill-defined behavior,
I chose to log a message instead of throwing an exception.
The new trace information will make it easy to determine which caller (QOS) is
adding
the incorrect element.
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/soap/impl/llom/SOAPHeaderImpl.java
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/factory/OMLinkedListImplFactoryTest.java
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/soap/impl/llom/SOAPHeaderImpl.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/soap/impl/llom/SOAPHeaderImpl.java?rev=627116&r1=627115&r2=627116&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/soap/impl/llom/SOAPHeaderImpl.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/soap/impl/llom/SOAPHeaderImpl.java
Tue Feb 12 13:25:17 2008
@@ -34,6 +34,8 @@
import org.apache.axiom.soap.SOAPHeaderBlock;
import org.apache.axiom.soap.SOAPProcessingException;
import org.apache.axiom.soap.SOAPVersion;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import java.util.ArrayList;
import java.util.Iterator;
@@ -159,6 +161,8 @@
/** A class representing the SOAP Header, primarily allowing access to the
contained HeaderBlocks. */
public abstract class SOAPHeaderImpl extends SOAPElement implements SOAPHeader
{
+
+ Log log = LogFactory.getLog(SOAPHeaderImpl.class);
/** An Iterator which walks the header list as needed, potentially
filtering as we traverse. */
class HeaderIterator implements Iterator {
SOAPHeaderBlock current;
@@ -401,5 +405,34 @@
throw new SOAPProcessingException(
"Expecting an implementation of SOAP Envelope as the
parent. But received some other implementation");
}
+ }
+
+
+ public void addChild(OMNode child) {
+
+ // Make sure a proper element is added. The children of a SOAPHeader
should be
+ // SOAPHeaderBlock objects.
+ // Due to legacy usages (AXIS2 has a lot of tests that violate this
constraint)
+ // I am only going to log an exception when debug is enabled.
+ if (log.isDebugEnabled()) {
+ if (child instanceof OMElement &&
+ !(child instanceof SOAPHeaderBlock)) {
+ Exception e = new SOAPProcessingException(
+ "An attempt was made to add a normal OMElement as a child of
a SOAPHeader." +
+ " This is not supported. The child should be a
SOAPHeaderBlock.");
+ log.debug(exceptionToString(e));
+ }
+ }
+ super.addChild(child);
+ }
+
+ public static String exceptionToString(Throwable e) {
+ java.io.StringWriter sw = new java.io.StringWriter();
+ java.io.BufferedWriter bw = new java.io.BufferedWriter(sw);
+ java.io.PrintWriter pw = new java.io.PrintWriter(bw);
+ e.printStackTrace(pw);
+ pw.close();
+ String text = sw.getBuffer().toString();
+ return text;
}
}
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/factory/OMLinkedListImplFactoryTest.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/factory/OMLinkedListImplFactoryTest.java?rev=627116&r1=627115&r2=627116&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/factory/OMLinkedListImplFactoryTest.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/factory/OMLinkedListImplFactoryTest.java
Tue Feb 12 13:25:17 2008
@@ -23,6 +23,7 @@
import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMNamespace;
+import org.apache.axiom.om.OMNode;
import org.apache.axiom.om.OMTestUtils;
import org.apache.axiom.om.OMText;
import org.apache.axiom.om.OMXMLParserWrapper;
@@ -67,7 +68,15 @@
OMXMLParserWrapper omBuilder = OMTestUtils.getOMBuilder(
getTestResourceFile("soap/whitespacedMessage.xml"));
OMElement envelope = omBuilder.getDocumentElement();
- OMElement body = envelope.getFirstElement();
+
+ // The body is the second element
+ OMNode node = envelope.getFirstElement();
+ node = node.getNextOMSibling();
+ while (node != null && !(node instanceof OMElement)) {
+ node = node.getNextOMSibling();
+ }
+ OMElement body = (OMElement) node;
+
OMElement child = omFactory.createOMElement("child",
namespace,
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]