首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >如何将数据(List<Customer>客户)作为RS查询(URI )的输入发送

如何将数据(List<Customer>客户)作为RS查询(URI )的输入发送
EN

Stack Overflow用户
提问于 2012-05-25 19:36:20
回答 1查看 2.5K关注 0票数 0

我有一个JAX-RS Jersey WebService,我正在尝试接受一个XML数据(或JSON),并返回一个String响应,显示传递的记录总数。

以下是我的服务代码:

代码语言:javascript
代码运行次数:0
运行
复制
@Path("customers")
@Singleton
public class CustomersResource {
...
    @POST
    @Path("addall")
    @Produces("text/html")
    @Consumes(javax.ws.rs.core.MediaType.APPLICATION_XML)
    public String addCustomers(List<Customer> customerList) {
        return "success : received " + customerList.size() ;
    }
    ...
}

下面是我的客户端代码:

代码语言:javascript
代码运行次数:0
运行
复制
public static void main(String[] args) {
    Client client = Client.create();

    WebResource webresource = client.resource( "http://localhost:8080/restdemo/services/customers/addall");

    String input  = "<customerList><customer><name>name1</name></customer><customer><name>name2</name></customer></customerList>";
    String response = webresource.type("application/xml").post( String.class, input );
    System.out.println(response);
}

错误:

代码语言:javascript
代码运行次数:0
运行
复制
Exception in thread "main" com.sun.jersey.api.client.ClientHandlerException: com.sun.jersey.api.client.ClientHandlerException: A message body writer for Java type, class java.util.ArrayList, and MIME media type, application/json, was not found
    at com.sun.jersey.client.urlconnection.URLConnectionClientHandler.handle(URLConnectionClientHandler.java:149)
    at com.sun.jersey.api.client.Client.handle(Client.java:648)
    at com.sun.jersey.api.client.WebResource.handle(WebResource.java:680)
    at com.sun.jersey.api.client.WebResource.access$200(WebResource.java:74)
    at com.sun.jersey.api.client.WebResource$Builder.post(WebResource.java:568)
    at restdemoclient.Main.main(Main.java:35)
Caused by: com.sun.jersey.api.client.ClientHandlerException: A message body writer for Java type, class java.util.ArrayList, and MIME media type, application/json, was not found
    at com.sun.jersey.api.client.RequestWriter.writeRequestEntity(RequestWriter.java:288)
    at com.sun.jersey.client.urlconnection.URLConnectionClientHandler._invoke(URLConnectionClientHandler.java:204)
    at com.sun.jersey.client.urlconnection.URLConnectionClientHandler.handle(URLConnectionClientHandler.java:147)
    ... 5 more

我将感谢任何帮助或任何示例代码的指针,这可能是有帮助的。

EN

回答 1

Stack Overflow用户

发布于 2012-05-25 19:57:22

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10753731

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档