wsimport bind xsd:int to Integer instead of int - java

Ok. The title really says it all.
I have a extremely large SOAP server I'm calling in a java application. To make my life easier I've been using wsimport to generate the source and jar for the service. I just ran into a problem. All the xsd:int types in the wsdl are being parsed as int types in the java code when I need them as Integer types. Reason for this is some of the int's i need to set as null, but since int types can't be null I can't do that.
I am currently going through and hand changing the fields, but I want to know if there is a easier way to do it through a agrument to the wsimport command
Here is my current wsimport command. Thanks
wsimport.exe -d E:\ServiceWSBuild -p com.example.wsdl -s E:\Service\src -verbose http://wsdl.example.com/?wsdl
Here is also a example of one of the custom types that does this:
<xsd:complexType name="SubPackageSell">
<xsd:complexContent>
<xsd:extension base="tns:APIObject">
<xsd:sequence>
<xsd:element name="sp" type="tns:SubPackage"/>
<xsd:element name="value" type="xsd:int"/>
<xsd:element name="days" type="xsd:int"/>
<xsd:element name="date" type="xsd:string"/>
<xsd:element name="combine" type="xsd:boolean"/>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>

For elements, specify minOccurs="0" and wsimport should generate a java.lang.Integer instead of a primitive int. The default values for minOccurs and maxOccurs is 1, which is why you are getting primitive ints. For example:
<xsd:element name="value" type="xsd:int" minOccurs="0"/>

Related

How to generate case sensitive fields in java from wsdl using cxf-codegen-plugin?

I'm using cxf-codegen-plugin and try to generate java from wsdl.
In my xsd schema I have following element
<xsd:element name="SomeElement">
<xsd:complexType>
<xsd:attribute name="version" type="xsd:string" use="optional">
</xsd:attribute>
<xsd:attribute name="Version" type="xsd:string" use="optional">
</xsd:attribute>
</xsd:complexType>
</xsd:element>
CXF tries to generate both attributes into field version and throws exception that property already exists.
Is there any way to generate properties as they described in XML? e.g.
protected String version;
protected String Version;
I know, that I can define binding and rename one of the properties, but I have ~100 wsdl, so I don't want write bindings for each file.
I also tried to add -autoNameResolution argument, but it didn't help.

SOA model Schema parsing error for complex types

The schema parser is able to parse the ComplexTypes of form:
<xsd:complexType name="PersonType">
<xsd:sequence>
<xsd:element name="id" type="xsd:string"/>
<xsd:element name="firstName" type="xsd:string" />
<xsd:element name="lastName" type="xsd:string" />
<xsd:element name="address" type="tns:AddressType"/>
</xsd:sequence>
</xsd:complexType>
But it is not able to parse the ComplexTypes of form:
<xsd:element name="PersonType">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="id" type="xsd:string"/>
<xsd:element name="firstName" type="xsd:string" />
<xsd:element name="lastName" type="xsd:string" />
<xsd:element name="address" type="tns:AddressType"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
In the later form it considers "PersonType" to be just an Element and not ComplexType. Hence the elements included in it are not parsed at all. Does anyone have a solution for this ?
I ran into the same problem today so I thought to see what SOAP-UI has to say about this when providing the wsdl file that has similar contents as the second image,
it showed them as Anonymous Complex Types yet have no solution for them, one thought can be to use the elements separately outside complexType tags.
Also anonymous types are not preferred. Probably the below link can help :
https://www.ibm.com/developerworks/library/ws-avoid-anonymous-types/ws-avoid-anonymous-types-pdf.pdf

SOAP via jax-ws: entity classes missing in schema

So, I have a soap server-side project. Annotations - #WebService over interface and implementation, #WebMethod over interface' methods, #XmlRootElement over entity-classes that are in return and arguments in web-methods, and #XmlElement over their fields(over getters actually). Tried also partially and fully swap #XmlRootElement with #XmlType, and #XmlElement with #XmlAttribute.
Project is launched via publisher class or via Tomcat(WSServletContextListener), everything's working after weeks of trial and error. In WSDL schema, for instance:
<xsd:element name="Sell_i">
<xsd:complexType>
<xsd:sequence>
<xsd:element minOccurs="0" name="session" nillable="true" type="xsd:string"/>
<xsd:element minOccurs="0" name="terminal" nillable="true" type="xsd:string"/>
<xsd:element minOccurs="0" name="info" nillable="true" type="tns:TransactionSellInfo"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
Represents the Sell_i method. TransactionSellInfo is an input argument here, and tns points to this namespace aka this wsdl. So, it should be described here. It of course has all the annonations. But, it's just missing, as well as every other class. What's the solution?
Worth noting: schema type is RPC(tho changing to Document doesn't cause classes to appear in wsdl). Also, on the same machine wsimport from wsdl creates classes for those missing entities, which is very wierd(didn't test wsimport on other machines tho). But soapUI won't work with that wsdl and rightfully says that it's malformed.
Maybe it's something quite basic that I'm missing, but google gives nothing useful on all my tries. Any help is appreciated!

some noob wsdl questions

<xsd:element name="loginResponse">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="loginReturn" type="tns:test"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:complexType name="test">
<xsd:sequence>
<xsd:element minOccurs="0" maxOccurs="1" name="tx" type="xsd:int"/>
<xsd:element minOccurs="0" maxOccurs="1" name="result" type="xsd:int"/>
<xsd:element minOccurs="0" maxOccurs="1" name="name_space" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
I just want to ask why is the type tns:test used? How can I get the tx, result, namespace values in complextype name="test", because that's the response should I get based on the api they given to me.
tns is the target namespace prefix, which should be defined at the top of your WSDL or XSD file (which includes test).
You didn't wrote how you do access the values, but I assume that your code is working in a different namespace, so that test cannot be indentified. Most likely there is a method which allows you to get values by element name and namespace. Note that in that case, the namespace isn't tns but rather the URL which is defined at top of source file.
If you're not familiar with namespaces: Each XML element is associated with a namespace, like a class in Java is part of a package. In XML there is no import statement, so you have to name an element by name and namespace. To keep the files readable you can define namespace prefixes (probably as an abbreviation).

How to create a generic XSD type

I have a java application where i can map a XSD type to another with same type. Now i have requirement to have one anyType xsd to which i can map any type. Like as we have Object type in java, is it possible to create like in XSD.
Edit: At complex type level is it possible.
Yes, it's possible. The type is xsd:anyType. Here's an example:
<xsd:element name="anything" type="xsd:anyType"/>
(Taken from the primer)
Here's a more complex example:
<xsd:complexType>
<xsd:complexContent>
<xsd:restriction base="xsd:anyType">
<xsd:attribute name="currency" type="xsd:string"/>
<xsd:attribute name="value" type="xsd:decimal"/>
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>
(From the primer as well - it's worth looking at at it)
You could use the xs:any element - this allows you to have a section of you schema that can contain any arbitrary XML.

Categories