You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@geronimo.apache.org by fr...@nc.rr.com on 2008/03/28 23:00:31 UTC
Returning String[] from WebService method
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
Re: Returning String[] from WebService method
Posted by Jarek Gawor <jg...@gmail.com>.
Fred,
Ok, I can reproduce this problem with Axis2 but not with CXF. Axis2
just serializes (and deserializes) the data completely wrong. Looks
like a bug in Axis2. There are two options:
1) Switch to CXF, or
2) Use jaxws-tools wsimport to generate the right classes from the
wsdl and use the generated PortType class to implement your service
and client. That's the option I would recommend.
Jarek
On Fri, Mar 28, 2008 at 6:00 PM, <fr...@nc.rr.com> wrote:
> 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
>
Re: Returning String[] from WebService method
Posted by Jarek Gawor <jg...@gmail.com>.
Just from a quick glance it looks like the result.jsp is not quite
right. It should look like the one shown here:
http://cwiki.apache.org/GMOxDOC21/simple-web-service-with-jax-ws.html
(titled add.jsp where jndi lookup is done). See if changing that
helps.
Jarek
On Fri, Mar 28, 2008 at 6:00 PM, <fr...@nc.rr.com> wrote:
> 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
>