axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gdani...@apache.org
Subject cvs commit: xml-axis/java/test/outparams PackageTests.java ServiceHandler.java TestOutParams.java
Date Tue, 28 Aug 2001 16:00:45 GMT
gdaniels    01/08/28 09:00:45

  Modified:    java/src/org/apache/axis/client ServiceClient.java
               java/src/org/apache/axis/handlers/soap SOAPService.java
               java/test/RPCDispatch TestRPC.java TestSerializedRPC.java
               java/test/encoding TestArrayListConversions.java
                        TestBody.java
  Added:       java/test/outparams PackageTests.java ServiceHandler.java
                        TestOutParams.java
  Log:
  * Add support for output parameters in ServiceClient.  If a SOAP response
    contains more than one param in the RPC element, we will return the first
    one as usual, and the user may call getOutputParams() to access a Vector
    containing all the others.  NOTE: the Vector contains the actual RPCParam
    objects, not their values.
  
  * Unit test for above.
  
  * Remove unused param in SOAPService constructor, and fix all refs (have I
    mentioned that IDEA *rocks* for refactoring? :))
  
  Revision  Changes    Path
  1.44      +35 -6     xml-axis/java/src/org/apache/axis/client/ServiceClient.java
  
  Index: ServiceClient.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/client/ServiceClient.java,v
  retrieving revision 1.43
  retrieving revision 1.44
  diff -u -r1.43 -r1.44
  --- ServiceClient.java	2001/08/18 21:18:22	1.43
  +++ ServiceClient.java	2001/08/28 16:00:43	1.44
  @@ -102,8 +102,9 @@
   
       private static Hashtable transports = new Hashtable();
       private static boolean initialized = false;
  -    
  -                                                        
  +
  +    private static FileProvider configProvider = new FileProvider("client-config.xml");
  +
       /** Register a Transport that should be used for URLs of the specified
        * protocol.
        * 
  @@ -176,9 +177,10 @@
       // Our Transport, if any
       private Transport transport;
       private String    transportName;
  -    
  -    private static FileProvider configProvider = new FileProvider("client-config.xml");
   
  +    // A place to store output parameters
  +    private Vector outParams = null;
  +
       /**
        * Basic, no-argument constructor.
        */
  @@ -373,8 +375,22 @@
       {
           this.serviceDesc = serviceDesc;
       }
  -    
  +
       /**
  +     * Get the output parameters (if any) from the last invocation.
  +     *
  +     * NOTE that the params returned are all RPCParams, containing
  +     * name and value - if you want the value, you'll need to call
  +     * param.getValue().
  +     *
  +     * @return a Vector of RPCParams
  +     */
  +    public Vector getOutputParams()
  +    {
  +        return this.outParams;
  +    }
  +
  +    /**
        * Map a type for serialization.
        * 
        * @param _class the Java class of the data type.
  @@ -472,7 +488,10 @@
           Message              resMsg = null ;
           Vector               resArgs = null ;
           Object               result = null ;
  -        
  +
  +        // Clear the output params
  +        outParams = null;
  +
           String uri = null;
           if (serviceDesc != null) uri = serviceDesc.getEncodingStyleURI();
           if (uri != null) reqEnv.setEncodingStyleURI(uri);
  @@ -540,6 +559,16 @@
           if (resArgs != null && resArgs.size() > 0) {
               RPCParam param = (RPCParam)resArgs.get(0);
               result = param.getValue();
  +
  +            /**
  +             * Are there out-params?  If so, return a Vector instead.
  +             */
  +            if (resArgs.size() > 1) {
  +                outParams = new Vector();
  +                for (int i = 1; i < resArgs.size(); i++) {
  +                    outParams.add(resArgs.get(i));
  +                }
  +            }
           }
           
           Debug.Print( 1, "Exit: ServiceClient::invoke(RPCElement)" );
  
  
  
  1.19      +1 -1      xml-axis/java/src/org/apache/axis/handlers/soap/SOAPService.java
  
  Index: SOAPService.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/handlers/soap/SOAPService.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- SOAPService.java	2001/08/03 19:12:59	1.18
  +++ SOAPService.java	2001/08/28 16:00:44	1.19
  @@ -121,7 +121,7 @@
       /** Convenience constructor for wrapping SOAP semantics around
        * "service handlers" which actually do work.
        */
  -    public SOAPService(Handler serviceHandler, String pivotName)
  +    public SOAPService(Handler serviceHandler)
       {
           this();
           setPivotHandler(serviceHandler);
  
  
  
  1.21      +4 -4      xml-axis/java/test/RPCDispatch/TestRPC.java
  
  Index: TestRPC.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/test/RPCDispatch/TestRPC.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- TestRPC.java	2001/08/14 03:49:19	1.20
  +++ TestRPC.java	2001/08/28 16:00:44	1.21
  @@ -101,7 +101,7 @@
        */
       public void testReverseString() throws Exception {
           // Register the reverseString service
  -        SOAPService reverse = new SOAPService(RPCDispatcher, "RPCDispatcher");
  +        SOAPService reverse = new SOAPService(RPCDispatcher);
           reverse.addOption("className", "test.RPCDispatch.Service");
           reverse.addOption("methodName", "reverseString");
           sr.add(SOAPAction, reverse);
  @@ -115,7 +115,7 @@
        */
       public void testReverseData() throws Exception {
           // Register the reverseData service
  -        SOAPService reverse = new SOAPService(RPCDispatcher, "RPCDispatcher");
  +        SOAPService reverse = new SOAPService(RPCDispatcher);
           reverse.addOption("className", "test.RPCDispatch.Service");
           reverse.addOption("methodName", "reverseData");
           sr.add(SOAPAction, reverse);
  @@ -131,7 +131,7 @@
        */
       public void testMessageContext() throws Exception {
           // Register the targetService service
  -        SOAPService tgtSvc = new SOAPService(RPCDispatcher, "RPCDispatcher");
  +        SOAPService tgtSvc = new SOAPService(RPCDispatcher);
           tgtSvc.addOption("className", "test.RPCDispatch.Service");
           tgtSvc.addOption("methodName", "targetService");
           sr.add(SOAPAction, tgtSvc);
  @@ -145,7 +145,7 @@
        */
       public void testNull() throws Exception {
           // Register the echoInt service
  -        SOAPService echoInt = new SOAPService(RPCDispatcher, "RPCDispatcher");
  +        SOAPService echoInt = new SOAPService(RPCDispatcher);
           echoInt.addOption("className", "test.RPCDispatch.Service");
           echoInt.addOption("methodName", "echoInt");
           sr.add(SOAPAction, echoInt);
  
  
  
  1.9       +1 -1      xml-axis/java/test/RPCDispatch/TestSerializedRPC.java
  
  Index: TestSerializedRPC.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/test/RPCDispatch/TestSerializedRPC.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- TestSerializedRPC.java	2001/08/11 14:26:11	1.8
  +++ TestSerializedRPC.java	2001/08/28 16:00:44	1.9
  @@ -48,7 +48,7 @@
           RPCDispatcher = hr.find("RPCDispatcher");
           
           // Register the reverseString service
  -        SOAPService reverse = new SOAPService(RPCDispatcher, "RPCDispatcher");
  +        SOAPService reverse = new SOAPService(RPCDispatcher);
           reverse.addOption("className", "test.RPCDispatch.Service");
           reverse.addOption("methodName", "*");
           engine.deployService(SOAPAction, reverse);
  
  
  
  1.4       +1 -1      xml-axis/java/test/encoding/TestArrayListConversions.java
  
  Index: TestArrayListConversions.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/test/encoding/TestArrayListConversions.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TestArrayListConversions.java	2001/07/01 12:38:47	1.3
  +++ TestArrayListConversions.java	2001/08/28 16:00:44	1.4
  @@ -46,7 +46,7 @@
       AxisServer server = new AxisServer();
       HandlerRegistry hr = (HandlerRegistry) server.getHandlerRegistry();
       Handler disp = hr.find("RPCDispatcher");    
  -    SOAPService service = new SOAPService(disp, "RPCDispatcher");
  +    SOAPService service = new SOAPService(disp);
       service.addOption("className", "test.encoding.TestArrayListConversions");
       service.addOption("methodName", "*");
       
  
  
  
  1.3       +1 -1      xml-axis/java/test/encoding/TestBody.java
  
  Index: TestBody.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/test/encoding/TestBody.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TestBody.java	2001/07/10 16:04:59	1.2
  +++ TestBody.java	2001/08/28 16:00:44	1.3
  @@ -47,7 +47,7 @@
          
          // register the service with the engine
          Handler RPCDispatcher = hr.find("RPCDispatcher");
  -       SOAPService target = new SOAPService(RPCDispatcher, "RPCDispatcher");
  +       SOAPService target = new SOAPService(RPCDispatcher);
          sr.add(namespace, target);
   
          // create a message in context
  
  
  
  1.1                  xml-axis/java/test/outparams/PackageTests.java
  
  Index: PackageTests.java
  ===================================================================
  package test.outparams;
  
  import junit.framework.TestCase;
  import junit.framework.Test;
  import junit.framework.TestSuite;
  
  /**
   *  Test package for output params
   */
  public class PackageTests extends TestCase {
  
      public PackageTests(String name) {
          super(name);
      }
  
      public static Test suite() throws Exception {
          TestSuite suite = new TestSuite();
  
          suite.addTestSuite(TestOutParams.class);
  
          return suite;
      }
  }
  
  
  
  1.1                  xml-axis/java/test/outparams/ServiceHandler.java
  
  Index: ServiceHandler.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Axis" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  package test.outparams;
  
  import org.apache.axis.handlers.BasicHandler;
  import org.apache.axis.MessageContext;
  import org.apache.axis.AxisFault;
  import org.apache.axis.Message;
  import org.apache.axis.message.SOAPEnvelope;
  import org.apache.axis.message.RPCElement;
  import org.apache.axis.message.RPCParam;
  
  public class ServiceHandler extends BasicHandler {
      public static final String OUTPARAM1 = "Output param value";
      public static final Float OUTPARAM2 = new Float(4.56);
  
      /** Must implement this in subclasses.
       */
      public void undo(MessageContext msgContext) {
      }
  
      public void invoke(MessageContext msgContext) throws AxisFault {
          SOAPEnvelope env = new SOAPEnvelope();
  
          RPCParam retVal = new RPCParam("return", new Integer(5));
          RPCParam outParam1 = new RPCParam("out1", OUTPARAM1);
          RPCParam outParam2 = new RPCParam("out2", OUTPARAM2);
  
          RPCElement rpc = new RPCElement("namespace", "response", new Object []
                              { retVal, outParam1, outParam2 });
  
          env.addBodyElement(rpc);
  
          msgContext.setResponseMessage(new Message(env));
      }
  }
  
  
  
  1.1                  xml-axis/java/test/outparams/TestOutParams.java
  
  Index: TestOutParams.java
  ===================================================================
  package test.outparams;
  
  import junit.framework.TestCase;
  
  import org.apache.axis.*;
  import org.apache.axis.transport.local.LocalTransport;
  import org.apache.axis.client.ServiceClient;
  import org.apache.axis.encoding.*;
  import org.apache.axis.handlers.soap.*;
  import org.apache.axis.message.*;
  import org.apache.axis.server.*;
  import org.apache.axis.registries.*;
  
  import java.util.Vector;
  
  import test.RPCDispatch.Data;
  
  /**
   * Test org.apache.axis.handlers.RPCDispatcher
   *
   * @author Sam Ruby <rubys@us.ibm.com>
   */
  public class TestOutParams extends TestCase {
      private final String serviceURN = "urn:X-test-outparams";
  
  
      /** A fixed message, since the return is hardcoded */
      private final String message =
          "<?xml version=\"1.0\"?>\n" +
          "<soap:Envelope " +
               "xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" " +
               "xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\" " +
               "xmlns:xsi=\"" + Constants.URI_CURRENT_SCHEMA_XSI + "\" " +
               "xmlns:xsd=\"" + Constants.URI_CURRENT_SCHEMA_XSD + "\">\n" +
               "<soap:Body>\n" +
               "<ns:someMethod xmlns:ns=\"" + serviceURN + "\"/>\n" +
               "</soap:Body>\n" +
          "</soap:Envelope>\n";
  
      private ServiceClient client = new ServiceClient();
      private AxisServer server = new AxisServer();
  
      private HandlerRegistry hr;
      private HandlerRegistry sr;
  
      public TestOutParams(String name) {
          super(name);
          server.init();
          hr = (HandlerRegistry) server.getHandlerRegistry();
          sr = (HandlerRegistry) server.getServiceRegistry();
      }
  
      /**
       * Test returning output params
       */
      public void testOutputParams() throws Exception {
          // Register the service
          Handler h = new ServiceHandler();
  
          // ??? Do we need to register the handler?
  
          SOAPService service = new SOAPService(h);
          sr.add(serviceURN, service);
  
          // Make sure the local transport uses the server we just configured
          client.setTransport(new LocalTransport(server));
  
          // Create the message context
          MessageContext msgContext = new MessageContext(server);
  
          // Construct the soap request
          SOAPEnvelope envelope = new SOAPEnvelope();
          msgContext.setRequestMessage(new Message(envelope));
  
          // Invoke the Axis server
          Object ret = client.invoke(serviceURN, "method",
                                  new Object [] { "test" });
  
          Vector outParams = client.getOutputParams();
          assertNotNull("Null outParams!", outParams);
  
          RPCParam param = (RPCParam)outParams.get(0);
          assertEquals(param.getValue(), ServiceHandler.OUTPARAM1);
  
          param = (RPCParam)outParams.get(1);
          assertEquals(param.getValue(), ServiceHandler.OUTPARAM2);
      }
  
      public static void main(String args[])
      {
        try {
          TestOutParams tester = new TestOutParams("RPC test");
          tester.testOutputParams();
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
  }
  
  
  

Mime
View raw message