WSDL with type int or blank is not readable by stubs generated by wsdl2java

I have created a simple type

   <xsd:simpleType name="IntOrBlank">
            <xsd:union memberTypes="xsd:int">
                <xsd:simpleType>
                    <xsd:restriction base="xsd:string">
                        <xsd:enumeration value=""/>
                    </xsd:restriction>
                </xsd:simpleType>
            </xsd:union>
        </xsd:simpleType>

I then create stubs using wsdl2java from axis2, the sending works and receiving seemed to work until I try to obtain the integer value from this type. My code is as such:

IntOrBlank get_part_custom_field7 = each_record[0].get_part_custom_field7(); Object object = get_part_custom_field7.getObject();

The object is null now. eventhough the SOAP message is coming in as

   <bm:_part_custom_field7>9</bm:_part_custom_field7>

Answers


I trace through the code and I found that wsdl2java has generated the stubs incorrectly. The object that was created was java.math.BigInteger while the stubs did a check to make sure the object is an instance of Integer, as a result, the object is null without throwing any exception. I changed the type to

  <xsd:simpleType name="IntOrBlank">
        <xsd:union memberTypes="xsd:integer">
            <xsd:simpleType>
                <xsd:restriction base="xsd:string">
                    <xsd:enumeration value=""/>
                </xsd:restriction>
            </xsd:simpleType>
        </xsd:union>
    </xsd:simpleType>

and solved the problem


I'd suggest you stop using union that way, maybe not at all.

You've just found one tool that doesn't deal with it the way you'd like - there will be many others. union doesn't really make much sense in this context. What Java type should be used in this case? Object?

What about in this case:

  <xs:simpleType name="SillyUnion">
    <xs:union memberTypes="xs:int xs:string"/>
  </xs:simpleType>

What data type would you have wsdl2java use for this? Object again? How would a programmer consuming this data determine whether integer or string data had been included? Do you really mean that everyone using this data should check first?

Union is one of those things that sounded like a good idea at the time, and which has turned out not to be as helpful as was previously thought.


Need Your Help

C# Show Dialog threading

c# multithreading dialog showdialog

I have a Dialog Box (Importer) which i use for choosing a file I want to import into an app. This Dialog Box (Importer) also has another Dialog Box (File) which is an OpenFileDialog.

Problems with web.xml

primefaces tomcat7 web.xml jdbcrealm

first of all i want to apologize for my bad English. Ok, i have a problem. I am building application that uses jdbcrealm and web.xml for security. Login is done by web form. Application is running on