You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commons-dev@ws.apache.org by sc...@apache.org on 2006/07/25 18:23:24 UTC
svn commit: r425447 - in /webservices/commons/trunk/modules/axiom: ./
src/org/apache/axiom/om/impl/llom/ src/org/apache/axiom/om/impl/serialize/
src/org/apache/axiom/om/impl/util/
src/org/apache/axiom/soap/impl/dom/soap11/ src/org/apache/axiom/soap/imp...
Author: scheu
Date: Tue Jul 25 09:23:21 2006
New Revision: 425447
URL: http://svn.apache.org/viewvc?rev=425447&view=rev
Log:
WSCOMMONS-66 WSCOMMONS-62
WSCOMMONS-66
Fixes to make sure that setPrefix and writeStartElement are correctly sequenced according to the specifications of the target writer
Contributor: Rich Scheuerle
WSCOMMONS-62
Contributed testcase
Contributor: David Illsley
Added:
webservices/commons/trunk/modules/axiom/test-resources/soap/soap11/soapfault1.xml
webservices/commons/trunk/modules/axiom/test-resources/soap/soap11/soapfault2.xml
webservices/commons/trunk/modules/axiom/test/org/apache/axiom/om/impl/serializer/OMFaultSerializerTest.java
Modified:
webservices/commons/trunk/modules/axiom/NOTICE.txt
webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/llom/OMTextImpl.java
webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/serialize/StreamingOMSerializer.java
webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/util/OMSerializerUtil.java
webservices/commons/trunk/modules/axiom/src/org/apache/axiom/soap/impl/dom/soap11/SOAP11FaultCodeImpl.java
webservices/commons/trunk/modules/axiom/src/org/apache/axiom/soap/impl/dom/soap11/SOAP11FaultDetailImpl.java
webservices/commons/trunk/modules/axiom/src/org/apache/axiom/soap/impl/dom/soap11/SOAP11FaultReasonImpl.java
webservices/commons/trunk/modules/axiom/src/org/apache/axiom/soap/impl/dom/soap11/SOAP11FaultRoleImpl.java
webservices/commons/trunk/modules/axiom/src/org/apache/axiom/soap/impl/llom/SOAPFaultDetailImpl.java
webservices/commons/trunk/modules/axiom/src/org/apache/axiom/soap/impl/llom/soap11/SOAP11FaultCodeImpl.java
webservices/commons/trunk/modules/axiom/src/org/apache/axiom/soap/impl/llom/soap11/SOAP11FaultDetailImpl.java
webservices/commons/trunk/modules/axiom/src/org/apache/axiom/soap/impl/llom/soap11/SOAP11FaultReasonImpl.java
webservices/commons/trunk/modules/axiom/src/org/apache/axiom/soap/impl/llom/soap11/SOAP11FaultRoleImpl.java
webservices/commons/trunk/modules/axiom/test/org/apache/axiom/om/DefaultNSHandlingTest.java
webservices/commons/trunk/modules/axiom/test/org/apache/axiom/om/OMElementCloneTest.java
Modified: webservices/commons/trunk/modules/axiom/NOTICE.txt
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/NOTICE.txt?rev=425447&r1=425446&r2=425447&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/NOTICE.txt (original)
+++ webservices/commons/trunk/modules/axiom/NOTICE.txt Tue Jul 25 09:23:21 2006
@@ -6,6 +6,7 @@
This product includes software developed by
The Apache Software Foundation (http://www.apache.org/).
+ Portions Copyright 2006 International Business Machines Corp.
Please read the different LICENSE files present in the licenses directory of
this distribution.
Modified: webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/llom/OMTextImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/llom/OMTextImpl.java?rev=425447&r1=425446&r2=425447&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/llom/OMTextImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/llom/OMTextImpl.java Tue Jul 25 09:23:21 2006
@@ -27,6 +27,7 @@
import org.apache.axiom.om.OMXMLParserWrapper;
import org.apache.axiom.om.impl.MTOMXMLStreamWriter;
import org.apache.axiom.om.impl.mtom.MTOMStAXSOAPModelBuilder;
+import org.apache.axiom.om.impl.util.OMSerializerUtil;
import org.apache.axiom.om.util.Base64;
import org.apache.axiom.om.util.UUIDGenerator;
@@ -437,9 +438,17 @@
writer.writeStartElement(nameSpaceName, this
.getLocalName());
} else {
- writer.writeStartElement(prefix, this.getLocalName(),
- nameSpaceName);
- writer.setPrefix(prefix, nameSpaceName);
+ // According to StAX, setPrefix must occur before
+ // writeStartElement
+ if (OMSerializerUtil.isSetPrefixBeforeStartElement(writer)) {
+ writer.setPrefix(prefix, nameSpaceName);
+ writer.writeStartElement(prefix, this.getLocalName(),
+ nameSpaceName);
+ } else {
+ writer.writeStartElement(prefix, this.getLocalName(),
+ nameSpaceName);
+ writer.setPrefix(prefix, nameSpaceName);
+ }
}
// add the elements attribute "href"
serializeAttribute(this.attribute, writer);
Modified: webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/serialize/StreamingOMSerializer.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/serialize/StreamingOMSerializer.java?rev=425447&r1=425446&r2=425447&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/serialize/StreamingOMSerializer.java (original)
+++ webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/serialize/StreamingOMSerializer.java Tue Jul 25 09:23:21 2006
@@ -16,7 +16,10 @@
package org.apache.axiom.om.impl.serialize;
+import java.util.ArrayList;
+
import org.apache.axiom.om.OMSerializer;
+import org.apache.axiom.om.impl.util.OMSerializerUtil;
import javax.xml.namespace.NamespaceContext;
import javax.xml.stream.XMLStreamConstants;
@@ -106,49 +109,202 @@
*/
protected void serializeElement(XMLStreamReader reader,
XMLStreamWriter writer)
- throws XMLStreamException {
- String prefix = reader.getPrefix();
- String nameSpaceName = reader.getNamespaceURI();
- if (nameSpaceName != null) {
- String writer_prefix = writer.getPrefix(nameSpaceName);
- if (writer_prefix != null) {
- writer.writeStartElement(nameSpaceName, reader.getLocalName());
- } else {
- if (prefix != null) {
- writer.writeStartElement(prefix, reader.getLocalName(),
- nameSpaceName);
- writer.writeNamespace(prefix, nameSpaceName);
- writer.setPrefix(prefix, nameSpaceName);
- } else {
- writer.writeStartElement(nameSpaceName,
- reader.getLocalName());
- writer.writeDefaultNamespace(nameSpaceName);
- writer.setDefaultNamespace(nameSpaceName);
- }
- }
- } else {
- writer.writeStartElement(reader.getLocalName());
+ throws XMLStreamException {
+
+ // Note: To serialize the start tag, we must follow the order dictated by the JSR-173 (StAX) specification.
+ // Please keep this code in sync with the code in OMSerializerUtil.serializeStartpart
+
+ // The algorithm is:
+ // ... generate setPrefix/setDefaultNamespace for each namespace declaration if the prefix is unassociated.
+ // ... generate setPrefix/setDefaultNamespace if the prefix of the element is unassociated
+ // ... generate setPrefix/setDefaultNamespace for each unassociated prefix of the attributes.
+ //
+ // ... generate writeStartElement (See NOTE_A)
+ //
+ // ... generate writeNamespace/writerDefaultNamespace for each namespace declaration on the element
+ // ... generate writeNamespace/writeDefaultNamespace for any new "autogen" namespace/prefixes
+ // ... generate writeAttribute for each attribute
+
+ // NOTE_A: To confuse matters, some StAX vendors (including woodstox), believe that the setPrefix bindings
+ // should occur after the writeStartElement. If this is the case, the writeStartElement is generated first.
+
+ ArrayList prefixList = null;
+ ArrayList nsList = null;
+
+
+ // Get the prefix and namespace of the element. "" and null are identical.
+ String ePrefix = reader.getPrefix();
+ ePrefix = (ePrefix != null && ePrefix.length() == 0) ? null : ePrefix;
+ String eNamespace = reader.getNamespaceURI();
+ eNamespace = (eNamespace != null && eNamespace.length() == 0) ? null : eNamespace;
+
+ // Write the startElement if required
+ boolean setPrefixFirst = OMSerializerUtil.isSetPrefixBeforeStartElement(writer);
+ if (!setPrefixFirst) {
+ if (eNamespace != null) {
+ if (ePrefix == null) {
+ writer.writeStartElement("", reader.getLocalName(), eNamespace);
+ } else {
+ writer.writeStartElement(ePrefix, reader.getLocalName(), eNamespace);
+ }
+ } else {
+ writer.writeStartElement(reader.getLocalName());
+ }
}
-
-
- // add the namespaces
+
+ // Generate setPrefix for the namespace declarations
int count = reader.getNamespaceCount();
- String namespacePrefix;
for (int i = 0; i < count; i++) {
- namespacePrefix = reader.getNamespacePrefix(i);
- if(namespacePrefix != null && namespacePrefix.length()==0)
- continue;
-
- serializeNamespace(namespacePrefix,
- reader.getNamespaceURI(i), writer);
+ String prefix = reader.getNamespacePrefix(i);
+ prefix = (prefix != null && prefix.length() == 0) ? null : prefix;
+ String namespace = reader.getNamespaceURI(i);
+ namespace = (namespace != null && namespace.length() == 0) ? null : namespace;
+
+ generateSetPrefix(prefix, namespace, writer);
+ }
+
+ // Generate setPrefix for the element
+ // If the prefix is not associated with a namespace yet, remember it so that we can
+ // write out a namespace declaration
+ String newPrefix = generateSetPrefix(ePrefix, eNamespace, writer);
+
+ if (newPrefix != null) {
+ if (prefixList == null) {
+ prefixList= new ArrayList();
+ nsList = new ArrayList();
+ }
+ if (!prefixList.contains(newPrefix)) {
+ prefixList.add(newPrefix);
+ nsList.add(eNamespace);
+ }
+ }
+
+ // Now write the namespaces for each attribute
+ count = reader.getAttributeCount();
+ for (int i = 0; i < count; i++) {
+ String prefix = reader.getAttributePrefix(i);
+ prefix = (prefix != null && prefix.length() == 0) ? null : prefix;
+ String namespace = reader.getAttributeNamespace(i);
+ namespace = (namespace != null && namespace.length() == 0) ? null : namespace;
+
+ // Default prefix referencing is not allowed on an attribute
+ if (prefix == null && namespace != null) {
+ String writerPrefix = writer.getPrefix(namespace);
+ writerPrefix = (writerPrefix != null && writerPrefix.length() == 0) ? null : writerPrefix;
+ prefix = (writerPrefix != null) ?
+ writerPrefix :
+ generateUniquePrefix(writer.getNamespaceContext());
+ }
+ newPrefix = generateSetPrefix(prefix, namespace, writer);
+ // If the prefix is not associated with a namespace yet, remember it so that we can
+ // write out a namespace declaration
+ if (newPrefix != null) {
+ if (prefixList == null) {
+ prefixList= new ArrayList();
+ nsList = new ArrayList();
+ }
+ if (!prefixList.contains(newPrefix)) {
+ prefixList.add(newPrefix);
+ nsList.add(namespace);
+ }
+ }
+ }
+
+ // Now write the startElement
+ if (setPrefixFirst) {
+ if (eNamespace != null) {
+ if (ePrefix == null) {
+ writer.writeStartElement("", reader.getLocalName(), eNamespace);
+ } else {
+ writer.writeStartElement(ePrefix, reader.getLocalName(), eNamespace);
+ }
+ } else {
+ writer.writeStartElement(reader.getLocalName());
+ }
}
- // add attributes
- serializeAttributes(reader, writer);
+ // add the namespaces
+ count = reader.getNamespaceCount();
+ String namespacePrefix;
+ for (int i = 0; i < count; i++) {
+ String prefix = reader.getNamespacePrefix(i);
+ prefix = (prefix != null && prefix.length() == 0) ? null : prefix;
+ String namespace = reader.getNamespaceURI(i);
+ if (prefix != null && namespace != null) {
+ writer.writeNamespace(prefix, namespace);
+ } else {
+ writer.writeDefaultNamespace(namespace);
+ }
+ // If this prefix is in the unassociated list, remove it.
+ if (prefixList != null) {
+ int j = prefixList.indexOf((prefix == null)?"":prefix);
+ if (j >= 0) {
+ prefixList.remove(j);
+ nsList.remove(j);
+ }
+ }
+ }
+
+ // Now write out the namespaces that for prefixes that are not associated
+ if (prefixList != null) {
+ for (int i=0; i<prefixList.size(); i++) {
+ String prefix = (String) prefixList.get(i);
+ String namespace = (String) nsList.get(i);
+
+ if (prefix != null) {
+ writer.writeNamespace(prefix, namespace);
+ } else {
+ writer.writeDefaultNamespace(namespace);
+ }
+ }
+ }
+
+ // Now write the attributes
+ count = reader.getAttributeCount();
+ for (int i = 0; i < count; i++) {
+ String prefix = reader.getAttributePrefix(i);
+ prefix = (prefix != null && prefix.length() == 0) ? null : prefix;
+ String namespace = reader.getAttributeNamespace(i);
+ namespace = (namespace != null && namespace.length() == 0) ? null : namespace;
+
+
+ if (prefix == null && namespace != null) {
+ // Default namespaces are not allowed on an attribute reference.
+ // Earlier in this code, a unique prefix was added for this case...now obtain and use it
+ prefix = writer.getPrefix(namespace);
+ } else if (namespace != null) {
+ // Use the writer's prefix if it is different
+ String writerPrefix = writer.getPrefix(namespace);
+ if (!prefix.equals(writerPrefix)) {
+ prefix = writerPrefix;
+ }
+ }
+ if (namespace != null) {
+ // Qualified attribute
+ writer.writeAttribute(prefix, namespace,
+ reader.getAttributeLocalName(i),
+ reader.getAttributeValue(i));
+ } else {
+ // Unqualified attribute
+ writer.writeAttribute(reader.getAttributeLocalName(i),
+ reader.getAttributeValue(i));
+ }
+ }
}
- /**
+ /**
+ * Generate setPrefix/setDefaultNamespace if the prefix is not associated
+ * @param prefix
+ * @param namespace
+ * @param writer
+ * @return prefix name if a setPrefix/setDefaultNamespace is performed
+ */
+ private String generateSetPrefix(String prefix, String namespace, XMLStreamWriter writer) throws XMLStreamException {
+ return OMSerializerUtil.generateSetPrefix(prefix, namespace, writer);
+ }
+
+ /**
* Method serializeEndElement.
*
* @param writer
Modified: webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/util/OMSerializerUtil.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/util/OMSerializerUtil.java?rev=425447&r1=425446&r2=425447&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/util/OMSerializerUtil.java (original)
+++ webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/util/OMSerializerUtil.java Tue Jul 25 09:23:21 2006
@@ -23,9 +23,12 @@
import org.apache.axiom.om.impl.OMNodeEx;
import org.apache.axiom.om.impl.serialize.StreamingOMSerializer;
+import javax.xml.namespace.NamespaceContext;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.XMLStreamWriter;
+
+import java.util.ArrayList;
import java.util.Iterator;
public class OMSerializerUtil {
@@ -50,6 +53,7 @@
* @param attr
* @param writer
* @throws XMLStreamException
+ * @deprecated use serializeStartpart instead
*/
public static void serializeAttribute(OMAttribute attr, XMLStreamWriter writer)
throws XMLStreamException {
@@ -83,6 +87,7 @@
* @param namespace
* @param writer
* @throws XMLStreamException
+ * @deprecated Use serializeStartpart instead
*/
public static void serializeNamespace(OMNamespace namespace, XMLStreamWriter writer)
throws XMLStreamException {
@@ -131,115 +136,257 @@
}
/**
+ * Unfortunately there is disagreement in the user community about the semantics of
+ * setPrefix on the XMLStreamWriter. An example will explain the difference:
+ * writer.startElement("a")
+ * writer.setPrefix("pre", "urn://sample")
+ * writer.startElement("b")
+ *
+ * Some user communities (woodstox) believe that the setPrefix is associate with the scope
+ * for "a" and thus remains in scope until the end of a. The basis for this believe is
+ * XMLStreamWriter javadoc (which some would argue is incomplete).
+ *
+ * Some user communities believe that the setPrefix is associated with the "b" element.
+ * These communities reference an example in the specification and historical usage of SAX.
+ *
+ * This method will return true if the setPrefix is associated with the next writeStartElement.
+ *
+ * @param writer
+ * @return true if setPrefix should be generated before startElement
+ */
+ public static boolean isSetPrefixBeforeStartElement(XMLStreamWriter writer) {
+ NamespaceContext nc = writer.getNamespaceContext();
+ return(nc ==null || !nc.getClass().getName().contains("wstx"));
+ }
+
+ /**
* Method serializeStartpart.
+ * Serialize the start tag of an element.
*
+ * @param element
* @param writer
* @throws XMLStreamException
*/
- public static void serializeStartpart
- (OMElement
- element, XMLStreamWriter writer)
+ public static void serializeStartpart(OMElement element,
+ XMLStreamWriter writer) throws XMLStreamException {
+ serializeStartpart(element, element.getLocalName(), writer);
+ }
+
+ /**
+ * Method serializeStartpart.
+ * Serialize the start tag of an element.
+ *
+ * @param element
+ * @param localName (in some cases, the caller wants to force a different localName)
+ * @param writer
+ * @throws XMLStreamException
+ */
+ public static void serializeStartpart(OMElement element, String localName, XMLStreamWriter writer)
throws XMLStreamException {
- String nameSpaceName;
- String writer_prefix;
- String prefix;
- if (element.getNamespace() != null) {
- nameSpaceName = element.getNamespace().getName();
- prefix = element.getNamespace().getPrefix();
- if (nameSpaceName != null && !"".equals(nameSpaceName)) {
- writer_prefix = writer.getPrefix(nameSpaceName);
-
- // if the writer has no prefix registered for the given namespace, no matter what prefix the
- // ns contains, use that to handle the ns
- if (writer_prefix == null && !"".equals(prefix)) {
- prefix = (prefix == null) ? getNextNSPrefix(writer) : prefix;
- writer.writeStartElement(prefix, element.getLocalName(),
- nameSpaceName);
- writer.writeNamespace(prefix, nameSpaceName);
- writer.setPrefix(prefix, nameSpaceName);
- } else if (prefix == null) {
- // by this time prefix is null and writer_prefix is not null
- writer.writeStartElement(nameSpaceName,
- element.getLocalName());
- } else {
- // now lets handle the case where (prefix != null && writer_prefix != null)
- if ("".equals(prefix) && "".equals(writer_prefix)) {
- // now this element is trying to use a default namespace and at the same point
- // exists a default namespace with the given ns URI.
- // but the problem here is that, what if the xml is like the following
- // <One xmlns="one.org" >
- // <Two xmlns="two.org">
- // <Three xmlns="one.org" />
- // </Two>
- // </One>
- //
- // if we ask the prefix registered with one.org, the parser will return ""
- // which is the default ns. But if we do not declare a new default ns explicitly here
- // then this causes problem as element Two has already overriden the default ns.
- //
- // Solution for this is to ask from the parser the nsURI attached to "" at this
- // moment and compare the return uri with namespace name
- if (nameSpaceName.equals(writer.getNamespaceContext().getNamespaceURI("")))
- {
- writer.writeStartElement(nameSpaceName, element.getLocalName());
- } else {
- writer.writeStartElement(prefix, element.getLocalName(),
- nameSpaceName);
- writer.writeDefaultNamespace(nameSpaceName);
- writer.setDefaultNamespace(nameSpaceName);
- }
- } else if (prefix.equals(writer_prefix)) {
- writer.writeStartElement(nameSpaceName, element.getLocalName());
- } else if ("".equals(prefix)) {
- writer.writeStartElement(prefix, element.getLocalName(),
- nameSpaceName);
- writer.writeDefaultNamespace(nameSpaceName);
- writer.setDefaultNamespace(nameSpaceName);
- } else {
- // now the left scenario is this
- // 1. prefix != "" && writer_prefix != "" but writer_prefix != prefix
- // 2. prefix != "" && writer_prefix == ""
-
- // In both the above cases this xml may contain more than one prefix for the
- // same URI. Check them all.
-
- // this flag will remember whether this ns is declared in the scope with the
- // given prefix or not
- boolean found = checkForPrefixInTheCurrentContext(writer, nameSpaceName, prefix);
-
- if (!found) {
- // seems we haven't found one in the current scope. So declare it.
- writer.writeStartElement(prefix, element.getLocalName(),
- nameSpaceName);
- writer.writeNamespace(prefix, nameSpaceName);
- writer.setPrefix(prefix, nameSpaceName);
- } else {
- writer.writeStartElement(prefix, element.getLocalName(), nameSpaceName);
- }
-
- }
- }
-
+
+ // Note: To serialize the start tag, we must follow the order dictated by the JSR-173 (StAX) specification.
+ // Please keep this code in sync with the code in StreamingOMSerializer.serializeElement
+
+ // The algorithm is:
+ // ... generate setPrefix/setDefaultNamespace for each namespace declaration if the prefix is unassociated.
+ // ... generate setPrefix/setDefaultNamespace if the prefix of the element is unassociated
+ // ... generate setPrefix/setDefaultNamespace for each unassociated prefix of the attributes.
+ //
+ // ... generate writeStartElement (See NOTE_A)
+ //
+ // ... generate writeNamespace/writerDefaultNamespace for each namespace declaration on the element
+ // ... generate writeNamespace/writeDefaultNamespace for any new "autogen" namespace/prefixes
+ // ... generate writeAttribute for each attribute
+
+ // NOTE_A: To confuse matters, some StAX vendors (including woodstox), believe that the setPrefix bindings
+ // should occur after the writeStartElement. If this is the case, the writeStartElement is generated first.
+
+
+ ArrayList prefixList = null;
+ ArrayList nsList = null;
+
+ // Get the namespace and prefix of the element
+ OMNamespace eOMNamespace = element.getNamespace();
+ String ePrefix = null;
+ String eNamespace = null;
+ if (eOMNamespace != null) {
+ ePrefix = eOMNamespace.getPrefix();
+ eNamespace = eOMNamespace.getName();
+ }
+ ePrefix = (ePrefix != null && ePrefix.length() == 0) ? null : ePrefix;
+ eNamespace = (eNamespace != null && eNamespace.length() == 0) ? null : eNamespace;
+
+ // Write the startElement if required
+ boolean setPrefixFirst = isSetPrefixBeforeStartElement(writer);
+ if (!setPrefixFirst) {
+ if (eNamespace != null) {
+ if (ePrefix == null) {
+ writer.writeStartElement("", localName, eNamespace);
+ } else {
+ writer.writeStartElement(ePrefix, localName, eNamespace);
+ }
+ } else {
+ writer.writeStartElement(localName);
+ }
+ }
+
+ // Generate setPrefix for the namespace declarations
+ Iterator it = element.getAllDeclaredNamespaces();
+ while (it != null && it.hasNext()) {
+ OMNamespace omNamespace = (OMNamespace) it.next();
+ String prefix = null;
+ String namespace = null;
+ if (omNamespace != null) {
+ prefix = omNamespace.getPrefix();
+ namespace = omNamespace.getName();
+ }
+ prefix = (prefix != null && prefix.length() == 0) ? null : prefix;
+ namespace = (namespace != null && namespace.length() == 0) ? null : namespace;
+
+ generateSetPrefix(prefix, namespace, writer);
+ }
+
+ // Generate setPrefix for the element
+ // Get the prefix and namespace of the element. "" and null are identical.
+
+ String newPrefix = generateSetPrefix(ePrefix, eNamespace, writer);
+ if (newPrefix != null) {
+ if (prefixList == null) {
+ prefixList= new ArrayList();
+ nsList = new ArrayList();
+ }
+ if (!prefixList.contains(newPrefix)) {
+ prefixList.add(newPrefix);
+ nsList.add(eNamespace);
+ }
+ }
+
+ // Now Generate setPrefix for each attribute
+ Iterator attrs = element.getAllAttributes();
+ while (attrs != null && attrs.hasNext()) {
+ OMAttribute attr = (OMAttribute) attrs.next();
+ OMNamespace omNamespace = attr.getNamespace();
+ String prefix = null;
+ String namespace = null;
+ if (omNamespace != null) {
+ prefix = omNamespace.getPrefix();
+ namespace = omNamespace.getName();
+ }
+ prefix = (prefix != null && prefix.length() == 0) ? null : prefix;
+ namespace = (namespace != null && namespace.length() == 0) ? null : namespace;
+
+ // Default prefix referencing is not allowed on an attribute
+ if (prefix == null && namespace != null) {
+ String writerPrefix = writer.getPrefix(namespace);
+ writerPrefix = (writerPrefix != null && writerPrefix.length() == 0) ? null : writerPrefix;
+ prefix = (writerPrefix != null) ?
+ writerPrefix : getNextNSPrefix();
+ }
+ newPrefix = generateSetPrefix(prefix, namespace, writer);
+ // If the prefix is not associated with a namespace yet, remember it so that we can
+ // write out a namespace declaration
+ if (newPrefix != null) {
+ if (prefixList == null) {
+ prefixList= new ArrayList();
+ nsList = new ArrayList();
+ }
+ if (!prefixList.contains(newPrefix)) {
+ prefixList.add(newPrefix);
+ nsList.add(namespace);
+ }
+ }
+ }
+
+ // Write the startElement if required
+ if (setPrefixFirst) {
+ if (eNamespace != null) {
+ if (ePrefix == null) {
+ writer.writeStartElement("", localName, eNamespace);
+ } else {
+ writer.writeStartElement(ePrefix, localName, eNamespace);
+ }
+ } else {
+ writer.writeStartElement(localName);
+ }
+ }
+
+ // Now write the namespace declarations
+ it = element.getAllDeclaredNamespaces();
+ while (it != null && it.hasNext()) {
+ OMNamespace omNamespace = (OMNamespace) it.next();
+ String prefix = null;
+ String namespace = null;
+ if (omNamespace != null) {
+ prefix = omNamespace.getPrefix();
+ namespace = omNamespace.getName();
+ }
+ prefix = (prefix != null && prefix.length() == 0) ? null : prefix;
+ namespace = (namespace != null && namespace.length() == 0) ? null : namespace;
+ if (prefix != null && namespace != null) {
+ writer.writeNamespace(prefix, namespace);
+ } else {
+ writer.writeDefaultNamespace(namespace);
+ }
+
+ // If this prefix is in the unassociated list, remove it.
+ if (prefixList != null) {
+ int i = prefixList.indexOf((prefix == null)?"":prefix);
+ if (i >= 0) {
+ prefixList.remove(i);
+ nsList.remove(i);
+ }
+ }
+ }
+
+ // Now write out the namespaces that for prefixes that are not associated (i.e. auto-generated)
+ if (prefixList != null) {
+ for (int i=0; i<prefixList.size(); i++) {
+ String prefix = (String) prefixList.get(i);
+ String namespace = (String) nsList.get(i);
+ if (prefix != null) {
+ writer.writeNamespace(prefix, namespace);
+ } else {
+ writer.writeDefaultNamespace(namespace);
+ }
+ }
+ }
+
+ // Now write the attributes
+ attrs = element.getAllAttributes();
+ while (attrs != null && attrs.hasNext()) {
+ OMAttribute attr = (OMAttribute) attrs.next();
+ OMNamespace omNamespace = attr.getNamespace();
+ String prefix = null;
+ String namespace = null;
+ if (omNamespace != null) {
+ prefix = omNamespace.getPrefix();
+ namespace = omNamespace.getName();
+ }
+ prefix = (prefix != null && prefix.length() == 0) ? null : prefix;
+ namespace = (namespace != null && namespace.length() == 0) ? null : namespace;
+
+ if (prefix == null && namespace != null) {
+ // Default namespaces are not allowed on an attribute reference.
+ // Earlier in this code, a unique prefix was added for this case...now obtain and use it
+ prefix = writer.getPrefix(namespace);
+ } else if (namespace != null) {
+ // Use the writer's prefix if it is different
+ String writerPrefix = writer.getPrefix(namespace);
+ if (!prefix.equals(writerPrefix)) {
+ prefix = writerPrefix;
+ }
+ }
+ if (namespace != null) {
+ // Qualified attribute
+ writer.writeAttribute(prefix, namespace,
+ attr.getLocalName(),
+ attr.getAttributeValue());
} else {
- writer.writeStartElement(element.getLocalName());
+ // Unqualified attribute
+ writer.writeAttribute(attr.getLocalName(),
+ attr.getAttributeValue());
}
- } else {
- writer.writeStartElement(element.getLocalName());
-
- /** // we need to check whether there's a default namespace visible at this point because
- // otherwise this element will go into that namespace unintentionally. So we check
- // whether there is a default NS visible and if so turn it off.
- if (writer.getNamespaceContext().getNamespaceURI("") != null) {
- writer.writeDefaultNamespace("");
- } */
-
}
-
- // add the namespaces
- serializeNamespaces(element, writer);
-
- // add the elements attributes
- serializeAttributes(element, writer);
}
private static boolean checkForPrefixInTheCurrentContext(XMLStreamWriter writer, String nameSpaceName, String prefix) throws XMLStreamException {
@@ -254,6 +401,14 @@
return false;
}
+ /**
+ * serializeNamespaces
+ *
+ * @param element
+ * @param writer
+ * @throws XMLStreamException
+ * @deprecated Use serializeStartpart instead
+ */
public static void serializeNamespaces
(OMElement
element,
@@ -266,6 +421,13 @@
}
}
+ /**
+ * Serialize attributes
+ * @param element
+ * @param writer
+ * @throws XMLStreamException
+ * @deprecated Consider using serializeStartpart instead
+ */
public static void serializeAttributes
(OMElement
element,
@@ -338,5 +500,47 @@
}
return prefix;
+ }
+
+ /**
+ * Generate setPrefix/setDefaultNamespace if the prefix is not associated
+ * @param prefix
+ * @param namespace
+ * @param writer
+ * @return prefix name if a setPrefix/setDefaultNamespace is performed
+ */
+ public static String generateSetPrefix(String prefix, String namespace, XMLStreamWriter writer) throws XMLStreamException {
+ // Generate setPrefix/setDefaultNamespace if the prefix is not associated.
+ String newPrefix = null;
+ if (namespace != null) {
+
+
+ // Get the namespace associated with this writer
+ String writerNS = writer.getNamespaceContext().getNamespaceURI((prefix==null) ? "" : prefix);
+ writerNS = (writerNS != null && writerNS.length() == 0) ? null : writerNS;
+ if (writerNS != null) {
+ String writerPrefix = writer.getPrefix(writerNS);
+ if (writerPrefix == null) {
+ ;
+ }
+ }
+
+ if (writerNS == null || !writerNS.equals(namespace)) {
+ // Writer has not associated this namespace with a prefix
+ if (prefix == null) {
+ writer.setDefaultNamespace(namespace);
+ newPrefix = "";
+ } else {
+ writer.setPrefix(prefix, namespace);
+ newPrefix = prefix;
+ }
+ } else {
+ // No Action needed..The writer already has associated this prefix to this namespace
+ }
+ } else {
+ // Disable the default namespace
+ writer.setDefaultNamespace("");
+ }
+ return newPrefix;
}
}
Modified: webservices/commons/trunk/modules/axiom/src/org/apache/axiom/soap/impl/dom/soap11/SOAP11FaultCodeImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/src/org/apache/axiom/soap/impl/dom/soap11/SOAP11FaultCodeImpl.java?rev=425447&r1=425446&r2=425447&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/src/org/apache/axiom/soap/impl/dom/soap11/SOAP11FaultCodeImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/src/org/apache/axiom/soap/impl/dom/soap11/SOAP11FaultCodeImpl.java Tue Jul 25 09:23:21 2006
@@ -93,20 +93,10 @@
new StreamWriterToContentHandlerConverter(writer));
}
- if (this.getNamespace() != null) {
- String prefix = this.getNamespace().getPrefix();
- String nameSpaceName = this.getNamespace().getName();
- writer.writeStartElement(prefix, SOAP11Constants.SOAP_FAULT_CODE_LOCAL_NAME,
- nameSpaceName);
- } else {
- writer.writeStartElement(
- SOAP11Constants.SOAP_FAULT_CODE_LOCAL_NAME);
- }
-
- OMSerializerUtil.serializeAttributes(this, writer);
- OMSerializerUtil.serializeNamespaces(this, writer);
-
-
+ OMSerializerUtil.serializeStartpart(this,
+ SOAP11Constants.SOAP_FAULT_CODE_LOCAL_NAME,
+ writer);
+
String text = this.getValue().getText();
writer.writeCharacters(text);
writer.writeEndElement();
Modified: webservices/commons/trunk/modules/axiom/src/org/apache/axiom/soap/impl/dom/soap11/SOAP11FaultDetailImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/src/org/apache/axiom/soap/impl/dom/soap11/SOAP11FaultDetailImpl.java?rev=425447&r1=425446&r2=425447&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/src/org/apache/axiom/soap/impl/dom/soap11/SOAP11FaultDetailImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/src/org/apache/axiom/soap/impl/dom/soap11/SOAP11FaultDetailImpl.java Tue Jul 25 09:23:21 2006
@@ -67,18 +67,9 @@
new StreamWriterToContentHandlerConverter(writer));
}
- if (this.getNamespace() != null) {
- String prefix = this.getNamespace().getPrefix();
- String nameSpaceName = this.getNamespace().getName();
- writer.writeStartElement(prefix, SOAP11Constants.SOAP_FAULT_DETAIL_LOCAL_NAME,
- nameSpaceName);
- } else {
- writer.writeStartElement(
- SOAP11Constants.SOAP_FAULT_DETAIL_LOCAL_NAME);
- }
- OMSerializerUtil.serializeAttributes(this, writer);
- OMSerializerUtil.serializeNamespaces(this, writer);
-
+ OMSerializerUtil.serializeStartpart(this,
+ SOAP11Constants.SOAP_FAULT_DETAIL_LOCAL_NAME,
+ writer);
String text = this.getText();
writer.writeCharacters(text);
Modified: webservices/commons/trunk/modules/axiom/src/org/apache/axiom/soap/impl/dom/soap11/SOAP11FaultReasonImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/src/org/apache/axiom/soap/impl/dom/soap11/SOAP11FaultReasonImpl.java?rev=425447&r1=425446&r2=425447&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/src/org/apache/axiom/soap/impl/dom/soap11/SOAP11FaultReasonImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/src/org/apache/axiom/soap/impl/dom/soap11/SOAP11FaultReasonImpl.java Tue Jul 25 09:23:21 2006
@@ -77,18 +77,10 @@
new StreamWriterToContentHandlerConverter(writer));
}
- if (this.getNamespace() != null) {
- String prefix = this.getNamespace().getPrefix();
- String nameSpaceName = this.getNamespace().getName();
- writer.writeStartElement(prefix, SOAP11Constants.SOAP_FAULT_STRING_LOCAL_NAME,
- nameSpaceName);
- } else {
- writer.writeStartElement(
- SOAP11Constants.SOAP_FAULT_STRING_LOCAL_NAME);
- }
- OMSerializerUtil.serializeAttributes(this, writer);
- OMSerializerUtil.serializeNamespaces(this, writer);
-
+ OMSerializerUtil.serializeStartpart(this,
+ SOAP11Constants.SOAP_FAULT_STRING_LOCAL_NAME,
+ writer);
+
String text = this.getFirstSOAPText().getText();
writer.writeCharacters(text);
writer.writeEndElement();
Modified: webservices/commons/trunk/modules/axiom/src/org/apache/axiom/soap/impl/dom/soap11/SOAP11FaultRoleImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/src/org/apache/axiom/soap/impl/dom/soap11/SOAP11FaultRoleImpl.java?rev=425447&r1=425446&r2=425447&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/src/org/apache/axiom/soap/impl/dom/soap11/SOAP11FaultRoleImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/src/org/apache/axiom/soap/impl/dom/soap11/SOAP11FaultRoleImpl.java Tue Jul 25 09:23:21 2006
@@ -64,18 +64,10 @@
new StreamWriterToContentHandlerConverter(writer));
}
- if (this.getNamespace() != null) {
- String prefix = this.getNamespace().getPrefix();
- String nameSpaceName = this.getNamespace().getName();
- writer.writeStartElement(prefix, SOAP11Constants.SOAP_FAULT_ACTOR_LOCAL_NAME,
- nameSpaceName);
- } else {
- writer.writeStartElement(
- SOAP11Constants.SOAP_FAULT_ACTOR_LOCAL_NAME);
- }
- OMSerializerUtil.serializeAttributes(this, writer);
- OMSerializerUtil.serializeNamespaces(this, writer);
-
+ OMSerializerUtil.serializeStartpart(this,
+ SOAP11Constants.SOAP_FAULT_ACTOR_LOCAL_NAME,
+ writer);
+
String text = this.getText();
writer.writeCharacters(text);
writer.writeEndElement();
Modified: webservices/commons/trunk/modules/axiom/src/org/apache/axiom/soap/impl/llom/SOAPFaultDetailImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/src/org/apache/axiom/soap/impl/llom/SOAPFaultDetailImpl.java?rev=425447&r1=425446&r2=425447&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/src/org/apache/axiom/soap/impl/llom/SOAPFaultDetailImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/src/org/apache/axiom/soap/impl/llom/SOAPFaultDetailImpl.java Tue Jul 25 09:23:21 2006
@@ -23,6 +23,7 @@
import org.apache.axiom.om.impl.llom.OMNodeImpl;
import org.apache.axiom.om.impl.util.OMSerializerUtil;
import org.apache.axiom.om.impl.serialize.StreamWriterToContentHandlerConverter;
+import org.apache.axiom.soap.SOAP11Constants;
import org.apache.axiom.soap.SOAP12Constants;
import org.apache.axiom.soap.SOAPFactory;
import org.apache.axiom.soap.SOAPFault;
@@ -74,18 +75,9 @@
builder.registerExternalContentHandler(new StreamWriterToContentHandlerConverter(writer));
}
- if (this.getNamespace() != null) {
- String prefix = this.getNamespace().getPrefix();
- String nameSpaceName = this.getNamespace().getName();
- writer.writeStartElement(prefix, SOAP12Constants.SOAP_FAULT_DETAIL_LOCAL_NAME,
- nameSpaceName);
- } else {
- writer.writeStartElement(
- SOAP12Constants.SOAP_FAULT_DETAIL_LOCAL_NAME);
- }
- OMSerializerUtil.serializeAttributes(this, writer);
- OMSerializerUtil.serializeNamespaces(this, writer);
-
+ OMSerializerUtil.serializeStartpart(this,
+ SOAP12Constants.SOAP_FAULT_DETAIL_LOCAL_NAME,
+ writer);
String text = this.getText();
writer.writeCharacters(text);
Modified: webservices/commons/trunk/modules/axiom/src/org/apache/axiom/soap/impl/llom/soap11/SOAP11FaultCodeImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/src/org/apache/axiom/soap/impl/llom/soap11/SOAP11FaultCodeImpl.java?rev=425447&r1=425446&r2=425447&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/src/org/apache/axiom/soap/impl/llom/soap11/SOAP11FaultCodeImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/src/org/apache/axiom/soap/impl/llom/soap11/SOAP11FaultCodeImpl.java Tue Jul 25 09:23:21 2006
@@ -91,20 +91,10 @@
new StreamWriterToContentHandlerConverter(writer));
}
- if (this.getNamespace() != null) {
- String prefix = this.getNamespace().getPrefix();
- String nameSpaceName = this.getNamespace().getName();
- writer.writeStartElement(prefix, SOAP11Constants.SOAP_FAULT_CODE_LOCAL_NAME,
- nameSpaceName);
- } else {
- writer.writeStartElement(
- SOAP11Constants.SOAP_FAULT_CODE_LOCAL_NAME);
- }
-
- OMSerializerUtil.serializeAttributes(this, writer);
- OMSerializerUtil.serializeNamespaces(this, writer);
-
-
+ OMSerializerUtil.serializeStartpart(this,
+ SOAP11Constants.SOAP_FAULT_CODE_LOCAL_NAME,
+ writer);
+
String text = this.getValue().getText();
writer.writeCharacters(text);
writer.writeEndElement();
Modified: webservices/commons/trunk/modules/axiom/src/org/apache/axiom/soap/impl/llom/soap11/SOAP11FaultDetailImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/src/org/apache/axiom/soap/impl/llom/soap11/SOAP11FaultDetailImpl.java?rev=425447&r1=425446&r2=425447&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/src/org/apache/axiom/soap/impl/llom/soap11/SOAP11FaultDetailImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/src/org/apache/axiom/soap/impl/llom/soap11/SOAP11FaultDetailImpl.java Tue Jul 25 09:23:21 2006
@@ -68,18 +68,10 @@
new StreamWriterToContentHandlerConverter(writer));
}
- if (this.getNamespace() != null) {
- String prefix = this.getNamespace().getPrefix();
- String nameSpaceName = this.getNamespace().getName();
- writer.writeStartElement(prefix, SOAP11Constants.SOAP_FAULT_DETAIL_LOCAL_NAME,
- nameSpaceName);
- } else {
- writer.writeStartElement(
- SOAP11Constants.SOAP_FAULT_DETAIL_LOCAL_NAME);
- }
- OMSerializerUtil.serializeAttributes(this, writer);
- OMSerializerUtil.serializeNamespaces(this, writer);
-
+ OMSerializerUtil.serializeStartpart(this,
+ SOAP11Constants.SOAP_FAULT_DETAIL_LOCAL_NAME,
+ writer);
+
OMNode child = (OMNodeImpl) firstChild;
while (child != null && ((!(child instanceof OMElement)) || child.isComplete())) {
((OMNodeImpl) child).internalSerializeAndConsume(writer);
Modified: webservices/commons/trunk/modules/axiom/src/org/apache/axiom/soap/impl/llom/soap11/SOAP11FaultReasonImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/src/org/apache/axiom/soap/impl/llom/soap11/SOAP11FaultReasonImpl.java?rev=425447&r1=425446&r2=425447&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/src/org/apache/axiom/soap/impl/llom/soap11/SOAP11FaultReasonImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/src/org/apache/axiom/soap/impl/llom/soap11/SOAP11FaultReasonImpl.java Tue Jul 25 09:23:21 2006
@@ -86,18 +86,9 @@
new StreamWriterToContentHandlerConverter(writer));
}
- if (this.getNamespace() != null) {
- String prefix = this.getNamespace().getPrefix();
- String nameSpaceName = this.getNamespace().getName();
- writer.writeStartElement(prefix,
- SOAP11Constants.SOAP_FAULT_STRING_LOCAL_NAME,
- nameSpaceName);
- } else {
- writer.writeStartElement(
- SOAP11Constants.SOAP_FAULT_STRING_LOCAL_NAME);
- }
- OMSerializerUtil.serializeAttributes(this, writer);
- OMSerializerUtil.serializeNamespaces(this, writer);
+ OMSerializerUtil.serializeStartpart(this,
+ SOAP11Constants.SOAP_FAULT_STRING_LOCAL_NAME,
+ writer);
String text = this.getFirstSOAPText().getText();
writer.writeCharacters(text);
Modified: webservices/commons/trunk/modules/axiom/src/org/apache/axiom/soap/impl/llom/soap11/SOAP11FaultRoleImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/src/org/apache/axiom/soap/impl/llom/soap11/SOAP11FaultRoleImpl.java?rev=425447&r1=425446&r2=425447&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/src/org/apache/axiom/soap/impl/llom/soap11/SOAP11FaultRoleImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/src/org/apache/axiom/soap/impl/llom/soap11/SOAP11FaultRoleImpl.java Tue Jul 25 09:23:21 2006
@@ -68,19 +68,10 @@
new StreamWriterToContentHandlerConverter(writer));
}
- if (this.getNamespace() != null) {
- String prefix = this.getNamespace().getPrefix();
- String nameSpaceName = this.getNamespace().getName();
- writer.writeStartElement(prefix,
- SOAP11Constants.SOAP_FAULT_ACTOR_LOCAL_NAME,
- nameSpaceName);
- } else {
- writer.writeStartElement(
- SOAP11Constants.SOAP_FAULT_ACTOR_LOCAL_NAME);
- }
- OMSerializerUtil.serializeAttributes(this, writer);
- OMSerializerUtil.serializeNamespaces(this, writer);
-
+ OMSerializerUtil.serializeStartpart(this,
+ SOAP11Constants.SOAP_FAULT_ACTOR_LOCAL_NAME,
+ writer);
+
String text = this.getText();
writer.writeCharacters(text);
writer.writeEndElement();
Added: webservices/commons/trunk/modules/axiom/test-resources/soap/soap11/soapfault1.xml
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/test-resources/soap/soap11/soapfault1.xml?rev=425447&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/test-resources/soap/soap11/soapfault1.xml (added)
+++ webservices/commons/trunk/modules/axiom/test-resources/soap/soap11/soapfault1.xml Tue Jul 25 09:23:21 2006
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
+<S:Header>
+<Action xmlns="http://www.w3.org/2005/08/addressing">http://www.w3.org/2005/08/addressing/fault</Action>
+<FaultDetail xmlns="http://www.w3.org/2005/08/addressing">
+<ProblemHeaderQName xmlns="http://www.w3.org/2005/08/addressing">ReplyTo</ProblemHeaderQName>
+</FaultDetail>
+<RelatesTo xmlns="http://www.w3.org/2005/08/addressing">urn:uuid:C6E4970C03887FC5C31153324076046143</RelatesTo>
+</S:Header>
+<S:Body>
+<SOAP-ENV:Fault xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
+<faultcode xmlns:wsa="http://www.w3.org/2005/08/addressing" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">wsa:OnlyAnonymousAddressSupported</faultcode>
+<faultstring xmlns="">A header representing a Message Addressing Property is not valid and the message cannot be processed</faultstring>
+</SOAP-ENV:Fault>
+</S:Body>
+</S:Envelope>
Added: webservices/commons/trunk/modules/axiom/test-resources/soap/soap11/soapfault2.xml
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/test-resources/soap/soap11/soapfault2.xml?rev=425447&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/test-resources/soap/soap11/soapfault2.xml (added)
+++ webservices/commons/trunk/modules/axiom/test-resources/soap/soap11/soapfault2.xml Tue Jul 25 09:23:21 2006
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
+<S:Header>
+<Action xmlns="http://www.w3.org/2005/08/addressing">http://www.w3.org/2005/08/addressing/fault</Action>
+<FaultDetail xmlns="http://www.w3.org/2005/08/addressing">
+<ProblemHeaderQName xmlns="http://www.w3.org/2005/08/addressing">ReplyTo</ProblemHeaderQName>
+</FaultDetail>
+<RelatesTo xmlns="http://www.w3.org/2005/08/addressing">urn:uuid:C6E4970C03887FC5C31153324076046143</RelatesTo>
+</S:Header>
+<S:Body>
+<SOAP-ENV:Fault xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
+<faultcode xmlns:wsa="http://www.w3.org/2005/08/addressing" xmlns="" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">wsa:OnlyAnonymousAddressSupported</faultcode>
+<faultstring xmlns="">A header representing a Message Addressing Property is not valid and the message cannot be processed</faultstring>
+</SOAP-ENV:Fault>
+</S:Body>
+</S:Envelope>
Modified: webservices/commons/trunk/modules/axiom/test/org/apache/axiom/om/DefaultNSHandlingTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/test/org/apache/axiom/om/DefaultNSHandlingTest.java?rev=425447&r1=425446&r2=425447&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/test/org/apache/axiom/om/DefaultNSHandlingTest.java (original)
+++ webservices/commons/trunk/modules/axiom/test/org/apache/axiom/om/DefaultNSHandlingTest.java Tue Jul 25 09:23:21 2006
@@ -100,7 +100,12 @@
StAXOMBuilder builder = new StAXOMBuilder(reader);
builder.getDocumentElement().build();
- assertTrue(xml.indexOf("<wst:Entropy xmlns:wst=\"http://schemas.xmlsoap.org/ws/2005/02/trust\" />") != -1);
+ // The StAX implementation may or may not have a trailing blank in the tag
+ String assertText1 = "<wst:Entropy xmlns:wst=\"http://schemas.xmlsoap.org/ws/2005/02/trust\" />";
+ String assertText2 = "<wst:Entropy xmlns:wst=\"http://schemas.xmlsoap.org/ws/2005/02/trust\"/>";
+
+ assertTrue((xml.indexOf(assertText1) != -1) ||
+ (xml.indexOf(assertText2) != -1));
}catch (Exception e) {
fail(e.getMessage());
}
Modified: webservices/commons/trunk/modules/axiom/test/org/apache/axiom/om/OMElementCloneTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/test/org/apache/axiom/om/OMElementCloneTest.java?rev=425447&r1=425446&r2=425447&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/test/org/apache/axiom/om/OMElementCloneTest.java (original)
+++ webservices/commons/trunk/modules/axiom/test/org/apache/axiom/om/OMElementCloneTest.java Tue Jul 25 09:23:21 2006
@@ -46,9 +46,12 @@
OMElement secondClonedBodyElement = new StAXOMBuilder(body.getXMLStreamReader()).getDocumentElement();
// first check whether both have the same information
- assertXMLEqual(newDocument(body.toString()), newDocument(firstClonedBodyElement.toString()));
- assertXMLEqual(newDocument(body.toString()), newDocument(secondClonedBodyElement.toString()));
- assertXMLEqual(newDocument(firstClonedBodyElement.toString()), newDocument(secondClonedBodyElement.toString()));
+ String firstClonedBodyElementText = firstClonedBodyElement.toString();
+ String secondClonedBodyElementText = secondClonedBodyElement.toString();
+ String bodyText = body.toString();
+ assertXMLEqual(newDocument(bodyText), newDocument(firstClonedBodyElementText));
+ assertXMLEqual(newDocument(bodyText), newDocument(secondClonedBodyElementText));
+ assertXMLEqual(newDocument(firstClonedBodyElementText), newDocument(secondClonedBodyElementText));
// lets check some links. They must not be equal
assertNotSame(body.getParent(), firstClonedBodyElement.getParent());
Added: webservices/commons/trunk/modules/axiom/test/org/apache/axiom/om/impl/serializer/OMFaultSerializerTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/test/org/apache/axiom/om/impl/serializer/OMFaultSerializerTest.java?rev=425447&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/test/org/apache/axiom/om/impl/serializer/OMFaultSerializerTest.java (added)
+++ webservices/commons/trunk/modules/axiom/test/org/apache/axiom/om/impl/serializer/OMFaultSerializerTest.java Tue Jul 25 09:23:21 2006
@@ -0,0 +1,80 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.om.impl.serializer;
+
+import org.apache.axiom.om.AbstractTestCase;
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMXMLParserWrapper;
+import org.apache.axiom.om.impl.llom.factory.OMXMLBuilderFactory;
+import org.apache.axiom.om.impl.serialize.StreamingOMSerializer;
+import org.apache.axiom.soap.SOAPBody;
+import org.apache.axiom.soap.SOAPEnvelope;
+import org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+import java.io.File;
+import java.io.FileReader;
+
+public class OMFaultSerializerTest extends AbstractTestCase {
+ private XMLStreamReader reader1;
+ private XMLStreamReader reader2;
+
+ public OMFaultSerializerTest(String testName) {
+ super(testName);
+ }
+
+ protected void setUp() throws Exception {
+ reader1 =
+ XMLInputFactory.newInstance().
+ createXMLStreamReader(
+ new FileReader(
+ getTestResourceFile("soap/soap11/soapfault1.xml")));
+ reader2 =
+ XMLInputFactory.newInstance().
+ createXMLStreamReader(
+ new FileReader(
+ getTestResourceFile("soap/soap11/soapfault2.xml")));
+
+ }
+
+ /**
+ * Test SOAPFault that does not disable the default namespace
+ * (i.e. does not use xmlns="")
+ * @throws Exception
+ */
+ public void test1() throws Exception {
+ StAXSOAPModelBuilder builder = new StAXSOAPModelBuilder(reader1, null);
+ OMElement ome = builder.getDocumentElement();
+ System.out.println(ome);
+ }
+ /**
+ * Test SOAPFault that does disable the default namespace
+ * (i.e. does use xmlns="")
+ * @throws Exception
+ */
+ public void test2() throws Exception {
+ StAXSOAPModelBuilder builder = new StAXSOAPModelBuilder(reader2, null);
+ OMElement ome = builder.getDocumentElement();
+ System.out.println(ome);
+ }
+}
+
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: commons-dev-help@ws.apache.org