Uploaded image for project: 'Axis2'
  1. Axis2
  2. AXIS2-5758

wsdl2java: nillable = "true" is ignored

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.7.1
    • Fix Version/s: 1.7.2
    • Component/s: adb
    • Labels:
      None

      Description

      I tried to create a java client with wsdl2java. With version 1.7.0 and older ones everything is fine. But since version 1.7.1 the nillable="true" attribute is ignored. Here is a small example wsdl:

         <definitions name="StockQuote" 
                targetNamespace="http://example.com/stockquote.wsdl"
                xmlns:tns="http://example.com/stockquote.wsdl"
                xmlns:xsd1="http://example.com/stockquote.xsd"
                xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
                xmlns="http://schemas.xmlsoap.org/wsdl/">
       
          <types>
             <schema targetNamespace="http://example.com/stockquote.xsd"
                    xmlns="http://www.w3.org/2001/XMLSchema">
                 <element name="TradePriceRequest">
                    <complexType>
                        <all>
                            <element name="tickerSymbol" nillable="true" type="string"/>
                        </all>
                    </complexType>
                 </element>
                 <element name="TradePrice">
                    <complexType>
                        <all>
                            <element name="price" nillable="true" type="float"/>
                        </all>
                    </complexType>
                 </element>
             </schema>
          </types>
       
          <message name="GetLastTradePriceInput">
              <part name="body" element="xsd1:TradePriceRequest"/>
          </message>
       
          <message name="GetLastTradePriceOutput">
              <part name="body" element="xsd1:TradePrice"/>
          </message>
       
          <portType name="StockQuotePortType">
              <operation name="GetLastTradePrice">
                 <input message="tns:GetLastTradePriceInput"/>
                 <output message="tns:GetLastTradePriceOutput"/>
              </operation>
          </portType>
       
          <binding name="StockQuoteSoapBinding" type="tns:StockQuotePortType">
              <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
              <operation name="GetLastTradePrice">
                 <soap:operation soapAction="http://example.com/GetLastTradePrice"/>
                 <input>
                     <soap:body use="literal"/>
                 </input>
                 <output>
                     <soap:body use="literal"/>
                 </output>
              </operation>
          </binding>
       
          <service name="StockQuoteService">
              <documentation>My first service</documentation>
              <port name="StockQuotePort" binding="tns:StockQuoteSoapBinding">
                 <soap:address location="http://example.com/stockquote"/>
              </port>
          </service>
       
       </definitions>
      

      For creating the client I use the -u option. The problem appears in the Factory's parse method for the defined types. For example for TradePrice.java from the given wsdl above:

      Genereated code from version 1.7.0 (snippet from Factory parse method):

      TradePrice.java
      if (!"true".equals(nillableValue) &&
              !"1".equals(nillableValue)) {
          java.lang.String content = reader.getElementText();
      
                   object.setPrice(org.apache.axis2.databinding.utils.ConverterUtil.convertToFloat(
                  content));
      } else {
          object.setPrice(java.lang.Float.NaN);
      
          reader.getElementText(); // throw away text nodes if any.
      }
      

      Genereated code from version 1.7.1 (snippet from Factory parse method):

      TradePrice.java
      if ("true".equals(nillableValue) ||
          "1".equals(nillableValue)) {
          throw new org.apache.axis2.databinding.ADBException(
              "The element: " + "price" +
              "  cannot be null");
      }
      
      java.lang.String content = reader.getElementText();
      
      object.setPrice(org.apache.axis2.databinding.utils.ConverterUtil.convertToFloat(
          content));
      

      So as you can see, in 1.7.1 the price element is handled as a non nillable value although it is nillable. So if the server sends a repsonse with price = null the client will throw an exception although everything is fine...

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              Moorhuhnfreak Philemon Schucker
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: