[ https://issues.apache.org/jira/browse/AXIS2-4369?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Marc Gosselin updated AXIS2-4369: --------------------------------- Description: This issue is close (yet different I believe) to AXIS2-4319, AXIS2-4177, and AXIS2-2391. WSDL2Java (and the code it uses) generates a stub code which throws an ADBException "Unexpected subelement" if a complex type defined in a WSDL with minOccurs="0" and maxOccurs="unbound" is missing in the SOAP reply received. This does not happen if maxOccurs is not defined. For instance, the following partial WSDL definition: <xs:complexType name="Address"> <xs:sequence> <xs:element name="Descriptions" type="ns:Description" minOccurs="0 " maxOccurs="unbounded"></xs:element> <xs:element name="Remarks" type="xs:string" minOccurs="0"></xs:element> </xs:sequence> </xs:complexType> will lead WSDL2Java to generate the following [truncatded] code: while (!reader.isStartElement() && !reader.isEndElement()) reader.next(); if (reader.isStartElement() && new javax.xml.namespace.QName("http://XXXREMOVEDXXX","Descriptions").equals(reader.getName())){ // Process the array and step past its final element's end. list1.add(Description.Factory.parse(reader)); //loop until we find a start element that is not part of this array boolean loopDone1 = false; while(!loopDone1){ // We should be at the end element, but make sure while (!reader.isEndElement()) reader.next(); // Step out of this element reader.next(); // Step to next element event. while (!reader.isStartElement() && !reader.isEndElement()) reader.next(); if (reader.isEndElement()){ //two continuous end elements means we are exiting the xml structure loopDone1 = true; } else { if (new javax.xml.namespace.QName("http://XXXREMOVEDXXX","Descriptions").equals(reader.getName())){ list1.add(IvrLocationDescription.Factory.parse(reader)); }else{ loopDone1 = true; } } } // call the converter utility to convert and set the array object.setDescriptions((Description[])org.apache.axis2.databinding.utils.ConverterUtil.convertToArray(Description.class, list1)); } // End of if for expected property start element else{ // A start element we are not expecting indicates an invalid parameter was passed throw new org.apache.axis2.databinding.ADBException("Unexpected subelement " + reader.getLocalName()); // !!!!! THE PREVIOUS LINE SHOULD NOT BE PRESENT - THIS IS THE SOURCE OF THE PROBLEM !!! } while (!reader.isStartElement() && !reader.isEndElement()) reader.next(); if (reader.isStartElement() && new javax.xml.namespace.QName("http://XXXREMOVEDXXX","Remarks").equals(reader.getName())){ java.lang.String content = reader.getElementText(); object.setRemarks(org.apache.axis2.databinding.utils.ConverterUtil.convertToString(content)); reader.next(); } // End of if for expected property start element else { /// !!! THIS IS CORRECT - NO EXCEPTION SHOULD BE THROWN IF THIS OPTIONAL VALUE IS MISSING !!! } I've marked in the code above (with exclamation marks "!!!") the incorrect throw statement added by WSDL2Java. Such statement is not present if maxOccurs is not defined, which is correct (2nd part of the code). The problem affects only the reply parsing code - the request generation code seems correct. It even explicitly mentions: if (localRemarks!=null){ for (int i = 0;i < localRemarks.length;i++){ if (localRemarks[i] != null){ localRemarks[i].serialize(new javax.xml.namespace.QName("http://XXXREMOVEDXXX","Remarks"), factory,xmlWriter); } else { // we don't have to do any thing since minOccures is zero } was: This issue is close (yet different I believe) to AXIS2-4319, AXIS-4177, and AXIS2-2391. WSDL2Java (and the code it uses) generates a stub code which throws an ADBException "Unexpected subelement" if a value defined in a WSDL with minOccurs="0" and maxOccurs="unbound" is missing in the SOAP reply received. This does not happen if maxOccurs is not defined. For instance, the following partial WSDL definition: <xs:complexType name="Address"> <xs:sequence> <xs:element name="Descriptions" type="ns:Description" minOccurs="0 " maxOccurs="unbounded"></xs:element> <xs:element name="Remarks" type="xs:string" minOccurs="0"></xs:element> </xs:sequence> </xs:complexType> will lead WSDL2Java to generate the following [truncatded] code: while (!reader.isStartElement() && !reader.isEndElement()) reader.next(); if (reader.isStartElement() && new javax.xml.namespace.QName("http://XXXREMOVEDXXX","Descriptions").equals(reader.getName())){ // Process the array and step past its final element's end. list1.add(Description.Factory.parse(reader)); //loop until we find a start element that is not part of this array boolean loopDone1 = false; while(!loopDone1){ // We should be at the end element, but make sure while (!reader.isEndElement()) reader.next(); // Step out of this element reader.next(); // Step to next element event. while (!reader.isStartElement() && !reader.isEndElement()) reader.next(); if (reader.isEndElement()){ //two continuous end elements means we are exiting the xml structure loopDone1 = true; } else { if (new javax.xml.namespace.QName("http://XXXREMOVEDXXX","Descriptions").equals(reader.getName())){ list1.add(IvrLocationDescription.Factory.parse(reader)); }else{ loopDone1 = true; } } } // call the converter utility to convert and set the array object.setDescriptions((Description[])org.apache.axis2.databinding.utils.ConverterUtil.convertToArray(Description.class, list1)); } // End of if for expected property start element else{ // A start element we are not expecting indicates an invalid parameter was passed throw new org.apache.axis2.databinding.ADBException("Unexpected subelement " + reader.getLocalName()); // !!!!! THE PREVIOUS LINE SHOULD NOT BE PRESENT - THIS IS THE SOURCE OF THE PROBLEM !!! } while (!reader.isStartElement() && !reader.isEndElement()) reader.next(); if (reader.isStartElement() && new javax.xml.namespace.QName("http://XXXREMOVEDXXX","Remarks").equals(reader.getName())){ java.lang.String content = reader.getElementText(); object.setRemarks(org.apache.axis2.databinding.utils.ConverterUtil.convertToString(content)); reader.next(); } // End of if for expected property start element else { /// !!! THIS IS CORRECT - NO EXCEPTION SHOULD BE THROWN IF THIS OPTIONAL VALUE IS MISSING !!! } I've marked in the code above (with exclamation marks "!!!") the incorrect throw statement added by WSDL2Java. Such statement is not present if maxOccurs is not defined, which is correct (2nd part of the code). > WSDL2Java ignores minOccurs="0" in sequence with maxOccurs="unbound" > -------------------------------------------------------------------- > > Key: AXIS2-4369 > URL: https://issues.apache.org/jira/browse/AXIS2-4369 > Project: Axis 2.0 (Axis2) > Issue Type: Bug > Components: databinding > Affects Versions: 1.5 > Environment: Axis2 1.5 > Java 1.6.0_05 > NetBeans 6.1 (Build 2008053000101) > Windows Vista SP1 > Reporter: Marc Gosselin > > This issue is close (yet different I believe) to AXIS2-4319, AXIS2-4177, and > AXIS2-2391. > WSDL2Java (and the code it uses) generates a stub code which throws an > ADBException "Unexpected subelement" if a complex type defined in a WSDL with > minOccurs="0" and maxOccurs="unbound" is missing in the SOAP reply received. > This does not happen if maxOccurs is not defined. > For instance, the following partial WSDL definition: > <xs:complexType name="Address"> > <xs:sequence> > <xs:element name="Descriptions" type="ns:Description" minOccurs="0 " > maxOccurs="unbounded"></xs:element> > <xs:element name="Remarks" type="xs:string" minOccurs="0"></xs:element> > </xs:sequence> > </xs:complexType> > will lead WSDL2Java to generate the following [truncatded] code: > while (!reader.isStartElement() && !reader.isEndElement()) reader.next(); > if (reader.isStartElement() && new > javax.xml.namespace.QName("http://XXXREMOVEDXXX","Descriptions").equals(reader.getName())){ > // Process the array and step past its final element's end. > list1.add(Description.Factory.parse(reader)); > //loop until we find a start element that is not part of this array > boolean loopDone1 = false; > while(!loopDone1){ > // We should be at the end element, but make sure > while (!reader.isEndElement()) > reader.next(); > // Step out of this element > reader.next(); > // Step to next element event. > while (!reader.isStartElement() && !reader.isEndElement()) > reader.next(); > if (reader.isEndElement()){ > //two continuous end elements means we are exiting the xml structure > loopDone1 = true; > } else { > if (new > javax.xml.namespace.QName("http://XXXREMOVEDXXX","Descriptions").equals(reader.getName())){ > list1.add(IvrLocationDescription.Factory.parse(reader)); > }else{ > loopDone1 = true; > } > } > } > // call the converter utility to convert and set the array > > object.setDescriptions((Description[])org.apache.axis2.databinding.utils.ConverterUtil.convertToArray(Description.class, > list1)); > } // End of if for expected property start element > else{ > // A start element we are not expecting indicates an invalid parameter > was passed > throw new org.apache.axis2.databinding.ADBException("Unexpected subelement > " + reader.getLocalName()); > // !!!!! THE PREVIOUS LINE SHOULD NOT BE PRESENT - THIS IS THE SOURCE OF > THE PROBLEM !!! > } > > while (!reader.isStartElement() && !reader.isEndElement()) reader.next(); > if (reader.isStartElement() && new > javax.xml.namespace.QName("http://XXXREMOVEDXXX","Remarks").equals(reader.getName())){ > java.lang.String content = reader.getElementText(); > object.setRemarks(org.apache.axis2.databinding.utils.ConverterUtil.convertToString(content)); > reader.next(); > } // End of if for expected property start element > else { > /// !!! THIS IS CORRECT - NO EXCEPTION SHOULD BE THROWN IF THIS OPTIONAL > VALUE IS MISSING !!! > } > I've marked in the code above (with exclamation marks "!!!") the incorrect > throw statement added by WSDL2Java. Such statement is not present if > maxOccurs is not defined, which is correct (2nd part of the code). > The problem affects only the reply parsing code - the request generation code > seems correct. It even explicitly mentions: > if (localRemarks!=null){ > for (int i = 0;i < > localRemarks.length;i++){ > if (localRemarks[i] != null){ > > localRemarks[i].serialize(new > javax.xml.namespace.QName("http://XXXREMOVEDXXX","Remarks"), > factory,xmlWriter); > } else { > > // we don't have to > do any thing since minOccures is zero > > } -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.