2012-10-31 35 views
0

我想返回一个有少量字符串的对象以及另一个字符串数组(这是有原因的,我保证)。我遇到的麻烦是,当我用SoapUI测试我的方法时,我只能得到字符串;字符串数组似乎完全丢失。任何线索我做错了什么?我的类看起来是这样的......通过Java Web服务返回数组时遇到问题

public class EmailListing { 
    public String type; 
    public String category; 
    public String[] emails; 

    public EmailListing() { 
    emails = new String[1]; 
    } 

    public void setEmailList(String emaillist) { 
    this.emails = emaillist.split("\\|"); 
    } 
} 

在使用这个类的Web服务功能,我做了以下内容:

public EmailListing getEmailListing(int id) { 
    EmailListing el = new EmailListing(); 
    try { 
    // get data from the database 
    // ... 
    // 
    while(rs.next()) { 
     el.type = rs.getString("type"); 
     el.category = rs.getString("category"); 
     el.setEmailList(rs.getString("emaillist")); 
    } 
    } catch(...) { 
    ... 
    } 
    return el; 
} 

我看到当我测试这项服务的唯一信息,尽管,是类型和类别。 :(

编辑:用于打印和服务器侧输出的结果的方法

public void print() { 
    StringBuffer sb = new StringBuffer(); 
    sb.append("Emails\n"); 
    for(int i = 0; i < emails.length; i++) { 
    sb.append(" " + emails[i] + "\n"); 
    } 
    System.out.println(sb.toString()); 
} 

输出看起来像:

Emails 
    [email protected] 
    [email protected] 

编辑:添加收到SOAP消息

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"  xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
    <soapenv:Body> 
    <getEmailListingResponse xmlns="http://services.test.com"> 
     <getEmailListingReturn> 
     <type>data</type> 
     <category>data</category> 
     </getEmailListingReturn> 
    </getEmailListingResponse> 
    </soapenv:Body> 
</soapenv:Envelope> 
+0

您的电子邮件数组中永远不会有多个元素。查看EmailListing类的构造函数。如果您要发布返回内容的示例,这将非常有帮助。 Web服务中的功能是否返回并列出电子邮件列表? – ChadNC

+0

我会添加我回来的肥皂信息。 – Tyler

+0

您的网络服务仅返回未包裹在其他任何内容中的电子邮件列表?有任何客户代码? – ChadNC

回答

0

调试它,看看你是否真的得到了“emailList”,如果是的话,你可能会分裂它,因为你的c颂歌对我来说很好。

+0

我打印对象服务器端的内容,数据全部存在,而不是当我在客户端请求它时。 – Tyler