cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject [cxf] 03/03: More work on using getEmptyDocument instead of createDocument
Date Thu, 19 Oct 2017 02:35:19 GMT
This is an automated email from the ASF dual-hosted git repository.

dkulp pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cxf.git

commit 51dd24fd417a4de6ede3282f7cac05c795eca1e4
Author: Daniel Kulp <dkulp@apache.org>
AuthorDate: Wed Oct 18 21:44:28 2017 -0400

    More work on using getEmptyDocument instead of createDocument
---
 .../main/java/org/apache/cxf/helpers/DOMUtils.java | 21 +++++++++++++++----
 .../org/apache/cxf/aegis/AbstractAegisTest.java    |  3 +--
 .../apache/cxf/jaxb/JAXBEncoderDecoderTest.java    |  8 ++++----
 .../jaxws/handler/logical/LogicalMessageImpl.java  |  9 ++++----
 .../saml/interceptor/WSS4JBasicAuthValidator.java  |  2 +-
 .../apache/cxf/ws/rm/EncoderDecoder10AImpl.java    |  6 +++---
 .../org/apache/cxf/ws/rm/EncoderDecoder10Impl.java |  6 +++---
 .../org/apache/cxf/ws/rm/EncoderDecoder11Impl.java |  6 +++---
 .../cxf/ws/security/kerberos/KerberosClient.java   |  2 +-
 .../cxf/ws/security/trust/STSLoginModule.java      |  2 +-
 .../ws/security/trust/STSStaxTokenValidator.java   |  4 ++--
 .../delegation/WSSUsernameCallbackHandler.java     |  2 +-
 .../integration/FragmentPutInsertAfterTest.java    | 10 ++++-----
 .../integration/FragmentPutInsertBeforeTest.java   | 10 ++++-----
 .../integration/FragmentPutReplaceTest.java        | 24 +++++++++++-----------
 .../transfer/integration/ResourceFactoryTest.java  |  2 +-
 .../transfer/unit/MemoryResourceManagerTest.java   |  4 ++--
 .../org/apache/cxf/wsdl11/ServiceWSDLBuilder.java  |  8 ++------
 .../cxf/sts/operation/AbstractOperation.java       |  2 +-
 .../cxf/sts/rest/RESTSecurityTokenServiceImpl.java |  2 +-
 .../apache/cxf/sts/token/provider/SCTProvider.java |  2 +-
 .../cxf/sts/token/provider/TokenProviderUtils.java |  8 +++++---
 .../sts/claims/mapper/JexlIssueSamlClaimsTest.java |  2 +-
 .../cxf/sts/operation/CancelSCTUnitTest.java       |  3 ---
 .../cxf/sts/operation/DummyTokenProvider.java      |  2 +-
 .../cxf/sts/operation/IssueJWTClaimsUnitTest.java  | 13 +++++++-----
 .../apache/cxf/sts/operation/IssueSCTUnitTest.java |  2 +-
 .../cxf/sts/operation/IssueSamlClaimsUnitTest.java |  2 +-
 .../operation/ValidateJWTTransformationTest.java   |  4 +---
 .../cxf/sts/operation/ValidateJWTUnitTest.java     |  4 +---
 .../cxf/sts/operation/ValidateSCTUnitTest.java     |  3 ---
 .../cxf/sts/token/canceller/SCTCancellerTest.java  |  2 +-
 .../validator/JWTTokenValidatorRealmTest.java      |  2 +-
 .../sts/token/validator/JWTTokenValidatorTest.java |  2 +-
 .../sts/deployment/CustomBSTTokenProvider.java     |  2 +-
 .../CustomUsernameTokenProvider.java               |  2 +-
 .../java/org/apache/cxf/wsn/util/WSNHelper.java    |  2 +-
 .../org/apache/cxf/wsn/jms/JmsSubscription.java    |  6 +++---
 .../oauth2/grants/CallbackHandlerLoginHandler.java |  2 +-
 .../java/org/apache/cxf/tools/util/JAXBUtils.java  |  2 +-
 .../tools/corba/common/WSDLCorbaWriterImpl.java    |  2 +-
 41 files changed, 102 insertions(+), 100 deletions(-)

diff --git a/core/src/main/java/org/apache/cxf/helpers/DOMUtils.java b/core/src/main/java/org/apache/cxf/helpers/DOMUtils.java
index 2f62bf6..c40e670 100644
--- a/core/src/main/java/org/apache/cxf/helpers/DOMUtils.java
+++ b/core/src/main/java/org/apache/cxf/helpers/DOMUtils.java
@@ -154,6 +154,23 @@ public final class DOMUtils {
     private static synchronized Document createEmptyDocument() {
         if (emptyDocument == null) {
             emptyDocument = createDocument();
+            
+            // uncomment this to see if anything is actually setting anything into the empty doc
+            /*
+            final Document doc  = createDocument();
+            emptyDocument = (Document)org.apache.cxf.common.util.ProxyHelper.getProxy(
+                DOMUtils.class.getClassLoader(), 
+                new Class<?>[] {Document.class}, 
+                new java.lang.reflect.InvocationHandler() {
+                    @Override
+                    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+                        if (method.getName().contains("create")) {
+                            return method.invoke(doc, args);
+                        }
+                        throw new IllegalStateException("Cannot modify factory document");
+                    }
+                });
+             */
         }
         return emptyDocument;
     }
@@ -168,10 +185,6 @@ public final class DOMUtils {
         if (doc == null) {
             doc = createEmptyDocument();
         }
-        if (emptyDocument.getDocumentElement() != null) {
-            // doc = createEmptyDocument();
-            throw new IllegalStateException("Document should be empty");
-        }
         return doc;
     }
 
diff --git a/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/AbstractAegisTest.java b/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/AbstractAegisTest.java
index c683612..ed3de37 100644
--- a/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/AbstractAegisTest.java
+++ b/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/AbstractAegisTest.java
@@ -305,14 +305,13 @@ public abstract class AbstractAegisTest extends AbstractCXFTest {
     }
 
     protected Element createElement(String namespace, String name, String namespacePrefix) {
+        //The Aegis tests use xpaths that require the created element be the root of a doc
         Document doc = DOMUtils.createDocument();
-
         Element element = doc.createElementNS(namespace, name);
         if (namespacePrefix != null) {
             element.setPrefix(namespacePrefix);
             DOMUtils.addNamespacePrefix(element, namespace, namespacePrefix);
         }
-
         doc.appendChild(element);
         return element;
     }
diff --git a/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/JAXBEncoderDecoderTest.java b/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/JAXBEncoderDecoderTest.java
index 5616fb8..2de9bcd 100644
--- a/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/JAXBEncoderDecoderTest.java
+++ b/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/JAXBEncoderDecoderTest.java
@@ -415,7 +415,7 @@ public class JAXBEncoderDecoderTest extends Assert {
         part.setTypeClass(Class.forName(wrapperAnnotation.className()));
 
 
-        Document doc = DOMUtils.createDocument();
+        Document doc = DOMUtils.getEmptyDocument();
         Element elNode = doc.createElementNS(elName.getNamespaceURI(),
                                              elName.getLocalPart());
         Element rtEl = doc.createElementNS(elName.getNamespaceURI(), "requestType");
@@ -454,7 +454,7 @@ public class JAXBEncoderDecoderTest extends Assert {
         part.setElementQName(elName);
         part.setTypeClass(Class.forName("org.apache.hello_world_soap_http.types.StringStruct"));
 
-        doc = DOMUtils.createDocument();
+        doc = DOMUtils.getEmptyDocument();
         elNode = doc.createElementNS(elName.getNamespaceURI(),
                                              elName.getLocalPart());
         rtEl = doc.createElementNS(elName.getNamespaceURI(), "arg1");
@@ -483,7 +483,7 @@ public class JAXBEncoderDecoderTest extends Assert {
         QName elName = new QName(wrapperAnnotation.targetNamespace(),
                                  wrapperAnnotation.localName());
 
-        Document doc = DOMUtils.createDocument();
+        Document doc = DOMUtils.getEmptyDocument();
         Element elNode = doc.createElementNS(elName.getNamespaceURI(),
                                              elName.getLocalPart());
         Element rtEl = doc.createElementNS(elName.getNamespaceURI(), "requestType");
@@ -501,7 +501,7 @@ public class JAXBEncoderDecoderTest extends Assert {
 
     @Test
     public void testMarshallExceptionWithOrder() throws Exception {
-        Document doc = DOMUtils.createDocument();
+        Document doc = DOMUtils.getEmptyDocument();
         Element elNode = doc.createElementNS("http://cxf.apache.org",  "ExceptionRoot");
 
         OrderException exception = new OrderException("Mymessage");
diff --git a/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/logical/LogicalMessageImpl.java b/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/logical/LogicalMessageImpl.java
index 2f62b91..2c0e405 100644
--- a/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/logical/LogicalMessageImpl.java
+++ b/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/logical/LogicalMessageImpl.java
@@ -39,7 +39,6 @@ import javax.xml.ws.LogicalMessage;
 import javax.xml.ws.Service;
 import javax.xml.ws.WebServiceException;
 
-import org.w3c.dom.Document;
 import org.w3c.dom.DocumentFragment;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
@@ -99,15 +98,15 @@ public class LogicalMessageImpl implements LogicalMessage {
 
                 if (source == null) {
                     try {
-                        Document doc = DOMUtils.newDocument();
-                        W3CDOMStreamWriter writer = new W3CDOMStreamWriter(doc.createDocumentFragment());
+                        DocumentFragment doc = DOMUtils.getEmptyDocument().createDocumentFragment();
+                        W3CDOMStreamWriter writer = new W3CDOMStreamWriter(doc);
                         reader = message.getContent(XMLStreamReader.class);
                         //content must be an element thing, skip over any whitespace
                         StaxUtils.toNextTag(reader);
                         StaxUtils.copy(reader, writer, true);
                         doc.appendChild(DOMUtils.getFirstElement(writer.getCurrentFragment()));
-                        source = new DOMSource(doc.getDocumentElement());
-                        reader = StaxUtils.createXMLStreamReader(doc.getDocumentElement());
+                        source = new DOMSource(DOMUtils.getFirstElement(doc));
+                        reader = StaxUtils.createXMLStreamReader(DOMUtils.getFirstElement(doc));
                     } catch (XMLStreamException e) {
                         throw new Fault(e);
                     }
diff --git a/rt/security-saml/src/main/java/org/apache/cxf/rt/security/saml/interceptor/WSS4JBasicAuthValidator.java b/rt/security-saml/src/main/java/org/apache/cxf/rt/security/saml/interceptor/WSS4JBasicAuthValidator.java
index e41cb80..0bdb608 100644
--- a/rt/security-saml/src/main/java/org/apache/cxf/rt/security/saml/interceptor/WSS4JBasicAuthValidator.java
+++ b/rt/security-saml/src/main/java/org/apache/cxf/rt/security/saml/interceptor/WSS4JBasicAuthValidator.java
@@ -96,7 +96,7 @@ public abstract class WSS4JBasicAuthValidator {
 
     protected UsernameToken convertPolicyToToken(AuthorizationPolicy policy) {
 
-        Document doc = DOMUtils.createDocument();
+        Document doc = DOMUtils.getEmptyDocument();
         UsernameToken token = new UsernameToken(false, doc,
                                                 WSS4JConstants.PASSWORD_TEXT);
         token.setName(policy.getUserName());
diff --git a/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/EncoderDecoder10AImpl.java b/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/EncoderDecoder10AImpl.java
index 95d51c7..08d0990 100644
--- a/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/EncoderDecoder10AImpl.java
+++ b/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/EncoderDecoder10AImpl.java
@@ -32,7 +32,7 @@ import javax.xml.bind.Marshaller;
 import javax.xml.bind.Unmarshaller;
 import javax.xml.namespace.QName;
 
-import org.w3c.dom.Document;
+import org.w3c.dom.DocumentFragment;
 import org.w3c.dom.Element;
 
 import org.apache.cxf.binding.soap.SoapHeader;
@@ -164,14 +164,14 @@ public final class EncoderDecoder10AImpl extends EncoderDecoder {
     }
 
     public Element encodeSequenceAcknowledgement(SequenceAcknowledgement ack) throws JAXBException {
-        Document doc = DOMUtils.createDocument();
+        DocumentFragment doc = DOMUtils.getEmptyDocument().createDocumentFragment();
         Marshaller marshaller = getContext().createMarshaller();
         marshaller.marshal(VersionTransformer.convert200502wsa15(ack), doc);
         return (Element)doc.getFirstChild();
     }
 
     public Element encodeIdentifier(Identifier id) throws JAXBException {
-        Document doc = DOMUtils.createDocument();
+        DocumentFragment doc = DOMUtils.getEmptyDocument().createDocumentFragment();
         Marshaller marshaller = getContext().createMarshaller();
         marshaller.marshal(VersionTransformer.convert200502wsa15(id), doc);
         return (Element)doc.getFirstChild();
diff --git a/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/EncoderDecoder10Impl.java b/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/EncoderDecoder10Impl.java
index 2c3e0f7..7a47e1f 100644
--- a/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/EncoderDecoder10Impl.java
+++ b/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/EncoderDecoder10Impl.java
@@ -32,7 +32,7 @@ import javax.xml.bind.Marshaller;
 import javax.xml.bind.Unmarshaller;
 import javax.xml.namespace.QName;
 
-import org.w3c.dom.Document;
+import org.w3c.dom.DocumentFragment;
 import org.w3c.dom.Element;
 
 import org.apache.cxf.binding.soap.SoapHeader;
@@ -163,14 +163,14 @@ public final class EncoderDecoder10Impl extends EncoderDecoder {
     }
 
     public Element encodeSequenceAcknowledgement(SequenceAcknowledgement ack) throws JAXBException {
-        Document doc = DOMUtils.createDocument();
+        DocumentFragment doc = DOMUtils.getEmptyDocument().createDocumentFragment();
         Marshaller marshaller = getContext().createMarshaller();
         marshaller.marshal(VersionTransformer.convert200502(ack), doc);
         return (Element)doc.getFirstChild();
     }
 
     public Element encodeIdentifier(Identifier id) throws JAXBException {
-        Document doc = DOMUtils.createDocument();
+        DocumentFragment doc = DOMUtils.getEmptyDocument().createDocumentFragment();
         Marshaller marshaller = getContext().createMarshaller();
         marshaller.marshal(VersionTransformer.convert200502(id), doc);
         return (Element)doc.getFirstChild();
diff --git a/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/EncoderDecoder11Impl.java b/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/EncoderDecoder11Impl.java
index b896272..ae94f2f 100644
--- a/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/EncoderDecoder11Impl.java
+++ b/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/EncoderDecoder11Impl.java
@@ -32,7 +32,7 @@ import javax.xml.bind.Marshaller;
 import javax.xml.bind.Unmarshaller;
 import javax.xml.namespace.QName;
 
-import org.w3c.dom.Document;
+import org.w3c.dom.DocumentFragment;
 import org.w3c.dom.Element;
 
 import org.apache.cxf.binding.soap.SoapHeader;
@@ -160,14 +160,14 @@ public final class EncoderDecoder11Impl extends EncoderDecoder {
     }
 
     public Element encodeSequenceAcknowledgement(SequenceAcknowledgement ack) throws JAXBException {
-        Document doc = DOMUtils.createDocument();
+        DocumentFragment doc = DOMUtils.getEmptyDocument().createDocumentFragment();
         Marshaller marshaller = getContext().createMarshaller();
         marshaller.marshal(ack, doc);
         return (Element)doc.getFirstChild();
     }
 
     public Element encodeIdentifier(Identifier id) throws JAXBException {
-        Document doc = DOMUtils.createDocument();
+        DocumentFragment doc = DOMUtils.getEmptyDocument().createDocumentFragment();
         Marshaller marshaller = getContext().createMarshaller();
         marshaller.marshal(id, doc);
         return (Element)doc.getFirstChild();
diff --git a/rt/ws/security/src/main/java/org/apache/cxf/ws/security/kerberos/KerberosClient.java b/rt/ws/security/src/main/java/org/apache/cxf/ws/security/kerberos/KerberosClient.java
index e6061b7..1361f7f 100644
--- a/rt/ws/security/src/main/java/org/apache/cxf/ws/security/kerberos/KerberosClient.java
+++ b/rt/ws/security/src/main/java/org/apache/cxf/ws/security/kerberos/KerberosClient.java
@@ -171,7 +171,7 @@ public class KerberosClient implements Configurable {
     }
 
     protected KerberosSecurity createKerberosSecurity() {
-        return new KerberosSecurity(DOMUtils.createDocument());
+        return new KerberosSecurity(DOMUtils.getEmptyDocument());
     }
 
     public boolean isUsernameServiceNameForm() {
diff --git a/rt/ws/security/src/main/java/org/apache/cxf/ws/security/trust/STSLoginModule.java b/rt/ws/security/src/main/java/org/apache/cxf/ws/security/trust/STSLoginModule.java
index ce00a9f..c438593 100644
--- a/rt/ws/security/src/main/java/org/apache/cxf/ws/security/trust/STSLoginModule.java
+++ b/rt/ws/security/src/main/java/org/apache/cxf/ws/security/trust/STSLoginModule.java
@@ -345,7 +345,7 @@ public class STSLoginModule implements LoginModule {
     private UsernameToken convertToToken(String username, String password)
         throws Exception {
 
-        Document doc = DOMUtils.createDocument();
+        Document doc = DOMUtils.getEmptyDocument();
         UsernameToken token = new UsernameToken(false, doc,
                                                 WSS4JConstants.PASSWORD_TEXT);
         token.setName(username);
diff --git a/rt/ws/security/src/main/java/org/apache/cxf/ws/security/trust/STSStaxTokenValidator.java b/rt/ws/security/src/main/java/org/apache/cxf/ws/security/trust/STSStaxTokenValidator.java
index 132ccfc..1fde85a 100644
--- a/rt/ws/security/src/main/java/org/apache/cxf/ws/security/trust/STSStaxTokenValidator.java
+++ b/rt/ws/security/src/main/java/org/apache/cxf/ws/security/trust/STSStaxTokenValidator.java
@@ -361,7 +361,7 @@ public class STSStaxTokenValidator
     private Element convertToDOM(
         String username, String password, String passwordType, String id
     ) {
-        Document doc = DOMUtils.newDocument();
+        Document doc = DOMUtils.getEmptyDocument();
 
         UsernameToken usernameToken = new UsernameToken(true, doc, passwordType);
         usernameToken.setName(username);
@@ -534,7 +534,7 @@ public class STSStaxTokenValidator
             BinarySecurityTokenType binarySecurityTokenType,
             byte[] securityTokenData
         ) throws WSSecurityException {
-            Document doc = DOMUtils.newDocument();
+            Document doc = DOMUtils.getEmptyDocument();
             BinarySecurity binarySecurity = null;
             if (WSSConstants.NS_X509_V3_TYPE.equals(binarySecurityTokenType.getValueType())) {
                 binarySecurity = new X509Security(doc);
diff --git a/rt/ws/security/src/main/java/org/apache/cxf/ws/security/trust/delegation/WSSUsernameCallbackHandler.java b/rt/ws/security/src/main/java/org/apache/cxf/ws/security/trust/delegation/WSSUsernameCallbackHandler.java
index 508a6fd..884e8d0 100644
--- a/rt/ws/security/src/main/java/org/apache/cxf/ws/security/trust/delegation/WSSUsernameCallbackHandler.java
+++ b/rt/ws/security/src/main/java/org/apache/cxf/ws/security/trust/delegation/WSSUsernameCallbackHandler.java
@@ -55,7 +55,7 @@ public class WSSUsernameCallbackHandler implements CallbackHandler {
                     if (contentNode != null) {
                         doc = contentNode.getOwnerDocument();
                     } else {
-                        doc = DOMUtils.createDocument();
+                        doc = DOMUtils.getEmptyDocument();
                     }
                     UsernameToken usernameToken = createWSSEUsernameToken(username, doc);
                     callback.setToken(usernameToken.getElement());
diff --git a/rt/ws/transfer/src/test/java/org/apache/cxf/ws/transfer/integration/FragmentPutInsertAfterTest.java b/rt/ws/transfer/src/test/java/org/apache/cxf/ws/transfer/integration/FragmentPutInsertAfterTest.java
index f5b141e..2988786 100644
--- a/rt/ws/transfer/src/test/java/org/apache/cxf/ws/transfer/integration/FragmentPutInsertAfterTest.java
+++ b/rt/ws/transfer/src/test/java/org/apache/cxf/ws/transfer/integration/FragmentPutInsertAfterTest.java
@@ -55,7 +55,7 @@ public class FragmentPutInsertAfterTest extends IntegrationBaseTest {
         expression.setLanguage(FragmentDialectConstants.XPATH10_LANGUAGE_IRI);
         expression.setMode(FragmentDialectConstants.FRAGMENT_MODE_INSERT_AFTER);
         expression.getContent().add("/a/b");
-        Element addedElement = DOMUtils.createDocument().createElement("d");
+        Element addedElement = DOMUtils.getEmptyDocument().createElement("d");
         ValueType value = new ValueType();
         value.getContent().add(addedElement);
         fragment.setExpression(expression);
@@ -90,7 +90,7 @@ public class FragmentPutInsertAfterTest extends IntegrationBaseTest {
         expression.setLanguage(FragmentDialectConstants.XPATH10_LANGUAGE_IRI);
         expression.setMode(FragmentDialectConstants.FRAGMENT_MODE_INSERT_AFTER);
         expression.getContent().add("/a/b[last()]");
-        Element addedElement = DOMUtils.createDocument().createElement("c");
+        Element addedElement = DOMUtils.getEmptyDocument().createElement("c");
         ValueType value = new ValueType();
         value.getContent().add(addedElement);
         fragment.setExpression(expression);
@@ -124,7 +124,7 @@ public class FragmentPutInsertAfterTest extends IntegrationBaseTest {
         expression.setLanguage(FragmentDialectConstants.XPATH10_LANGUAGE_IRI);
         expression.setMode(FragmentDialectConstants.FRAGMENT_MODE_INSERT_AFTER);
         expression.getContent().add("/");
-        Element addedElement = DOMUtils.createDocument().createElement("a");
+        Element addedElement = DOMUtils.getEmptyDocument().createElement("a");
         ValueType value = new ValueType();
         value.getContent().add(addedElement);
         fragment.setExpression(expression);
@@ -153,7 +153,7 @@ public class FragmentPutInsertAfterTest extends IntegrationBaseTest {
         expression.setLanguage(FragmentDialectConstants.XPATH10_LANGUAGE_IRI);
         expression.setMode(FragmentDialectConstants.FRAGMENT_MODE_INSERT_AFTER);
         expression.getContent().add("/");
-        Element addedElement = DOMUtils.createDocument().createElement("b");
+        Element addedElement = DOMUtils.getEmptyDocument().createElement("b");
         ValueType value = new ValueType();
         value.getContent().add(addedElement);
         fragment.setExpression(expression);
@@ -180,7 +180,7 @@ public class FragmentPutInsertAfterTest extends IntegrationBaseTest {
         expression.setLanguage(FragmentDialectConstants.XPATH10_LANGUAGE_IRI);
         expression.setMode(FragmentDialectConstants.FRAGMENT_MODE_INSERT_AFTER);
         expression.getContent().add("/a/@foo");
-        Element addedElement = DOMUtils.createDocument().createElement("b");
+        Element addedElement = DOMUtils.getEmptyDocument().createElement("b");
         ValueType value = new ValueType();
         value.getContent().add(addedElement);
         fragment.setExpression(expression);
diff --git a/rt/ws/transfer/src/test/java/org/apache/cxf/ws/transfer/integration/FragmentPutInsertBeforeTest.java b/rt/ws/transfer/src/test/java/org/apache/cxf/ws/transfer/integration/FragmentPutInsertBeforeTest.java
index f0079e8..4b4de4b 100644
--- a/rt/ws/transfer/src/test/java/org/apache/cxf/ws/transfer/integration/FragmentPutInsertBeforeTest.java
+++ b/rt/ws/transfer/src/test/java/org/apache/cxf/ws/transfer/integration/FragmentPutInsertBeforeTest.java
@@ -55,7 +55,7 @@ public class FragmentPutInsertBeforeTest extends IntegrationBaseTest {
         expression.setLanguage(FragmentDialectConstants.XPATH10_LANGUAGE_IRI);
         expression.setMode(FragmentDialectConstants.FRAGMENT_MODE_INSERT_BEFORE);
         expression.getContent().add("/a/b");
-        Element addedElement = DOMUtils.createDocument().createElement("d");
+        Element addedElement = DOMUtils.getEmptyDocument().createElement("d");
         ValueType value = new ValueType();
         value.getContent().add(addedElement);
         fragment.setExpression(expression);
@@ -90,7 +90,7 @@ public class FragmentPutInsertBeforeTest extends IntegrationBaseTest {
         expression.setLanguage(FragmentDialectConstants.XPATH10_LANGUAGE_IRI);
         expression.setMode(FragmentDialectConstants.FRAGMENT_MODE_INSERT_BEFORE);
         expression.getContent().add("/a/b[1]");
-        Element addedElement = DOMUtils.createDocument().createElement("c");
+        Element addedElement = DOMUtils.getEmptyDocument().createElement("c");
         ValueType value = new ValueType();
         value.getContent().add(addedElement);
         fragment.setExpression(expression);
@@ -124,7 +124,7 @@ public class FragmentPutInsertBeforeTest extends IntegrationBaseTest {
         expression.setLanguage(FragmentDialectConstants.XPATH10_LANGUAGE_IRI);
         expression.setMode(FragmentDialectConstants.FRAGMENT_MODE_INSERT_BEFORE);
         expression.getContent().add("/");
-        Element addedElement = DOMUtils.createDocument().createElement("a");
+        Element addedElement = DOMUtils.getEmptyDocument().createElement("a");
         ValueType value = new ValueType();
         value.getContent().add(addedElement);
         fragment.setExpression(expression);
@@ -153,7 +153,7 @@ public class FragmentPutInsertBeforeTest extends IntegrationBaseTest {
         expression.setLanguage(FragmentDialectConstants.XPATH10_LANGUAGE_IRI);
         expression.setMode(FragmentDialectConstants.FRAGMENT_MODE_INSERT_BEFORE);
         expression.getContent().add("/");
-        Element addedElement = DOMUtils.createDocument().createElement("b");
+        Element addedElement = DOMUtils.getEmptyDocument().createElement("b");
         ValueType value = new ValueType();
         value.getContent().add(addedElement);
         fragment.setExpression(expression);
@@ -180,7 +180,7 @@ public class FragmentPutInsertBeforeTest extends IntegrationBaseTest {
         expression.setLanguage(FragmentDialectConstants.XPATH10_LANGUAGE_IRI);
         expression.setMode(FragmentDialectConstants.FRAGMENT_MODE_INSERT_BEFORE);
         expression.getContent().add("/a/@f");
-        Element addedElement = DOMUtils.createDocument().createElement("b");
+        Element addedElement = DOMUtils.getEmptyDocument().createElement("b");
         ValueType value = new ValueType();
         value.getContent().add(addedElement);
         fragment.setExpression(expression);
diff --git a/rt/ws/transfer/src/test/java/org/apache/cxf/ws/transfer/integration/FragmentPutReplaceTest.java b/rt/ws/transfer/src/test/java/org/apache/cxf/ws/transfer/integration/FragmentPutReplaceTest.java
index 44476f5..e7375ab 100644
--- a/rt/ws/transfer/src/test/java/org/apache/cxf/ws/transfer/integration/FragmentPutReplaceTest.java
+++ b/rt/ws/transfer/src/test/java/org/apache/cxf/ws/transfer/integration/FragmentPutReplaceTest.java
@@ -54,7 +54,7 @@ public class FragmentPutReplaceTest extends IntegrationBaseTest {
         ExpressionType expression = new ExpressionType();
         expression.setLanguage(FragmentDialectConstants.XPATH10_LANGUAGE_IRI);
         expression.getContent().add("/root/a");
-        Element replacedElement = DOMUtils.createDocument().createElement("b");
+        Element replacedElement = DOMUtils.getEmptyDocument().createElement("b");
         replacedElement.setTextContent("Better text");
         ValueType value = new ValueType();
         value.getContent().add(replacedElement);
@@ -84,7 +84,7 @@ public class FragmentPutReplaceTest extends IntegrationBaseTest {
         ExpressionType expression = new ExpressionType();
         expression.setLanguage(FragmentDialectConstants.XPATH10_LANGUAGE_IRI);
         expression.getContent().add("/a");
-        Element replacedElement = DOMUtils.createDocument().createElement("b");
+        Element replacedElement = DOMUtils.getEmptyDocument().createElement("b");
         ValueType value = new ValueType();
         value.getContent().add(replacedElement);
         fragment.setExpression(expression);
@@ -142,7 +142,7 @@ public class FragmentPutReplaceTest extends IntegrationBaseTest {
         ExpressionType expression = new ExpressionType();
         expression.setLanguage(FragmentDialectConstants.XPATH10_LANGUAGE_IRI);
         expression.getContent().add("/root/a/@foo");
-        Element replacedAttr = DOMUtils.createDocument().createElementNS(
+        Element replacedAttr = DOMUtils.getEmptyDocument().createElementNS(
                 FragmentDialectConstants.FRAGMENT_2011_03_IRI,
                 FragmentDialectConstants.FRAGMENT_ATTR_NODE_NAME
         );
@@ -181,7 +181,7 @@ public class FragmentPutReplaceTest extends IntegrationBaseTest {
         ExpressionType expression = new ExpressionType();
         expression.setLanguage(FragmentDialectConstants.XPATH10_LANGUAGE_IRI);
         expression.getContent().add("/");
-        Element replacedElement = DOMUtils.createDocument().createElement("a");
+        Element replacedElement = DOMUtils.getEmptyDocument().createElement("a");
         ValueType value = new ValueType();
         value.getContent().add(replacedElement);
         fragment.setExpression(expression);
@@ -209,7 +209,7 @@ public class FragmentPutReplaceTest extends IntegrationBaseTest {
         ExpressionType expression = new ExpressionType();
         expression.setLanguage(FragmentDialectConstants.XPATH10_LANGUAGE_IRI);
         expression.getContent().add("/");
-        Element replacedElement = DOMUtils.createDocument().createElement("b");
+        Element replacedElement = DOMUtils.getEmptyDocument().createElement("b");
         ValueType value = new ValueType();
         value.getContent().add(replacedElement);
         fragment.setExpression(expression);
@@ -237,7 +237,7 @@ public class FragmentPutReplaceTest extends IntegrationBaseTest {
         ExpressionType expression = new ExpressionType();
         expression.setLanguage(FragmentDialectConstants.XPATH10_LANGUAGE_IRI);
         expression.getContent().add("/*");
-        Element replacedElement = DOMUtils.createDocument().createElement("b");
+        Element replacedElement = DOMUtils.getEmptyDocument().createElement("b");
         ValueType value = new ValueType();
         value.getContent().add(replacedElement);
         fragment.setExpression(expression);
@@ -265,7 +265,7 @@ public class FragmentPutReplaceTest extends IntegrationBaseTest {
         ExpressionType expression = new ExpressionType();
         expression.setLanguage(FragmentDialectConstants.XPATH10_LANGUAGE_IRI);
         expression.getContent().add("/a/b[1]");
-        Element replacedElement = DOMUtils.createDocument().createElement("c");
+        Element replacedElement = DOMUtils.getEmptyDocument().createElement("c");
         ValueType value = new ValueType();
         value.getContent().add(replacedElement);
         fragment.setExpression(expression);
@@ -294,7 +294,7 @@ public class FragmentPutReplaceTest extends IntegrationBaseTest {
         ExpressionType expression = new ExpressionType();
         expression.setLanguage(FragmentDialectConstants.XPATH10_LANGUAGE_IRI);
         expression.getContent().add("/a/b");
-        Element replacedElement = DOMUtils.createDocument().createElement("c");
+        Element replacedElement = DOMUtils.getEmptyDocument().createElement("c");
         ValueType value = new ValueType();
         value.getContent().add(replacedElement);
         fragment.setExpression(expression);
@@ -323,7 +323,7 @@ public class FragmentPutReplaceTest extends IntegrationBaseTest {
         ExpressionType expression = new ExpressionType();
         expression.setLanguage(FragmentDialectConstants.XPATH10_LANGUAGE_IRI);
         expression.getContent().add("/a/b");
-        Element replacedElement = DOMUtils.createDocument().createElement("b");
+        Element replacedElement = DOMUtils.getEmptyDocument().createElement("b");
         ValueType value = new ValueType();
         value.getContent().add(replacedElement);
         fragment.setExpression(expression);
@@ -351,7 +351,7 @@ public class FragmentPutReplaceTest extends IntegrationBaseTest {
         ExpressionType expression = new ExpressionType();
         expression.setLanguage(FragmentDialectConstants.XPATH10_LANGUAGE_IRI);
         expression.getContent().add("/a");
-        Element replacedElement = DOMUtils.createDocument().createElement("a");
+        Element replacedElement = DOMUtils.getEmptyDocument().createElement("a");
         ValueType value = new ValueType();
         value.getContent().add(replacedElement);
         fragment.setExpression(expression);
@@ -379,7 +379,7 @@ public class FragmentPutReplaceTest extends IntegrationBaseTest {
         ExpressionType expression = new ExpressionType();
         expression.setLanguage(FragmentDialectConstants.XPATH10_LANGUAGE_IRI);
         expression.getContent().add("//b");
-        Element replacedElement = DOMUtils.createDocument().createElement("b");
+        Element replacedElement = DOMUtils.getEmptyDocument().createElement("b");
         ValueType value = new ValueType();
         value.getContent().add(replacedElement);
         fragment.setExpression(expression);
@@ -405,7 +405,7 @@ public class FragmentPutReplaceTest extends IntegrationBaseTest {
         ExpressionType expression = new ExpressionType();
         expression.setLanguage(FragmentDialectConstants.XPATH10_LANGUAGE_IRI);
         expression.getContent().add("/a/[local-name() = 'b'");
-        Element replacedElement = DOMUtils.createDocument().createElement("b");
+        Element replacedElement = DOMUtils.getEmptyDocument().createElement("b");
         ValueType value = new ValueType();
         value.getContent().add(replacedElement);
         fragment.setExpression(expression);
diff --git a/rt/ws/transfer/src/test/java/org/apache/cxf/ws/transfer/integration/ResourceFactoryTest.java b/rt/ws/transfer/src/test/java/org/apache/cxf/ws/transfer/integration/ResourceFactoryTest.java
index ff0d082..624a69f 100644
--- a/rt/ws/transfer/src/test/java/org/apache/cxf/ws/transfer/integration/ResourceFactoryTest.java
+++ b/rt/ws/transfer/src/test/java/org/apache/cxf/ws/transfer/integration/ResourceFactoryTest.java
@@ -43,7 +43,7 @@ public class ResourceFactoryTest extends IntegrationBaseTest {
 
     private ReferenceParametersType createReferenceParameters() {
         ReferenceParametersType refParam = new ReferenceParametersType();
-        Element uuidEl = DOMUtils.createDocument().createElementNS(
+        Element uuidEl = DOMUtils.getEmptyDocument().createElementNS(
                 REF_PARAM_NAMESPACE, REF_PARAM_LOCAL_NAME);
         uuidEl.setTextContent(RESOURCE_UUID);
         refParam.getAny().add(uuidEl);
diff --git a/rt/ws/transfer/src/test/java/org/apache/cxf/ws/transfer/unit/MemoryResourceManagerTest.java b/rt/ws/transfer/src/test/java/org/apache/cxf/ws/transfer/unit/MemoryResourceManagerTest.java
index 0a71446..3ac0c92 100644
--- a/rt/ws/transfer/src/test/java/org/apache/cxf/ws/transfer/unit/MemoryResourceManagerTest.java
+++ b/rt/ws/transfer/src/test/java/org/apache/cxf/ws/transfer/unit/MemoryResourceManagerTest.java
@@ -77,7 +77,7 @@ public class MemoryResourceManagerTest {
     @Test(expected = UnknownResource.class)
     public void getUnknownReferenceParamsTest() {
         ReferenceParametersType refParams = new ReferenceParametersType();
-        Element uuid = DOMUtils.createDocument().createElementNS(
+        Element uuid = DOMUtils.getEmptyDocument().createElementNS(
                 MemoryResourceManager.REF_NAMESPACE, MemoryResourceManager.REF_LOCAL_NAME);
         uuid.setTextContent("123456");
         refParams.getAny().add(uuid);
@@ -92,7 +92,7 @@ public class MemoryResourceManagerTest {
     @Test(expected = UnknownResource.class)
     public void putUnknownReferenceParamsTest() {
         ReferenceParametersType refParams = new ReferenceParametersType();
-        Element uuid = DOMUtils.createDocument().createElementNS(
+        Element uuid = DOMUtils.getEmptyDocument().createElementNS(
                 MemoryResourceManager.REF_NAMESPACE, MemoryResourceManager.REF_LOCAL_NAME);
         uuid.setTextContent("123456");
         refParams.getAny().add(uuid);
diff --git a/rt/wsdl/src/main/java/org/apache/cxf/wsdl11/ServiceWSDLBuilder.java b/rt/wsdl/src/main/java/org/apache/cxf/wsdl11/ServiceWSDLBuilder.java
index 5e69199..65ca956 100644
--- a/rt/wsdl/src/main/java/org/apache/cxf/wsdl11/ServiceWSDLBuilder.java
+++ b/rt/wsdl/src/main/java/org/apache/cxf/wsdl11/ServiceWSDLBuilder.java
@@ -102,8 +102,7 @@ public class ServiceWSDLBuilder {
     private int xsdCount;
     private final Bus bus;
     private final NSManager nsMan;
-    private Document docDoc;
-
+    
     /**
      * Sets up the builder on a bus with a list of services.
      * @param b the bus.
@@ -243,10 +242,7 @@ public class ServiceWSDLBuilder {
         if (text == null) {
             return;
         }
-        if (docDoc == null) {
-            docDoc = DOMUtils.newDocument();
-        }
-        Element el = docDoc.createElementNS(WSDLConstants.NS_WSDL11, "wsdl:documentation");
+        Element el = DOMUtils.getEmptyDocument().createElementNS(WSDLConstants.NS_WSDL11, "wsdl:documentation");
         el.setTextContent(text);
         wsdlel.setDocumentationElement(el);
     }
diff --git a/services/sts/sts-core/src/main/java/org/apache/cxf/sts/operation/AbstractOperation.java b/services/sts/sts-core/src/main/java/org/apache/cxf/sts/operation/AbstractOperation.java
index 15f229b..129d2ac 100644
--- a/services/sts/sts-core/src/main/java/org/apache/cxf/sts/operation/AbstractOperation.java
+++ b/services/sts/sts-core/src/main/java/org/apache/cxf/sts/operation/AbstractOperation.java
@@ -362,7 +362,7 @@ public abstract class AbstractOperation {
             }
         }
 
-        Document doc = DOMUtils.createDocument();
+        Document doc = DOMUtils.getEmptyDocument();
 
         WSSecEncryptedKey builder = new WSSecEncryptedKey(doc);
         builder.setUserInfo(name);
diff --git a/services/sts/sts-core/src/main/java/org/apache/cxf/sts/rest/RESTSecurityTokenServiceImpl.java b/services/sts/sts-core/src/main/java/org/apache/cxf/sts/rest/RESTSecurityTokenServiceImpl.java
index 7a676aa..0e3f1d0 100644
--- a/services/sts/sts-core/src/main/java/org/apache/cxf/sts/rest/RESTSecurityTokenServiceImpl.java
+++ b/services/sts/sts-core/src/main/java/org/apache/cxf/sts/rest/RESTSecurityTokenServiceImpl.java
@@ -211,7 +211,7 @@ public class RESTSecurityTokenServiceImpl extends SecurityTokenServiceImpl imple
         if (STSConstants.PUBLIC_KEY_KEYTYPE.equals(desiredKeyType)) {
             X509Certificate clientCert = getTLSClientCertificate();
             if (clientCert != null) {
-                Document doc = DOMUtils.createDocument();
+                Document doc = DOMUtils.getEmptyDocument();
                 Element keyInfoElement = doc.createElementNS("http://www.w3.org/2000/09/xmldsig#", "KeyInfo");
 
                 try {
diff --git a/services/sts/sts-core/src/main/java/org/apache/cxf/sts/token/provider/SCTProvider.java b/services/sts/sts-core/src/main/java/org/apache/cxf/sts/token/provider/SCTProvider.java
index 2cbd37a..ce707df 100644
--- a/services/sts/sts-core/src/main/java/org/apache/cxf/sts/token/provider/SCTProvider.java
+++ b/services/sts/sts-core/src/main/java/org/apache/cxf/sts/token/provider/SCTProvider.java
@@ -118,7 +118,7 @@ public class SCTProvider implements TokenProvider {
         keyHandler.createSymmetricKey();
 
         try {
-            Document doc = DOMUtils.createDocument();
+            Document doc = DOMUtils.getEmptyDocument();
             SecurityContextToken sct =
                 new SecurityContextToken(getWSCVersion(tokenRequirements.getTokenType()), doc);
             WSSConfig wssConfig = WSSConfig.getNewInstance();
diff --git a/services/sts/sts-core/src/main/java/org/apache/cxf/sts/token/provider/TokenProviderUtils.java b/services/sts/sts-core/src/main/java/org/apache/cxf/sts/token/provider/TokenProviderUtils.java
index 71e0b39..f96e156 100644
--- a/services/sts/sts-core/src/main/java/org/apache/cxf/sts/token/provider/TokenProviderUtils.java
+++ b/services/sts/sts-core/src/main/java/org/apache/cxf/sts/token/provider/TokenProviderUtils.java
@@ -29,6 +29,7 @@ import javax.xml.bind.JAXBElement;
 import javax.xml.namespace.QName;
 
 import org.w3c.dom.Document;
+import org.w3c.dom.DocumentFragment;
 import org.w3c.dom.Element;
 
 import org.apache.cxf.common.logging.LogUtils;
@@ -151,7 +152,8 @@ public final class TokenProviderUtils {
         }
 
         Document doc = element.getOwnerDocument();
-        doc.appendChild(element);
+        DocumentFragment frag = doc.createDocumentFragment();
+        frag.appendChild(element);
 
         WSSecEncrypt builder = new WSSecEncrypt(doc);
         if (ConfigurationConstants.USE_REQ_SIG_CERT.equals(name)) {
@@ -170,8 +172,8 @@ public final class TokenProviderUtils {
 
         builder.prepare(stsProperties.getEncryptionCrypto());
         builder.encryptForRef(null, Collections.singletonList(encryptionPart));
-
-        return doc.getDocumentElement();
+        
+        return (Element)frag.getFirstChild();
     }
 
     /**
diff --git a/services/sts/sts-core/src/test/java/org/apache/cxf/sts/claims/mapper/JexlIssueSamlClaimsTest.java b/services/sts/sts-core/src/test/java/org/apache/cxf/sts/claims/mapper/JexlIssueSamlClaimsTest.java
index 300a91b..f74f41d 100644
--- a/services/sts/sts-core/src/test/java/org/apache/cxf/sts/claims/mapper/JexlIssueSamlClaimsTest.java
+++ b/services/sts/sts-core/src/test/java/org/apache/cxf/sts/claims/mapper/JexlIssueSamlClaimsTest.java
@@ -214,7 +214,7 @@ public class JexlIssueSamlClaimsTest extends org.junit.Assert {
         ClaimsType claimsType = new ClaimsType();
         claimsType.setDialect(STSConstants.IDT_NS_05_05);
 
-        Document doc = DOMUtils.createDocument();
+        Document doc = DOMUtils.getEmptyDocument();
         Element claimType = createClaimsType(doc, ClaimTypes.LASTNAME);
         claimsType.getAny().add(claimType);
 
diff --git a/services/sts/sts-core/src/test/java/org/apache/cxf/sts/operation/CancelSCTUnitTest.java b/services/sts/sts-core/src/test/java/org/apache/cxf/sts/operation/CancelSCTUnitTest.java
index 0f01627..fae7171 100644
--- a/services/sts/sts-core/src/test/java/org/apache/cxf/sts/operation/CancelSCTUnitTest.java
+++ b/services/sts/sts-core/src/test/java/org/apache/cxf/sts/operation/CancelSCTUnitTest.java
@@ -26,7 +26,6 @@ import java.util.Properties;
 import javax.xml.bind.JAXBElement;
 import javax.xml.namespace.QName;
 
-import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
 import org.apache.cxf.jaxws.context.WrappedMessageContext;
@@ -98,8 +97,6 @@ public class CancelSCTUnitTest extends org.junit.Assert {
         // Get a SecurityContextToken via the SCTProvider
         TokenProviderResponse providerResponse = createSCT();
         Element sct = (Element)providerResponse.getToken();
-        Document doc = sct.getOwnerDocument();
-        sct = (Element)doc.appendChild(sct);
         CancelTargetType cancelTarget = new CancelTargetType();
         cancelTarget.setAny(sct);
 
diff --git a/services/sts/sts-core/src/test/java/org/apache/cxf/sts/operation/DummyTokenProvider.java b/services/sts/sts-core/src/test/java/org/apache/cxf/sts/operation/DummyTokenProvider.java
index e28c540..36d3f69 100644
--- a/services/sts/sts-core/src/test/java/org/apache/cxf/sts/operation/DummyTokenProvider.java
+++ b/services/sts/sts-core/src/test/java/org/apache/cxf/sts/operation/DummyTokenProvider.java
@@ -50,7 +50,7 @@ public class DummyTokenProvider implements TokenProvider {
 
     public TokenProviderResponse createToken(TokenProviderParameters tokenParameters) {
         try {
-            Document doc = DOMUtils.createDocument();
+            Document doc = DOMUtils.getEmptyDocument();
 
             // Mock up a dummy BinarySecurityToken
             String id = "BST-1234";
diff --git a/services/sts/sts-core/src/test/java/org/apache/cxf/sts/operation/IssueJWTClaimsUnitTest.java b/services/sts/sts-core/src/test/java/org/apache/cxf/sts/operation/IssueJWTClaimsUnitTest.java
index af4af68..d72120a 100644
--- a/services/sts/sts-core/src/test/java/org/apache/cxf/sts/operation/IssueJWTClaimsUnitTest.java
+++ b/services/sts/sts-core/src/test/java/org/apache/cxf/sts/operation/IssueJWTClaimsUnitTest.java
@@ -32,6 +32,7 @@ import javax.xml.bind.JAXBElement;
 import javax.xml.namespace.QName;
 
 import org.w3c.dom.Document;
+import org.w3c.dom.DocumentFragment;
 import org.w3c.dom.Element;
 import org.apache.cxf.helpers.DOMUtils;
 import org.apache.cxf.jaxws.context.WrappedMessageContext;
@@ -246,7 +247,7 @@ public class IssueJWTClaimsUnitTest extends org.junit.Assert {
         // Add a ClaimsType
         ClaimsType claimsType = new ClaimsType();
         claimsType.setDialect(STSConstants.IDT_NS_05_05);
-        Document doc = DOMUtils.createDocument();
+        Document doc = DOMUtils.getEmptyDocument();
         Element claimType = createClaimsType(doc);
         claimsType.getAny().add(claimType);
 
@@ -347,7 +348,7 @@ public class IssueJWTClaimsUnitTest extends org.junit.Assert {
         ClaimsType claimsType = new ClaimsType();
         claimsType.setDialect(STSConstants.IDT_NS_05_05);
 
-        Document doc = DOMUtils.createDocument();
+        Document doc = DOMUtils.getEmptyDocument();
         Element claimType = createClaimsType(doc);
         claimsType.getAny().add(claimType);
 
@@ -364,6 +365,9 @@ public class IssueJWTClaimsUnitTest extends org.junit.Assert {
         Element samlToken =
             createSAMLAssertion(WSS4JConstants.WSS_SAML2_TOKEN_TYPE, crypto, "mystskey",
                     callbackHandler, realms);
+        
+        DocumentFragment f = samlToken.getOwnerDocument().createDocumentFragment();
+        f.appendChild(samlToken);
         Document docToken = samlToken.getOwnerDocument();
         samlToken = (Element)docToken.appendChild(samlToken);
         String samlString = DOM2Writer.nodeToString(samlToken);
@@ -499,8 +503,7 @@ public class IssueJWTClaimsUnitTest extends org.junit.Assert {
         ClaimsType claimsType = new ClaimsType();
         claimsType.setDialect(STSConstants.IDT_NS_05_05);
 
-        Document doc = DOMUtils.createDocument();
-        Element claimType = createClaimsType(doc);
+        Element claimType = createClaimsType(DOMUtils.getEmptyDocument());
         claimsType.getAny().add(claimType);
 
         JAXBElement<ClaimsType> claimsTypeJaxb =
@@ -637,7 +640,7 @@ public class IssueJWTClaimsUnitTest extends org.junit.Assert {
      * Mock up a SecondaryParameters DOM Element containing some claims
      */
     private Element createSecondaryParameters() {
-        Document doc = DOMUtils.createDocument();
+        Document doc = DOMUtils.getEmptyDocument();
         Element secondary = doc.createElementNS(STSConstants.WST_NS_05_12, "SecondaryParameters");
         secondary.setAttributeNS(WSS4JConstants.XMLNS_NS, "xmlns", STSConstants.WST_NS_05_12);
 
diff --git a/services/sts/sts-core/src/test/java/org/apache/cxf/sts/operation/IssueSCTUnitTest.java b/services/sts/sts-core/src/test/java/org/apache/cxf/sts/operation/IssueSCTUnitTest.java
index 29b0f66..893ae73 100644
--- a/services/sts/sts-core/src/test/java/org/apache/cxf/sts/operation/IssueSCTUnitTest.java
+++ b/services/sts/sts-core/src/test/java/org/apache/cxf/sts/operation/IssueSCTUnitTest.java
@@ -226,7 +226,7 @@ public class IssueSCTUnitTest extends org.junit.Assert {
         String tokenString = DOM2Writer.nodeToString(securityContextToken);
         assertFalse(tokenString.contains("SecurityContextToken"));
         assertFalse(tokenString.contains("Identifier"));
-        assertTrue(tokenString.contains("EncryptedData"));
+        assertTrue(tokenString, tokenString.contains("EncryptedData"));
     }
 
     /**
diff --git a/services/sts/sts-core/src/test/java/org/apache/cxf/sts/operation/IssueSamlClaimsUnitTest.java b/services/sts/sts-core/src/test/java/org/apache/cxf/sts/operation/IssueSamlClaimsUnitTest.java
index 388b9ae..368fb1c 100644
--- a/services/sts/sts-core/src/test/java/org/apache/cxf/sts/operation/IssueSamlClaimsUnitTest.java
+++ b/services/sts/sts-core/src/test/java/org/apache/cxf/sts/operation/IssueSamlClaimsUnitTest.java
@@ -840,7 +840,7 @@ public class IssueSamlClaimsUnitTest extends org.junit.Assert {
      * Mock up a SecondaryParameters DOM Element containing a custom claim dialect.
      */
     private Element createCustomSecondaryParameters() {
-        Document doc = DOMUtils.createDocument();
+        Document doc = DOMUtils.getEmptyDocument();
         Element secondary = doc.createElementNS(STSConstants.WST_NS_05_12, "SecondaryParameters");
         secondary.setAttributeNS(WSS4JConstants.XMLNS_NS, "xmlns", STSConstants.WST_NS_05_12);
 
diff --git a/services/sts/sts-core/src/test/java/org/apache/cxf/sts/operation/ValidateJWTTransformationTest.java b/services/sts/sts-core/src/test/java/org/apache/cxf/sts/operation/ValidateJWTTransformationTest.java
index 235ea5b..446dcdb 100644
--- a/services/sts/sts-core/src/test/java/org/apache/cxf/sts/operation/ValidateJWTTransformationTest.java
+++ b/services/sts/sts-core/src/test/java/org/apache/cxf/sts/operation/ValidateJWTTransformationTest.java
@@ -127,8 +127,6 @@ public class ValidateJWTTransformationTest extends org.junit.Assert {
         // Create a JWTToken
         TokenProviderResponse providerResponse = createJWT();
         Element wrapper = createTokenWrapper((String)providerResponse.getToken());
-        Document doc = wrapper.getOwnerDocument();
-        wrapper = (Element)doc.appendChild(wrapper);
 
         ValidateTargetType validateTarget = new ValidateTargetType();
         validateTarget.setAny(wrapper);
@@ -348,7 +346,7 @@ public class ValidateJWTTransformationTest extends org.junit.Assert {
     }
 
     private Element createTokenWrapper(String token) {
-        Document doc = DOMUtils.newDocument();
+        Document doc = DOMUtils.getEmptyDocument();
         Element tokenWrapper = doc.createElementNS(null, "TokenWrapper");
         tokenWrapper.setTextContent(token);
         return tokenWrapper;
diff --git a/services/sts/sts-core/src/test/java/org/apache/cxf/sts/operation/ValidateJWTUnitTest.java b/services/sts/sts-core/src/test/java/org/apache/cxf/sts/operation/ValidateJWTUnitTest.java
index b0b28e2..11acf0a 100644
--- a/services/sts/sts-core/src/test/java/org/apache/cxf/sts/operation/ValidateJWTUnitTest.java
+++ b/services/sts/sts-core/src/test/java/org/apache/cxf/sts/operation/ValidateJWTUnitTest.java
@@ -96,8 +96,6 @@ public class ValidateJWTUnitTest extends org.junit.Assert {
         // Get a JWTToken via the JWTTokenProvider
         TokenProviderResponse providerResponse = createJWT();
         Element wrapper = createTokenWrapper((String)providerResponse.getToken());
-        Document doc = wrapper.getOwnerDocument();
-        wrapper = (Element)doc.appendChild(wrapper);
         ValidateTargetType validateTarget = new ValidateTargetType();
         validateTarget.setAny(wrapper);
 
@@ -123,7 +121,7 @@ public class ValidateJWTUnitTest extends org.junit.Assert {
     }
 
     private Element createTokenWrapper(String token) {
-        Document doc = DOMUtils.newDocument();
+        Document doc = DOMUtils.getEmptyDocument();
         Element tokenWrapper = doc.createElementNS(null, "TokenWrapper");
         tokenWrapper.setTextContent(token);
         return tokenWrapper;
diff --git a/services/sts/sts-core/src/test/java/org/apache/cxf/sts/operation/ValidateSCTUnitTest.java b/services/sts/sts-core/src/test/java/org/apache/cxf/sts/operation/ValidateSCTUnitTest.java
index 696ed0d..d82def5 100644
--- a/services/sts/sts-core/src/test/java/org/apache/cxf/sts/operation/ValidateSCTUnitTest.java
+++ b/services/sts/sts-core/src/test/java/org/apache/cxf/sts/operation/ValidateSCTUnitTest.java
@@ -26,7 +26,6 @@ import java.util.Properties;
 import javax.xml.bind.JAXBElement;
 import javax.xml.namespace.QName;
 
-import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
 import org.apache.cxf.jaxws.context.WrappedMessageContext;
@@ -105,8 +104,6 @@ public class ValidateSCTUnitTest extends org.junit.Assert {
         // Get a SecurityContextToken via the SCTProvider
         TokenProviderResponse providerResponse = createSCT();
         Element sct = (Element)providerResponse.getToken();
-        Document doc = sct.getOwnerDocument();
-        sct = (Element)doc.appendChild(sct);
         ValidateTargetType validateTarget = new ValidateTargetType();
         validateTarget.setAny(sct);
 
diff --git a/services/sts/sts-core/src/test/java/org/apache/cxf/sts/token/canceller/SCTCancellerTest.java b/services/sts/sts-core/src/test/java/org/apache/cxf/sts/token/canceller/SCTCancellerTest.java
index b283f96..aef2881 100644
--- a/services/sts/sts-core/src/test/java/org/apache/cxf/sts/token/canceller/SCTCancellerTest.java
+++ b/services/sts/sts-core/src/test/java/org/apache/cxf/sts/token/canceller/SCTCancellerTest.java
@@ -92,7 +92,7 @@ public class SCTCancellerTest extends org.junit.Assert {
         TokenRequirements tokenRequirements = cancellerParameters.getTokenRequirements();
 
         // Create a CancelTarget consisting of a SecurityContextToken
-        Document doc = DOMUtils.createDocument();
+        Document doc = DOMUtils.getEmptyDocument();
         SecurityContextToken sct = new SecurityContextToken(doc);
         ReceivedToken cancelTarget = new ReceivedToken(sct.getElement());
         tokenRequirements.setCancelTarget(cancelTarget);
diff --git a/services/sts/sts-core/src/test/java/org/apache/cxf/sts/token/validator/JWTTokenValidatorRealmTest.java b/services/sts/sts-core/src/test/java/org/apache/cxf/sts/token/validator/JWTTokenValidatorRealmTest.java
index 697d84c..c384e7e 100644
--- a/services/sts/sts-core/src/test/java/org/apache/cxf/sts/token/validator/JWTTokenValidatorRealmTest.java
+++ b/services/sts/sts-core/src/test/java/org/apache/cxf/sts/token/validator/JWTTokenValidatorRealmTest.java
@@ -253,7 +253,7 @@ public class JWTTokenValidatorRealmTest extends org.junit.Assert {
     }
 
     private Element createTokenWrapper(String token) {
-        Document doc = DOMUtils.newDocument();
+        Document doc = DOMUtils.getEmptyDocument();
         Element tokenWrapper = doc.createElementNS(null, "TokenWrapper");
         tokenWrapper.setTextContent(token);
         return tokenWrapper;
diff --git a/services/sts/sts-core/src/test/java/org/apache/cxf/sts/token/validator/JWTTokenValidatorTest.java b/services/sts/sts-core/src/test/java/org/apache/cxf/sts/token/validator/JWTTokenValidatorTest.java
index 433ec30..cce39d2 100644
--- a/services/sts/sts-core/src/test/java/org/apache/cxf/sts/token/validator/JWTTokenValidatorTest.java
+++ b/services/sts/sts-core/src/test/java/org/apache/cxf/sts/token/validator/JWTTokenValidatorTest.java
@@ -428,7 +428,7 @@ public class JWTTokenValidatorTest extends org.junit.Assert {
     }
 
     private Element createTokenWrapper(String token) {
-        Document doc = DOMUtils.newDocument();
+        Document doc = DOMUtils.getEmptyDocument();
         Element tokenWrapper = doc.createElementNS(null, "TokenWrapper");
         tokenWrapper.setTextContent(token);
         return tokenWrapper;
diff --git a/services/sts/systests/advanced/src/test/java/org/apache/cxf/systest/sts/deployment/CustomBSTTokenProvider.java b/services/sts/systests/advanced/src/test/java/org/apache/cxf/systest/sts/deployment/CustomBSTTokenProvider.java
index 0337b60..97583a5 100644
--- a/services/sts/systests/advanced/src/test/java/org/apache/cxf/systest/sts/deployment/CustomBSTTokenProvider.java
+++ b/services/sts/systests/advanced/src/test/java/org/apache/cxf/systest/sts/deployment/CustomBSTTokenProvider.java
@@ -49,7 +49,7 @@ public class CustomBSTTokenProvider implements TokenProvider {
 
     public TokenProviderResponse createToken(TokenProviderParameters tokenParameters) {
         try {
-            Document doc = DOMUtils.createDocument();
+            Document doc = DOMUtils.getEmptyDocument();
 
             // Mock up a BinarySecurityToken
             String id = "BST-1234";
diff --git a/services/sts/systests/advanced/src/test/java/org/apache/cxf/systest/sts/distributed_caching/CustomUsernameTokenProvider.java b/services/sts/systests/advanced/src/test/java/org/apache/cxf/systest/sts/distributed_caching/CustomUsernameTokenProvider.java
index d763090..b9a555a 100644
--- a/services/sts/systests/advanced/src/test/java/org/apache/cxf/systest/sts/distributed_caching/CustomUsernameTokenProvider.java
+++ b/services/sts/systests/advanced/src/test/java/org/apache/cxf/systest/sts/distributed_caching/CustomUsernameTokenProvider.java
@@ -48,7 +48,7 @@ public class CustomUsernameTokenProvider implements TokenProvider {
 
     public TokenProviderResponse createToken(TokenProviderParameters tokenParameters) {
         try {
-            Document doc = DOMUtils.createDocument();
+            Document doc = DOMUtils.getEmptyDocument();
 
             // Mock up a UsernameToken
             UsernameToken usernameToken = new UsernameToken(true, doc, WSS4JConstants.PASSWORD_TEXT);
diff --git a/services/wsn/wsn-api/src/main/java/org/apache/cxf/wsn/util/WSNHelper.java b/services/wsn/wsn-api/src/main/java/org/apache/cxf/wsn/util/WSNHelper.java
index 2b4c23d..e6f5cef 100644
--- a/services/wsn/wsn-api/src/main/java/org/apache/cxf/wsn/util/WSNHelper.java
+++ b/services/wsn/wsn-api/src/main/java/org/apache/cxf/wsn/util/WSNHelper.java
@@ -152,7 +152,7 @@ public class WSNHelper {
     }
 
     public String getWSAAddress(W3CEndpointReference ref) {
-        Element element = DOMUtils.createDocument().createElement("elem");
+        Element element = DOMUtils.getEmptyDocument().createElement("elem");
         ref.writeTo(new DOMResult(element));
         NodeList nl = element.getElementsByTagNameNS("http://www.w3.org/2005/08/addressing", "Address");
         if (nl != null && nl.getLength() > 0) {
diff --git a/services/wsn/wsn-core/src/main/java/org/apache/cxf/wsn/jms/JmsSubscription.java b/services/wsn/wsn-core/src/main/java/org/apache/cxf/wsn/jms/JmsSubscription.java
index b1a55ab..12cd7d7 100644
--- a/services/wsn/wsn-core/src/main/java/org/apache/cxf/wsn/jms/JmsSubscription.java
+++ b/services/wsn/wsn-core/src/main/java/org/apache/cxf/wsn/jms/JmsSubscription.java
@@ -43,7 +43,7 @@ import javax.xml.xpath.XPathExpression;
 import javax.xml.xpath.XPathExpressionException;
 import javax.xml.xpath.XPathFactory;
 
-import org.w3c.dom.Document;
+import org.w3c.dom.DocumentFragment;
 import org.w3c.dom.Element;
 
 import org.apache.cxf.common.logging.LogUtils;
@@ -221,9 +221,9 @@ public abstract class JmsSubscription extends AbstractSubscription implements Me
                 NotificationMessageHolderType h = ith.next();
                 Object content = h.getMessage().getAny();
                 if (!(content instanceof Element)) {
-                    Document doc = DOMUtils.createDocument();
+                    DocumentFragment doc = DOMUtils.getEmptyDocument().createDocumentFragment();
                     jaxbContext.createMarshaller().marshal(content, doc);
-                    content = doc.getDocumentElement();
+                    content = DOMUtils.getFirstElement(doc);
                 }
                 if (!doFilter((Element) content)) {
                     ith.remove();
diff --git a/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/grants/CallbackHandlerLoginHandler.java b/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/grants/CallbackHandlerLoginHandler.java
index e64d5f3..a9ed02f 100644
--- a/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/grants/CallbackHandlerLoginHandler.java
+++ b/systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oauth2/grants/CallbackHandlerLoginHandler.java
@@ -48,7 +48,7 @@ public class CallbackHandlerLoginHandler implements ResourceOwnerLoginHandler {
 
     @Override
     public UserSubject createSubject(Client client, String user, String pass) {
-        Document doc = DOMUtils.createDocument();
+        Document doc = DOMUtils.getEmptyDocument();
         UsernameToken token = new UsernameToken(false, doc,
                                                 WSS4JConstants.PASSWORD_TEXT);
         token.setName(user);
diff --git a/tools/common/src/main/java/org/apache/cxf/tools/util/JAXBUtils.java b/tools/common/src/main/java/org/apache/cxf/tools/util/JAXBUtils.java
index 7a8053f..7e386bc 100644
--- a/tools/common/src/main/java/org/apache/cxf/tools/util/JAXBUtils.java
+++ b/tools/common/src/main/java/org/apache/cxf/tools/util/JAXBUtils.java
@@ -112,7 +112,7 @@ public final class JAXBUtils {
      * @return file
      */
     public static File getPackageMappingSchemaBindingFile(String namespace, String pkgName) {
-        Document doc = DOMUtils.createDocument();
+        Document doc = DOMUtils.getEmptyDocument();
         Element rootElement = doc.createElementNS(ToolConstants.SCHEMA_URI, "schema");
         rootElement.setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "xmlns", ToolConstants.SCHEMA_URI);
         rootElement.setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "xmlns:jaxb", ToolConstants.NS_JAXB_BINDINGS);
diff --git a/tools/corba/src/main/java/org/apache/cxf/tools/corba/common/WSDLCorbaWriterImpl.java b/tools/corba/src/main/java/org/apache/cxf/tools/corba/common/WSDLCorbaWriterImpl.java
index d15dc62..fced291 100644
--- a/tools/corba/src/main/java/org/apache/cxf/tools/corba/common/WSDLCorbaWriterImpl.java
+++ b/tools/corba/src/main/java/org/apache/cxf/tools/corba/common/WSDLCorbaWriterImpl.java
@@ -127,7 +127,7 @@ public class WSDLCorbaWriterImpl implements WSDLWriter {
 
 
     private void fixSchema(Schema sc, String pfx) throws ParserConfigurationException {
-        Document doc = DOMUtils.newDocument();
+        Document doc = DOMUtils.getEmptyDocument();
         Element el = doc.createElementNS(sc.getElementType().getNamespaceURI(),
                             pfx + ":" + sc.getElementType().getLocalPart());
         sc.setElement(el);

-- 
To stop receiving notification emails like this one, please contact
"commits@cxf.apache.org" <commits@cxf.apache.org>.

Mime
View raw message