Author: jim.ma
Date: 2011-08-15 02:08:06 -0400 (Mon, 15 Aug 2011)
New Revision: 14842
Modified:
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/soap/SOAPFactoryImpl.java
stack/native/trunk/modules/testsuite/native-tests/src/test/java/org/jboss/test/ws/common/soap/SOAPFactoryTestCase.java
Log:
[JBWS-3209]:Remove additional namespace declaration
Modified:
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/soap/SOAPFactoryImpl.java
===================================================================
---
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/soap/SOAPFactoryImpl.java 2011-08-14
09:59:28 UTC (rev 14841)
+++
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/soap/SOAPFactoryImpl.java 2011-08-15
06:08:06 UTC (rev 14842)
@@ -21,6 +21,9 @@
*/
package org.jboss.ws.core.soap;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
import java.util.ResourceBundle;
import javax.xml.namespace.QName;
@@ -37,6 +40,7 @@
import org.jboss.ws.common.Constants;
import org.jboss.ws.common.DOMUtils;
import org.jboss.ws.extensions.xop.XOPContext;
+import org.w3c.dom.Attr;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
@@ -157,10 +161,39 @@
}
}
}
-
+ Iterator ite = soapElement.getNamespacePrefixes();
+ List<String> prefixs = new ArrayList<String>();
+ while (ite != null && ite.hasNext())
+ {
+ prefixs.add((String) ite.next());
+ }
+ removeNSAttribute(soapElement, prefixs);
return soapElement;
}
+ private void removeNSAttribute(SOAPElement soapElement, List<String> prefixes)
+ {
+ Iterator ite2 = soapElement.getChildElements();
+ while (ite2 != null && ite2.hasNext())
+ {
+ Object obj = ite2.next();
+ if (obj instanceof SOAPElement)
+ {
+ SOAPElement ele = (SOAPElement) obj;
+ removeNSAttribute(ele, prefixes);
+ for (String str : prefixes)
+ {
+ Attr attr = ele.getAttributeNode("xmlns:" + str);
+ if (attr != null)
+ ele.removeAttribute("xmlns:" + str);
+
+ }
+ }
+
+ }
+
+ }
+
@Override
public Detail createDetail() throws SOAPException
{
Modified:
stack/native/trunk/modules/testsuite/native-tests/src/test/java/org/jboss/test/ws/common/soap/SOAPFactoryTestCase.java
===================================================================
---
stack/native/trunk/modules/testsuite/native-tests/src/test/java/org/jboss/test/ws/common/soap/SOAPFactoryTestCase.java 2011-08-14
09:59:28 UTC (rev 14841)
+++
stack/native/trunk/modules/testsuite/native-tests/src/test/java/org/jboss/test/ws/common/soap/SOAPFactoryTestCase.java 2011-08-15
06:08:06 UTC (rev 14842)
@@ -21,12 +21,21 @@
*/
package org.jboss.test.ws.common.soap;
+import java.io.StringReader;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.soap.Detail;
import javax.xml.soap.Name;
import javax.xml.soap.SOAPElement;
import javax.xml.soap.SOAPFactory;
import org.jboss.wsf.test.JBossWSTest;
+import org.w3c.dom.Attr;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+import org.xml.sax.InputSource;
/**
* Test the SOAPFactory
@@ -84,5 +93,28 @@
assertEquals("pre", name.getPrefix());
assertEquals("http://someURI", name.getURI());
}
+
+
+ public void testNSDeclaration() throws Exception
+ {
+ String CONTENTS =
+ "<say:sayHiResponse
xmlns:say='http://www.jboss.org/sayHi'
xmlns:say2='http://www.jboss.org/sayHi2'>" +
+
"<say2:arg0><say2:arg2>Response</say2:arg2></say2:arg0>"
+
+ "</say:sayHiResponse>" ;
+
+ DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance() ;
+ builderFactory.setNamespaceAware(true);
+ DocumentBuilder builder = builderFactory.newDocumentBuilder() ;
+
+ Document doc = builder.parse(new InputSource(new StringReader(CONTENTS))) ;
+ Element root = doc.getDocumentElement() ;
+
+ SOAPFactory factory = SOAPFactory.newInstance();
+ SOAPElement soapElement = factory.createElement(root) ;
+ NodeList elementList = soapElement.getElementsByTagName("say2:arg2");
+ Element element = (Element)elementList.item(0);
+ Attr attr = element.getAttributeNode("xmlns:say2");
+ assertNull(attr);
+ }
}