You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-commits@axis.apache.org by sc...@apache.org on 2010/11/18 18:44:54 UTC

svn commit: r1036556 - in /axis/axis2/java/core/trunk/modules: addressing/src/org/apache/axis2/handlers/addressing/ jaxws/src/org/apache/axis2/jaxws/dispatchers/ kernel/src/org/apache/axis2/engine/ kernel/src/org/apache/axis2/handlers/

Author: scheu
Date: Thu Nov 18 17:44:54 2010
New Revision: 1036556

URL: http://svn.apache.org/viewvc?rev=1036556&view=rev
Log:
AXIS2-4881
Contributor:Rich Scheuerle
Introduce (optional) two-phase handler model

Modified:
    axis/axis2/java/core/trunk/modules/addressing/src/org/apache/axis2/handlers/addressing/AddressingInHandler.java
    axis/axis2/java/core/trunk/modules/addressing/src/org/apache/axis2/handlers/addressing/AddressingOutHandler.java
    axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/dispatchers/MustUnderstandChecker.java
    axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/engine/Phase.java
    axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/handlers/AbstractHandler.java

Modified: axis/axis2/java/core/trunk/modules/addressing/src/org/apache/axis2/handlers/addressing/AddressingInHandler.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/addressing/src/org/apache/axis2/handlers/addressing/AddressingInHandler.java?rev=1036556&r1=1036555&r2=1036556&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/addressing/src/org/apache/axis2/handlers/addressing/AddressingInHandler.java (original)
+++ axis/axis2/java/core/trunk/modules/addressing/src/org/apache/axis2/handlers/addressing/AddressingInHandler.java Thu Nov 18 17:44:54 2010
@@ -22,6 +22,7 @@ package org.apache.axis2.handlers.addres
 import org.apache.axiom.om.OMAttribute;
 import org.apache.axiom.om.OMElement;
 import org.apache.axiom.soap.RolePlayer;
+import org.apache.axiom.soap.SOAPEnvelope;
 import org.apache.axiom.soap.SOAPHeader;
 import org.apache.axiom.soap.SOAPHeaderBlock;
 import org.apache.axis2.AxisFault;
@@ -36,6 +37,7 @@ import org.apache.axis2.context.MessageC
 import org.apache.axis2.description.HandlerDescription;
 import org.apache.axis2.description.Parameter;
 import org.apache.axis2.engine.AxisConfiguration;
+import org.apache.axis2.engine.Handler.InvocationResponse;
 import org.apache.axis2.handlers.AbstractHandler;
 import org.apache.axis2.util.JavaUtils;
 import org.apache.axis2.util.LoggingControl;
@@ -71,16 +73,18 @@ public class AddressingInHandler extends
     }
     
     public InvocationResponse invoke(MessageContext msgContext) throws AxisFault {
+        
+        if (invoke_stage1(msgContext)) {
+            return invoke_stage2(msgContext);
+        } else {
+            return InvocationResponse.CONTINUE;
+        }
+    }
+    public boolean invoke_stage1(MessageContext msgContext) throws AxisFault {
         //Set the defaults on the message context.
         msgContext.setProperty(DISABLE_ADDRESSING_FOR_OUT_MESSAGES, Boolean.TRUE);
         msgContext.setProperty(IS_ADDR_INFO_ALREADY_PROCESSED, Boolean.FALSE);
 
-
-        // if there are not headers put a flag to disable addressing temporary
-        SOAPHeader header = msgContext.getEnvelope().getHeader();
-        if (header == null) {
-            return InvocationResponse.CONTINUE;
-        }
         //Determine if we want to ignore addressing headers. This parameter must
         //be retrieved from the message context because it's value can vary on a
         //per service basis.
@@ -91,10 +95,19 @@ public class AddressingInHandler extends
                 log.debug(
                         "The AddressingInHandler has been disabled. No further processing will take place.");
             }
-            return InvocationResponse.CONTINUE;         
+            return false;         
         }
 
-
+        // if there are not headers put a flag to disable addressing temporary
+        SOAPHeader header = msgContext.getEnvelope().getHeader();
+        if (header == null) {
+            return false;
+        }
+        return true;
+    }
+    
+    public InvocationResponse invoke_stage2(MessageContext msgContext) throws AxisFault {
+        SOAPHeader header = msgContext.getEnvelope().getHeader();
         if(configuration == null){
         	AxisConfiguration conf = msgContext.getConfigurationContext().getAxisConfiguration();
         	rolePlayer = (RolePlayer)conf.getParameterValue(Constants.SOAP_ROLE_PLAYER_PARAMETER);

Modified: axis/axis2/java/core/trunk/modules/addressing/src/org/apache/axis2/handlers/addressing/AddressingOutHandler.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/addressing/src/org/apache/axis2/handlers/addressing/AddressingOutHandler.java?rev=1036556&r1=1036555&r2=1036556&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/addressing/src/org/apache/axis2/handlers/addressing/AddressingOutHandler.java (original)
+++ axis/axis2/java/core/trunk/modules/addressing/src/org/apache/axis2/handlers/addressing/AddressingOutHandler.java Thu Nov 18 17:44:54 2010
@@ -64,6 +64,14 @@ public class AddressingOutHandler extend
     private static final String MODULE_NAME = "addressing";
     
     public InvocationResponse invoke(MessageContext msgContext) throws AxisFault {
+        
+        if (invoke_stage1(msgContext)) {
+            return invoke_stage2(msgContext);
+        } else {
+            return InvocationResponse.CONTINUE;
+        }
+    }
+    public boolean invoke_stage1(MessageContext msgContext) throws AxisFault {
         Parameter param = null;
         boolean disableAddressing = false;
         
@@ -85,8 +93,13 @@ public class AddressingOutHandler extend
                 log.trace(msgContext.getLogIDString() +
                         " Addressing is disabled. Not adding WS-Addressing headers.");
             }
-            return InvocationResponse.CONTINUE;
+            return false;
         }
+        return true;
+    }
+    
+    public InvocationResponse invoke_stage2(MessageContext msgContext) throws AxisFault {
+        
 
         // Determine the addressin namespace in effect.
         Object addressingVersionFromCurrentMsgCtxt = msgContext.getProperty(WS_ADDRESSING_VERSION);
@@ -99,7 +112,7 @@ public class AddressingOutHandler extend
 
         // Determine whether to include optional addressing headers in the output.
         // Get default value from module.xml or axis2.xml files
-        param = msgContext.getModuleParameter(
+        Parameter param = msgContext.getModuleParameter(
                 INCLUDE_OPTIONAL_HEADERS, MODULE_NAME, handlerDesc);
         boolean includeOptionalHeaders =
             msgContext.isPropertyTrue(INCLUDE_OPTIONAL_HEADERS,

Modified: axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/dispatchers/MustUnderstandChecker.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/dispatchers/MustUnderstandChecker.java?rev=1036556&r1=1036555&r2=1036556&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/dispatchers/MustUnderstandChecker.java (original)
+++ axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/dispatchers/MustUnderstandChecker.java Thu Nov 18 17:44:54 2010
@@ -19,6 +19,7 @@
 
 package org.apache.axis2.jaxws.dispatchers;
 
+import org.apache.axiom.soap.SOAPEnvelope;
 import org.apache.axis2.AxisFault;
 import org.apache.axis2.context.MessageContext;
 import org.apache.commons.logging.Log;
@@ -34,6 +35,22 @@ import org.apache.commons.logging.LogFac
 public class MustUnderstandChecker extends org.apache.axis2.handlers.AbstractHandler {
     private static final Log log = LogFactory.getLog(MustUnderstandChecker.class);
 
+    public boolean invoke_stage1(MessageContext msgContext) throws AxisFault {
+        if (msgContext == null) {
+            return false;
+        }
+        
+        SOAPEnvelope envelope = msgContext.getEnvelope();
+        if (envelope.getHeader() == null) {
+            return false;
+        }  
+        return true;
+    }
+    
+    public InvocationResponse invoke_stage2(MessageContext msgContext) throws AxisFault {
+        return invoke(msgContext);
+    }
+    
     public InvocationResponse invoke(MessageContext msgContext) throws AxisFault {
         // Get the list of headers for the roles we're acting in, then mark any we understand
         // as processed.

Modified: axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/engine/Phase.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/engine/Phase.java?rev=1036556&r1=1036555&r2=1036556&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/engine/Phase.java (original)
+++ axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/engine/Phase.java Thu Nov 18 17:44:54 2010
@@ -25,6 +25,7 @@ import org.apache.axis2.context.MessageC
 import org.apache.axis2.description.HandlerDescription;
 import org.apache.axis2.description.Parameter;
 import org.apache.axis2.description.PhaseRule;
+import org.apache.axis2.handlers.AbstractHandler;
 import org.apache.axis2.phaseresolver.PhaseException;
 import org.apache.axis2.util.LoggingControl;
 import org.apache.commons.logging.Log;
@@ -294,8 +295,6 @@ public class Phase implements Handler {
                     "\"");
         }
 
-        InvocationResponse pi = InvocationResponse.CONTINUE;
-
         int currentIndex = msgctx.getCurrentPhaseIndex();
 
         if (currentIndex == 0) {
@@ -308,21 +307,17 @@ public class Phase implements Handler {
 
         int handlersSize = handlers.size();
         
-        while (currentIndex < handlersSize) {
-            Handler handler = (Handler) handlers.get(currentIndex);
-
-            if (isDebugEnabled) {
-                log.debug(msgctx.getLogIDString() + " Invoking Handler '" + handler.getName() +
-                        "' in Phase '" + phaseName + "'");
-            }
-            pi = handler.invoke(msgctx);
+        for (int i= currentIndex; i < handlersSize; i++) {
+            Handler handler = (Handler) handlers.get(i);
 
+            InvocationResponse pi = invokeHandler(handler, msgctx);
+           
             if (!pi.equals(InvocationResponse.CONTINUE)) {
                 return pi;
             }
-
-            currentIndex++;
-            msgctx.setCurrentPhaseIndex(currentIndex);
+            
+            // Set phase index to the next handler
+            msgctx.setCurrentPhaseIndex(i+1);
         }
 
         if (isDebugEnabled) {
@@ -332,7 +327,28 @@ public class Phase implements Handler {
 
         msgctx.setCurrentPhaseIndex(0);
         checkPostConditions(msgctx);
-        return pi;
+        return InvocationResponse.CONTINUE;
+    }
+    
+    private InvocationResponse invokeHandler(Handler handler, MessageContext msgctx) throws AxisFault  {
+        if (isDebugEnabled) {
+            log.debug(msgctx.getLogIDString() + " Invoking Handler '" + handler.getName() +
+                    "' in Phase '" + phaseName + "'");
+        }
+        if (handler instanceof AbstractHandler) {
+            // Call this as a two stage handler.
+            boolean needStage2 = ((AbstractHandler)handler).invoke_stage1(msgctx);
+
+            if (needStage2) {
+                return ((AbstractHandler)handler).invoke_stage2(msgctx);
+            } else {
+                return InvocationResponse.CONTINUE;
+            } 
+           
+            
+        } else {
+            return handler.invoke(msgctx);
+        }
     }
 
     public void flowComplete(MessageContext msgContext) {

Modified: axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/handlers/AbstractHandler.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/handlers/AbstractHandler.java?rev=1036556&r1=1036555&r2=1036556&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/handlers/AbstractHandler.java (original)
+++ axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/handlers/AbstractHandler.java Thu Nov 18 17:44:54 2010
@@ -20,10 +20,12 @@
 
 package org.apache.axis2.handlers;
 
+import org.apache.axis2.AxisFault;
 import org.apache.axis2.context.MessageContext;
 import org.apache.axis2.description.HandlerDescription;
 import org.apache.axis2.description.Parameter;
 import org.apache.axis2.engine.Handler;
+import org.apache.axis2.engine.Handler.InvocationResponse;
 
 /**
  * Class AbstractHandler
@@ -100,4 +102,34 @@ public abstract class AbstractHandler im
 
     public void flowComplete(MessageContext msgContext) {
     }
+    
+    /**
+     * Alternative to calling invoke()
+     * The handler developer can place code in stage1 that 
+     * will do quick checking to make sure that the handler is
+     * enabled and useful for this message.
+     * Some handler developers may wish to split the invoke into
+     * two stages if the handler is often disabled.
+     * @param msgContext
+     * @return true if stage2 processing is needed; 
+     *   false if stage2 processing is not needed and flow should continue to the next handler
+     */
+    public boolean invoke_stage1(MessageContext msgContext) throws AxisFault {
+        // The default behavior is to continue to stage2
+        return true;
+    }
+    
+    /**
+     * Alternative to calling invoke()
+     * The handler developer can place code in stage2 that 
+     * will do the actual processing.
+     * Some handler developers may wish to split the invoke into
+     * two stages if the handler is often disabled.
+     * @param msgContext
+     * @return InvocationResponse
+     */
+    public InvocationResponse invoke_stage2(MessageContext msgContext) throws AxisFault {
+        // The default behavior is to call the existing invoke method
+        return invoke(msgContext);
+    }
 }