You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by ru...@apache.org on 2006/02/07 06:42:22 UTC

svn commit: r375495 - in /webservices/axis2/trunk/java/modules: doom/src/org/apache/axis2/om/impl/dom/jaxp/ doom/test/org/apache/axis2/om/impl/dom/ security/src/org/apache/axis2/security/

Author: ruchithf
Date: Mon Feb  6 21:42:20 2006
New Revision: 375495

URL: http://svn.apache.org/viewcvs?rev=375495&view=rev
Log:
Integrated the fix to DocumentBuilderFactory from Juanda Zeng and fixed the tests, thanks Juanda Zeng

Modified:
    webservices/axis2/trunk/java/modules/doom/src/org/apache/axis2/om/impl/dom/jaxp/DocumentBuilderFactoryImpl.java
    webservices/axis2/trunk/java/modules/doom/test/org/apache/axis2/om/impl/dom/DOMImplementationTest.java
    webservices/axis2/trunk/java/modules/doom/test/org/apache/axis2/om/impl/dom/ElementImplTest.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

Modified: webservices/axis2/trunk/java/modules/doom/src/org/apache/axis2/om/impl/dom/jaxp/DocumentBuilderFactoryImpl.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/doom/src/org/apache/axis2/om/impl/dom/jaxp/DocumentBuilderFactoryImpl.java?rev=375495&r1=375494&r2=375495&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/doom/src/org/apache/axis2/om/impl/dom/jaxp/DocumentBuilderFactoryImpl.java (original)
+++ webservices/axis2/trunk/java/modules/doom/src/org/apache/axis2/om/impl/dom/jaxp/DocumentBuilderFactoryImpl.java Mon Feb  6 21:42:20 2006
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 package org.apache.axis2.om.impl.dom.jaxp;
 
 import javax.xml.parsers.DocumentBuilder;
@@ -6,13 +21,55 @@
 
 public class DocumentBuilderFactoryImpl extends DocumentBuilderFactory {
 
+    /**
+     * Temporary solution until DOOM's DocumentBuilder module is done.
+     * Use ThreadLocal to determine whether or not DOOM implementation is required.
+     * By default (isDOOMRequired() == false), we will use the one from JDK (Crimson)
+     */
+    private static DocumentBuilderFactory originalDocumentBuilderFactory = null;
+    private static String originalDocumentBuilderFactoryClassName = null;
+    private static ThreadLocal documentBuilderFactoryTracker = new ThreadLocal();
+    
+    public static boolean isDOOMRequired() {
+        Object value = documentBuilderFactoryTracker.get();
+        return (value != null);
+    }
+    
+    public static void setDOOMRequired(boolean isDOOMRequired) {
+        String systemKey = DocumentBuilderFactory.class.getName();
+        if (isDOOMRequired) {
+            if (!isDOOMRequired()) {
+                originalDocumentBuilderFactory = DocumentBuilderFactory.newInstance();
+                originalDocumentBuilderFactoryClassName = originalDocumentBuilderFactory.getClass().getName();
+                documentBuilderFactoryTracker.set(Boolean.TRUE);
+                System.setProperty(systemKey, DocumentBuilderFactoryImpl.class.getName());
+            }
+        } else {
+            String currentFactoryClassName = DocumentBuilderFactory.newInstance().getClass().getName();
+            if (currentFactoryClassName != null && currentFactoryClassName.equals(DocumentBuilderFactoryImpl.class.getName())) {
+                System.getProperties().remove(systemKey);
+                if (originalDocumentBuilderFactoryClassName != null) {
+                    System.setProperty(DocumentBuilderFactory.class.getName(), originalDocumentBuilderFactoryClassName);
+                }
+            }
+            documentBuilderFactoryTracker.set(null);
+            originalDocumentBuilderFactory = null;
+        }
+    }
+    
+
     public DocumentBuilderFactoryImpl() {
         super();
     }
 
     public DocumentBuilder newDocumentBuilder()
             throws ParserConfigurationException {
-        return new DocumentBuilderImpl();
+        /**
+         * Determine which DocumentBuilder implementation should be returned
+         */
+        return isDOOMRequired()
+                ? new DocumentBuilderImpl()
+                : originalDocumentBuilderFactory.newDocumentBuilder();
     }
 
     public Object getAttribute(String arg0) throws IllegalArgumentException {

Modified: webservices/axis2/trunk/java/modules/doom/test/org/apache/axis2/om/impl/dom/DOMImplementationTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/doom/test/org/apache/axis2/om/impl/dom/DOMImplementationTest.java?rev=375495&r1=375494&r2=375495&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/doom/test/org/apache/axis2/om/impl/dom/DOMImplementationTest.java (original)
+++ webservices/axis2/trunk/java/modules/doom/test/org/apache/axis2/om/impl/dom/DOMImplementationTest.java Mon Feb  6 21:42:20 2006
@@ -32,8 +32,10 @@
 	
 	public void testDOMImpl() {
 		try {
-			System.setProperty("javax.xml.parsers.DocumentBuilderFactory",DocumentBuilderFactoryImpl.class.getName());
-			
+//			System.setProperty("javax.xml.parsers.DocumentBuilderFactory",DocumentBuilderFactoryImpl.class.getName());
+		    
+            DocumentBuilderFactoryImpl.setDOOMRequired(true);
+            
 			DocumentBuilderFactory fac = DocumentBuilderFactory.newInstance();
 			DocumentBuilder builder = fac.newDocumentBuilder();
 			Document doc = builder.newDocument();
@@ -41,10 +43,12 @@
 			assertEquals("Incorrect DocumentBuilderFactory instance", DocumentBuilderFactoryImpl.class.getName(),fac.getClass().getName());
 			assertEquals("Incorrect DocumentBuilder instance", DocumentBuilderImpl.class.getName(),builder.getClass().getName());
 			assertEquals("Incorrect Document instance", DocumentImpl.class.getName(),doc.getClass().getName());
-			
+            
 		} catch (Exception e) {
 			e.printStackTrace();
 			fail(e.getMessage());
-		}
+		} finally {
+            DocumentBuilderFactoryImpl.setDOOMRequired(false);
+        }
 	}
 }

Modified: webservices/axis2/trunk/java/modules/doom/test/org/apache/axis2/om/impl/dom/ElementImplTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/doom/test/org/apache/axis2/om/impl/dom/ElementImplTest.java?rev=375495&r1=375494&r2=375495&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/doom/test/org/apache/axis2/om/impl/dom/ElementImplTest.java (original)
+++ webservices/axis2/trunk/java/modules/doom/test/org/apache/axis2/om/impl/dom/ElementImplTest.java Mon Feb  6 21:42:20 2006
@@ -108,6 +108,7 @@
 			String childTextValue = "text value of the child text node";
 			
 			//Apending am Element node
+            DocumentBuilderFactoryImpl.setDOOMRequired(true);
 			Document doc = DocumentBuilderFactoryImpl.newInstance().newDocumentBuilder().newDocument();
 			Element elem = doc.createElement(elementName);
 			Element childElem = doc.createElement(childElemName);
@@ -129,7 +130,9 @@
 		} catch (Exception e) {
 			e.printStackTrace();
 			fail(e.getMessage());
-		}
+		} finally {
+            DocumentBuilderFactoryImpl.setDOOMRequired(false);      
+        }
 	}
 	
 	/**
@@ -139,6 +142,8 @@
 		try {
 			String childElementLN = "Child";
 			
+            DocumentBuilderFactoryImpl.setDOOMRequired(true);
+            
 			Document doc = DocumentBuilderFactoryImpl.newInstance().newDocumentBuilder().newDocument();
 			Element docElem = doc.getDocumentElement();
 			assertNull("The document element shoudl be null", docElem);
@@ -159,7 +164,9 @@
 		} catch (Exception e) {
 			e.printStackTrace();
 			fail(e.getMessage());
-		}
+		} finally {
+            DocumentBuilderFactoryImpl.setDOOMRequired(false);      
+        }
 	}
 	
 	public void testGetElementsbyTagNameNS() {
@@ -167,6 +174,7 @@
 			String childElementLN = "test:Child";
 			String childElementNS = "http://ws.apache.org/ns/axis2/dom";
 			
+            DocumentBuilderFactoryImpl.setDOOMRequired(true);
 			Document doc = DocumentBuilderFactoryImpl.newInstance().newDocumentBuilder().newDocument();
 			Element docElem = doc.getDocumentElement();
 			assertNull("The document element shoudl be null", docElem);
@@ -188,6 +196,8 @@
 		} catch (Exception e) {
 			e.printStackTrace();
 			fail(e.getMessage());
-		}
+		} finally {
+            DocumentBuilderFactoryImpl.setDOOMRequired(false);      
+        }
 	}	
 }

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=375495&r1=375494&r2=375495&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 Mon Feb  6 21:42:20 2006
@@ -16,20 +16,26 @@
 
 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 org.apache.axis2.AxisFault;
 import org.apache.axis2.context.MessageContext;
 import org.apache.axis2.context.OperationContext;
-import org.apache.ws.commons.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.ws.commons.soap.SOAPHeader;
-import org.apache.ws.commons.soap.SOAPHeaderBlock;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.ws.commons.om.OMException;
+import org.apache.ws.commons.soap.SOAPHeader;
+import org.apache.ws.commons.soap.SOAPHeaderBlock;
 import org.apache.ws.security.SOAPConstants;
 import org.apache.ws.security.WSConstants;
 import org.apache.ws.security.WSSecurityEngineResult;
@@ -42,70 +48,67 @@
 import org.apache.wsdl.WSDLConstants;
 import org.w3c.dom.Document;
 
-import javax.security.auth.callback.CallbackHandler;
-import javax.xml.parsers.DocumentBuilderFactory;
-import java.security.cert.X509Certificate;
-import java.util.Iterator;
-import java.util.Vector;
-
 public class WSDoAllReceiver extends WSDoAllHandler {
-
-	private static final long serialVersionUID = 7685802089392898320L;
-	
-	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() {
-    	super();
-    	inHandler = true;
+        super();
+        inHandler = true;
     }
     
-	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());
-
+    public void invoke(MessageContext msgContext) throws AxisFault {
+        
+        boolean doDebug = log.isDebugEnabled();
+        
+        /**
+         * Temporary solution until DOOM's DocumentBuilder module is done.
+         * Use ThreadLocal to determine whether or not DOOM implementation is required.
+         */
+        // Set the DOM impl to DOOM
+        DocumentBuilderFactoryImpl.setDOOMRequired(true);
+        
         try {
-        	//populate the properties
-        	try {
-        		HandlerParameterDecoder.processParameters(msgContext,true);
-        	} catch (Exception e) {
-        		throw new AxisFault("Configureation error", e);
-        	}
-        	/**
-        	 * Cannot do the following right now since we cannot access the req 
-        	 * mc when this handler runs in the client side.
-        	 */
-        	
-        	//Copy the WSHandlerConstants.SEND_SIGV over to the new message 
-        	//context - if it exists
-        	if(!msgContext.isServerSide()) {//To make sure this is a response message 
-        		OperationContext opCtx = msgContext.getOperationContext();
-        		MessageContext outMsgCtx = opCtx.getMessageContext(WSDLConstants.MESSAGE_LABEL_OUT_VALUE);
-        		msgContext.setProperty(WSHandlerConstants.SEND_SIGV,outMsgCtx.getProperty(WSHandlerConstants.SEND_SIGV));
-        	}
-        	
+            //populate the properties
+            try {
+                HandlerParameterDecoder.processParameters(msgContext,true);
+            } catch (Exception e) {
+                throw new AxisFault("Configuration error", e);
+            }
+            /**
+             * Cannot do the following right now since we cannot access the req 
+             * mc when this handler runs in the client side.
+             */
+            
+            //Copy the WSHandlerConstants.SEND_SIGV over to the new message 
+            //context - if it exists
+            if(!msgContext.isServerSide()) {//To make sure this is a response message 
+                OperationContext opCtx = msgContext.getOperationContext();
+                MessageContext outMsgCtx = opCtx.getMessageContext(WSDLConstants.MESSAGE_LABEL_OUT_VALUE);
+                msgContext.setProperty(WSHandlerConstants.SEND_SIGV,outMsgCtx.getProperty(WSHandlerConstants.SEND_SIGV));
+            }
+            
             if (doDebug) {
                 log.debug("WSDoAllReceiver: enter invoke() ");
             }
             reqData = new RequestData();
-        
-        	reqData.setMsgContext(msgContext);
-        	
-        	//Figureout if the handler should run
-        	Object inFlowSecurity = null;
-        	if((inFlowSecurity = getOption(WSSHandlerConstants.INFLOW_SECURITY)) == null) {
-        		inFlowSecurity = getProperty(msgContext, WSSHandlerConstants.INFLOW_SECURITY);
-        	}
-
-        	
-        	if(inFlowSecurity == null) {
-        		return;
-        	}
-        	
+            
+            reqData.setMsgContext(msgContext);
+            
+            //Figureout if the handler should run
+            Object inFlowSecurity = null;
+            if((inFlowSecurity = getOption(WSSHandlerConstants.INFLOW_SECURITY)) == null) {
+                inFlowSecurity = getProperty(msgContext, WSSHandlerConstants.INFLOW_SECURITY);
+            }
+            
+            
+            if(inFlowSecurity == null) {
+                return;
+            }
+            
             Vector actions = new Vector();
             String action = null;
             if ((action = (String) getOption(WSSHandlerConstants.ACTION_ITEMS)) == null) {
@@ -115,47 +118,47 @@
                 throw new AxisFault("WSDoAllReceiver: No action items defined");
             }
             int doAction = WSSecurityUtil.decodeAction(action, actions);
-
+            
             if(doAction == WSConstants.NO_SECURITY) {
-            	return;
+                return;
             }
             
             String actor = (String) getOption(WSHandlerConstants.ACTOR);
-
+            
             Document doc = 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);
+                throw new AxisFault("WSDoAllReceiver: Error in converting to Document", wssEx);
             }
-        	
+            
             //Do not process faults
             SOAPConstants soapConstants = WSSecurityUtil.getSOAPConstants(doc.getDocumentElement());
             if (WSSecurityUtil.findElement(doc.getDocumentElement(), "Fault",
-					soapConstants.getEnvelopeURI()) != null) {
-				return;
-			}
-
+                    soapConstants.getEnvelopeURI()) != null) {
+                return;
+            }
+            
             
             /*
-            * To check a UsernameToken or to decrypt an encrypted message we
-            * need a password.
-            */
+             * To check a UsernameToken or to decrypt an encrypted message we
+             * need a password.
+             */
             CallbackHandler cbHandler = null;
             if ((doAction & (WSConstants.ENCR | WSConstants.UT)) != 0) {
                 cbHandler = getPasswordCB(reqData);
             }
             
-
+            
             
             /*
-            * Get and check the Signature specific parameters first because
-            * they may be used for encryption too.
-            */
-
+             * Get and check the Signature specific parameters first because
+             * they may be used for encryption too.
+             */
+            
             doReceiverAction(doAction, reqData);
-
+            
             Vector wsResult = null;
             try {
                 wsResult = secEngine.processSecurityHeader(doc, actor,
@@ -170,10 +173,10 @@
                     return;
                 } else {
                     throw new AxisFault(
-                            "WSDoAllReceiver: Request does not contain required Security header");
+                    "WSDoAllReceiver: Request does not contain required Security header");
                 }
             }
-
+            
             if (reqData.getWssConfig().isEnableSignatureConfirmation() && !msgContext.isServerSide()) {
                 checkSignatureConfirmation(reqData, wsResult);
             }
@@ -181,15 +184,15 @@
             /**
              * 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());
+//          
+//          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));
-			
+            
             /*
              * After setting the new current message, probably modified because
              * of decryption, we need to locate the security header. That is, we
@@ -203,50 +206,50 @@
              */
             SOAPHeader header = null;
             try {
-				header = msgContext.getEnvelope().getHeader();
-			} catch (OMException ex) {
+                header = msgContext.getEnvelope().getHeader();
+            } catch (OMException ex) {
                 throw new AxisFault(
                         "WSDoAllReceiver: cannot get SOAP header after security processing",
                         ex);
-			}
-			
-			Iterator headers = header.examineHeaderBlocks(actor);
-			
-			SOAPHeaderBlock headerBlock = null;
-			
-			while(headers.hasNext()) { //Find the wsse header
-				SOAPHeaderBlock hb = (SOAPHeaderBlock)headers.next();
+            }
+            
+            Iterator headers = header.examineHeaderBlocks(actor);
+            
+            SOAPHeaderBlock headerBlock = null;
+            
+            while(headers.hasNext()) { //Find the wsse header
+                SOAPHeaderBlock hb = (SOAPHeaderBlock)headers.next();
                 if (hb.getLocalName().equals(WSConstants.WSSE_LN)
                         && hb.getNamespace().getName().equals(WSConstants.WSSE_NS)) {
                     headerBlock = hb;
                     break;
                 }
-			}
+            }
+            
+            headerBlock.setProcessed();
+            
             
-			headerBlock.setProcessed();
-			
-
             /*
-            * Now we can check the certificate used to sign the message. In the
-            * following implementation the certificate is only trusted if
-            * either it itself or the certificate of the issuer is installed in
-            * the keystore.
-            *
-            * Note: the method verifyTrust(X509Certificate) allows custom
-            * implementations with other validation algorithms for subclasses.
-            */
-
+             * Now we can check the certificate used to sign the message. In the
+             * following implementation the certificate is only trusted if
+             * either it itself or the certificate of the issuer is installed in
+             * the keystore.
+             *
+             * Note: the method verifyTrust(X509Certificate) allows custom
+             * implementations with other validation algorithms for subclasses.
+             */
+            
             // Extract the signature action result from the action vector
             WSSecurityEngineResult actionResult = WSSecurityUtil
-                    .fetchActionResult(wsResult, WSConstants.SIGN);
-
+            .fetchActionResult(wsResult, WSConstants.SIGN);
+            
             if (actionResult != null) {
                 X509Certificate returnCert = actionResult.getCertificate();
-
+                
                 if (returnCert != null) {
                     if (!verifyTrust(returnCert, reqData)) {
                         throw new AxisFault(
-                                "WSDoAllReceiver: The certificate used for the signature is not trusted");
+                        "WSDoAllReceiver: The certificate used for the signature is not trusted");
                     }
                 }
             }
@@ -260,83 +263,81 @@
              * Note: the method verifyTimestamp(Timestamp) allows custom
              * implementations with other validation algorithms for subclasses.
              */
-
-             // Extract the timestamp action result from the action vector
-             actionResult = WSSecurityUtil.fetchActionResult(wsResult,
-                     WSConstants.TS);
-
-             if (actionResult != null) {
-                 Timestamp timestamp = actionResult.getTimestamp();
-
-                 if (timestamp != null) {
-                     String ttl = null;
-                     if ((ttl = (String) getOption(WSHandlerConstants.TTL_TIMESTAMP)) == null) {
-                         ttl = (String) getProperty(msgContext,WSHandlerConstants.TTL_TIMESTAMP);
-                     }
-                     int ttl_i = 0;
-                     if (ttl != null) {
-                         try {
-                             ttl_i = Integer.parseInt(ttl);
-                         } catch (NumberFormatException e) {
-                             ttl_i = reqData.getTimeToLive();
-                         }
-                     }
-                     if (ttl_i <= 0) {
-                         ttl_i = reqData.getTimeToLive();
-                     }
-
-                     if (!verifyTimestamp(timestamp, reqData.getTimeToLive())) {
-                         throw new AxisFault(
-                                 "WSDoAllReceiver: The timestamp could not be validated");
-                     }
-                 }
-             }
-       
-             /*
+            
+            // Extract the timestamp action result from the action vector
+            actionResult = WSSecurityUtil.fetchActionResult(wsResult,
+                    WSConstants.TS);
+            
+            if (actionResult != null) {
+                Timestamp timestamp = actionResult.getTimestamp();
+                
+                if (timestamp != null) {
+                    String ttl = null;
+                    if ((ttl = (String) getOption(WSHandlerConstants.TTL_TIMESTAMP)) == null) {
+                        ttl = (String) getProperty(msgContext,WSHandlerConstants.TTL_TIMESTAMP);
+                    }
+                    int ttl_i = 0;
+                    if (ttl != null) {
+                        try {
+                            ttl_i = Integer.parseInt(ttl);
+                        } catch (NumberFormatException e) {
+                            ttl_i = reqData.getTimeToLive();
+                        }
+                    }
+                    if (ttl_i <= 0) {
+                        ttl_i = reqData.getTimeToLive();
+                    }
+                    
+                    if (!verifyTimestamp(timestamp, reqData.getTimeToLive())) {
+                        throw new AxisFault(
+                        "WSDoAllReceiver: The timestamp could not be validated");
+                    }
+                }
+            }
+            
+            /*
              * now check the security actions: do they match, in right order?
              */
-             if (!checkReceiverResults(wsResult, actions)) {
-                        throw new AxisFault(
-                                "WSDoAllReceiver: security processing failed (actions mismatch)");
-
+            if (!checkReceiverResults(wsResult, actions)) {
+                throw new AxisFault(
+                "WSDoAllReceiver: security processing failed (actions mismatch)");
+                
             }
             /*
-            * All ok up to this point. Now construct and setup the security
-            * result structure. The service may fetch this and check it.
-            * Also the DoAllSender will use this in certain situations such as:
-            * USE_REQ_SIG_CERT to encrypt
-            */
-             Vector results = null;
-             if ((results = (Vector) getProperty(msgContext, WSHandlerConstants.RECV_RESULTS)) == null) {
-                 results = new Vector();
-                 msgContext
-                         .setProperty(WSHandlerConstants.RECV_RESULTS, results);
-             }
-             WSHandlerResult rResult = new WSHandlerResult(actor, wsResult);
-             results.add(0, rResult);
-             if (doDebug) {
-                 log.debug("WSDoAllReceiver: exit invoke()");
-             }
-
+             * All ok up to this point. Now construct and setup the security
+             * result structure. The service may fetch this and check it.
+             * Also the DoAllSender will use this in certain situations such as:
+             * USE_REQ_SIG_CERT to encrypt
+             */
+            Vector results = null;
+            if ((results = (Vector) getProperty(msgContext, WSHandlerConstants.RECV_RESULTS)) == null) {
+                results = new Vector();
+                msgContext
+                .setProperty(WSHandlerConstants.RECV_RESULTS, results);
+            }
+            WSHandlerResult rResult = new WSHandlerResult(actor, wsResult);
+            results.add(0, rResult);
+            if (doDebug) {
+                log.debug("WSDoAllReceiver: exit invoke()");
+            }
+            
         } catch (WSSecurityException wssEx) {
-        	throw new AxisFault(wssEx);
+            throw new AxisFault(wssEx);
+        } catch (AxisFault axisFault) {
+            throw axisFault;
         } finally {
             reqData.clear();
             reqData = null;
-
+            
+            /**
+             * Temporary solution until DOOM's DocumentBuilder module is done.
+             * Use ThreadLocal to determine whether or not DOOM implementation is required.
+             */
             //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);
-					System.setProperty(DocumentBuilderFactory.class.getName(), originalDOcumentBuilderFactory);
-                } else {
-					System.getProperties().remove(docBuilderFactory);
-				}
-            }
+            DocumentBuilderFactoryImpl.setDOOMRequired(false);
         }
         
     }
-
-
+    
+    
 }

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=375495&r1=375494&r2=375495&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 Mon Feb  6 21:42:20 2006
@@ -16,6 +16,8 @@
 
 package org.apache.axis2.security;
 
+import java.util.Vector;
+
 import org.apache.axis2.AxisFault;
 import org.apache.axis2.context.MessageContext;
 import org.apache.axis2.context.OperationContext;
@@ -26,9 +28,9 @@
 import org.apache.axis2.security.util.Axis2Util;
 import org.apache.axis2.security.util.HandlerParameterDecoder;
 import org.apache.axis2.security.util.MessageOptimizer;
-import org.apache.ws.commons.soap.SOAPEnvelope;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.ws.commons.soap.SOAPEnvelope;
 import org.apache.ws.security.WSConstants;
 import org.apache.ws.security.WSSecurityException;
 import org.apache.ws.security.handler.RequestData;
@@ -37,44 +39,46 @@
 import org.apache.wsdl.WSDLConstants;
 import org.w3c.dom.Document;
 
-import javax.xml.parsers.DocumentBuilderFactory;
-import java.util.Vector;
-
 public class WSDoAllSender extends WSDoAllHandler {
-
-	private static final long serialVersionUID = 3016802164501419165L;
-
-	protected static Log log = LogFactory.getLog(WSDoAllSender.class.getName());
-	
-	/**
-	 * 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;
-	
+    
+    private static final long serialVersionUID = 3016802164501419165L;
+    
+    protected static Log log = LogFactory.getLog(WSDoAllSender.class.getName());
+    
+    /**
+     * 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;
+    
     public WSDoAllSender() {
-    	super();
-    	inHandler = false;
+        super();
+        inHandler = false;
     }
-	
-	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());
-
+    
+    public void invoke(MessageContext msgContext) throws AxisFault {
+        
+        /**
+         * Temporary solution until DOOM's DocumentBuilder module is done.
+         * Use ThreadLocal to determine whether or not DOOM implementation is required.
+         */
+        // Set the DOM impl to DOOM
+        DocumentBuilderFactoryImpl.setDOOMRequired(true);
+        
+        
         try {
             boolean doDebug = log.isDebugEnabled();
             
             try {
-            	HandlerParameterDecoder.processParameters(msgContext,false);
+                HandlerParameterDecoder.processParameters(msgContext,false);
             } catch (Exception e) {
-        		throw new AxisFault("Configureation error", e);
-        	}
+                throw new AxisFault("Configureation error", e);
+            }
             
             if (doDebug) {
                 log.debug("WSDoAllSender: enter invoke()");
             }
-        	
+            
             /*
              * Copy the RECV_RESULTS over to the current message context
              * - IF available 
@@ -82,9 +86,9 @@
             OperationContext opCtx = msgContext.getOperationContext();
             MessageContext inMsgCtx;
             if(opCtx != null && 
-            		(inMsgCtx = opCtx.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE)) != null) {
-            	msgContext.setProperty(WSHandlerConstants.RECV_RESULTS, 
-            			inMsgCtx.getProperty(WSHandlerConstants.RECV_RESULTS));
+                    (inMsgCtx = opCtx.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE)) != null) {
+                msgContext.setProperty(WSHandlerConstants.RECV_RESULTS, 
+                        inMsgCtx.getProperty(WSHandlerConstants.RECV_RESULTS));
             }
             
             reqData = new RequestData();
@@ -92,18 +96,19 @@
             reqData.setNoSerialization(false);
             reqData.setMsgContext(msgContext);
             
-        	//Figureout if the handler should run
-        	Object outFlowSecurity;
-        	if((outFlowSecurity = getOption(WSSHandlerConstants.OUTFLOW_SECURITY)) == null) {
-        		outFlowSecurity = getProperty(msgContext, WSSHandlerConstants.OUTFLOW_SECURITY);
-        	}
-    
-        	if(outFlowSecurity == null) {
-        		return;
-        	}
-    	
-	        Vector actions = new Vector();
-	        String action = null;
+            //Figureout if the handler should run
+            Object outFlowSecurity;
+            if((outFlowSecurity = getOption(WSSHandlerConstants.OUTFLOW_SECURITY)) == null) {
+                outFlowSecurity = getProperty(msgContext, WSSHandlerConstants.OUTFLOW_SECURITY);
+            }
+            
+            if(outFlowSecurity == null) {
+                return;
+            }
+            
+
+            Vector actions = new Vector();
+            String action = null;
             if ((action = (String) getOption(WSSHandlerConstants.ACTION_ITEMS)) == null) {
                 action = (String) getProperty(msgContext, WSSHandlerConstants.ACTION_ITEMS);
             }
@@ -111,169 +116,165 @@
                 throw new AxisFault("WSDoAllReceiver: No action items defined");
             }
             
-	        int doAction = WSSecurityUtil.decodeAction(action, actions);
-	        if (doAction == WSConstants.NO_SECURITY) {
-	            return;
-	        }
-	        
+            int doAction = WSSecurityUtil.decodeAction(action, actions);
+            if (doAction == WSConstants.NO_SECURITY) {
+                return;
+            }
+            
             /*
              * For every action we need a username, so get this now. The
              * username defined in the deployment descriptor takes precedence.
              */
-	        reqData.setUsername((String) getOption(WSHandlerConstants.USER));
-	        if (reqData.getUsername() == null || reqData.getUsername().equals("")) {
-	        	String username = (String) getProperty(reqData.getMsgContext(), WSHandlerConstants.USER);
-	        	if (username != null) {
-	        		reqData.setUsername(username);
-	        	}
-	        }
-         
-	        /*
-			 * Now we perform some set-up for UsernameToken and Signature
-			 * functions. No need to do it for encryption only. Check if
-			 * username is available and then get a passowrd.
-			 */
-			if ((doAction & (WSConstants.SIGN | WSConstants.UT | WSConstants.UT_SIGN)) != 0) {
-				/*
-				 * We need a username - if none throw an AxisFault. For
-				 * encryption there is a specific parameter to get a username.
-				 */
-				if (reqData.getUsername() == null
-						|| reqData.getUsername().equals("")) {
-					throw new AxisFault(
-							"WSDoAllSender: Empty username for specified action");
-				}
-			}
-         
-         /*
-			 * Now get the SOAPEvelope from the message context and convert it
-			 * into a Document
-			 * 
-			 * Now we can perform our security operations on this request.
-			 */
-	     	
-         
-         Document doc = null;
+            reqData.setUsername((String) getOption(WSHandlerConstants.USER));
+            if (reqData.getUsername() == null || reqData.getUsername().equals("")) {
+                String username = (String) getProperty(reqData.getMsgContext(), WSHandlerConstants.USER);
+                if (username != null) {
+                    reqData.setUsername(username);
+                }
+            }
+            
+            /*
+             * Now we perform some set-up for UsernameToken and Signature
+             * functions. No need to do it for encryption only. Check if
+             * username is available and then get a passowrd.
+             */
+            if ((doAction & (WSConstants.SIGN | WSConstants.UT | WSConstants.UT_SIGN)) != 0) {
+                /*
+                 * We need a username - if none throw an AxisFault. For
+                 * encryption there is a specific parameter to get a username.
+                 */
+                if (reqData.getUsername() == null
+                        || reqData.getUsername().equals("")) {
+                    throw new AxisFault(
+                    "WSDoAllSender: Empty username for specified action");
+                }
+            }
+            
+            /*
+             * Now get the SOAPEvelope from the message context and convert it
+             * into a Document
+             * 
+             * Now we can perform our security operations on this request.
+             */
+            
+            
+            Document doc = null;
             /*
              * If the message context property conatins a document then this is
              * a chained handler.
              */
             if ((doc = (Document) ((MessageContext)reqData.getMsgContext())
                     .getProperty(WSHandlerConstants.SND_SECURITY)) == null) {
-            	try {
-            		doc = Axis2Util.getDocumentFromSOAPEnvelope(msgContext.getEnvelope());
-            	} catch (WSSecurityException wssEx) {
-            		throw new AxisFault("WSDoAllReceiver: Error in converting to Document", wssEx);
-            	}
+                try {
+                    doc = Axis2Util.getDocumentFromSOAPEnvelope(msgContext.getEnvelope());
+                } catch (WSSecurityException wssEx) {
+                    throw new AxisFault("WSDoAllReceiver: Error in converting to Document", wssEx);
+                }
             }
-	     
-
-        	doSenderAction(doAction, doc, reqData, actions, !msgContext.isServerSide());
-
+            
+            
+            doSenderAction(doAction, doc, reqData, actions, !msgContext.isServerSide());
+            
             /*
-                * If required convert the resulting document into a message first.
-                * The outputDOM() method performs the necessary c14n call. After
-                * that we extract it as a string for further processing.
-                *
-                * Set the resulting byte array as the new SOAP message.
-                *
-                * If noSerialization is false, this handler shall be the last (or
-                * only) one in a handler chain. If noSerialization is true, just
-                * set the processed Document in the transfer property. The next
-                * Axis WSS4J handler takes it and performs additional security
-                * processing steps.
-                *
-                */
+             * If required convert the resulting document into a message first.
+             * The outputDOM() method performs the necessary c14n call. After
+             * that we extract it as a string for further processing.
+             *
+             * Set the resulting byte array as the new SOAP message.
+             *
+             * If noSerialization is false, this handler shall be the last (or
+             * only) one in a handler chain. If noSerialization is true, just
+             * set the processed Document in the transfer property. The next
+             * Axis WSS4J handler takes it and performs additional security
+             * processing steps.
+             *
+             */
             if (reqData.isNoSerialization()) {
                 ((MessageContext)reqData.getMsgContext()).setProperty(WSHandlerConstants.SND_SECURITY,
                         doc);
             } else {
-
-    	        String preserve = null;
+                
+                String preserve = null;
                 if ((preserve = (String) getOption(WSSHandlerConstants.PRESERVE_ORIGINAL_ENV)) == null) {
                     preserve = (String) getProperty(msgContext, WSSHandlerConstants.PRESERVE_ORIGINAL_ENV);
                 }
                 if(preserve != null) {
-                	this.preserveOriginalEnvelope = "true".equalsIgnoreCase(preserve);
+                    this.preserveOriginalEnvelope = "true".equalsIgnoreCase(preserve);
                 }
                 
-            	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((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
              */
-			String optimizeParts;
-			
-			if((optimizeParts = (String) getOption(WSSHandlerConstants.OPTIMIZE_PARTS)) == null) {
-				optimizeParts = (String)
-                	getProperty(reqData.getMsgContext(), WSSHandlerConstants.OPTIMIZE_PARTS);
-			}
+            String optimizeParts;
+            
+            if((optimizeParts = (String) getOption(WSSHandlerConstants.OPTIMIZE_PARTS)) == null) {
+                optimizeParts = (String)
+                getProperty(reqData.getMsgContext(), WSSHandlerConstants.OPTIMIZE_PARTS);
+            }
             if(optimizeParts != null) {
-	            // Optimize the Envelope
-	            MessageOptimizer.optimize(msgContext.getEnvelope(),optimizeParts);
+                // Optimize the Envelope
+                MessageOptimizer.optimize(msgContext.getEnvelope(),optimizeParts);
             }
             
             //Enable handler repetition
             Integer repeat;
             int repeatCount;
-	        if ((repeat = (Integer)getOption(WSSHandlerConstants.SENDER_REPEAT_COUNT)) == null) {
-	            repeat = (Integer)
-	                    getProperty(reqData.getMsgContext(), WSSHandlerConstants.SENDER_REPEAT_COUNT);
-	        }
-	        
-        	repeatCount = repeat.intValue();
-            
-	        //Get the current repetition from message context
-	        int repetition = this.getCurrentRepetition(msgContext);
-	        
-	        if(repeatCount > 0 && repetition < repeatCount) {
-		        
-		        reqData.clear();
-				reqData = null;
-
-				// Increment the repetition to indicate the next repetition
-				// of the same handler
-				repetition++;
-				msgContext.setProperty(WSSHandlerConstants.CURRENT_REPETITON,
-						new Integer(repetition));
-				/**
-				 * Preserving the OM stuff doesn't work for the repeting case
-				 */
-				this.preserveOriginalEnvelope = false;
-
-				this.invoke(msgContext);
-	        }
-	        
-	        if (doDebug) {
-				log.debug("WSDoAllSender: exit invoke()");
-			}
+            if ((repeat = (Integer)getOption(WSSHandlerConstants.SENDER_REPEAT_COUNT)) == null) {
+                repeat = (Integer)
+                getProperty(reqData.getMsgContext(), WSSHandlerConstants.SENDER_REPEAT_COUNT);
+            }
+            
+            repeatCount = repeat.intValue();
+            
+            //Get the current repetition from message context
+            int repetition = this.getCurrentRepetition(msgContext);
+            
+            if(repeatCount > 0 && repetition < repeatCount) {
+                
+                reqData.clear();
+                reqData = null;
+                
+                // Increment the repetition to indicate the next repetition
+                // of the same handler
+                repetition++;
+                msgContext.setProperty(WSSHandlerConstants.CURRENT_REPETITON,
+                        new Integer(repetition));
+                /**
+                 * Preserving the OM stuff doesn't work for the repeting case
+                 */
+                this.preserveOriginalEnvelope = false;
+                
+                this.invoke(msgContext);
+            }
+            
+            if (doDebug) {
+                log.debug("WSDoAllSender: exit invoke()");
+            }
         } catch (WSSecurityException e) {
             throw new AxisFault(e.getMessage(), e);
         } finally {
             if(reqData != null) {
-            	reqData.clear();
-            	reqData = null;
+                reqData.clear();
+                reqData = null;
             }
             
+            /**
+             * Temporary solution until DOOM's DocumentBuilder module is done.
+             * Use ThreadLocal to determine whether or not DOOM implementation is required.
+             */
             //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);
-					System.setProperty(DocumentBuilderFactory.class.getName(), originalDOcumentBuilderFactory);
-                } else {
-					System.getProperties().remove(docBuilderFactory);
-				}
-            }
+            DocumentBuilderFactoryImpl.setDOOMRequired(false);
         }     
     }
 }