[ 
https://issues.apache.org/jira/browse/AXIS2C-551?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12482642
 ] 

Milinda Lakmal Pathirage commented on AXIS2C-551:
-------------------------------------------------

The above suggestion will fix the bug. I think we have done some mistakes when 
checking the text_value.
Consider the following example coplex type:

 <s:complexType name="AllComplexType">
          <s:all>
            <s:element minOccurs="0" name="IntValue" type="s:int" />
            <s:element minOccurs="0" name="StringValue" type="s:string" />
          </s:all>
 </s:complexType>


When minOccurs=0 the set function of parameter IntValue will be like this:

axis2_status_t AXIS2_CALL
            axis2_AllComplexType_set_IntValue(
                    axis2_AllComplexType_t* AllComplexType,
                    const axis2_env_t *env,
                    int  param_IntValue)
             {
                

                AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
                if(!AllComplexType)
                {
                    return AXIS2_FAILURE;
                }

                AllComplexType-> attrib_IntValue = param_IntValue;
                return AXIS2_SUCCESS;
}

Inside set method we didn't check for null.

For the following type:

<xs:complexType name="AddressType">

                                <xs:all>

                                        <xs:element name="StreetNum" 
type="xs:int"/>

                                        <xs:element name="PhoneNumber" 
type="PhoneType"/>

                                
</xs:all>

</xs:complexType>

set function of PhoneNumber will look like this:

axis2_status_t AXIS2_CALL
            axis2_AddressType_set_PhoneNumber(
                    axis2_AddressType_t* AddressType,
                    const axis2_env_t *env,
                    axis2_PhoneType_t*  param_PhoneNumber)
{
                axis2_AddressType_impl_t *AddressType_impl = NULL;
                

                AXIS2_ENV_CHECK(env, AXIS2_FAILURE);

                AddressType_impl = AXIS2_INTF_TO_IMPL(AddressType);

                
                  if( NULL == param_PhoneNumber )
                  {
                      AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "PhoneNumber is 
NULL, but not a nullable element"
                                                 " %d :: %s", 
env->error->error_number,
                                                 
AXIS2_ERROR_GET_MESSAGE(env->error));
                      return AXIS2_FAILURE;
                  }
                AddressType_impl-> attrib_PhoneNumber = param_PhoneNumber;
                return AXIS2_SUCCESS;
}

And there is some problems with default types set methods when minOccurs are 
not zero.

I think we can drop the null check in the deserialization code and include is 
inside the set method will be a better solution. Then we can check if the 
parameter is compulsory or optional inside the set method according to the type 
definition. 
 

> WSDL2C: generated code does not handle optional elements
> --------------------------------------------------------
>
>                 Key: AXIS2C-551
>                 URL: https://issues.apache.org/jira/browse/AXIS2C-551
>             Project: Axis2-C
>          Issue Type: Bug
>          Components: code generation
>    Affects Versions: Current (Nightly)
>         Environment: Windows XP
>            Reporter: Dave Meier
>
> With an optional element specified in the WSDL, the generated code returns an 
> error if the element is not provided.  In the following WSDL I have an 
> optional element called "name".
> ----------
> WSDL:
> ----------
> <?xml version="1.0" encoding="UTF-8"?>
> <definitions name="test"
>  targetNamespace="http://localhost:80/gsoap/test.wsdl";
>  xmlns:tns="http://localhost:80/gsoap/test.wsdl";
>  xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/";
>  xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/";
>  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
>  xmlns:xsd="http://www.w3.org/2001/XMLSchema";
>  xmlns:c14n="http://www.w3.org/2001/10/xml-exc-c14n#";
>  
> xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd";
>  xmlns:ds="http://www.w3.org/2000/09/xmldsig#";
>  
> xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd";
>  xmlns:tt="urn:test"
>  xmlns:SOAP="http://schemas.xmlsoap.org/wsdl/soap/";
>  xmlns:MIME="http://schemas.xmlsoap.org/wsdl/mime/";
>  xmlns:DIME="http://schemas.xmlsoap.org/ws/2002/04/dime/wsdl/";
>  xmlns:WSDL="http://schemas.xmlsoap.org/wsdl/";
>  xmlns="http://schemas.xmlsoap.org/wsdl/";>
> <types>
>  <schema targetNamespace="urn:test"
>   xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/";
>   xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/";
>   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
>   xmlns:xsd="http://www.w3.org/2001/XMLSchema";
>   xmlns:c14n="http://www.w3.org/2001/10/xml-exc-c14n#";
>   
> xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd";
>   xmlns:ds="http://www.w3.org/2000/09/xmldsig#";
>   
> xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd";
>   xmlns:tt="urn:test"
>   xmlns="http://www.w3.org/2001/XMLSchema";
>   elementFormDefault="qualified"
>   attributeFormDefault="qualified">
>   <import namespace="http://www.w3.org/2001/10/xml-exc-c14n#"/>
>   <import 
> namespace="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"/>
>   <import namespace="http://www.w3.org/2000/09/xmldsig#"/>
>   <import 
> namespace="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"/>
>   <import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
>   <simpleType name="Attachment-Access-Type">
>    <restriction base="xsd:string">
>     <enumeration value="ATTACHACCESS-DEFAULT"/>
>     <enumeration value="ATTACHACCESS-RESTRICTED"/>
>     <enumeration value="ATTACHACCESS-UNRESTRICTED"/>
>    </restriction>
>   </simpleType>
>   <!-- operation request element -->
>   <element name="SetAccess">
>    <complexType>
>     <sequence>
>      <element name="name" type="xsd:string" minOccurs="0" maxOccurs="1" 
> nillable="true"/>
>      <element name="activeInactive" type="xsd:boolean" minOccurs="1" 
> maxOccurs="1"/>
>     </sequence>
>    </complexType>
>   </element>
>   <!-- operation response element -->
>   <element name="SetAccessResponse">
>    <complexType>
>     <sequence>
>     </sequence>
>    </complexType>
>   </element>
>  </schema>
> </types>
> <message name="SetAccess">
>  <part name="parameters" element="tt:SetAccess"/>
> </message>
> <message name="SetAccessResponse">
>  <part name="parameters" element="tt:SetAccessResponse"/>
> </message>
> <portType name="testPortType">
>  <operation name="SetAccess">
>   <documentation>SetAccess</documentation>
>   <input message="tns:SetAccess"/>
>   <output message="tns:SetAccessResponse"/>
>  </operation>
> </portType>
> <binding name="test" type="tns:testPortType">
>  <SOAP:binding style="document" 
> transport="http://schemas.xmlsoap.org/soap/http"/>
>  <operation name="SetAccess">
>   <SOAP:operation soapAction=""/>
>   <input>
>      <SOAP:body parts="parameters" use="literal"/>
>   </input>
>   <output>
>      <SOAP:body parts="parameters" use="literal"/>
>   </output>
>  </operation>
> </binding>
> <service name="test">
>  <documentation>gSOAP 2.7.6e generated service definition</documentation>
>  <port name="test" binding="tns:test">
>   <SOAP:address location="http://localhost:80/gsoap/gsoap_ssl.dll?test"/>
>  </port>
> </service>
> </definitions>
> ------------------------
> Generated Code:
> ------------------------
> current_element = AXIOM_NODE_GET_DATA_ELEMENT( current_node, env);
> text_value = AXIOM_ELEMENT_GET_TEXT(current_element, env, current_node );
> if ( NULL == text_value )
> {
>   status = AXIS2_FAILURE;
> }
> else
> {
>   status = AXIS2_SETACCESS_SET_NAME( SetAccess, env,
>                                                                    
> text_value);
> }
> --------------------------
> Recommendation:
> --------------------------
> Do not check if the value is NULL.  Instead, just set it.  It's okay to set 
> the value to NULL in the structure.  Right now, the data is not filled in 
> because of the error being returned, so everything fails.  Should generated 
> this code instead:
> current_element = AXIOM_NODE_GET_DATA_ELEMENT( current_node, env);
> text_value = AXIOM_ELEMENT_GET_TEXT(current_element, env, current_node );
> status = AXIS2_SETACCESS_SET_NAME( SetAccess, env,
>                                                                    
> text_value);

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to