Arrays wrapped in a complex type are expanded in Java code (Axis 1.4)

WSDL is as follows:

<xsd:element name="Parent"> <xsd:complexType> <xsd:sequence> <xsd:element maxOccurs="unbounded" ref="tns:Child"/> </xsd:sequence> </xsd:complexType> </xsd:element> 

Expected Behavior

If I pass Axis 1.4 WSDL-based Java code, I expect the following field in my object:

 public class MyComplexObject { private Parent parent; } 

The Parent class will consist of an array of Child objects.

 public class Parent { private Child[] child; } 

Actual behavior

The actual behavior is that the list of Child objects is defined directly at the parent object level:

 public class MyComplexObject { private Child[] parent; } 

When we call webservice, filling the array, it will result in the following XML:

 <Parent> ... </Parent> <Parent> ... </Parent> 

causes server-side failures. Axis seems to be having difficulty with nested arrays of complex types. Anyone who encounters the same problem and knows any workarounds / fixes?

conclusions

After some research, I was able to produce the expected behavior by adding a dummy field to the XSD definition:

 <xsd:element name="Parent"> <xsd:complexType> <xsd:sequence> <xsd:element name="Dummy" type="xsd:string"/> <xsd:element maxOccurs="unbounded" ref="tns:Child"/> </xsd:sequence> </xsd:complexType> </xsd:element> 

It seems that in this case, Axis creates the Parent wrapper object correctly:

 public class Parent { private String dummy; private Child[] child; } 

And my XML output is correct:

 <Parent> <Dummy>...</Dummy> <Child>...</Child> <Child>...</Child> </Parent> 

So it seems that this is really a bug in Axis 1.4 ...

+4
source share
2 answers

I recently found a solution for this. wsdl2java seems to have the undocumented -w option, which is short for --wrapArrays . If you create your classes using SoapUI, you can select this option:

SoapUI and wsdl2java

As indicated, this parameter will create classes for "specific patterns of the array of schemas", for example the pattern described in my question.

If you use Eclipse to create a web service client, you can configure the same option by going to Axis Emitter in the Eclipse settings and checking the corresponding box.

Eclipse and wsdl2java

+5
source

Have you tried using the -W option in the wsdl2java ?

From the Link to Tools :

-W, --noWrapped This disables the special handling of so-called "wrapped" operations with documents / literal styles. By default, WSDL2Java will recognize the following conditions:

  • If the input message has one part.
  • A part is an element.
  • The item has the same name as the operation.
  • A complex type element has no attributes

    When he sees this, WSDL2Java "pushes" the top-level element and processes each of the element's components as arguments to the operation. This type of WSDL is standard for Microsoft.NET web services that complete the RPC style arguments in this top-level element scheme.

Perhaps this can fix it.

+1
source

Source: https://habr.com/ru/post/1397406/


All Articles