scheu       2002/06/21 11:37:48

  Modified:    java/samples/jaxrpc GetQuote1.java
               java/src/org/apache/axis/client Call.java
  Log:
  Based on input from Doug Davis and discussions on the chat,
  we decided to allow modification of any Call object.
  
  The addParameter, setReturnType, and removeAllParameters methods
  will now modify the Call object (without throwing a JAXRPCException)
  regardless of the setting of the parmAndRetReq flag.
  
  Note that invoking these methods also causes the parmAndRetReq flag to be
  set to true.
  
  Added the GetQuote1 method that was removed by my last commit.
  
  Revision  Changes    Path
  1.5       +59 -0     xml-axis/java/samples/jaxrpc/GetQuote1.java
  
  Index: GetQuote1.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/samples/jaxrpc/GetQuote1.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- GetQuote1.java    21 Jun 2002 16:48:59 -0000      1.4
  +++ GetQuote1.java    21 Jun 2002 18:37:48 -0000      1.5
  @@ -173,6 +173,58 @@
           return ((Float) result).floatValue();
       } // getQuote2
   
  +    /**
  +     * This method does the same thing that getQuote1 does, but in
  +     * addition it reuses the Call object to make another call.
  +     */
  +    public float getQuote3(String args[]) throws Exception {
  +        Options opts = new Options(args);
  +
  +        args = opts.getRemainingArgs();
  +
  +        if (args == null) {
  +            System.err.println("Usage: GetQuote <symbol>");
  +            System.exit(1);
  +        }
  +
  +        /* Define the service QName and port QName */
  +        /*******************************************/
  +        QName servQN = new QName("urn:xmltoday-delayed-quotes",
  +                "GetQuoteService");
  +        QName portQN = new QName("urn:xmltoday-delayed-quotes", "GetQuote");
  +
  +        /* Now use those QNames as pointers into the WSDL doc */
  +        /******************************************************/
  +        Service service = ServiceFactory.newInstance().createService(
  +                new URL("file:samples/stock/GetQuote.wsdl"), servQN);
  +        Call call = service.createCall(portQN, "getQuote");
  +
  +        /* Strange - but allows the user to change just certain portions of */
  +        /* the URL we're gonna use to invoke the service.  Useful when you  */
  +        /* want to run it thru tcpmon (ie. put  -p81 on the cmd line).      */
  +        /********************************************************************/
  +        opts.setDefaultURL(call.getTargetEndpointAddress());
  +        call.setTargetEndpointAddress(opts.getURL());
  +
  +        /* Define some service specific properties */
  +        /*******************************************/
  +        call.setProperty(Call.USERNAME_PROPERTY, opts.getUser());
  +        call.setProperty(Call.PASSWORD_PROPERTY, opts.getPassword());
  +
  +        /* Get symbol and invoke the service */
  +        /*************************************/
  +        Object result = call.invoke(new Object[] {symbol = args[0]});
  +
  +        /* Reuse the Call object for a different call */
  +        /**********************************************/
  +        call.setOperationName(new QName("urn:xmltoday-delayed-quotes", "test"));
  +        call.removeAllParameters();
  +        call.setReturnType(XMLType.XSD_STRING);
  +
  +        System.out.println(call.invoke(new Object[]{}));
  +        return ((Float) result).floatValue();
  +    } // getQuote3
  +
       public static void main(String args[]) throws Exception {
           String    save_args[] = new String[args.length];
           float     val;
  @@ -190,6 +242,13 @@
           System.out.println("Manually");
           System.arraycopy(save_args, 0, args, 0, args.length);
           val = gq.getQuote2(args);
  +        System.out.println(gq.symbol + ": " + val);
  +
  +        /* Call the getQuote() that uses Axis's generated WSDL */
  +        /*******************************************************/
  +        System.out.println("WSDL + Reuse Call");
  +        System.arraycopy(save_args, 0, args, 0, args.length);
  +        val = gq.getQuote3(args);
           System.out.println(gq.symbol + ": " + val);
       } // main
   }
  
  
  
  1.145     +69 -49    xml-axis/java/src/org/apache/axis/client/Call.java
  
  Index: Call.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/client/Call.java,v
  retrieving revision 1.144
  retrieving revision 1.145
  diff -u -r1.144 -r1.145
  --- Call.java 21 Jun 2002 16:49:00 -0000      1.144
  +++ Call.java 21 Jun 2002 18:37:48 -0000      1.145
  @@ -652,11 +652,15 @@
       ////////////////////////////
   
       /**
  -     * Is the caller required to provide the parameter and return type 
specification?  If true, then
  -     * addParameter and setReturnType MUST be called to provide the meta data.  If 
false, then
  -     * addParameter and setReturnType CANNOT be called because the Call object 
already has the meta
  -     * data and the user is not allowed to mess with it.  These methods throw 
JAXRPCException if
  -     * this method returns false.
  +     * Is the caller required to provide the parameter and return type
  +     * specification? 
  +     * If true, then
  +     *  addParameter and setReturnType MUST be called to provide the meta data.
  +     * If false, then
  +     *  addParameter and setReturnType SHOULD NOT be called because the 
  +     *  Call object already has the meta data describing the 
  +     *  parameters and return type. If addParameter is called, the specified 
  +     *  parameter is added to the end of the list of parameters.
        */
       public boolean isParameterAndReturnSpecRequired(QName operationName) {
           return parmAndRetReq;
  @@ -668,9 +672,9 @@
        *
        * Note: Not part of JAX-RPC specification.
        *
  -     * @param paramName      Name that will be used for the parameter in the XML
  -     * @param xmlType      XMLType of the parameter
  -     * @param parameterMode  one of IN, OUT or INOUT
  +     * @param paramName Name that will be used for the parameter in the XML
  +     * @param xmlType XMLType of the parameter
  +     * @param parameterMode one of IN, OUT or INOUT
        */
       public void addParameter(QName paramName, QName xmlType,
               ParameterMode parameterMode) {
  @@ -689,31 +693,37 @@
        *
        * Note: Not part of JAX-RPC specification.
        *
  -     * @param paramName      Name that will be used for the parameter in the XML
  -     * @param xmlType      XMLType of the parameter
  -     * @param javaType - The Java class of the parameter
  -     * @param parameterMode  one of IN, OUT or INOUT
  +     * @param paramName Name that will be used for the parameter in the XML
  +     * @param xmlType XMLType of the parameter
  +     * @param javaType The Java class of the parameter
  +     * @param parameterMode one of IN, OUT or INOUT
        */
       public void addParameter(QName paramName, QName xmlType,
               Class javaType, ParameterMode parameterMode) {
  -        if (parmAndRetReq) {
  -            ParameterDesc param = new ParameterDesc();
  -            param.setQName( paramName );
  -            param.setTypeQName( xmlType );
  -            param.setJavaType( javaType );
  -            byte mode = ParameterDesc.IN;
  -            if (parameterMode == ParameterMode.INOUT) {
  -                mode = ParameterDesc.INOUT;
  -            } else if (parameterMode == ParameterMode.OUT) {
  -                mode = ParameterDesc.OUT;
  -            }
  -            param.setMode(mode);
  -
  -            operation.addParameter(param);
  -        }
  -        else {
  -            throw new JAXRPCException(JavaUtils.getMessage("noParmAndRetReq"));
  -        }
  +        // In order to allow any Call to be re-used, Axis
  +        // chooses to allow parameters to be added when
  +        // parmAndRetReq==false.  This does not conflict with
  +        // JSR 101 which indicates an exception MAY be thrown.
  +
  +        //if (parmAndRetReq) {
  +        ParameterDesc param = new ParameterDesc();
  +        param.setQName( paramName );
  +        param.setTypeQName( xmlType );
  +        param.setJavaType( javaType );
  +        byte mode = ParameterDesc.IN;
  +        if (parameterMode == ParameterMode.INOUT) {
  +            mode = ParameterDesc.INOUT;
  +        } else if (parameterMode == ParameterMode.OUT) {
  +            mode = ParameterDesc.OUT;
  +        }
  +        param.setMode(mode);
  +        
  +        operation.addParameter(param);
  +        parmAndRetReq = true;
  +        //}
  +        //else {
  +        //throw new JAXRPCException(JavaUtils.getMessage("noParmAndRetReq"));
  +        //}
       }
   
       /**
  @@ -746,8 +756,9 @@
        * @param javaType - The Java class of the parameter
        * @param parameterMode - Mode of the parameter-whether IN, OUT or INOUT
        * @exception JAXRPCException - if isParameterAndReturnSpecRequired returns
  -     *                              false, then addParameter will throw
  -     *                              JAXRPCException.
  +     *                              false, then addParameter MAY throw
  +     *                              JAXRPCException....actually Axis allows
  +     *                              modification in such cases
        */
       public void addParameter(String paramName, QName xmlType,
                                Class javaType, ParameterMode parameterMode) {
  @@ -788,15 +799,21 @@
        * @param type QName of the return value type.
        */
       public void setReturnType(QName type) {
  -        if (parmAndRetReq) {
  -            returnType = type ;
  -            operation.setReturnType(type);
  -            TypeMapping tm = getTypeMapping();
  -            operation.setReturnClass(tm.getClassForQName(type));
  -        }
  -        else {
  -            throw new JAXRPCException(JavaUtils.getMessage("noParmAndRetReq"));
  -        }
  +        // In order to allow any Call to be re-used, Axis
  +        // chooses to allow setReturnType to be changed when
  +        // parmAndRetReq==false.  This does not conflict with
  +        // JSR 101 which indicates an exception MAY be thrown.
  +
  +        //if (parmAndRetReq) {
  +        returnType = type ;
  +        operation.setReturnType(type);
  +        TypeMapping tm = getTypeMapping();
  +        operation.setReturnClass(tm.getClassForQName(type));
  +        parmAndRetReq = true;
  +        //}
  +        //else {
  +        //throw new JAXRPCException(JavaUtils.getMessage("noParmAndRetReq"));
  +        //}
       }
   
       /**
  @@ -805,7 +822,8 @@
        * @param xmlType - QName of the data type of the return value
        * @param javaType - Java class of the return value
        * @exception JAXRPCException - if isParameterAndReturnSpecRequired returns
  -     * false, then setReturnType will throw JAXRPCException.
  +     * false, then setReturnType MAY throw JAXRPCException...Axis allows 
  +     * modification without throwing the exception.
        */
       public void setReturnType(QName xmlType, Class javaType) {
           setReturnType(xmlType);
  @@ -847,15 +865,17 @@
       /**
        * Clears the list of parameters.
        * @exception JAXRPCException - if isParameterAndReturnSpecRequired returns 
false, then
  -     * removeAllParameters will throw JAXRPCException.
  +     * removeAllParameters MAY throw JAXRPCException...Axis allows modification to
  +     * the Call object without throwing an exception.
        */
       public void removeAllParameters() {
  -        if (parmAndRetReq) {
  -            operation = new OperationDesc();
  -        }
  -        else {
  -            throw new JAXRPCException(JavaUtils.getMessage("noParmAndRetReq"));
  -        }
  +        //if (parmAndRetReq) {
  +        operation = new OperationDesc();
  +        parmAndRetReq = true;
  +        //}
  +        //else {
  +        //throw new JAXRPCException(JavaUtils.getMessage("noParmAndRetReq"));
  +        //}
       }
   
       /**
  
  
  


Reply via email to