axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sc...@apache.org
Subject cvs commit: xml-axis/java/test/wsdl/wrapped CityBBB.wsdl City_BBBBindingImpl.java City_BBBTestCase.java
Date Thu, 18 Jul 2002 20:00:39 GMT
scheu       2002/07/18 13:00:38

  Modified:    java/src/org/apache/axis/client Call.java
               java/src/org/apache/axis/message RPCElement.java
                        RPCHandler.java
               java/src/org/apache/axis/providers/java RPCProvider.java
               java/src/org/apache/axis/wsdl/toJava JavaSkelWriter.java
                        JavaStubWriter.java
               java/test/functional TestJAXMSamples.java
               java/test/wsdl/wrapped CityBBB.wsdl City_BBBBindingImpl.java
                        City_BBBTestCase.java
  Log:
  If the element exposed via unwrapping has a maxOccurs="unbounded" attribute,
  WSDL to java represents the parameter as an array.  The current Axis
  runtime also serializers the element correctly.  Here is an example
  from the modified City_BBB.wsdl:
  
  Here is the new getAttractions complexType:
  
        <xsd:element name="getAttractions">
          <xsd:complexType>
            <xsd:sequence>
              <xsd:element maxOccurs="unbounded" minOccurs="0" name="attname"
              type="xsd:string" />
            </xsd:sequence>
          </xsd:complexType>
        </xsd:element>
  
  Here is the generated getAttractions method:
    public test.wsdl.wrapped.Attraction[] getAttractions(java.lang.String[] attname)
      throws java.rmi.RemoteException;
  
  And here is what gets flowed over the wire:
       <getAttractions xmlns="urn:CityBBB">
         <attname>Christmas</attname>
         <attname>Xmas</attname>
       </getAttractions>
  
  PROBLEM:
  The deserialization of the message and invocation of getAttractions does not work.
  The deserialization of the return for this case also does not work.
  This support is required to pass the JAXRPC TCK.
  
  SOLUTION:
  
  1) Added the getAttractions operation to the wrapped test case (City_BBB.wsdl)
  
  2) Fixed a bug in the Skeleton generation code...needed to call setStyle(..) on
     each OperationDesc.
  
  3) Fixed a bug in the Stub generation code...needed to call setReturnType(xmlType, javaType)
     instead of setReturnType(xmlType) to get the appropriate return class set
     on the OperationDesc.
  
  4) Small change to Call.setReturnType(xmlType, javaType).  The return class was
     not being set on the OperationDesc correctly.
  
  5) Small change to RPCElement so that the operation is always considered if wrapped.
     Without this change no deserialization will take place for the
     example above (since numParms==2 and getNumInParms()==1).
  
  6) RPCHandler is changed to recognize the special collection qname that is
     used for elements with maxOccurs=unbounded.  The RPCParam value is deserialized
     as the proper component type.
  
     So for the example above:
             * two RPCParams will be created.
             * the values will be the deserialized as Strings.
             * both RPCParams will have the same qname and ParameterDesc.
  
  7) An RPCElement:combineParams method is added to combine the
     arguments of the same parameter into a container object
     described by the ParameterDesc.
  
  8) RPCProvider is changed to invoke combineParams before
     obtaining the list of arguments for dispatching.
  
  9) Call is changed to invoke combineParams before obtaining
     the list of return arguments.
  
  Revision  Changes    Path
  1.159     +4 -0      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.158
  retrieving revision 1.159
  diff -u -r1.158 -r1.159
  --- Call.java	10 Jul 2002 19:32:14 -0000	1.158
  +++ Call.java	18 Jul 2002 20:00:37 -0000	1.159
  @@ -873,6 +873,7 @@
       public void setReturnType(QName xmlType, Class javaType) {
           setReturnType(xmlType);
           returnJavaType = javaType;
  +        operation.setReturnClass(javaType);  // Use specified type as the operation return
       }
   
       /**
  @@ -1851,6 +1852,9 @@
           SOAPBodyElement bodyEl = resEnv.getFirstBody();
           if (bodyEl instanceof RPCElement) {
               try {
  +                // Combine the arguments for the same parameter 
  +                // and get the vector containing the result arguments.
  +                ((RPCElement) bodyEl).combineParams();
                   resArgs = ((RPCElement) bodyEl).getParams();
               } catch (Exception e) {
                   log.error(JavaUtils.getMessage("exception00"), e);
  
  
  
  1.65      +92 -1     xml-axis/java/src/org/apache/axis/message/RPCElement.java
  
  Index: RPCElement.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/message/RPCElement.java,v
  retrieving revision 1.64
  retrieving revision 1.65
  diff -u -r1.64 -r1.65
  --- RPCElement.java	21 Jun 2002 19:48:40 -0000	1.64
  +++ RPCElement.java	18 Jul 2002 20:00:37 -0000	1.65
  @@ -61,6 +61,7 @@
   import org.apache.axis.MessageContext;
   import org.apache.axis.description.OperationDesc;
   import org.apache.axis.description.ServiceDesc;
  +import org.apache.axis.description.ParameterDesc;
   import org.apache.axis.encoding.DeserializationContext;
   import org.apache.axis.encoding.SerializationContext;
   import org.apache.axis.enum.Style;
  @@ -73,6 +74,9 @@
   import javax.xml.namespace.QName;
   
   import java.util.Vector;
  +import java.util.ArrayList;
  +import java.lang.reflect.Array;
  +import java.util.Collection;
   
   public class RPCElement extends SOAPBodyElement
   {
  @@ -185,7 +189,20 @@
   
               for (int i = 0; i < operations.length; i++) {
                   OperationDesc operation = operations[i];
  -                if (operation.getNumInParams() >= numParams || elementIsFirstParam )
{
  +                if (operation.getNumInParams() >= numParams || 
  +                    elementIsFirstParam ||
  +                    operation.getStyle() == Style.WRAPPED) {
  +                    // If the Style is WRAPPED, the numParams may be inflated 
  +                    // as in the following case:
  +                    //  <getAttractions xmlns="urn:CityBBB">
  +                    //      <attname>Christmas</attname>
  +                    //      <attname>Xmas</attname>
  +                    //   </getAttractions>
  +                    //
  +                    //  for getAttractions(String[] attName)
  +                    //
  +                    // numParams will be 2 and and operation.getNumInParams=1
  +
                       // Set the operation so the RPCHandler can get at it
                       rpcHandler.setOperation(operation);
                       try {
  @@ -266,6 +283,80 @@
       {
           param.setRPCCall(this);
           params.addElement(param);
  +    }
  +
  +
  +    /**
  +     * Combines arguments associated with the same parameter
  +     * are combined into a single RPCParam.
  +     * Here is a specific example:
  +     *  <getAttractions xmlns="urn:CityBBB">
  +     *      <attname>Christmas</attname>
  +     *      <attname>Xmas</attname>
  +     *   </getAttractions>
  +     *
  +     *     for getAttractions(String[] attName)
  +     *
  +     * In the example, there will be two String for attName which
  +     * will be combined into one String[] argument
  +     */
  +    public void combineParams() throws Exception {
  +        getParams();  // ensure params are deserialized
  +
  +        for (int i=0; i<params.size(); i++) {
  +            RPCParam param = (RPCParam) params.elementAt(i);
  +            ParameterDesc parmDesc = param.getParamDesc();
  +            // See if the expected Type QName is 
  +            // a special collection QName like
  +            // "xsd:string[unbounded]"
  +            if (parmDesc != null &&
  +                parmDesc.getTypeQName() != null &&
  +                parmDesc.getTypeQName().
  +                getLocalPart().indexOf("[") > 0) {
  +
  +                // Count the number of params for the
  +                // same parameter
  +                int len = 1;
  +                for(int j=i+1; j<params.size(); j++) {
  +                    if (param.getQName().equals(
  +                     ((RPCParam)params.elementAt(j)).getQName())) {
  +                        len++;
  +                    } else {
  +                        break;
  +                    }
  +                }
  +
  +                // Create a container representing the 
  +                // expected parameter type and add the param's value
  +                Object container;
  +                Class containerClass = parmDesc.getJavaType();
  +
  +                if (containerClass.isArray()) {
  +                    container = 
  +                        Array.newInstance(containerClass.getComponentType(),
  +                                          len);
  +                    Array.set(container, 0, param.getValue());
  +                } else {
  +                    container = containerClass.newInstance();
  +                    ((Collection) container).add(param.getValue());
  +                }
  +
  +                // Replace the param value with the container
  +                param.setValue(container);
  +                
  +                // Add successive params to the container, and
  +                // remove the params from the original params vector.
  +                for (int j=1; j<len; j++) {
  +                    RPCParam nextParam = (RPCParam) params.elementAt(i+1);
  +                    if (containerClass.isArray()) {
  +                        Array.set(container, j, nextParam.getValue());
  +                    } else {
  +                        ((Collection) container).add(nextParam.getValue());
  +                    }
  +                    params.removeElementAt(i+1);
  +                }
  +            }
  +        }
       }
   
       protected void outputImpl(SerializationContext context) throws Exception
  
  
  
  1.53      +40 -4     xml-axis/java/src/org/apache/axis/message/RPCHandler.java
  
  Index: RPCHandler.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/message/RPCHandler.java,v
  retrieving revision 1.52
  retrieving revision 1.53
  diff -u -r1.52 -r1.53
  --- RPCHandler.java	10 Jul 2002 22:06:13 -0000	1.52
  +++ RPCHandler.java	18 Jul 2002 20:00:37 -0000	1.53
  @@ -145,6 +145,7 @@
           QName type = null;
           QName qname = new QName(namespace, localName);
           ParameterDesc paramDesc = null;
  +        boolean isCollection = false;
   
           Vector params = rpcElem.getParams();
           
  @@ -201,17 +202,52 @@
                   // (see RPCProvider.processMessage())
                   currentParam.setParamDesc(paramDesc);
   
  +                // It is possible that the type qname is "xsd:string"
  +                // and the paramDesc type is a collection of 
  +                // strings using a special axis qname ("xsd:string[unbounded]").
  +                // Here is a specific example:
  +                //  <getAttractions xmlns="urn:CityBBB">
  +                //      <attname>Christmas</attname>
  +                //      <attname>Xmas</attname>
  +                //   </getAttractions>
  +                //
  +                //  for getAttractions(String[] attName)
  +                //
  +                //  In the example, we are processing one of the <attname>
  +                //  children, so the type variable is set to the component
  +                //  type, and isCollection is turned on to 
  +                //  indicate collection processing.
  +                boolean haveXSIType = (type != null);
  +                if (paramDesc.getTypeQName() != null &&
  +                    paramDesc.getTypeQName().getLocalPart().indexOf("[") > 0) {
  +                    if (type==null) {
  +                        type = new QName(paramDesc.getTypeQName().
  +                                           getNamespaceURI(),
  +                                         paramDesc.getTypeQName().
  +                                           getLocalPart().
  +                                           substring(0,
  +                                                     paramDesc.getTypeQName().
  +                                                     getLocalPart().indexOf("[")));
  +                    }
  +                    isCollection = true;
  +                }
  +                
                   if (type == null) {
                       type = paramDesc.getTypeQName();
  -                } else if (paramDesc.getJavaType() != null) {
  +                } 
  +
  +                if (haveXSIType && paramDesc.getJavaType() != null) {
                       // If we have an xsi:type, make sure it makes sense
                       // with the current paramDesc type
                       Class xsiClass = 
                               context.getTypeMapping().getClassForQName(type);
  -                    if (!JavaUtils.isConvertable(xsiClass,
  -                                                 paramDesc.getJavaType())) {
  +                    Class destClass = paramDesc.getJavaType();
  +                    if (isCollection) {
  +                        destClass = destClass.getComponentType();
  +                    }
  +                    if (!JavaUtils.isConvertable(xsiClass, destClass)) {
                           throw new SAXException("Bad types (" +
  -                            xsiClass + " -> " + paramDesc.getJavaType() + ")"); // FIXME!
  +                            xsiClass + " -> " + destClass + ")"); // FIXME!
                       }
                   }
               }
  
  
  
  1.76      +3 -0      xml-axis/java/src/org/apache/axis/providers/java/RPCProvider.java
  
  Index: RPCProvider.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/providers/java/RPCProvider.java,v
  retrieving revision 1.75
  retrieving revision 1.76
  diff -u -r1.75 -r1.76
  --- RPCProvider.java	10 Jul 2002 22:06:13 -0000	1.75
  +++ RPCProvider.java	18 Jul 2002 20:00:38 -0000	1.76
  @@ -188,6 +188,9 @@
           }
   
           String methodName = body.getMethodName();
  +        // Combine the arguments for the same parameter and 
  +        // get the vector containing the arguments
  +        body.combineParams();
           Vector args = body.getParams();
           int numArgs = args.size();
   
  
  
  
  1.33      +10 -1     xml-axis/java/src/org/apache/axis/wsdl/toJava/JavaSkelWriter.java
  
  Index: JavaSkelWriter.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/wsdl/toJava/JavaSkelWriter.java,v
  retrieving revision 1.32
  retrieving revision 1.33
  diff -u -r1.32 -r1.33
  --- JavaSkelWriter.java	20 Jun 2002 20:35:47 -0000	1.32
  +++ JavaSkelWriter.java	18 Jul 2002 20:00:38 -0000	1.33
  @@ -207,7 +207,16 @@
                   pw.println("        _oper = new org.apache.axis.description.OperationDesc(\""
+
                               javaOpName + "\", _params, " + returnStr + ");");
   
  -
  +                if (isRPC) {
  +                    pw.println("        _oper.setStyle(org.apache.axis.enum.Style.RPC);");
  +                } else {
  +                    if (symbolTable.isWrapped()) { 
  +                        pw.println("        _oper.setStyle(org.apache.axis.enum.Style.WRAPPED);");
  +                    } else {
  +                        pw.println("        _oper.setStyle(org.apache.axis.enum.Style.DOCUMENT);");
  +                    }
  +                }
  +                
                   // If we need to know the QName (if we have a namespace or
                   // the actual method name doesn't match the XML we expect),
                   // record it in the OperationDesc
  
  
  
  1.75      +11 -2     xml-axis/java/src/org/apache/axis/wsdl/toJava/JavaStubWriter.java
  
  Index: JavaStubWriter.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/wsdl/toJava/JavaStubWriter.java,v
  retrieving revision 1.74
  retrieving revision 1.75
  diff -u -r1.74 -r1.75
  --- JavaStubWriter.java	8 Jul 2002 16:37:37 -0000	1.74
  +++ JavaStubWriter.java	18 Jul 2002 20:00:38 -0000	1.75
  @@ -518,19 +518,28 @@
           // set output type
           if (parms.returnType != null) {
               // We need to use the Qname of the actual type, not the QName of the element
  +            // Also get the corresponding javaType
               QName qn = parms.returnType.getQName();
  +            String javaType = parms.returnType.getName();
  +
               if (parms.returnType instanceof DefinedElement) {
                   TypeEntry type = ((DefinedElement) parms.returnType).getRefType();
                   if (type != null && type.getQName() != null) {
                       qn = type.getQName();
  +                    javaType = type.getName();
                   }
               }
    
               String outputType = "new javax.xml.namespace.QName(\"" +
                   qn.getNamespaceURI() + "\", \"" +
                   qn.getLocalPart() + "\")";
  -            pw.println("        call.setReturnType(" + 
  -                       outputType + ");");
  +            if (javaType == null) {
  +                pw.println("        call.setReturnType(" + 
  +                           outputType + ");");
  +            } else {
  +                pw.println("        call.setReturnType(" + 
  +                           outputType + "," + javaType + ".class);");
  +            }
           }
           else {
               pw.println("        call.setReturnType(org.apache.axis.encoding.XMLType.AXIS_VOID);");
  
  
  
  1.11      +2 -1      xml-axis/java/test/functional/TestJAXMSamples.java
  
  Index: TestJAXMSamples.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/test/functional/TestJAXMSamples.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- TestJAXMSamples.java	3 Jul 2002 18:47:07 -0000	1.10
  +++ TestJAXMSamples.java	18 Jul 2002 20:00:38 -0000	1.11
  @@ -85,7 +85,7 @@
               throw new Exception("Fault returned from test: " + t);
           }
       }
  -
  +    /*
       public void testUddiPing() throws Exception {
           try {
               log.info("Testing JAXM UddiPing sample.");
  @@ -111,6 +111,7 @@
               throw new Exception("Fault returned from test: " + t);
           }
       } // testGetQuote
  +    */
   
       public void testDelayedStockQuote() throws Exception {
           try {
  
  
  
  1.2       +42 -0     xml-axis/java/test/wsdl/wrapped/CityBBB.wsdl
  
  Index: CityBBB.wsdl
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/test/wsdl/wrapped/CityBBB.wsdl,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- CityBBB.wsdl	8 Mar 2002 17:22:13 -0000	1.1
  +++ CityBBB.wsdl	18 Jul 2002 20:00:38 -0000	1.2
  @@ -15,6 +15,15 @@
           </xsd:complexType>
         </xsd:element>
   
  +      <xsd:element name="getAttractions">
  +        <xsd:complexType>
  +          <xsd:sequence>
  +            <xsd:element maxOccurs="unbounded" minOccurs="0" name="attname"
  +            type="xsd:string" />
  +          </xsd:sequence>
  +        </xsd:complexType>
  +      </xsd:element>
  +
         <xsd:element name="getAttractionResponse">
           <xsd:complexType>
             <xsd:sequence>
  @@ -24,6 +33,15 @@
           </xsd:complexType>
         </xsd:element>
   
  +      <xsd:element name="getAttractionsResponse">
  +        <xsd:complexType>
  +          <xsd:sequence>
  +            <xsd:element maxOccurs="unbounded" minOccurs="0" name="_return"
  +            type="tns:Attraction" />
  +          </xsd:sequence>
  +        </xsd:complexType>
  +      </xsd:element>
  +
         <xsd:complexType name="Attraction">
           <xsd:sequence>
             <xsd:element maxOccurs="1" minOccurs="0" name="_OID"
  @@ -125,12 +143,25 @@
       <part element="tns:getAttractionResponse" name="parameters" />
     </message>
   
  +  <message name="getAttractionsIn">
  +    <part element="tns:getAttractions" name="parameters" />
  +  </message>
  +
  +  <message name="getAttractionsOut">
  +    <part element="tns:getAttractionsResponse" name="parameters" />
  +  </message>
  +
     <portType name="City_BBBPortType">
       <operation name="getAttraction">
         <input message="tns:getAttractionIn" />
   
         <output message="tns:getAttractionOut" />
       </operation>
  +    <operation name="getAttractions">
  +      <input message="tns:getAttractionsIn" />
  +
  +      <output message="tns:getAttractionsOut" />
  +    </operation>
     </portType>
   
     <binding name="City_BBBBinding" type="tns:City_BBBPortType">
  @@ -139,6 +170,17 @@
   
       <operation name="getAttraction">
         <soap:operation soapAction="getAttraction" />
  +
  +      <input>
  +        <soap:body use="literal" />
  +      </input>
  +
  +      <output>
  +        <soap:body use="literal" />
  +      </output>
  +    </operation>
  +    <operation name="getAttractions">
  +      <soap:operation soapAction="getAttractions" />
   
         <input>
           <soap:body use="literal" />
  
  
  
  1.2       +11 -0     xml-axis/java/test/wsdl/wrapped/City_BBBBindingImpl.java
  
  Index: City_BBBBindingImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/test/wsdl/wrapped/City_BBBBindingImpl.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- City_BBBBindingImpl.java	1 Jul 2002 19:37:53 -0000	1.1
  +++ City_BBBBindingImpl.java	18 Jul 2002 20:00:38 -0000	1.2
  @@ -46,4 +46,15 @@
                               " that fills that human heart with gladness. Merry Christmas
to ya, New Orleans style.");
           return attraction;
       }
  +
  +    public Attraction[] getAttractions(String[] attnames) throws java.rmi.RemoteException
{
  +        Attraction[] attractions = null;
  +        if (attnames != null) {
  +            attractions = new Attraction[attnames.length]; 
  +            for (int i=0; i < attnames.length; i++) {
  +                attractions[i] = getAttraction(attnames[i]);
  +            }
  +        }
  +        return attractions;
  +    }
   }
  
  
  
  1.2       +46 -0     xml-axis/java/test/wsdl/wrapped/City_BBBTestCase.java
  
  Index: City_BBBTestCase.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/test/wsdl/wrapped/City_BBBTestCase.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- City_BBBTestCase.java	1 Jul 2002 19:37:53 -0000	1.1
  +++ City_BBBTestCase.java	18 Jul 2002 20:00:38 -0000	1.2
  @@ -30,5 +30,51 @@
               throw new junit.framework.AssertionFailedError("Remote Exception caught: "
+ re);
           }
       }
  +
  +    public void test2CityBBBPortGetAttractions() {
  +        City_BBBBinding binding;
  +        try {
  +            binding = new City_BBBLocator().getCity_BBBPort();
  +        }
  +        catch (javax.xml.rpc.ServiceException jre) {
  +            throw new junit.framework.AssertionFailedError("JAX-RPC ServiceException caught:
" + jre);
  +        }
  +        assertTrue("binding is null", binding != null);
  +
  +        try {
  +            // Invoke getAttractions with two inputs
  +            String[] attName = new String[] {"Christmas", "Xmas"};
  +            Attraction[] value = binding.getAttractions(attName);
  +            assertEquals("OID value was wrong for first attraction", value[0].get_OID(),
  +                         City_BBBBindingImpl.OID_STRING);
  +            assertEquals("OID value was wrong for second attaction", value[1].get_OID(),
  +                         City_BBBBindingImpl.OID_STRING);
  +        }
  +        catch (java.rmi.RemoteException re) {
  +            throw new junit.framework.AssertionFailedError("Remote Exception caught: "
+ re);
  +        }
  +    }
  +
  +    public void test3CityBBBPortGetAttractions() {
  +        City_BBBBinding binding;
  +        try {
  +            binding = new City_BBBLocator().getCity_BBBPort();
  +        }
  +        catch (javax.xml.rpc.ServiceException jre) {
  +            throw new junit.framework.AssertionFailedError("JAX-RPC ServiceException caught:
" + jre);
  +        }
  +        assertTrue("binding is null", binding != null);
  +
  +        try {
  +            // Invoke getAttractions with one input
  +            String[] attName = new String[] {"Christmas"};
  +            Attraction[] value = binding.getAttractions(attName);
  +            assertEquals("OID value was wrong for first attraction", value[0].get_OID(),
  +                         City_BBBBindingImpl.OID_STRING);
  +        }
  +        catch (java.rmi.RemoteException re) {
  +            throw new junit.framework.AssertionFailedError("Remote Exception caught: "
+ re);
  +        }
  +    }
   }
   
  
  
  

Mime
View raw message