English 中文(简体)
如何将数据(列表 < Customer > 客户)作为 RS 查询( URI) 的输入发送 。
原标题:How to send data (List<Customer> customers ) as input of an RS query (URI

我有一个JAX-RS 泽西岛网络服务公司, 我试图接受 XML 数据( 或 JSON) 并返回 < code> String 回复, 显示通过的记录总数 。

这是我的服役守则:

@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() ;
    }
    ...
}

这是我的客户代码:

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);
}

错误 :

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

我将感谢任何帮助或指示 任何可以帮助的示例代码。

问题回答

这是最需要功能的样本: < a href="http://search.maven.org/remotecontent? filepath=com/sun/jersey/samples/jaxb/1.12/jaxb-1.12-project.zip" rel=“nofollow” >http://search.maven.org/remotecontent?filepath=com/sun/jersey/samples/jaxb/1.12/jaxb-1.12-project.zip

Jersey用户指南 对你也有用。





相关问题
IIS 6.0 hangs when serving a web-service

I am having issues with one of our web-services. It works fine on my development machine (win XP) whether I host it as a separate application or using cassini from Visual studio. Once I deploy on the ...

ASP.net web services

I am using a web service which sets the Thread.CurrentPrincipal object while logging in and soon later when another webmethod of the same web service accesses Thread.CurrentPrincipal, its different/...

Unity Container Disposing and XML Web Service

I am registering some wrapers over un-managed objects in container. How can I dispose of them at the end of the container s lifetime? Please bear in mind I have an XML Web service.

SharePoint : web service permission error

I have a sharepoint site, and I am calling a standard sharepoint web service. I create the web service request like this : wsDws.Url = this.SiteAddress + @"/_vti_bin/Dws.asmx"; When I use ...

热门标签