I'm having a problem returning a String array from a method of a webservice.  
In order to provide a simple way to recreate the problem, I modified the 2.1 
webservices sample ( 
http://cwiki.apache.org/GMOxDOC21/developing-a-simple-calculator-web-service.html
 ) such that the add() method returns a String[] instead of an int.  The mods 
were simple, I changed the "return" element of the addResponse in the wsdl of 
the sample
from:
        <xsd:element name="return" type="xsd:int"/>
to:
        <xsd:element name="return" type="xsd:string" minOccurs="0" 
maxOccurs="unbounded"/>
and the CalculatorService.java (and the corresponding interface it implements) 
from:
    public int add(int value1, int value2) {
...
      return value1 + value2;
to:
    public String[] add(int value1, int value2) {
...
      return new String[]{"Value 1", String.valueOf(value1), "Value 2", 
String.valueOf(value2), String.valueOf(value1 + value2)};

and then changed the result.jsp to expect a String[] and iterate over the 
contents printing out each element,  If I add 3 + 4, I expected the result.jsp 
to display:

Value 1
3
Value 2
4
7

but I get instead:
Value
1
3
Value
2
4
7

It seems that in the process of converting the response into a Java String[], 
the whitespace of the individual strings is acting as a delimiter.  Thus 
instead of getting an array of 5 strings, I get an array of 7 strings instead.  
What have I misconfigured?

Fred

Reply via email to