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 gd...@apache.org on 2007/06/29 00:10:50 UTC

svn commit: r551714 - in /webservices/axis2/trunk/java/modules/kernel: src/org/apache/axis2/context/ src/org/apache/axis2/engine/ test/org/apache/axis2/description/ test/org/apache/axis2/engine/

Author: gdaniels
Date: Thu Jun 28 15:10:48 2007
New Revision: 551714

URL: http://svn.apache.org/viewvc?view=rev&rev=551714
Log:
Resolve https://issues.apache.org/jira/browse/AXIS2-2857

Deprecate Handler.cleanup(), add MessageContext.getFailureReason(), and make sure that we set it when the AxisEngine catches a fault.

Add test for the above in EnginePausingTest, which might want to be renamed "EngineFlowTest" or something...

Modified:
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/MessageContext.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/engine/AxisEngine.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/engine/Handler.java
    webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/description/RegistryTest.java
    webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/engine/EnginePausingTest.java
    webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/engine/MessageContextChangeTest.java

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/MessageContext.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/MessageContext.java?view=diff&rev=551714&r1=551713&r2=551714
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/MessageContext.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/MessageContext.java Thu Jun 28 15:10:48 2007
@@ -324,6 +324,12 @@
     private int currentPhaseIndex;
 
     /**
+     * If we're processing this MC due to flowComplete() being called in the case
+     * of an Exception, this will hold the Exception which caused the problem.
+     */
+    private Exception failureReason;
+
+    /**
      * @serial SOAP envelope
      */
     private SOAPEnvelope envelope;
@@ -4272,5 +4278,23 @@
         } catch (Exception e) {
             return false;
         }
+    }
+
+
+    /**
+     * Obtain the Exception which caused the processing chain to halt.
+     * @return null, or an Exception.
+     */
+    public Exception getFailureReason() {
+        return failureReason;
+    }
+
+    /**
+     * Set the failure reason.  Only AxisEngine should ever do this.
+     *
+     * @param failureReason an Exception which caused processing to halt.
+     */
+    public void setFailureReason(Exception failureReason) {
+        this.failureReason = failureReason;
     }
 }

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/engine/AxisEngine.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/engine/AxisEngine.java?view=diff&rev=551714&r1=551713&r2=551714
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/engine/AxisEngine.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/engine/AxisEngine.java Thu Jun 28 15:10:48 2007
@@ -172,6 +172,7 @@
             }
         }
         catch (AxisFault e) {
+            msgContext.setFailureReason(e);
             flowComplete(msgContext);
             throw e;
         }
@@ -422,6 +423,7 @@
             }
         }
         catch (AxisFault e) {
+            msgContext.setFailureReason(e);
             flowComplete(msgContext);
             throw e;
         }
@@ -470,6 +472,7 @@
                 }
             }
             catch (AxisFault e) {
+                msgContext.setFailureReason(e);
                 flowComplete(msgContext);
                 throw e;
             }

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/engine/Handler.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/engine/Handler.java?view=diff&rev=551714&r1=551713&r2=551714
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/engine/Handler.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/engine/Handler.java Thu Jun 28 15:10:48 2007
@@ -32,9 +32,7 @@
 public interface Handler {
 
     /**
-     * Since this might change the whole behavior of Axis2 handlers, and since this is still under discussion
-     * (http://marc.theaimsgroup.com/?l=axis-dev&m=114504084929285&w=2) implementation of this method is deferred.
-     * Note : This method will not be automatically called, from Axis2 engine, until this is fully implemented.
+     * @deprecated This method will be going away after the 1.3 release, it was never used.
      */
     public void cleanup();
 
@@ -72,7 +70,9 @@
      * invoke(...) method called during the processing of the message, once
      * the message processing has completed.  During execution of the
      * flowComplete's, handlers are invoked in the opposite order that they
-     * were invoked originally.
+     * were invoked originally.  Note that implementations SHOULD check
+     * msgContext.getFailureReason() to see if this is an error or a normal
+     * completion.
      *
      * @param msgContext the <code>MessageContext</code> to process with this
      *                   <code>Handler</code>.

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?view=diff&rev=551714&r1=551713&r2=551714
==============================================================================
--- 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 Thu Jun 28 15:10:48 2007
@@ -89,7 +89,6 @@
         handler.init(new HandlerDescription());
         assertNull(handler.getName());
         assertNull(handler.getParameter("hello"));
-        handler.cleanup();
     }
 
 

Modified: webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/engine/EnginePausingTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/engine/EnginePausingTest.java?view=diff&rev=551714&r1=551713&r2=551714
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/engine/EnginePausingTest.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/engine/EnginePausingTest.java Thu Jun 28 15:10:48 2007
@@ -47,6 +47,9 @@
 
 public class EnginePausingTest extends TestCase {
 
+    public static final String FAULT_IDX = "FaultIndex";
+    public static final String FAULT_REASON = "I faulted because I was told to!";
+
     private QName serviceName = new QName("NullService");
     private QName operationName = new QName("DummyOp");
     private ConfigurationContext configContext;
@@ -182,21 +185,36 @@
     public void testReceive() throws Exception {
         mc.setTo(new EndpointReference("/axis2/services/NullService"));
         mc.setWSAAction("DummyOp");
-        AxisEngine engine = new AxisEngine(configContext);
-        engine.receive(mc);
+        AxisEngine.receive(mc);
         assertEquals(14, executedHandlers.size());
         for (int i = 0; i < 14; i++) {
             assertEquals(((Integer) executedHandlers.get(i)).intValue(),
                          i + 1);
         }
-        engine.resume(mc);
+        AxisEngine.resume(mc);
 
         assertEquals(27, executedHandlers.size());
         for (int i = 15; i < 27; i++) {
             assertEquals(((Integer) executedHandlers.get(i)).intValue(),
                          i + 1);
         }
+    }
 
+    public void testFlowComplete() throws Exception {
+        mc.setTo(new EndpointReference("/axis2/services/NullService"));
+        mc.setWSAAction("DummyOp");
+
+        // Fault on Handler #5
+        mc.setProperty(FAULT_IDX, new Integer(5));
+
+        try {
+            AxisEngine.receive(mc);
+        } catch (AxisFault axisFault) {
+            // Expected this fault.
+            assertEquals(4, executedHandlers.size());
+            return;
+        }
+        fail("Expected fault did not occur");
     }
 
     public class TempHandler extends AbstractHandler {
@@ -219,11 +237,27 @@
                 msgContext.pause();
                 pause = false;
                 return InvocationResponse.SUSPEND;
-            } else {
-                executedHandlers.add(index);
-                return InvocationResponse.CONTINUE;
             }
+
+            Integer faultIndex = (Integer)msgContext.getProperty(FAULT_IDX);
+            if (faultIndex != null && faultIndex.equals(index)) {
+                throw new AxisFault(FAULT_REASON);
+            }
+
+            executedHandlers.add(index);
+            return InvocationResponse.CONTINUE;
         }
 
+
+        public void flowComplete(MessageContext msgContext) {
+            if (msgContext.getProperty(FAULT_IDX) != null) {
+                // If we're here on an invocation where someone was supposed to fault...
+                AxisFault fault = (AxisFault)msgContext.getFailureReason();
+                assertNotNull("No fault!", fault);
+
+                // Make sure it's the right fault.
+                assertEquals(FAULT_REASON, fault.getReason());
+            }
+        }
     }
 }

Modified: webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/engine/MessageContextChangeTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/engine/MessageContextChangeTest.java?view=diff&rev=551714&r1=551713&r2=551714
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/engine/MessageContextChangeTest.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/engine/MessageContextChangeTest.java Thu Jun 28 15:10:48 2007
@@ -109,6 +109,7 @@
                                  "class$org$apache$axis2$context$MessageContext"),
             new FieldDescription("java.lang.Class",
                                  "class$org$apache$axis2$context$SelfManagedDataManager"),
+            new FieldDescription("java.lang.Exception", "failureReason"),
     };
 
 



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