0
votes

I am new in java web service programming and this question might seem really basic. But I can't find the problem.

I have developed a Apache CXF(v 2.7.6) webservice for Tomcat 6.0.37 using Eclipse. Basically, I created a dynamic web project, created webservice class and created webservice from that class (eclipse generated the rest, including wsdl and xsd). All works fine, except when I try to return array of String. This is my method

@WebMethod(action="getFriends")
    public String[] getFriends(String u, String p){
        return new String[] {"item 1","item 2","item 3"};
    }

response type definition

<xs:complexType name="getFriendsResponse">
    <xs:sequence>
      <xs:element maxOccurs="unbounded" minOccurs="0" name="return" type="xs:string"/>
    </xs:sequence>
  </xs:complexType>

and here is the returned message

INFO: Outbound Message

ID: 34 Encoding: UTF-8 Content-Type: text/xml Headers: {} Payload:

As you can see there is no even return part. Any idea what can be wrong?

I use Windows 7, Eclipse Kepler and JDK6 for this project.

1

1 Answers

0
votes

Whatever I remember it won't work because you can't parse an array as plain text in a HTTP response.

Try these two approaches - 1 ) Change the return type of your method to String and then return a string like this

 return Arrays.toString(new String[] {"item 1","item 2","item 3"});

2 ) You can change the return type of list and return a list like this -

return Arrays.asList(new String[] {"item 1","item 2","item 3"});

Thanks