axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject cvs commit: ws-axis/java/src/org/apache/axis/handlers/soap SOAPService.java
Date Wed, 07 Jul 2004 03:04:01 GMT
dims        2004/07/06 20:04:01

  Modified:    java/src/org/apache/axis/handlers HandlerChainImpl.java
               java/src/org/apache/axis/handlers/soap SOAPService.java
  Added:       java/test/jaxrpc AAAHandler.java build.xml PackageTests.java
                        TestSOAPService.java
  Log:
  Fix for AXIS-1310 - Fault Processing for JAXRPC Handler chain not to spec
  from Algirdas Veitas
  
  Revision  Changes    Path
  1.1                  ws-axis/java/test/jaxrpc/AAAHandler.java
  
  Index: AAAHandler.java
  ===================================================================
  package test.jaxrpc;
  
  import javax.xml.namespace.QName;
  import javax.xml.rpc.handler.Handler;
  import javax.xml.rpc.handler.HandlerInfo;
  import javax.xml.rpc.handler.MessageContext;
  import java.util.Map;
  
  public class AAAHandler implements Handler {
      private int handleRequestInvocations = 0;
      private int handleResponseInvocations = 0;
      private int handleFaultInvocations = 0;
  
      public Object handleRequestReturnValue = null;
      public Object handleResponseReturnValue = null;
      public Object handleFaultReturnValue = null;
  
      public boolean handleRequest(MessageContext context) {
          handleRequestInvocations++;
          return returnAppropriateValue(handleRequestReturnValue);
      }
  
      public boolean handleResponse(MessageContext context) {
          handleResponseInvocations++;
          return returnAppropriateValue(handleResponseReturnValue);
      }
  
      public boolean handleFault(MessageContext context) {
          handleFaultInvocations++;
          return returnAppropriateValue(handleFaultReturnValue);
      }
  
      private boolean returnAppropriateValue(Object returnValue) {
          if (returnValue == null)
              return true;
          else if (returnValue instanceof Boolean)
              return ((Boolean) returnValue).booleanValue();
          else if (returnValue instanceof RuntimeException)
              throw (RuntimeException) returnValue;
          else {
              throw new RuntimeException();
          }
      }
  
      public void init(HandlerInfo config) {
          Map map = config.getHandlerConfig();
          handleRequestReturnValue = map.get("HANDLE_REQUEST_RETURN_VALUE");
          handleResponseReturnValue = map.get("HANDLE_RESPONSE_RETURN_VALUE");
          handleFaultReturnValue = map.get("HANDLE_FAULT_RETURN_VALUE");
      }
  
      public void destroy() {
      }
  
      public QName[] getHeaders() {
          return new QName[0];
      }
  
      public int getHandleRequestInvocations() {
          return handleRequestInvocations;
      }
  
      public int getHandleResponseInvocations() {
          return handleResponseInvocations;
      }
  
      public int getHandleFaultInvocations() {
          return handleFaultInvocations;
      }
  
      public Object getHandleRequestReturnValue() {
          return handleRequestReturnValue;
      }
  
      public void setHandleRequestReturnValue(Object handleRequestReturnValue) {
          this.handleRequestReturnValue = handleRequestReturnValue;
      }
  
      public Object getHandleResponseReturnValue() {
          return handleResponseReturnValue;
      }
  
      public void setHandleResponseReturnValue(Object handleResponseReturnValue) {
          this.handleResponseReturnValue = handleResponseReturnValue;
      }
  
      public Object getHandleFaultReturnValue() {
          return handleFaultReturnValue;
      }
  
      public void setHandleFaultReturnValue(Object handleFaultReturnValue) {
          this.handleFaultReturnValue = handleFaultReturnValue;
      }
  
  }
  
  
  1.1                  ws-axis/java/test/jaxrpc/build.xml
  
  Index: build.xml
  ===================================================================
  <?xml version="1.0" ?>
  <!DOCTYPE project [
          <!ENTITY properties SYSTEM "file:../../xmls/properties.xml">
          <!ENTITY paths  SYSTEM "file:../../xmls/path_refs.xml">
          <!ENTITY taskdefs SYSTEM "file:../../xmls/taskdefs.xml">
          <!ENTITY taskdefs_post_compile SYSTEM "file:../../xmls/taskdefs_post_compile.xml">
          <!ENTITY targets SYSTEM "file:../../xmls/targets.xml">
  ]>
  
  <!-- ===================================================================
  <description>
     Test/Sample Component file for Axis
  
  Notes:
     This is a build file for use with the Jakarta Ant build tool.
  
  Prerequisites:
  
     jakarta-ant from http://jakarta.apache.org
  
  Build Instructions:
     To compile
  	ant compile
     To execute
  	ant run
  
  Author:
    Matt Seibert mseibert@us.ibm.com
  
  Copyright:
    Copyright (c) 2002-2003 Apache Software Foundation.
  </description>
  ==================================================================== -->
  
  <project default="compile">
  <property name="axis.home" location="../.." />
  <property name="componentName" value="test/jaxrpc" />
          &properties;
          &paths;
          &taskdefs;
          &taskdefs_post_compile;
  	&targets;
  
  <target name="clean">
      <echo message="Removing ${build.dir}/classes/${componentName} and ${build.dir}/work/${componentName}"
/>
      <delete dir="${build.dir}/classes/${componentName}"/>
      <delete dir="${build.dir}/work/${componentName}"/>
  </target>
  
  <target name="copy" depends="setenv"/>
  
  <target name="compile" depends="copy">
    <echo message="Compiling test.jaxrpc"/>
    <javac srcdir="${axis.home}" destdir="${build.dest}" debug="${debug}" nowarn="${nowarn}"
source="${source}" fork="${javac.fork}">
      <classpath>
          <path refid="classpath"/>
      </classpath>
      <include name="test/jaxrpc/*.java"/>
    </javac>
  </target>
  
  <target name="run" >
    <antcall target="execute-Component-noServer" />
  </target>
  
  </project>
  
  
  
  1.1                  ws-axis/java/test/jaxrpc/PackageTests.java
  
  Index: PackageTests.java
  ===================================================================
  package test.jaxrpc;
  
  /**
   * SAAJ PackageTests tests
   */
  public class PackageTests extends junit.framework.TestCase {
      public PackageTests(String name) {
          super(name);
      }
  
      public static junit.framework.Test suite() throws Exception {
          junit.framework.TestSuite suite = new junit.framework.TestSuite();
          suite.addTestSuite(test.jaxrpc.TestSOAPService.class);
          return suite;
      }
  }
  
  
  
  
  1.1                  ws-axis/java/test/jaxrpc/TestSOAPService.java
  
  Index: TestSOAPService.java
  ===================================================================
  package test.jaxrpc;
  
  import junit.framework.TestCase;
  import org.apache.axis.AxisFault;
  import org.apache.axis.Constants;
  import org.apache.axis.Handler;
  import org.apache.axis.Message;
  import org.apache.axis.MessageContext;
  import org.apache.axis.handlers.BasicHandler;
  import org.apache.axis.handlers.HandlerInfoChainFactory;
  import org.apache.axis.handlers.soap.SOAPService;
  import org.apache.axis.message.Detail;
  import org.apache.axis.server.AxisServer;
  
  import javax.xml.rpc.JAXRPCException;
  import javax.xml.rpc.handler.HandlerChain;
  import javax.xml.rpc.handler.HandlerInfo;
  import javax.xml.rpc.soap.SOAPFaultException;
  import java.util.ArrayList;
  import java.util.HashMap;
  import java.util.List;
  import java.util.Map;
  
  public class TestSOAPService
          extends TestCase {
      HandlerInfo handlerInfo0 = null;
      HandlerInfo handlerInfo1 = null;
      HandlerInfo handlerInfo2 = null;
  
      Map handler0Config = null;
      Map handler1Config = null;
      Map handler2Config = null;
  
      /**
       * Sets up the handlerInfo and handlerConfigs for all tests.
       * Each test has 3 JAX-RPC Handlers of the same type to keep things
       * simple.
       * 
       * @throws Exception 
       */
      protected void setUp() throws Exception {
          handlerInfo0 = new HandlerInfo();
          handlerInfo0.setHandlerClass(AAAHandler.class);
          handlerInfo1 = new HandlerInfo();
          handlerInfo1.setHandlerClass(AAAHandler.class);
          handlerInfo2 = new HandlerInfo();
          handlerInfo2.setHandlerClass(AAAHandler.class);
          handler0Config = new HashMap();
          handler1Config = new HashMap();
          handler2Config = new HashMap();
          handlerInfo0.setHandlerConfig(handler0Config);
          handlerInfo1.setHandlerConfig(handler1Config);
          handlerInfo2.setHandlerConfig(handler2Config);
      }
  
      /**
       * All Handlers in Chain return true for handleRequest and handleResponse
       * <p/>
       * <p/>
       * * Expected Chain invocation sequence looks like.....
       * H0.handleRequest
       * H1.handleRequest
       * H2.handleRequest
       * H2.handleResponse
       * H1.handleResponse
       * H0.handleResponse
       * 
       * @throws Exception 
       */
      public void testPositiveCourseFlow() throws Exception {
          TestHandlerInfoChainFactory factory = buildInfoChainFactory();
          SOAPService soapService = new SOAPService();
          soapService.setOption(Constants.ATTR_HANDLERINFOCHAIN, factory);
          soapService.init();
          soapService.invoke(new TestMessageContext());
          AAAHandler handlerZero = factory.getHandlers()[0];
          AAAHandler handlerOne = factory.getHandlers()[1];
          AAAHandler handlerTwo = factory.getHandlers()[2];
          assertHandlerRuntime("handlerZero", handlerZero, 1, 1, 0);
          assertHandlerRuntime("handlerOne", handlerOne, 1, 1, 0);
          assertHandlerRuntime("handlerTwo", handlerTwo, 1, 1, 0);
      }
  
      /**
       * Tests scenario where one handler returns false on a call
       * to handleRequest(...).
       * <p/>
       * Expected Chain invocation sequence looks like.....
       * H0.handleRequest
       * H1.handleRequest returns false
       * H1.handleResponse
       * H0.handleResponse
       * 
       * @throws Exception 
       */
      public void testRequestHandlerReturnsFalse() throws Exception {
          SOAPService soapService = new SOAPService();
  
          // SETUP THE 2nd HANDLER IN THE REQUEST CHAIN TO RETURN FALSE
          handler1Config.put("HANDLE_REQUEST_RETURN_VALUE", Boolean.FALSE);
          TestHandlerInfoChainFactory factory = buildInfoChainFactory();
          soapService.setOption(Constants.ATTR_HANDLERINFOCHAIN, factory);
          soapService.init();
          MessageContext msgContext = new TestMessageContext();
          soapService.invoke(msgContext);
          AAAHandler handlerZero = factory.getHandlers()[0];
          AAAHandler handlerOne = factory.getHandlers()[1];
          AAAHandler handlerTwo = factory.getHandlers()[2];
          assertHandlerRuntime("handlerZero", handlerZero, 1, 1, 0);
          assertHandlerRuntime("handlerOne", handlerOne, 1, 1, 0);
          assertHandlerRuntime("handlerTwo", handlerTwo, 0, 0, 0);
      }
  
      /**
       * @throws Exception 
       */
      public void testRequestHandlerThrowsSFE() throws Exception {
          SOAPService soapService = new SOAPService();
  
          // SETUP THE 2nd HANDLER IN THE REQUEST CHAIN TO THROW SOAPFaultException
          handler1Config.put("HANDLE_REQUEST_RETURN_VALUE",
                  new SOAPFaultException(null, "f", "f", new Detail()));
          TestHandlerInfoChainFactory factory = buildInfoChainFactory();
          soapService.setOption(Constants.ATTR_HANDLERINFOCHAIN, factory);
          soapService.init();
          MessageContext msgContext = new TestMessageContext();
          soapService.invoke(msgContext);
          AAAHandler handlerZero = factory.getHandlers()[0];
          AAAHandler handlerOne = factory.getHandlers()[1];
          AAAHandler handlerTwo = factory.getHandlers()[2];
          assertHandlerRuntime("handlerZero", handlerZero, 1, 0, 1);
          assertHandlerRuntime("handlerOne", handlerOne, 1, 0, 1);
          assertHandlerRuntime("handlerTwo", handlerTwo, 0, 0, 0);
      }
  
      /**
       * @throws Exception 
       */
      public void testRequestHandlerThrowsJAXRPCException() throws Exception {
          SOAPService soapService = new SOAPService();
  
          // SETUP THE 2nd HANDLER IN THE REQUEST CHAIN TO THROW JAXRPCException
          handler1Config.put("HANDLE_REQUEST_RETURN_VALUE",
                  new JAXRPCException());
          TestHandlerInfoChainFactory factory = buildInfoChainFactory();
          soapService.setOption(Constants.ATTR_HANDLERINFOCHAIN, factory);
          soapService.init();
          MessageContext msgContext = new TestMessageContext();
          try {
              soapService.invoke(msgContext);
          } catch (AxisFault e) {
              AAAHandler handlerZero = factory.getHandlers()[0];
              AAAHandler handlerOne = factory.getHandlers()[1];
              AAAHandler handlerTwo = factory.getHandlers()[2];
              assertHandlerRuntime("handlerZero", handlerZero, 1, 0, 0);
              assertHandlerRuntime("handlerOne", handlerOne, 1, 0, 0);
              assertHandlerRuntime("handlerTwo", handlerTwo, 0, 0, 0);
          }
      }
  
      public void testRequestHandlerThrowsRuntimeException() throws Exception {
          SOAPService soapService = new SOAPService();
  
          // SETUP THE 2nd HANDLER IN THE REQUEST CHAIN TO THROW JAXRPCException
          handler1Config.put("HANDLE_REQUEST_RETURN_VALUE",
                  new RuntimeException());
          TestHandlerInfoChainFactory factory = buildInfoChainFactory();
          soapService.setOption(Constants.ATTR_HANDLERINFOCHAIN, factory);
          soapService.init();
          MessageContext msgContext = new TestMessageContext();
          try {
              soapService.invoke(msgContext);
          } catch (AxisFault e) {
              AAAHandler handlerZero = factory.getHandlers()[0];
              AAAHandler handlerOne = factory.getHandlers()[1];
              AAAHandler handlerTwo = factory.getHandlers()[2];
              assertHandlerRuntime("handlerZero", handlerZero, 1, 0, 0);
              assertHandlerRuntime("handlerOne", handlerOne, 1, 0, 0);
              assertHandlerRuntime("handlerTwo", handlerTwo, 0, 0, 0);
          }
      }
  
      public void testResponseHandlerReturnsFalse() throws Exception {
          SOAPService soapService = new SOAPService();
  
          // SETUP THE 3rd HANDLER IN THE CHAIN TO RETURN FALSE on handleResponse
          handler2Config.put("HANDLE_RESPONSE_RETURN_VALUE", Boolean.FALSE);
          TestHandlerInfoChainFactory factory = buildInfoChainFactory();
          soapService.setOption(Constants.ATTR_HANDLERINFOCHAIN, factory);
          soapService.init();
          MessageContext msgContext = new TestMessageContext();
          soapService.invoke(msgContext);
          AAAHandler handlerZero = factory.getHandlers()[0];
          AAAHandler handlerOne = factory.getHandlers()[1];
          AAAHandler handlerTwo = factory.getHandlers()[2];
          assertHandlerRuntime("handlerZero", handlerZero, 1, 0, 0);
          assertHandlerRuntime("handlerOne", handlerOne, 1, 0, 0);
          assertHandlerRuntime("handlerTwo", handlerTwo, 1, 1, 0);
      }
  
      public void testResponseHandlerThrowsJAXRPCException() throws Exception {
          SOAPService soapService = new SOAPService();
  
          // SETUP THE 2nd HANDLER IN THE CHAIN TO THROW JAXRPCException on handleResponse
          handler1Config.put("HANDLE_RESPONSE_RETURN_VALUE",
                  new JAXRPCException());
          TestHandlerInfoChainFactory factory = buildInfoChainFactory();
          soapService.setOption(Constants.ATTR_HANDLERINFOCHAIN, factory);
          soapService.init();
          MessageContext msgContext = new TestMessageContext();
          try {
              soapService.invoke(msgContext);
              fail("Expected AxisFault to be thrown");
          } catch (AxisFault e) {
              AAAHandler handlerZero = factory.getHandlers()[0];
              AAAHandler handlerOne = factory.getHandlers()[1];
              AAAHandler handlerTwo = factory.getHandlers()[2];
              assertHandlerRuntime("handlerZero", handlerZero, 1, 0, 0);
              assertHandlerRuntime("handlerOne", handlerOne, 1, 1, 0);
              assertHandlerRuntime("handlerTwo", handlerTwo, 1, 1, 0);
          }
      }
  
      public void testResponseHandlerThrowsRuntimeException() throws Exception {
          SOAPService soapService = new SOAPService();
  
          // SETUP THE 2nd HANDLER IN THE CHAIN TO THROW RuntimeException on handleResponse
          handler1Config.put("HANDLE_RESPONSE_RETURN_VALUE",
                  new RuntimeException());
          TestHandlerInfoChainFactory factory = buildInfoChainFactory();
          soapService.setOption(Constants.ATTR_HANDLERINFOCHAIN, factory);
          soapService.init();
          MessageContext msgContext = new TestMessageContext();
          try {
              soapService.invoke(msgContext);
              fail("Expected AxisFault to be thrown");
          } catch (AxisFault e) {
              AAAHandler handlerZero = factory.getHandlers()[0];
              AAAHandler handlerOne = factory.getHandlers()[1];
              AAAHandler handlerTwo = factory.getHandlers()[2];
              assertHandlerRuntime("handlerZero", handlerZero, 1, 0, 0);
              assertHandlerRuntime("handlerOne", handlerOne, 1, 1, 0);
              assertHandlerRuntime("handlerTwo", handlerTwo, 1, 1, 0);
          }
      }
  
      public void testHandleFaultReturnsFalse() throws Exception {
          SOAPService soapService = new SOAPService();
  
          // SETUP THE LAST HANDLER IN THE REQUEST CHAIN TO THROW SOAPFaultException
          handler2Config.put("HANDLE_REQUEST_RETURN_VALUE",
                  new SOAPFaultException(null, "f", "f", new Detail()));
          handler1Config.put("HANDLE_FAULT_RETURN_VALUE", Boolean.FALSE);
          TestHandlerInfoChainFactory factory = buildInfoChainFactory();
          soapService.setOption(Constants.ATTR_HANDLERINFOCHAIN, factory);
          soapService.init();
          MessageContext msgContext = new TestMessageContext();
          soapService.invoke(msgContext);
          AAAHandler handlerZero = factory.getHandlers()[0];
          AAAHandler handlerOne = factory.getHandlers()[1];
          AAAHandler handlerTwo = factory.getHandlers()[2];
          assertHandlerRuntime("handlerZero", handlerZero, 1, 0, 0);
          assertHandlerRuntime("handlerOne", handlerOne, 1, 0, 1);
          assertHandlerRuntime("handlerTwo", handlerTwo, 1, 0, 1);
      }
  
      /**
       * Tests to see if we handle the scenario of a handler throwing a
       * runtime exception during the handleFault(...) processing correctly
       * <p/>
       * Expected chain sequence:
       * H0.handleRequest
       * H1.handleRequest
       * H2.handleRequest SOAPFaultException
       * H2.handleFault
       * H1.handleFault throws JAXRPCException
       * 
       * @throws Exception 
       */
      public void testFaultHandlerThrowsJAXRPCException() throws Exception {
          SOAPService soapService = new SOAPService();
  
          // SETUP THE LAST HANDLER IN THE REQUEST CHAIN TO THROW SOAPFaultException
          handler2Config.put("HANDLE_REQUEST_RETURN_VALUE",
                  new SOAPFaultException(null, "f", "f", new Detail()));
          handler1Config.put("HANDLE_FAULT_RETURN_VALUE", new JAXRPCException());
          TestHandlerInfoChainFactory factory = buildInfoChainFactory();
          soapService.setOption(Constants.ATTR_HANDLERINFOCHAIN, factory);
          soapService.init();
          MessageContext msgContext = new TestMessageContext();
          try {
              soapService.invoke(msgContext);
              fail("Expected AxisFault to be thrown");
          } catch (AxisFault e) {
              AAAHandler handlerZero = factory.getHandlers()[0];
              AAAHandler handlerOne = factory.getHandlers()[1];
              AAAHandler handlerTwo = factory.getHandlers()[2];
              assertHandlerRuntime("handlerZero", handlerZero, 1, 0, 0);
              assertHandlerRuntime("handlerOne", handlerOne, 1, 0, 1);
              assertHandlerRuntime("handlerTwo", handlerTwo, 1, 0, 1);
          }
      }
  
      /**
       * Tests to see if we handle the scenario of a handler throwing a
       * runtime exception during the handleFault(...) processing correctly
       * <p/>
       * Expected chain sequence:
       * H0.handleRequest
       * H1.handleRequest
       * H2.handleRequest throws SOAPFaultException
       * H2.handleFault
       * H1.handleFault throws RuntimeException
       * 
       * @throws Exception 
       */
      public void testFaultHandlerThrowsRuntimeException() throws Exception {
          SOAPService soapService = new SOAPService();
  
          // SETUP THE LAST HANDLER IN THE REQUEST CHAIN TO THROW SOAPFaultException
          handler2Config.put("HANDLE_REQUEST_RETURN_VALUE",
                  new SOAPFaultException(null, "f", "f", new Detail()));
          handler1Config.put("HANDLE_FAULT_RETURN_VALUE", new RuntimeException());
          TestHandlerInfoChainFactory factory = buildInfoChainFactory();
          soapService.setOption(Constants.ATTR_HANDLERINFOCHAIN, factory);
          soapService.init();
          MessageContext msgContext = new TestMessageContext();
          try {
              soapService.invoke(msgContext);
              fail("Expected AxisFault to be thrown");
          } catch (AxisFault e) {
              AAAHandler handlerZero = factory.getHandlers()[0];
              AAAHandler handlerOne = factory.getHandlers()[1];
              AAAHandler handlerTwo = factory.getHandlers()[2];
              assertHandlerRuntime("handlerZero", handlerZero, 1, 0, 0);
              assertHandlerRuntime("handlerOne", handlerOne, 1, 0, 1);
              assertHandlerRuntime("handlerTwo", handlerTwo, 1, 0, 1);
          }
      }
  
      /**
       * Tests scenario where service object throws Axis Fault.
       * <p/>
       * Expected chain sequence:
       * H0.handleRequest
       * H1.handleRequest
       * H2.handleRequest
       * ServiceObject.invoke() throws AxisFault
       * H2.handleFault
       * H1.handleFault
       * H0.handleFault
       * 
       * @throws Exception 
       */
      public void testServiceObjectThrowsAxisFault() throws Exception {
          Handler serviceHandler = new MockServiceHandler();
          SOAPService soapService = new SOAPService(null, null, serviceHandler);
          TestHandlerInfoChainFactory factory = buildInfoChainFactory();
          soapService.setOption(Constants.ATTR_HANDLERINFOCHAIN, factory);
          soapService.init();
          MessageContext msgContext = new TestMessageContext();
          try {
              soapService.invoke(msgContext);
              fail("Expected AxisFault to be thrown");
          } catch (AxisFault e) {
              AAAHandler handlerZero = factory.getHandlers()[0];
              AAAHandler handlerOne = factory.getHandlers()[1];
              AAAHandler handlerTwo = factory.getHandlers()[2];
              assertHandlerRuntime("handlerZero", handlerZero, 1, 0, 1);
              assertHandlerRuntime("handlerOne", handlerOne, 1, 0, 1);
              assertHandlerRuntime("handlerTwo", handlerTwo, 1, 0, 1);
          }
      }
  
      /**
       * Convenience method to organize all test checking for a particular
       * handler.
       * <p/>
       * Checks to see if the expected number of calls to handleRequest, handleResponse
       * and handleFault reconciles with actuals
       * 
       * @param message           
       * @param handler           the target handler to reconcile
       * @param numHandleRequest  # of expected calls to handleRequest
       * @param numHandleResponse # of expected calls to handleResponse
       * @param numHandleFault    # of expected call to handleFault
       */
      protected void assertHandlerRuntime(String message, AAAHandler handler,
                                          int numHandleRequest,
                                          int numHandleResponse,
                                          int numHandleFault) {
          assertEquals(message + ": handleRequest", numHandleRequest,
                  handler.getHandleRequestInvocations());
          assertEquals(message + ": handleResponse", numHandleResponse,
                  handler.getHandleResponseInvocations());
          assertEquals(message + ": handleFault", numHandleFault,
                  handler.getHandleFaultInvocations());
      }
  
      /**
       * Convenience method to create a HandlerInfoChainFactory
       * 
       * @return 
       */
      protected TestHandlerInfoChainFactory buildInfoChainFactory() {
          List handlerInfos = new ArrayList();
          handlerInfos.add(handlerInfo0);
          handlerInfos.add(handlerInfo1);
          handlerInfos.add(handlerInfo2);
          TestHandlerInfoChainFactory factory = new TestHandlerInfoChainFactory(
                  handlerInfos);
          return factory;
      }
  
      /**
       * Mock Service Handler used to simulate a service object throwing
       * an AxisFault.
       */
      private class MockServiceHandler extends BasicHandler {
          public void invoke(MessageContext msgContext) throws AxisFault {
              throw new AxisFault();
          }
      }
  
      /**
       * Helper class for keeping references to the JAX-RPC Handlers
       * that are created by the Factory.
       * <p/>
       * This class allows us to access the individual handlers after
       * the test case has been executed in order to make sure that
       * the expected methods of the handler instance have been invoked.
       */
      private class TestHandlerInfoChainFactory extends HandlerInfoChainFactory {
          AAAHandler[] handlers;
  
          public TestHandlerInfoChainFactory(List handlerInfos) {
              super(handlerInfos);
          }
  
          public HandlerChain createHandlerChain() {
              HandlerChain chain = super.createHandlerChain();
              handlers = new AAAHandler[chain.size()];
              for (int i = 0; i < chain.size(); i++) {
                  handlers[i] = (AAAHandler) chain.get(i);
              }
              return chain;
          }
  
          public AAAHandler[] getHandlers() {
              return handlers;
          }
  
      }
  
      private class TestMessageContext extends org.apache.axis.MessageContext {
  
          public String listByAreaCode = "<soap:Envelope\n" +
                  "xmlns:s0=\"http://www.tilisoft.com/ws/LocInfo/literalTypes\"\n" +
                  "xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"\n" +
                  "xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">\n" +
                  "<soap:Header>\n" +
                  "<WSABIHeader>\n" +
                  "<SubscriptionId>192168001100108165800640600008</SubscriptionId>\n"
+
                  "</WSABIHeader>\n" +
                  "</soap:Header>\n" +
                  "<soap:Body>\n" +
                  "<s0:ListByAreaCode>\n" +
                  "<s0:AreaCode>617</s0:AreaCode>\n" +
                  "</s0:ListByAreaCode>\n" +
                  "</soap:Body>\n" +
                  "</soap:Envelope>\n";
  
          public TestMessageContext() {
              super(new AxisServer());
              Message message = new Message(listByAreaCode);
              message.setMessageType(Message.REQUEST);
              setRequestMessage(message);
          }
      }
  
  }
  
  
  
  1.14      +7 -3      ws-axis/java/src/org/apache/axis/handlers/HandlerChainImpl.java
  
  Index: HandlerChainImpl.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/handlers/HandlerChainImpl.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- HandlerChainImpl.java	25 Feb 2004 14:02:40 -0000	1.13
  +++ HandlerChainImpl.java	7 Jul 2004 03:04:01 -0000	1.14
  @@ -81,7 +81,11 @@
       public boolean handleFault(MessageContext _context) {
           SOAPMessageContext context = (SOAPMessageContext) _context;
   
  -        for (int i = size() - 1; i >= 0; i--) {
  +        int endIdx = size() - 1;
  +        if (falseIndex != -1) {
  +            endIdx = falseIndex;
  +        }
  +        for (int i = endIdx; i >= 0; i--) {
               if (getHandlerInstance(i).handleFault(context) == false) {
                   return false;
               }
  @@ -95,7 +99,6 @@
           
           SOAPMessageContext context = (SOAPMessageContext) _context;
   
  -        falseIndex = -1;
           for (int i = 0; i < size(); i++) {
               Handler currentHandler = getHandlerInstance(i);
               try {
  @@ -104,7 +107,7 @@
                       return false;
                   }
               } catch (SOAPFaultException sfe) {
  -                currentHandler.handleFault(context);
  +                falseIndex = i;
                   throw sfe;
               }
           }
  @@ -128,6 +131,7 @@
           for (int i = 0; i < size(); i++) {
               getHandlerInstance(i).destroy();
           }
  +        falseIndex = -1;
           clear();
       }
   
  
  
  
  1.120     +16 -6     ws-axis/java/src/org/apache/axis/handlers/soap/SOAPService.java
  
  Index: SOAPService.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/handlers/soap/SOAPService.java,v
  retrieving revision 1.119
  retrieving revision 1.120
  diff -u -r1.119 -r1.120
  --- SOAPService.java	30 Jun 2004 12:34:37 -0000	1.119
  +++ SOAPService.java	7 Jul 2004 03:04:01 -0000	1.120
  @@ -437,10 +437,17 @@
           HandlerChainImpl handlerImpl = null;
           if (handlerFactory != null) handlerImpl = (HandlerChainImpl) handlerFactory.createHandlerChain();
           boolean result = true;
  -        
  +
           try {
               if (handlerImpl != null) {
  -                result = handlerImpl.handleRequest(msgContext);
  +                try {
  +                    result = handlerImpl.handleRequest(msgContext);
  +                }
  +                catch (SOAPFaultException e) {
  +                    handlerImpl.handleFault(msgContext);
  +                    msgContext.setPastPivot(true);
  +                    return;
  +                }
               }
   
               if (result) {
  @@ -450,22 +457,20 @@
                       msgContext.setPastPivot(true);
                       if (handlerImpl != null) {
                           handlerImpl.handleFault(msgContext);
  -                        handlerImpl.destroy();
                       }
                       throw e;
                   }
               } else {
                   msgContext.setPastPivot(true);
               }
  - 
  +
               if ( handlerImpl != null) {
                   handlerImpl.handleResponse(msgContext);
  -                handlerImpl.destroy();
               }
           } catch (SOAPFaultException e) {
               msgContext.setPastPivot(true);
               throw AxisFault.makeFault(e);
  -            
  +
           } catch (RuntimeException e) {
               SOAPFault fault = new SOAPFault(new AxisFault("Server", "Server Error", null,
null));
               SOAPEnvelope env = new SOAPEnvelope();
  @@ -474,6 +479,11 @@
               message.setMessageType(Message.RESPONSE);
               msgContext.setResponseMessage(message);
               throw AxisFault.makeFault(e);
  +        }
  +        finally {
  +            if (handlerImpl != null) {
  +                handlerImpl.destroy();
  +            }
           }
       }
   }
  
  
  

Mime
View raw message