You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by ru...@apache.org on 2005/12/13 18:31:22 UTC

svn commit: r356546 - in /webservices/axis2/trunk/java/modules: integration/ saaj/src/org/apache/axis2/om/impl/dom/ security/src/org/apache/axis2/security/ security/src/org/apache/axis2/security/util/ xml/src/org/apache/axis2/om/xpath/ xml/src/org/apac...

Author: ruchithf
Date: Tue Dec 13 09:30:15 2005
New Revision: 356546

URL: http://svn.apache.org/viewcvs?rev=356546&view=rev
Log:
DOOM working with ALL security test cases... and integrated :-)

Changes:
 - Fixed a defaul ns problem in DOOM - We have all

 - Removed some more LLOM dependancies from the builders

 - removed org.apache.axis2.om.impl.llom.OMDocumentImpl dependancy from the org.apache.axis2.om.xpath.DocumentNavigator - TODO remove org.apache.axis2.om.impl.llom.OMAttributeImpl dependancy


Modified:
    webservices/axis2/trunk/java/modules/integration/project.xml
    webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/om/impl/dom/AttrImpl.java
    webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/om/impl/dom/AttributeMap.java
    webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/om/impl/dom/ChildNode.java
    webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/om/impl/dom/ElementImpl.java
    webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/om/impl/dom/NodeImpl.java
    webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/om/impl/dom/ParentNode.java
    webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/om/impl/dom/TextImpl.java
    webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/WSDoAllReceiver.java
    webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/WSDoAllSender.java
    webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/util/Axis2Util.java
    webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/xpath/DocumentNavigator.java
    webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/soap/impl/llom/builder/SOAP11BuilderHelper.java
    webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/soap/impl/llom/builder/SOAP12BuilderHelper.java
    webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/soap/impl/llom/builder/StAXSOAPModelBuilder.java

Modified: webservices/axis2/trunk/java/modules/integration/project.xml
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/integration/project.xml?rev=356546&r1=356545&r2=356546&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/integration/project.xml (original)
+++ webservices/axis2/trunk/java/modules/integration/project.xml Tue Dec 13 09:30:15 2005
@@ -75,7 +75,11 @@
             <artifactId>axis2-common</artifactId>
             <version>${pom.currentVersion}</version>
         </dependency>
-        
+        <dependency>
+            <groupId>axis2</groupId>
+            <artifactId>axis2-saaj</artifactId>
+            <version>${pom.currentVersion}</version>
+        </dependency> 
 
         <!-- external JARs -->
         <dependency>

Modified: webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/om/impl/dom/AttrImpl.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/om/impl/dom/AttrImpl.java?rev=356546&r1=356545&r2=356546&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/om/impl/dom/AttrImpl.java (original)
+++ webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/om/impl/dom/AttrImpl.java Tue Dec 13 09:30:15 2005
@@ -340,23 +340,22 @@
     	//TODO Error checking
         return (this.namespace == null)?null:this.namespace.getPrefix();
     }
-
-	public Node cloneNode(boolean deep) {
+    
+    public Node cloneNode(boolean deep) {
 
         AttrImpl clone = (AttrImpl) super.cloneNode(deep);
 
-        // take care of case where there are kids
-    	if (!this.hasChildNodes()) {
-
-            clone.attrValue = null;
-
-            for (Node child = (Node) attrValue; child != null; child = child.getNextSibling()) {
-                 clone.appendChild(child.cloneNode(true));
+    	if (clone.attrValue == null) {
+            // Need to break the association w/ original kids
+            clone.attrValue = new TextImpl(this.attrValue.toString());
+            if(this.attrValue.nextSibling != null) {
+            	throw new UnsupportedOperationException("Attribute value can contain only a text node with out any siblings");
             }
-        }
+    	}
         clone.isSpecified(true);
         return clone;
-	}
+    }
+    
 
 	/*
 	 * DOM-Level 3 methods
@@ -375,4 +374,5 @@
 	public String toString() {
 		return (this.namespace == null)?this.attrName: this.namespace.getPrefix() + ":" + this.attrName;
 	}
+	
 }

Modified: webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/om/impl/dom/AttributeMap.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/om/impl/dom/AttributeMap.java?rev=356546&r1=356545&r2=356546&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/om/impl/dom/AttributeMap.java (original)
+++ webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/om/impl/dom/AttributeMap.java Tue Dec 13 09:30:15 2005
@@ -175,4 +175,46 @@
         }
         return previous;
 	}
+	
+	
+
+    /**
+     * BORROWED from Xerces impl
+     * Cloning a NamedNodeMap is a DEEP OPERATION; it always clones
+     * all the nodes contained in the map.
+     */
+     
+    public NamedNodeMapImpl cloneMap(NodeImpl ownerNode) {
+        AttributeMap newmap =
+            new AttributeMap((ParentNode) ownerNode);
+        newmap.hasDefaults(hasDefaults());
+        newmap.cloneContent(this);
+        return newmap;
+    } // cloneMap():AttributeMap
+
+    /**
+     * BORROWED from Xerces impl
+     */
+    protected void cloneContent(NamedNodeMapImpl srcmap) {
+        Vector srcnodes = srcmap.nodes;
+        if (srcnodes != null) {
+            int size = srcnodes.size();
+            if (size != 0) {
+                if (nodes == null) {
+                    nodes = new Vector(size);
+                }
+                nodes.setSize(size);
+                for (int i = 0; i < size; ++i) {
+                    NodeImpl n = (NodeImpl) srcnodes.elementAt(i);
+                    NodeImpl clone = (NodeImpl) n.cloneNode(true);
+                    clone.isSpecified(n.isSpecified());
+                    nodes.setElementAt(clone, i);
+                    clone.ownerNode = this.ownerNode.ownerNode;
+                    clone.isOwned(true);
+                }
+            }
+        }
+    } // cloneContent():AttributeMap
+
+
 }

Modified: webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/om/impl/dom/ChildNode.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/om/impl/dom/ChildNode.java?rev=356546&r1=356545&r2=356546&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/om/impl/dom/ChildNode.java (original)
+++ webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/om/impl/dom/ChildNode.java Tue Dec 13 09:30:15 2005
@@ -158,5 +158,18 @@
 		}
 		
 	}
+	
+	
+    public Node cloneNode(boolean deep) {
+
+    	ChildNode newnode = (ChildNode) super.cloneNode(deep);
+    	
+        // Need to break the association w/ original kids
+    	newnode.previousSibling = null;
+        newnode.nextSibling     = null;
+        newnode.isFirstChild(false);
+
+    	return newnode;
+    }
 
 }

Modified: webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/om/impl/dom/ElementImpl.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/om/impl/dom/ElementImpl.java?rev=356546&r1=356545&r2=356546&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/om/impl/dom/ElementImpl.java (original)
+++ webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/om/impl/dom/ElementImpl.java Tue Dec 13 09:30:15 2005
@@ -32,9 +32,11 @@
 import org.apache.axis2.om.OMNode;
 import org.apache.axis2.om.OMText;
 import org.apache.axis2.om.OMXMLParserWrapper;
-import org.apache.axis2.om.impl.OMOutputImpl;
 import org.apache.axis2.om.impl.OMNodeEx;
+import org.apache.axis2.om.impl.OMOutputImpl;
+import org.apache.axis2.om.impl.dom.factory.OMDOMFactory;
 import org.apache.axis2.om.impl.llom.OMSerializerUtil;
+import org.apache.axis2.om.impl.llom.builder.StAXOMBuilder;
 import org.apache.axis2.om.impl.llom.traverse.OMChildElementIterator;
 import org.apache.axis2.om.impl.llom.util.EmptyIterator;
 import org.apache.axis2.om.util.ElementHelper;
@@ -265,7 +267,8 @@
 		if(attributes == null) {
 			return "";
 		} else {
-			return ((Attr)attributes.getNamedItem(name)).getValue();
+			Attr attr = ((Attr)attributes.getNamedItem(name));
+			return (attr != null)?attr.getValue():"";
 		}
 	}
 
@@ -619,9 +622,19 @@
      * This can also be used to retrieve the prefix of a known namespace URI
      */
     private OMNamespace findDeclaredNamespace(String uri, String prefix) {
-        if (namespaces == null) {
+    	
+    	if(uri == null) {
+    		return null;
+    	}
+    	//If the prefix is available and uri is available and its the xml namespace
+    	if(prefix != null && prefix.equals(OMConstants.XMLNS_PREFIX) && uri.equals(OMConstants.XMLNS_URI)) {
+    		return new NamespaceImpl(uri, prefix);
+    	}
+    	
+    	if (namespaces == null) {
             return null;
         }
+    	   
         if (prefix == null || "".equals(prefix)) {
             Iterator namespaceListIterator = namespaces.values().iterator();
             while (namespaceListIterator.hasNext()) {
@@ -634,7 +647,12 @@
             }
             return null;
         } else {
-            return (OMNamespace) namespaces.get(prefix);
+            OMNamespace namespace = (OMNamespace) namespaces.get(prefix);
+            if (namespace != null && uri.equalsIgnoreCase(namespace.getName())) {
+                return namespace;
+            } else {
+            	return null;
+            }
         }
     }
     
@@ -782,7 +800,7 @@
 	 * @see org.apache.axis2.om.OMElement#setNamespace(org.apache.axis2.om.OMNamespace)
 	 */
 	public void setNamespace(OMNamespace namespace) {
-		this.namespace = namespace;
+			this.namespace = namespace;
 	}
 
 	/**
@@ -976,10 +994,26 @@
         return helper.resolveQName(qname);
     }
 
+    /**
+     * This will create a clone which belongs to a new document 
+     * @see org.apache.axis2.om.OMElement#cloneOMElement()
+     */
     public OMElement cloneOMElement() {
-        throw new UnsupportedOperationException("Cloning is not supported yet !!");
+		ElementImpl elem = (ElementImpl)(new StAXOMBuilder(new OMDOMFactory(), this.getXMLStreamReader(true))).getDocumentElement();
+		return elem;
     }
 
+    public Node cloneNode(boolean deep) {
+
+    	ElementImpl newnode = (ElementImpl) super.cloneNode(deep);
+    	// Replicate NamedNodeMap rather than sharing it.
+        if (attributes != null) {
+            newnode.attributes = (AttributeMap) attributes.cloneMap(newnode);
+        }
+    	return newnode;
+
+    }
+    
     /**
      * This will return the set of attributes of this node and the 
      * namespace declarations available
@@ -997,7 +1031,7 @@
 	    	Iterator nsDecls = this.namespaces.keySet().iterator();
 			while (nsDecls.hasNext()) {
 				String prefix = (String) nsDecls.next();
-				if(!prefix.equals(OMConstants.XMLNS_NS_PREFIX)){
+				if(prefix != null && !"".equals(prefix) && !prefix.equals(OMConstants.XMLNS_NS_PREFIX)){
 					OMNamespace ns = (OMNamespace) this.namespaces.get(prefix);
 					AttrImpl attr = new AttrImpl(this.ownerNode, prefix, ns
 							.getName());
@@ -1014,9 +1048,13 @@
 							.equals(this.namespace.getPrefix()))
 					&& this.namespace.getName() != null) {
 
-				AttrImpl attr = new AttrImpl(this.ownerNode, "xmlns",
-						this.namespace.getName());
-				attributeMap.addItem(attr);
+				//check if the parent of this element has the same namespace
+				// as the default and if NOT add the attr
+				if(this.parentNode.getNamespaceURI() != this.getNamespaceURI()) {
+					AttrImpl attr = new AttrImpl(this.ownerNode, "xmlns",
+							this.namespace.getName());
+					attributeMap.addItem(attr);
+				}
 			}
     	}
     	
@@ -1048,6 +1086,7 @@
     	}
     	
     }
+    
     
 	/*
 	 * DOM-Level 3 methods

Modified: webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/om/impl/dom/NodeImpl.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/om/impl/dom/NodeImpl.java?rev=356546&r1=356545&r2=356546&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/om/impl/dom/NodeImpl.java (original)
+++ webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/om/impl/dom/NodeImpl.java Tue Dec 13 09:30:15 2005
@@ -20,8 +20,10 @@
 import javax.xml.stream.XMLOutputFactory;
 
 import org.apache.axis2.om.OMContainer;
+import org.apache.axis2.om.OMElement;
 import org.apache.axis2.om.OMException;
 import org.apache.axis2.om.OMNode;
+import org.apache.axis2.om.OMText;
 import org.apache.axis2.om.OMXMLParserWrapper;
 import org.apache.axis2.om.OMOutputFormat;
 import org.apache.axis2.om.impl.OMNodeEx;
@@ -39,7 +41,7 @@
 /**
  * @author Ruchith Fernando (ruchith.fernando@gmail.com)
  */
-public abstract class NodeImpl implements Node, NodeList,OMNodeEx {
+public abstract class NodeImpl implements Node, NodeList,OMNodeEx, Cloneable {
 
 
     /**
@@ -198,6 +200,16 @@
         return null;            // default behavior, overriden in ChildNode
     }
 
+//    public Node cloneNode(boolean deep) {
+//    	if(this instanceof OMElement) {
+//    		return (Node)((OMElement)this).cloneOMElement();
+//    	} else if(this instanceof OMText ){
+//    		return ((TextImpl)this).cloneText();
+//    	} else {
+//    		throw new UnsupportedOperationException("Only elements can be cloned right now");
+//    	}
+//    }
+//    
     public Node cloneNode(boolean deep) {
         NodeImpl newnode;
         try {

Modified: webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/om/impl/dom/ParentNode.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/om/impl/dom/ParentNode.java?rev=356546&r1=356545&r2=356546&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/om/impl/dom/ParentNode.java (original)
+++ webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/om/impl/dom/ParentNode.java Tue Dec 13 09:30:15 2005
@@ -181,6 +181,7 @@
 				this.lastChild = newDomChild;
 				this.firstChild = newDomChild;
 				this.firstChild.isFirstChild(true);
+				newDomChild.setParent(this);
 			} else {
 				this.lastChild.nextSibling = newDomChild;
 				newDomChild.previousSibling = this.lastChild;
@@ -409,5 +410,28 @@
 		//TODO isAncestor
 		return true;
 	}
+	
+    public Node cloneNode(boolean deep) {
+
+    	ParentNode newnode = (ParentNode) super.cloneNode(deep);
+
+        // set owner document
+        newnode.ownerNode = ownerNode;
+
+    	// Need to break the association w/ original kids
+    	newnode.firstChild = null;
+    	newnode.lastChild = null;
+
+        // Then, if deep, clone the kids too.
+    	if (deep) {
+            for (ChildNode child = firstChild;
+                 child != null;
+                 child = child.nextSibling) {
+                newnode.appendChild(child.cloneNode(true));
+            }
+        }
+
+    	return newnode;
 
+    }
 }

Modified: webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/om/impl/dom/TextImpl.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/om/impl/dom/TextImpl.java?rev=356546&r1=356545&r2=356546&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/om/impl/dom/TextImpl.java (original)
+++ webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/om/impl/dom/TextImpl.java Tue Dec 13 09:30:15 2005
@@ -470,6 +470,20 @@
         }
     }
 
+    
+//    ///
+//    ///Special clone method to be used in cloneNode
+//    ///
+//    public Text cloneText() {
+//    	return new TextImpl(this.textValue.toString());
+//    }
+//    
+    public Node cloneNode(boolean deep) {
+    	TextImpl textImpl = new TextImpl(this.textValue.toString());
+    	textImpl.setOwnerDocument(this.ownerNode);
+		return textImpl;
+    }
+    
 	/*
 	 * DOM-Level 3 methods
 	 */

Modified: webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/WSDoAllReceiver.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/WSDoAllReceiver.java?rev=356546&r1=356545&r2=356546&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/WSDoAllReceiver.java (original)
+++ webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/WSDoAllReceiver.java Tue Dec 13 09:30:15 2005
@@ -16,17 +16,28 @@
 
 package org.apache.axis2.security;
 
+import java.security.cert.X509Certificate;
+import java.util.Iterator;
+import java.util.Vector;
+
+import javax.security.auth.callback.CallbackHandler;
+import javax.xml.parsers.DocumentBuilderFactory;
+
 import org.apache.axis2.AxisFault;
 import org.apache.axis2.context.MessageContext;
 import org.apache.axis2.context.OperationContext;
+import org.apache.axis2.om.OMElement;
 import org.apache.axis2.om.OMException;
+import org.apache.axis2.om.impl.dom.DocumentImpl;
+import org.apache.axis2.om.impl.dom.jaxp.DocumentBuilderFactoryImpl;
 import org.apache.axis2.security.handler.WSDoAllHandler;
 import org.apache.axis2.security.handler.WSSHandlerConstants;
 import org.apache.axis2.security.util.Axis2Util;
 import org.apache.axis2.security.util.HandlerParameterDecoder;
-import org.apache.axis2.soap.SOAPEnvelope;
+import org.apache.axis2.soap.SOAP11Constants;
 import org.apache.axis2.soap.SOAPHeader;
 import org.apache.axis2.soap.SOAPHeaderBlock;
+import org.apache.axis2.soap.impl.llom.builder.StAXSOAPModelBuilder;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.ws.security.SOAPConstants;
@@ -41,15 +52,11 @@
 import org.apache.wsdl.WSDLConstants;
 import org.w3c.dom.Document;
 
-import java.security.cert.X509Certificate;
-import java.util.Iterator;
-import java.util.Vector;
-
-import javax.security.auth.callback.CallbackHandler;
-
 public class WSDoAllReceiver extends WSDoAllHandler {
 
-    protected static Log log = LogFactory.getLog(WSDoAllReceiver.class.getName());
+	private static final long serialVersionUID = 7685802089392898320L;
+	
+	protected static Log log = LogFactory.getLog(WSDoAllReceiver.class.getName());
 
     
     public WSDoAllReceiver() {
@@ -58,7 +65,12 @@
     }
     
 	public void invoke(MessageContext msgContext) throws AxisFault {
+		
     	boolean doDebug = log.isDebugEnabled();
+		
+		//Set the DOM impl to DOOM
+		String originalDOcumentBuilderFactory = System.getProperty(DocumentBuilderFactory.class.getName());
+		System.setProperty(DocumentBuilderFactory.class.getName(),DocumentBuilderFactoryImpl.class.getName());
 
     	//populate the properties
     	try {
@@ -170,20 +182,18 @@
                 checkSignatureConfirmation(reqData, wsResult);
             }
             
-            //TODO: Copy the processed headers
-
             /**
              * Set the new SOAPEnvelope
              */
+//         
+//            log.debug("Creating LLOM Structure");
+// 	        OMElement docElem = (OMElement)doc.getDocumentElement();
+//	        StAXSOAPModelBuilder stAXSOAPModelBuilder = new StAXSOAPModelBuilder(docElem.getXMLStreamReader(), SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);
+//	        log.debug("Creating LLOM Structure - DONE");
+//			msgContext.setEnvelope((stAXSOAPModelBuilder).getSOAPEnvelope());
             
-            try {
-            	SOAPEnvelope envelope = Axis2Util.getSOAPEnvelopeFromDocument(doc,soapConstants.getEnvelopeURI());
-            	msgContext.setEnvelope(envelope);
-            } catch (WSSecurityException e) {
-            	throw new AxisFault(
-						"WSDoAllReceiver: Error in converting into a SOAPEnvelope",e);            	
-            }
-            
+            msgContext.setEnvelope(Axis2Util.getSOAPEnvelopeFromDOOMDocument((DocumentImpl)doc));
+			
             /*
              * After setting the new current message, probably modified because
              * of decryption, we need to locate the security header. That is, we
@@ -311,12 +321,22 @@
              if (doDebug) {
                  log.debug("WSDoAllReceiver: exit invoke()");
              }
-             
+
         } catch (WSSecurityException wssEx) {
         	throw new AxisFault(wssEx);
         } finally {
             reqData.clear();
             reqData = null;
+
+            //Reset the document builder factory
+            String docBuilderFactory = System.getProperty("javax.xml.parsers.DocumentBuilderFactory");
+            if(docBuilderFactory != null && docBuilderFactory.equals(DocumentBuilderFactoryImpl.class.getName())) {
+				if(originalDOcumentBuilderFactory != null) {
+					System.getProperties().remove(docBuilderFactory);
+				} else {
+					System.getProperties().remove(docBuilderFactory);
+				}
+            }
         }
         
     }

Modified: webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/WSDoAllSender.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/WSDoAllSender.java?rev=356546&r1=356545&r2=356546&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/WSDoAllSender.java (original)
+++ webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/WSDoAllSender.java Tue Dec 13 09:30:15 2005
@@ -16,9 +16,15 @@
 
 package org.apache.axis2.security;
 
+import java.util.Vector;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+
 import org.apache.axis2.AxisFault;
 import org.apache.axis2.context.MessageContext;
 import org.apache.axis2.context.OperationContext;
+import org.apache.axis2.om.impl.dom.DocumentImpl;
+import org.apache.axis2.om.impl.dom.jaxp.DocumentBuilderFactoryImpl;
 import org.apache.axis2.security.handler.WSDoAllHandler;
 import org.apache.axis2.security.handler.WSSHandlerConstants;
 import org.apache.axis2.security.util.Axis2Util;
@@ -35,23 +41,15 @@
 import org.apache.wsdl.WSDLConstants;
 import org.w3c.dom.Document;
 
-import java.util.Vector;
-
 public class WSDoAllSender extends WSDoAllHandler {
 
+	private static final long serialVersionUID = 3016802164501419165L;
+
 	protected static Log log = LogFactory.getLog(WSDoAllSender.class.getName());
 	
 	/**
-	 * Right now we convert the processed DOM - SOAP Envelope into
-	 * and OM-SOAPEnvelope
-	 * But in the simple case where only the wsse:Security header is inserted into the document
-	 * we can insert only the wsse:Security header into the OM-SOAPEnvelope and preserve the 
-	 * metadata of OM such as base64 MTOM optimization
-	 * 
-	 * TODO: Get this as an option from the user or 
-	 * go through the actions and set it appropriately
-	 * Earlier this handler traversed the actions and at that point we used to
-	 * set this value, but now WSS4J goes through the action vector
+	 * TODO: This is not handled right now since converting to DOOM does not preserve
+	 * the optimization information of the text nodes
 	 */
 	private boolean preserveOriginalEnvelope = false;
 	
@@ -62,6 +60,10 @@
 	
 	public void invoke(MessageContext msgContext) throws AxisFault {
 		
+		//Set the DOM impl to DOOM
+		String originalDOcumentBuilderFactory = System.getProperty(DocumentBuilderFactory.class.getName());
+		System.setProperty(DocumentBuilderFactory.class.getName(),DocumentBuilderFactoryImpl.class.getName());
+		
         boolean doDebug = log.isDebugEnabled();
         
         try {
@@ -161,7 +163,7 @@
             if ((doc = (Document) ((MessageContext)reqData.getMsgContext())
                     .getProperty(WSHandlerConstants.SND_SECURITY)) == null) {
             	try {
-            	doc = Axis2Util.getDocumentFromSOAPEnvelope(msgContext.getEnvelope());
+            		doc = Axis2Util.getDocumentFromSOAPEnvelope(msgContext.getEnvelope());
             	} catch (WSSecurityException wssEx) {
             		throw new AxisFault("WSDoAllReceiver: Error in converting to Document", wssEx);
             	}
@@ -188,7 +190,6 @@
                 ((MessageContext)reqData.getMsgContext()).setProperty(WSHandlerConstants.SND_SECURITY,
                         doc);
             } else {
-            	SOAPEnvelope processedEnv = null;
 
     	        String preserve = null;
                 if ((preserve = (String) getOption(WSSHandlerConstants.PRESERVE_ORIGINAL_ENV)) == null) {
@@ -198,16 +199,17 @@
                 	this.preserveOriginalEnvelope = "true".equalsIgnoreCase(preserve);
                 }
                 
-            	if(preserveOriginalEnvelope) {
-            		processedEnv = Axis2Util.getSOAPEnvelopeFromDocument(doc,reqData.getSoapConstants(), msgContext.getEnvelope());
-                   // msgContext.getEnvelope().build();
-            	} else {
-            		processedEnv = Axis2Util.getSOAPEnvelopeFromDocument(doc, reqData.getSoapConstants().getEnvelopeURI());
-            	}
-            	msgContext.setEnvelope(processedEnv);
+            	msgContext.setEnvelope((SOAPEnvelope)doc.getDocumentElement());
+            	
             	((MessageContext)reqData.getMsgContext()).setProperty(WSHandlerConstants.SND_SECURITY, null);
             }
     		
+//	        log.debug("Creating LLOM Structure");
+//	        OMElement docElem = (OMElement)doc.getDocumentElement();
+//	        StAXSOAPModelBuilder stAXSOAPModelBuilder = new StAXSOAPModelBuilder(docElem.getXMLStreamReader(), SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);
+//	        log.debug("Creating LLOM Structure - DONE");
+//			msgContext.setEnvelope(stAXSOAPModelBuilder.getSOAPEnvelope());
+            msgContext.setEnvelope(Axis2Util.getSOAPEnvelopeFromDOOMDocument((DocumentImpl)doc));
             /**
              * If the optimizeParts parts are set then optimize them
              */
@@ -263,7 +265,17 @@
             	reqData.clear();
             	reqData = null;
             }
-        }        
+            
+            //Reset the document builder factory
+            String docBuilderFactory = System.getProperty(DocumentBuilderFactory.class.getName());
+            if(docBuilderFactory != null && docBuilderFactory.equals(DocumentBuilderFactoryImpl.class.getName())) {
+				if(originalDOcumentBuilderFactory != null) {
+					System.getProperties().remove(docBuilderFactory);
+				} else {
+					System.getProperties().remove(docBuilderFactory);
+				}
+            }
+        }     
     }
 }
 

Modified: webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/util/Axis2Util.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/util/Axis2Util.java?rev=356546&r1=356545&r2=356546&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/util/Axis2Util.java (original)
+++ webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/util/Axis2Util.java Tue Dec 13 09:30:15 2005
@@ -16,27 +16,29 @@
 
 package org.apache.axis2.security.util;
 
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
 import org.apache.axis2.om.OMElement;
+import org.apache.axis2.om.impl.dom.DocumentImpl;
 import org.apache.axis2.om.impl.llom.builder.StAXOMBuilder;
 import org.apache.axis2.security.handler.WSSHandlerConstants;
 import org.apache.axis2.security.trust.TrustException;
+import org.apache.axis2.soap.SOAP11Constants;
 import org.apache.axis2.soap.SOAPEnvelope;
+import org.apache.axis2.soap.impl.dom.soap11.SOAP11Factory;
 import org.apache.axis2.soap.impl.llom.builder.StAXSOAPModelBuilder;
 import org.apache.ws.security.SOAPConstants;
 import org.apache.ws.security.WSSecurityException;
-import org.apache.ws.security.util.WSSecurityUtil;
 import org.apache.xml.security.utils.XMLUtils;
-import org.apache.xml.serialize.XMLSerializer;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.stream.XMLInputFactory;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamReader;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-
 /**
  * Utility class for the Axis2-WSS4J Module
  */
@@ -51,122 +53,28 @@
 	public static Document getDocumentFromSOAPEnvelope(SOAPEnvelope env)
 			throws WSSecurityException {
 		try {
-			ByteArrayOutputStream baos = new ByteArrayOutputStream();
-
-			/**
-			 * There are plans to deprecate the OmNode.serializeAndConsume(XMLStreamWriter)
-			 * method therefore using OMOutoutImpl to serializeAndConsume the env
-			 */
-			env.serialize(baos);
+			env.build();
+			StAXSOAPModelBuilder stAXSOAPModelBuilder = new StAXSOAPModelBuilder(env.getXMLStreamReader(),new SOAP11Factory(), SOAPConstants.SOAP11_CONSTANTS.getEnvelopeURI());
+			SOAPEnvelope envelope = (stAXSOAPModelBuilder).getSOAPEnvelope();
+			envelope.build();
+			
+			Element envElem = (Element)envelope;
+			return envElem.getOwnerDocument();
 			
-			ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
-
-			DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
-			factory.setNamespaceAware(true);
-			return factory.newDocumentBuilder().parse(bais);
 		} catch (Exception e) {
 			throw new WSSecurityException(
 					"Error in converting SOAP Envelope to Document", e);
 		}
 	}
 
-	/**
-	 * Covert a DOM Document containing a SOAP Envelope in to a
-	 * org.apache.axis2.soap.SOAPEnvelope 
-	 * @param doc DOM Document
-	 * @param envelopeNS SOAP Namespace of the the given Envelope
-	 * @return
-	 * @throws Exception
-	 */
-	public static SOAPEnvelope getSOAPEnvelopeFromDocument(Document doc,
-			String envelopeNS) throws WSSecurityException {
-		try {
-			//Set the new SOAPEnvelope
-			ByteArrayOutputStream os = new ByteArrayOutputStream();
-			XMLUtils.outputDOM(doc, os, true);
-			
-			ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray());
-			XMLStreamReader reader = XMLInputFactory.newInstance()
-					.createXMLStreamReader(is);
-
-			StAXSOAPModelBuilder builder = new StAXSOAPModelBuilder(reader,
-					envelopeNS);
-			builder.setCache(true);
-
-			return builder.getSOAPEnvelope();
-
-		} catch (Exception e) {
-			throw new WSSecurityException(
-					"Error in converting document to SOAPEnvelope", e);
-		}
-
+	public static SOAPEnvelope getSOAPEnvelopeFromDOOMDocument(DocumentImpl doc) {
+        OMElement docElem = (OMElement)doc.getDocumentElement();
+        StAXSOAPModelBuilder stAXSOAPModelBuilder = new StAXSOAPModelBuilder(docElem.getXMLStreamReader(), SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);
+        return stAXSOAPModelBuilder.getSOAPEnvelope();
 	}
 	
-	/**
-	 * This is to be used only in the signature situation
-	 * where the security header can be inserted into the original SOAPEnvelope
-	 * rather than replacing the whole envelope
-	 * @param doc
-	 * @param envelopeNS
-	 * @param reqEnv
-	 * @return
-	 * @throws WSSecurityException
-	 */
-	public static SOAPEnvelope getSOAPEnvelopeFromDocument(Document doc,
-			SOAPConstants constants, SOAPEnvelope reqEnv) throws WSSecurityException {
-		
-		//Get holdof the security header
-		Element secElem = WSSecurityUtil.getSecurityHeader(doc,null, constants);
-		
-		//insert the header into the OM-SOAPEnvelope
-		
-		OMElement secOmElem = convertToOMelement(secElem, constants);
-		
-		reqEnv.getHeader().addChild(secOmElem);
-		
-		return reqEnv;
-		
-	}
 	
 	/**
-	 * Converts the given DOM Element to an OMElement
-	 * @param elem
-	 * @param constants
-	 * @return
-	 * @throws WSSecurityException
-	 */
-	private static OMElement convertToOMelement(Element elem, SOAPConstants constants) throws WSSecurityException {
-
-		try {
-			XMLSerializer xmlSer = new XMLSerializer();
-			
-			/*
-			 *When we extract the wsse:Security header by serializing it
-			 *The namespaces declared globally will not be copied into the
-			 *serialized element. Therefore we have to add the missing namespaces 
-			 *in to the element before DOm serialization 
-			 */
-			elem.setAttribute("xmlns:soapenv",constants.getEnvelopeURI());
-			ByteArrayOutputStream baos = new ByteArrayOutputStream();
-			
-			xmlSer.setOutputByteStream(baos);
-			
-			xmlSer.serialize(elem);
-			
-			ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
-			XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(bais);
-			StAXOMBuilder builder = new StAXOMBuilder(reader);
-			builder.setCache(true);
-			
-			return builder.getDocumentElement();
-			
-		} catch (Exception e) {
-			throw new WSSecurityException(e.getMessage(),e);
-		}
-
-	}
-
-	/**
 	 * This is used to provide the appropriate key to pickup 
 	 * config params from the message context.
 	 * This is acutally used when the outflow handler (WSDoAllSender)
@@ -223,7 +131,6 @@
 	public static Element toDOM(OMElement element) throws TrustException {
 		try {
 			ByteArrayOutputStream baos = new ByteArrayOutputStream();
-	
 			element.serialize(baos);
 			ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
 	

Modified: webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/xpath/DocumentNavigator.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/xpath/DocumentNavigator.java?rev=356546&r1=356545&r2=356546&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/xpath/DocumentNavigator.java (original)
+++ webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/xpath/DocumentNavigator.java Tue Dec 13 09:30:15 2005
@@ -1,14 +1,25 @@
 package org.apache.axis2.om.xpath;
 
+import java.io.FileInputStream;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamReader;
+
 import org.apache.axis2.om.OMAttribute;
 import org.apache.axis2.om.OMComment;
 import org.apache.axis2.om.OMContainer;
+import org.apache.axis2.om.OMDocument;
 import org.apache.axis2.om.OMElement;
 import org.apache.axis2.om.OMNamespace;
 import org.apache.axis2.om.OMNode;
 import org.apache.axis2.om.OMProcessingInstruction;
 import org.apache.axis2.om.OMText;
-import org.apache.axis2.om.impl.llom.OMDocumentImpl;
 import org.apache.axis2.om.impl.llom.OMNamespaceImpl;
 import org.apache.axis2.om.impl.llom.builder.StAXOMBuilder;
 import org.jaxen.BaseXPath;
@@ -20,16 +31,6 @@
 import org.jaxen.saxpath.SAXPathException;
 import org.jaxen.util.SingleObjectIterator;
 
-import javax.xml.namespace.QName;
-import javax.xml.stream.XMLInputFactory;
-import javax.xml.stream.XMLStreamReader;
-import java.io.FileInputStream;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-
 public class DocumentNavigator extends DefaultNavigator {
     /**
      * Returns a parsed form of the given xpath string, which will be suitable
@@ -131,7 +132,7 @@
      *         else <code>false</code>
      */
     public boolean isDocument(Object object) {
-        return object instanceof OMDocumentImpl;
+        return object instanceof OMDocument;
     }
 
     /**
@@ -347,7 +348,7 @@
         List nsList = new ArrayList();
         HashSet prefixes = new HashSet();
         for (OMContainer context = (OMContainer) contextNode;
-             context != null && !(context instanceof OMDocumentImpl);
+             context != null && !(context instanceof OMDocument);
              context = ((OMElement) context).getParent()) {
             OMElement element = (OMElement) context;
             ArrayList declaredNS = new ArrayList();
@@ -583,7 +584,7 @@
      * @see #isDocument(Object)
      */
     public Object getDocumentNode(Object contextNode) {
-        if (contextNode instanceof OMDocumentImpl) {
+        if (contextNode instanceof OMDocument) {
             return contextNode;
         }
         return getDocumentNode(((OMNode) contextNode).getParent());
@@ -658,7 +659,7 @@
      */
     public Object getParentNode(Object contextNode) throws UnsupportedAxisException {
         if (contextNode == null ||
-                contextNode instanceof OMDocumentImpl) {
+                contextNode instanceof OMDocument) {
             return null;
         } else if (contextNode instanceof OMAttributeEx) {
             return ((OMAttributeEx) contextNode).getParent();

Modified: webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/soap/impl/llom/builder/SOAP11BuilderHelper.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/soap/impl/llom/builder/SOAP11BuilderHelper.java?rev=356546&r1=356545&r2=356546&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/soap/impl/llom/builder/SOAP11BuilderHelper.java (original)
+++ webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/soap/impl/llom/builder/SOAP11BuilderHelper.java Tue Dec 13 09:30:15 2005
@@ -16,7 +16,6 @@
 
 package org.apache.axis2.soap.impl.llom.builder;
 
-import org.apache.axis2.om.OMAbstractFactory;
 import org.apache.axis2.om.OMElement;
 import org.apache.axis2.om.OMText;
 import org.apache.axis2.om.impl.OMNodeEx;
@@ -42,7 +41,7 @@
 
     public SOAP11BuilderHelper(StAXSOAPModelBuilder builder) {
         super(builder);
-        factory = OMAbstractFactory.getSOAP11Factory();
+        factory = builder.getSoapFactory();
     }
 
     public OMElement handleEvent(XMLStreamReader parser,
@@ -104,7 +103,7 @@
                 processAttributes(element);
             } else {
                 element =
-                        OMAbstractFactory.getOMFactory().createOMElement(
+                        factory.createOMElement(
                                 localName, null, parent, builder);
                 processNamespaceData(element, false);
                 processAttributes(element);
@@ -125,7 +124,7 @@
                         "faultactor element should not have children");
             } else {
                 element =
-                        OMAbstractFactory.getOMFactory().createOMElement(
+                        this.factory.createOMElement(
                                 localName, null, parent, builder);
                 processNamespaceData(element, false);
                 processAttributes(element);
@@ -133,7 +132,7 @@
 
         } else if (elementLevel > 5) {
             element =
-                    OMAbstractFactory.getOMFactory().createOMElement(localName,
+                    this.factory.createOMElement(localName,
                             null,
                             parent,
                             builder);

Modified: webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/soap/impl/llom/builder/SOAP12BuilderHelper.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/soap/impl/llom/builder/SOAP12BuilderHelper.java?rev=356546&r1=356545&r2=356546&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/soap/impl/llom/builder/SOAP12BuilderHelper.java (original)
+++ webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/soap/impl/llom/builder/SOAP12BuilderHelper.java Tue Dec 13 09:30:15 2005
@@ -16,7 +16,7 @@
 
 package org.apache.axis2.soap.impl.llom.builder;
 
-import org.apache.axis2.om.OMAbstractFactory;
+
 import org.apache.axis2.om.OMElement;
 import org.apache.axis2.om.impl.OMNodeEx;
 import org.apache.axis2.om.impl.llom.exception.OMBuilderException;
@@ -51,7 +51,7 @@
 
     public SOAP12BuilderHelper(StAXSOAPModelBuilder builder) {
         super(builder);
-        factory = OMAbstractFactory.getSOAP12Factory();
+        factory = builder.getSoapFactory();
     }
 
     public OMElement handleEvent(XMLStreamReader parser,
@@ -233,7 +233,7 @@
             } else if (parent.getLocalName().equals(
                     SOAP12Constants.SOAP_FAULT_DETAIL_LOCAL_NAME)) {
                 element =
-                        OMAbstractFactory.getOMFactory().createOMElement(
+                        this.factory.createOMElement(
                                 parser.getLocalName(), null, parent, builder);
                 builder.setProcessingDetailElements(true);
                 detailElementNames = new Vector();
@@ -299,7 +299,7 @@
                 if (localNameExist) {
                     detailElementNames.setSize(detailElementLevel);
                     element =
-                            OMAbstractFactory.getOMFactory().createOMElement(
+                            this.factory.createOMElement(
                                     parser.getLocalName(),
                                     null,
                                     parent,

Modified: webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/soap/impl/llom/builder/StAXSOAPModelBuilder.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/soap/impl/llom/builder/StAXSOAPModelBuilder.java?rev=356546&r1=356545&r2=356546&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/soap/impl/llom/builder/StAXSOAPModelBuilder.java (original)
+++ webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/soap/impl/llom/builder/StAXSOAPModelBuilder.java Tue Dec 13 09:30:15 2005
@@ -428,4 +428,11 @@
         return (OMDocument) this.soapMessage;
     }
 
+	/**
+	 * @return Returns the soapFactory.
+	 */
+	protected SOAPFactory getSoapFactory() {
+		return soapFactory;
+	}
+
 }