You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by Andy Dysart <AD...@prospricing.com> on 2011/05/05 03:39:40 UTC

Problem with multiple array arguments in POJO method?

I am using the POJO approach, and have a server class with a method like this:

public void myMethod(String[] options, MyData[] data) { ... }

Using SoapUI, I can call this method successfully with this message:

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsd="http://interfaces.mybiz.com/xsd">
   <soap:Header/>
   <soap:Body>
      <xsd:myMethod>
         <xsd:options>option1</xsd:options>
         <xsd:options>option2</xsd:options>
         <xsd:data>
            <xsd:Field1>TEST</xsd:Field1>
            <xsd:Field2>1234</xsd:Field2>
         </xsd:data>
      </xsd:myMethod>
   </soap:Body>
</soap:Envelope>

In this case, I get exactly what I expect - the options array has two strings "option1" and "option2", and the data array has my single data object.

But if I don't have any options to pass, the WSDL indicates that the appropriate message to send would be this (minOccurs on the <options> element is 0):

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsd="http://interfaces.mybiz.com/xsd">
   <soap:Header/>
   <soap:Body>
      <xsd:myMethod>
         <xsd:data>
            <xsd:Field1>TEST</xsd:Field1>
            <xsd:Field2>1234</xsd:Field2>
         </xsd:data>
      </xsd:myMethod>
   </soap:Body>
</soap:Envelope>

But this fails miserably in my POJO code because the options array now has a single element which is a string containing nothing but newlines and spaces, and the data array has a length of zero.

Looking at the code, I see that this method in org/apache/axis2/databinding/utils/BeanUtil.java seems to be the key:

    deserialize(OMElement response,
                           Object [] javaTypes,
                           ObjectSupplier objectSupplier)

It appears that this code has no way to identify that the first argument was supposed to be populated from <option> elements and the second from <data> elements, so it just builds the first argument from the first contiguous run of same-named elements (the <data> element), and then realizes that it has no elements for the second argument so just sets that to an empty array (of the correct type).  Then when getting the string values for the first argument, the spaces and newlines are just the concatenated text nodes of the direct children of the <data> element.

Has anyone else run into this problem and have a suggested solution?

I am using an older version of Axis2 (1.4.1), but I just pulled the latest release source code (1.5.4) and this part of the code does not appear to have changed any...

Thanks


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@axis.apache.org
For additional commands, e-mail: java-user-help@axis.apache.org