axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dee...@apache.org
Subject svn commit: r606916 - in /webservices/axis2/trunk/java/modules/kernel: src/org/apache/axis2/deployment/ src/org/apache/axis2/deployment/util/ src/org/apache/axis2/engine/ test-resources/deployment/module1/META-INF/ test/org/apache/axis2/deployment/ tes...
Date Wed, 26 Dec 2007 15:56:52 GMT
Author: deepal
Date: Wed Dec 26 07:56:51 2007
New Revision: 606916

URL: http://svn.apache.org/viewvc?rev=606916&view=rev
Log:
Adding dynamic phase support , so if a module want a add a new phase then it can add an entry
like below into module.xml

<phase name="Foo" after="After_phase_Name" before="Before_Phase_Name" flow="[InFlow,OutFlow,OutFaultFlow,InFaultFlow]"/>

Modified:
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/DeploymentConstants.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/ModuleBuilder.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/util/PhasesInfo.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/engine/AxisConfiguration.java
    webservices/axis2/trunk/java/modules/kernel/test-resources/deployment/module1/META-INF/module.xml
    webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/deployment/DeploymentTotalTest.java
    webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/description/RegistryTest.java

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/DeploymentConstants.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/DeploymentConstants.java?rev=606916&r1=606915&r2=606916&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/DeploymentConstants.java
(original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/DeploymentConstants.java
Wed Dec 26 07:56:51 2007
@@ -36,7 +36,6 @@
 
     String TAG_AXISCONFIG = "axisconfig";
     String TAG_PHASE_ORDER = "phaseOrder";
-    String TAG_PHASE = "phase";
     String TAG_PARAMETER = "parameter";
     String TAG_MAPPING = "mapping";
     String TAG_PACKAGE_NAME = "packageName";
@@ -60,6 +59,7 @@
     String TAG_PHASE_FIRST = "phaseFirst";
     String TAG_ORDER = "order";           // to resolve the order tag
     String TAG_OPERATION = "operation";       // operation start tag
+    String TAG_PHASE = "phase";       // operation start tag
     String TAG_OBJECT_SUPPLIER = "ObjectSupplier";       // operation start tag
     String TAG_EXCLUDE_OPERATIONS = "excludeOperations";
     String TAG_MESSAGE_RECEIVER = "messageReceiver";

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/ModuleBuilder.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/ModuleBuilder.java?rev=606916&r1=606915&r2=606916&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/ModuleBuilder.java
(original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/ModuleBuilder.java
Wed Dec 26 07:56:51 2007
@@ -23,12 +23,9 @@
 import org.apache.axiom.om.OMAttribute;
 import org.apache.axiom.om.OMElement;
 import org.apache.axis2.AxisFault;
+import org.apache.axis2.phaseresolver.PhaseMetadata;
 import org.apache.axis2.deployment.util.PhasesInfo;
-import org.apache.axis2.description.AxisModule;
-import org.apache.axis2.description.AxisOperation;
-import org.apache.axis2.description.AxisOperationFactory;
-import org.apache.axis2.description.InOnlyAxisOperation;
-import org.apache.axis2.description.PolicyInclude;
+import org.apache.axis2.description.*;
 import org.apache.axis2.engine.AxisConfiguration;
 import org.apache.axis2.engine.MessageReceiver;
 import org.apache.axis2.i18n.Messages;
@@ -88,7 +85,11 @@
             OMElement moduleElement = buildOM();
             // Setting Module Class , if it is there
             OMAttribute moduleClassAtt = moduleElement.getAttribute(new QName(TAG_CLASS_NAME));
+            // processing Parameters
+            // Processing service level parameters
+            Iterator itr = moduleElement.getChildrenWithName(new QName(TAG_PARAMETER));
 
+            processParameters(itr, module, module.getParent());
             if (moduleClassAtt != null) {
                 String moduleClass = moduleClassAtt.getAttributeValue();
 
@@ -150,12 +151,6 @@
                                          module.getPolicyInclude());
             }
 
-            // processing Parameters
-            // Processing service level parameters
-            Iterator itr = moduleElement.getChildrenWithName(new QName(TAG_PARAMETER));
-
-            processParameters(itr, module, module.getParent());
-
             // process INFLOW
             OMElement inFlow = moduleElement.getFirstChildWithName(new QName(TAG_FLOW_IN));
 
@@ -212,8 +207,14 @@
 
                 module.addOperation(operation);
             }
+
+            // Processing Dynamic Phase
+            Iterator phaseItr = moduleElement.getChildrenWithName(new QName(TAG_PHASE));
+            processModulePhase(phaseItr);
         } catch (XMLStreamException e) {
             throw new DeploymentException(e);
+        } catch(AxisFault e) {
+            throw new DeploymentException(e);
         }
     }
 
@@ -314,5 +315,40 @@
         }
 
         return operations;
+    }
+
+    /**
+     * This will process the phase list and then added the phases specified in module.xml
to
+     * axisConfiguration. The format of a phase element will something like
+     *  <phase name="Foo" after="After_phase_Name" before="Before_Phase_Name"
+     *  flow="[InFlow,OutFlow,OutFaultFlow,InFaultFlow]"/>
+     *  Here before and after can be null
+     * @param phases : OMElement iterator
+     * @throws AxisFault : If something went wrong
+     */
+    private void processModulePhase(Iterator phases) throws AxisFault {
+        if (phases == null){
+            return;
+        }
+        while (phases.hasNext()) {
+            OMElement element = (OMElement) phases.next();
+            String phaseName = element.getAttributeValue(new QName(ATTRIBUTE_NAME));
+            String after = element.getAttributeValue(new QName(TAG_AFTER));
+            String before = element.getAttributeValue(new QName(TAG_BEFORE));
+            String flowName = element.getAttributeValue(new QName("flow"));
+            int flowInex ;
+            if (TAG_FLOW_IN.equals(flowName)){
+                flowInex = PhaseMetadata.IN_FLOW ;
+            } else if (TAG_FLOW_OUT.equals(flowName)) {
+                flowInex = PhaseMetadata.OUT_FLOW ;
+            } else if (TAG_FLOW_OUT_FAULT.equals(flowName)) {
+                flowInex = PhaseMetadata.FAULT_OUT_FLOW;
+            } else if (TAG_FLOW_IN_FAULT.equals(flowName)) {
+                flowInex = PhaseMetadata.FAULT_IN_FLOW;
+            } else {
+                throw new DeploymentException(" Flow can not be null for the phase name "
+ phaseName);
+            }
+            axisConfig.insertPhase(phaseName,before,after,flowInex);
+        }
     }
 }

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/util/PhasesInfo.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/util/PhasesInfo.java?rev=606916&r1=606915&r2=606916&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/util/PhasesInfo.java
(original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/util/PhasesInfo.java
Wed Dec 26 07:56:51 2007
@@ -151,6 +151,10 @@
         return OUTPhases;
     }
 
+    public ArrayList getOutFaultPhaseList(){
+        return OUT_FaultPhases;
+    }
+
     public ArrayList getOUT_FaultPhases() throws DeploymentException {
         ArrayList globalPhaseList = new ArrayList();
         boolean messageOut = false;

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/engine/AxisConfiguration.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/engine/AxisConfiguration.java?rev=606916&r1=606915&r2=606916&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/engine/AxisConfiguration.java
(original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/engine/AxisConfiguration.java
Wed Dec 26 07:56:51 2007
@@ -32,6 +32,7 @@
 import org.apache.axis2.description.java2wsdl.Java2WSDLConstants;
 import org.apache.axis2.i18n.Messages;
 import org.apache.axis2.phaseresolver.PhaseResolver;
+import org.apache.axis2.phaseresolver.PhaseMetadata;
 import org.apache.axis2.transport.MessageFormatter;
 import org.apache.axis2.util.TargetResolver;
 import org.apache.axis2.util.Utils;
@@ -815,14 +816,14 @@
     /**
      * This method needs to remain for a few Axis2 releases to support
      * legacy apps still using it.
-     * 
+     *
      * @param qname
      * @deprecated Use {@link #isEngaged(String)}
      */
     public boolean isEngaged(QName qname) {
         return isEngaged(qname.getLocalPart());
     }
-    
+
     public boolean isEngaged(String moduleId) {
         AxisModule module = getModule(moduleId);
         if (module == null) {
@@ -1105,5 +1106,128 @@
         if (configurator != null) {
             configurator.cleanup();
         }
+    }
+
+    /**
+     * This method can be used to insert a phase at the runtime for a given location
+     * And the relative location can be specified by beforePhase and afterPhase. Parameters
+     * Either or both of them can be null , if both the parameters are null then the phase
+     * will be added some where in the global phase. If one of them are null then the phase
+     * will be added
+     *  - If the beforePhase is null then the phase will be added after the afterPhase
+     *  - If the after phase is null then the phase will be added before the beforePhase
+     * Type of the flow will be specified by the parameter flow.
+     *   1 - Inflow
+     *   2 - out flow
+     *   3 - fault in flow
+     *   4 - fault out flow
+     *
+     * @param phaseName : Not null parameter , specifying the phase name
+     * @param beforePhase : can be null , will tell the name of before phase
+     * @param afterPhase : Can be null and will tell the name of after phase
+     * @param flow : Type of the flow
+     * @throws org.apache.axis2.AxisFault : If something went wrong
+     */
+    public void insertPhase(String phaseName ,
+                            String beforePhase,
+                            String afterPhase ,
+                            int flow) throws AxisFault {
+
+
+        switch (flow) {
+            case PhaseMetadata.IN_FLOW : {
+                ArrayList phaseList = phasesinfo.getINPhases();
+                phaseList = findAndInsertPhase(beforePhase, phaseList, afterPhase, phaseName);
+                if (phaseList != null) {
+                    phasesinfo.setINPhases(phaseList);
+                }
+                break;
+            }
+            case PhaseMetadata.OUT_FLOW : {
+                ArrayList phaseList = phasesinfo.getOUTPhases();
+                phaseList = findAndInsertPhase(beforePhase, phaseList, afterPhase, phaseName);
+                if (phaseList != null) {
+                    phasesinfo.setOUTPhases(phaseList);
+                }
+                break;
+            }
+            case PhaseMetadata.FAULT_OUT_FLOW : {
+                ArrayList phaseList = phasesinfo.getOutFaultPhaseList();
+                phaseList = findAndInsertPhase(beforePhase, phaseList, afterPhase, phaseName);
+                if (phaseList != null) {
+                    phasesinfo.setOUT_FaultPhases(phaseList);
+                }
+                break;
+            }
+            case PhaseMetadata.FAULT_IN_FLOW : {
+                ArrayList phaseList = phasesinfo.getIN_FaultPhases();
+                phaseList = findAndInsertPhase(beforePhase, phaseList, afterPhase, phaseName);
+                if (phaseList != null) {
+                    phasesinfo.setIN_FaultPhases(phaseList);
+                }
+                break;
+            }
+        }
+    }
+
+    /**
+     * This method will added a given phase into the location specified by the phase before
+     * and phase after.  If given phase are not found then an exception will be thrown.
+     * @param beforePhase : Name of the before phase
+     * @param phaseList : ArrayList of phase
+     * @param afterPhase : Name of the after phase
+     * @param phaseName : name of the phase we need to add
+     * @throws AxisFault : If something went wrong
+     * @return : Modified list
+     */
+    private ArrayList findAndInsertPhase(String beforePhase,
+                                         ArrayList phaseList,
+                                         String afterPhase,
+                                         String phaseName) throws AxisFault {
+        int beforeIndex = -1;
+        int afterIndex = -1;
+        for (int i = 0; i < phaseList.size(); i++) {
+            Phase phase = (Phase) phaseList.get(i);
+            if (phase.getPhaseName().equals(beforePhase)) {
+                beforeIndex = i;
+            } else if (phase.getPhaseName().equals(afterPhase)){
+                afterIndex = i;
+            } else if (phase.getPhaseName().equals(phaseName)){
+                return null;
+            }
+        }
+        if (beforeIndex == -1 && afterIndex == -1) {
+            throw new AxisFault("Trying to add a phase " + phaseName + " before "
+                    + beforePhase + " and after " + afterPhase + " but none of the phases
" +
+                    "found in the system please refer to axis2.xml for available phases");
+        }
+
+        if (afterIndex > beforeIndex) {
+            throw new AxisFault("Trying to add a phase " + phaseName + " before "
+                    + beforePhase + " and after " + afterPhase + " phase order is invalid
, " +
+                    "please refer axis2.xml for the correct phase order");
+        }
+        Phase phase = new Phase();
+        phase.setName(phaseName);
+        if (beforeIndex == -1){
+            if (afterIndex == phaseList.size() -1) {
+                // Need to add to the last phase since the after phase is the
+                // last phase in the system
+                phaseList.add(phase);
+            } else {
+                phaseList.add(afterIndex, phase);
+            }
+        } else   if (afterIndex == -1) {
+            if (beforeIndex == 0) {
+                // Need to add to the first place of the phase since the before
+                // phase index is 0
+                phaseList.add(0, phase);
+            } else {
+                phaseList.add(beforeIndex, phase);
+            }
+        } else {
+            phaseList.add(afterIndex, phase);
+        }
+        return phaseList;
     }
 }

Modified: webservices/axis2/trunk/java/modules/kernel/test-resources/deployment/module1/META-INF/module.xml
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/test-resources/deployment/module1/META-INF/module.xml?rev=606916&r1=606915&r2=606916&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/test-resources/deployment/module1/META-INF/module.xml
(original)
+++ webservices/axis2/trunk/java/modules/kernel/test-resources/deployment/module1/META-INF/module.xml
Wed Dec 26 07:56:51 2007
@@ -48,4 +48,6 @@
         <messageReceiver class="org.apache.axis2.receivers.RawXMLINOutMessageReceiver"/>
         <parameter name="para1" locked="xsd:true">10</parameter>
     </operation>
+    <phase name="NewPhase" before="Dispatch" after="Security" flow="InFlow"/>
+    <phase name="NewPhase" before="Dispatch"  flow="InFaultFlow"/>
 </module>

Modified: webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/deployment/DeploymentTotalTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/deployment/DeploymentTotalTest.java?rev=606916&r1=606915&r2=606916&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/deployment/DeploymentTotalTest.java
(original)
+++ webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/deployment/DeploymentTotalTest.java
Wed Dec 26 07:56:51 2007
@@ -20,28 +20,56 @@
 package org.apache.axis2.deployment;
 
 import junit.framework.TestCase;
-import org.apache.axis2.AxisFault;
 import org.apache.axis2.AbstractTestCase;
+import org.apache.axis2.AxisFault;
 import org.apache.axis2.context.ConfigurationContextFactory;
 import org.apache.axis2.description.Parameter;
 import org.apache.axis2.engine.AxisConfiguration;
+import org.apache.axis2.engine.Phase;
 
 import javax.xml.stream.XMLStreamException;
+import java.util.ArrayList;
 
 public class DeploymentTotalTest extends TestCase {
     AxisConfiguration er;
 
-    public void testparseService1() throws AxisFault, XMLStreamException {
+
+    protected void setUp() throws Exception {
         String filename = AbstractTestCase.basedir + "/target/test-resources/deployment";
         er = ConfigurationContextFactory
                 .createConfigurationContextFromFileSystem(filename, filename + "/axis2.xml")
                 .getAxisConfiguration();
+         // OK, no exceptions.  Now make sure we read the correct file...
+    }
 
-        // OK, no exceptions.  Now make sure we read the correct file...
+    public void testparseService1() throws AxisFault, XMLStreamException {
         Parameter param = er.getParameter("FavoriteColor");
         assertNotNull("No FavoriteColor parameter in axis2.xml!", param);
-
         assertEquals("purple", param.getValue());
+    }
+
+    public void testDynamicPhase() {
+        ArrayList inFlow = er.getInFlowPhases();
+        boolean found = false;
+        int index = 0;
+        for (int i = 0; i < inFlow.size(); i++) {
+            Phase phase = (Phase) inFlow.get(i);
+            if (phase.getName().equals("NewPhase")) {
+                found = true;
+                index = i;
+            }
+        }
+        assertEquals("Phase has insert into a wrong location" ,index,3);
+        assertTrue("Problem in Dynamic Phases for Inflow", found);
+        inFlow = er.getInFaultFlowPhases();
+        found = false;
+        for (int i = 0; i < inFlow.size(); i++) {
+            Phase phase = (Phase) inFlow.get(i);
+            if (phase.getName().equals("NewPhase")) {
+                found = true;
+            }
+        }
+        assertTrue("Problem in Dynamic Phases for InFaultflow", found);
     }
 
 }

Modified: webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/description/RegistryTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/description/RegistryTest.java?rev=606916&r1=606915&r2=606916&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/description/RegistryTest.java
(original)
+++ webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/description/RegistryTest.java
Wed Dec 26 07:56:51 2007
@@ -24,12 +24,14 @@
 import org.apache.axis2.context.MessageContext;
 import org.apache.axis2.engine.AxisConfiguration;
 import org.apache.axis2.engine.Handler;
+import org.apache.axis2.engine.Phase;
 import org.apache.axis2.handlers.AbstractHandler;
 
 import javax.xml.namespace.QName;
+import java.util.ArrayList;
 
 public class RegistryTest extends AbstractTestCase {
-    private AxisConfiguration reg = new AxisConfiguration();
+    private AxisConfiguration axisConfiguration = new AxisConfiguration();
     AxisService service = new AxisService("Service1");
 
     public RegistryTest(String testName) {
@@ -43,13 +45,13 @@
     }
 
     public void testService() throws AxisFault {
-        reg.addService(service);
+        axisConfiguration.addService(service);
         testParameteInClude(service);
     }
 
     public void testModule() throws AxisFault {
         AxisModule module = new AxisModule("module1");
-        module.setParent(reg);
+        module.setParent(axisConfiguration);
         testParameteInClude(module);
         testFlowIncludeTest(module);
     }



---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org


Mime
View raw message