Author: klape
Date: 2011-05-31 00:13:10 -0400 (Tue, 31 May 2011)
New Revision: 14454
Added:
stack/native/branches/jbossws-native-3.1.2/modules/testsuite/native-tests/src/test/java/org/jboss/test/ws/common/soap/JBWS3251TestCase.java
Modified:
stack/native/branches/jbossws-native-3.1.2/
stack/native/branches/jbossws-native-3.1.2/modules/core/
stack/native/branches/jbossws-native-3.1.2/modules/core/src/main/java/org/jboss/ws/core/soap/SOAPElementImpl.java
stack/native/branches/jbossws-native-3.1.2/modules/testsuite/native-tests/
Log:
[JBPAPP-6285] Backporting SOAPElementImpl concurrency issue (DOMException). Also adding
test case.
Property changes on: stack/native/branches/jbossws-native-3.1.2
___________________________________________________________________
Modified: svn:mergeinfo
- /stack/native/trunk:12502,13992,14181,14183
+ /stack/native/branches/jbossws-native-3.4.0.SP1:13928,13933,13936,13946
/stack/native/trunk:12502,13992,14181,14183
Property changes on: stack/native/branches/jbossws-native-3.1.2/modules/core
___________________________________________________________________
Modified: svn:mergeinfo
- /stack/native/trunk/modules/core:12502,13992,14011,14181,14183
+ /stack/native/branches/jbossws-native-3.4.0.SP1/modules/core:13928,13933,13936,13946
/stack/native/trunk/modules/core:12502,13992,14011,14181,14183
Modified:
stack/native/branches/jbossws-native-3.1.2/modules/core/src/main/java/org/jboss/ws/core/soap/SOAPElementImpl.java
===================================================================
---
stack/native/branches/jbossws-native-3.1.2/modules/core/src/main/java/org/jboss/ws/core/soap/SOAPElementImpl.java 2011-05-31
02:50:56 UTC (rev 14453)
+++
stack/native/branches/jbossws-native-3.1.2/modules/core/src/main/java/org/jboss/ws/core/soap/SOAPElementImpl.java 2011-05-31
04:13:10 UTC (rev 14454)
@@ -80,7 +80,7 @@
public SOAPElementImpl(String localPart, String prefix, String nsURI)
{
super(DOMUtils.createElement(localPart, prefix, nsURI));
- this.element = (Element)domNode;
+ this.element = (Element)domNode;
log.trace("new SOAPElementImpl: " + getElementName());
}
@@ -89,6 +89,13 @@
{
this(name.getLocalName(), name.getPrefix(), name.getURI());
}
+
+ /** Called by addChild */
+ private SOAPElementImpl(Element element)
+ {
+ super(element);
+ this.element = element;
+ }
/** Called by SOAPFactory */
public SOAPElementImpl(QName qname)
@@ -187,9 +194,8 @@
*/
public SOAPElement addChildElement(String name) throws SOAPException
{
- SOAPElement soapElement = new SOAPElementImpl(name);
- soapElement = addChildElement(soapElement);
- return soapElement;
+ Name nameImp = new NameImpl(name);
+ return addChildElement(nameImp);
}
/**
@@ -206,9 +212,8 @@
if (nsURI == null)
throw new IllegalArgumentException("Cannot obtain namespace URI for prefix:
" + prefix);
- SOAPElement soapElement = new SOAPElementImpl(localName, prefix, nsURI);
- soapElement = addChildElement(soapElement);
- return soapElement;
+ Name nameImp = new NameImpl(localName, prefix, nsURI);
+ return addChildElement(nameImp);
}
/**
@@ -222,9 +227,8 @@
*/
public SOAPElement addChildElement(String localName, String prefix, String uri) throws
SOAPException
{
- SOAPElement soapElement = new SOAPElementImpl(localName, prefix, uri);
- soapElement = addChildElement(soapElement);
- return soapElement;
+ Name nameImpl = new NameImpl(localName, prefix, uri);
+ return addChildElement(nameImpl);
}
/**
@@ -235,10 +239,19 @@
* @throws javax.xml.soap.SOAPException if there is an error in creating the
SOAPElement object
*/
public SOAPElement addChildElement(Name name) throws SOAPException
- {
- SOAPElement soapElement = new SOAPElementImpl(name);
- soapElement = addChildElement(soapElement);
- return soapElement;
+ {
+ Document doc = this.element.getOwnerDocument();
+ Element childEle = null;
+ if (name.getPrefix() == null || name.getPrefix().length() == 0)
+ {
+ childEle = doc.createElementNS(name.getURI(), name.getLocalName());
+ } else
+ {
+ childEle = doc.createElementNS(name.getURI(), name.getPrefix() + ":" +
name.getLocalName());
+ }
+
+ SOAPElement child = new SOAPElementImpl(childEle);
+ return addChildElement(child);
}
public SOAPElement addChildElement(QName qname) throws SOAPException
@@ -269,7 +282,16 @@
{
log.trace("addChildElement: " + getElementName() + " -> " +
child.getElementName());
SOAPElementImpl soapElement = (SOAPElementImpl)child;
- soapElement = (SOAPElementImpl)appendChild(soapElement);
+
+ if (soapElement.domNode.getOwnerDocument() != element.getOwnerDocument())
+ {
+ Document oldDoc = DOMUtils.peekOwnerDocument();
+ DOMUtils.setOwnerDocument(element.getOwnerDocument());
+ soapElement = (SOAPElementImpl)
SOAPFactoryImpl.newInstance().createElement((Element) (soapElement.domNode));
+ DOMUtils.setOwnerDocument(oldDoc);
+
+ }
+ soapElement = (SOAPElementImpl) appendChild(soapElement);
return soapElement.completeNamespaceDeclaration();
}
Property changes on:
stack/native/branches/jbossws-native-3.1.2/modules/testsuite/native-tests
___________________________________________________________________
Modified: svn:mergeinfo
- /stack/native/trunk/modules/testsuite/native-tests:12502,13992,14013,14181,14183
+
/stack/native/branches/jbossws-native-3.4.0.SP1/modules/testsuite/native-tests:13928,13933,13936,13946
/stack/native/trunk/modules/testsuite/native-tests:12502,13992,14013,14181,14183
Added:
stack/native/branches/jbossws-native-3.1.2/modules/testsuite/native-tests/src/test/java/org/jboss/test/ws/common/soap/JBWS3251TestCase.java
===================================================================
---
stack/native/branches/jbossws-native-3.1.2/modules/testsuite/native-tests/src/test/java/org/jboss/test/ws/common/soap/JBWS3251TestCase.java
(rev 0)
+++
stack/native/branches/jbossws-native-3.1.2/modules/testsuite/native-tests/src/test/java/org/jboss/test/ws/common/soap/JBWS3251TestCase.java 2011-05-31
04:13:10 UTC (rev 14454)
@@ -0,0 +1,120 @@
+package org.jboss.test.ws.common.soap;
+
+import java.util.Iterator;
+import java.util.concurrent.CountDownLatch;
+
+import javax.xml.soap.SOAPElement;
+import javax.xml.soap.Name;
+
+import org.jboss.ws.core.soap.MessageFactoryImpl;
+import org.jboss.ws.core.soap.NameImpl;
+import org.jboss.ws.core.soap.SOAPBodyImpl;
+import org.jboss.ws.core.soap.SOAPContentElement;
+import org.jboss.ws.core.soap.SOAPElementImpl;
+import org.jboss.ws.core.soap.XMLFragment;
+import org.jboss.wsf.test.JBossWSTest;
+
+public class JBWS3251TestCase extends JBossWSTest
+{
+ public void test() throws Exception
+ {
+ int threadCount = 20;
+ SoapElementTester test = new SoapElementTester();
+ CountDownLatch latch = new CountDownLatch(threadCount);
+
+ test.latch = latch;
+
+ for(int i=0; i<threadCount; i++)
+ {
+ Thread t = new Thread(test);
+ t.start();
+ }
+
+ latch.await();
+ Thread.currentThread().sleep(200);
+
+ assertTrue(test.allRunsSuccessful);
+ }
+
+ private class SoapElementTester implements Runnable
+ {
+ private final String soapXml =
+ "<soapenv:Envelope
xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"
xmlns:wsp=\"http://examples.jboss.com/ws\">\n" +
+ " <soapenv:Header>\n" +
+ " <wsp:info>\n" +
+ " <wsp:test>Child of Child</wsp:test>\n" +
+ " </wsp:info>\n" +
+ " </soapenv:Header>\n" +
+ " <soapenv:Body>\n" +
+ " </soapenv:Body>\n" +
+ "</soapenv:Envelope>";
+
+ private SOAPElement sharedElement;
+ public boolean allRunsSuccessful = true;
+ public CountDownLatch latch;
+
+ public void run()
+ {
+ Name name = new NameImpl(
+ "Envelope",
+ "soapenv",
+ "http://schemas.xmlsoap.org/soap/envelope/"
+ );
+
+ //Do we even need this part?
+ SOAPContentElement soapEl = new SOAPContentElement(name);
+ soapEl.setXMLFragment(new XMLFragment(soapXml));
+
+ sharedElement = soapEl;
+
+ if(!printNodeNames())
+ allRunsSuccessful = false;
+ }
+
+ public boolean printNodeNames()
+ {
+ try
+ {
+ Iterator i = sharedElement.getChildElements();
+ while(i.hasNext())
+ {
+ Object o = i.next();
+ if(!(o instanceof SOAPElement))
+ continue;
+
+ SOAPElement elt = (SOAPElement)o;
+
+ Iterator i2 = elt.getChildElements();
+ while(i2.hasNext())
+ {
+ o = i2.next();
+ if(!(o instanceof SOAPElement))
+ continue;
+
+ SOAPElement child = (SOAPElement)o;
+
+ Iterator i3 = child.getChildElements();
+ while(i3.hasNext())
+ {
+ o = i3.next();
+ if(!(o instanceof SOAPElement))
+ continue;
+
+ SOAPElement grandchild = (SOAPElement)o;
+ }
+ }
+ }
+ }
+ catch(Exception e)
+ {
+ e.printStackTrace();
+ return false;
+ }
+ finally
+ {
+ latch.countDown();
+ }
+ return true;
+ }
+ }
+}