列出Resteasy服务中的param

时间:2011-08-22 16:48:55

标签: web-services resteasy

好mournig家伙!

如何将像param这样的List发送到Resteasy服务?

当我执行throws时,异常如下:

java.lang.RuntimeException: could not find writer for content-type multipart/mixed type: java.util.ArrayList
    at org.jboss.resteasy.client.ClientRequest.writeRequestBody(ClientRequest.java:474)
    at org.jboss.resteasy.client.core.executors.ApacheHttpClientExecutor$ClientRequestEntity.<init>(ApacheHttpClientExecutor.java:154)
    at org.jboss.resteasy.client.core.executors.ApacheHttpClientExecutor.loadHttpMethod(ApacheHttpClientExecutor.java:226)
    at org.jboss.resteasy.client.core.executors.ApacheHttpClientExecutor.execute(ApacheHttpClientExecutor.java:78)
    at org.jboss.resteasy.core.interception.ClientExecutionContextImpl.proceed(ClientExecutionContextImpl.java:39)
    at org.jboss.resteasy.plugins.interceptors.encoding.AcceptEncodingGZIPInterceptor.execute(AcceptEncodingGZIPInterceptor.java:40)
    at org.jboss.resteasy.core.interception.ClientExecutionContextImpl.proceed(ClientExecutionContextImpl.java:45)
    at org.jboss.resteasy.client.ClientRequest.execute(ClientRequest.java:449)
    at org.jboss.resteasy.client.ClientRequest.httpMethod(ClientRequest.java:679)
    at org.jboss.resteasy.client.ClientRequest.put(ClientRequest.java:541)
    at org.jboss.resteasy.client.ClientRequest.put(ClientRequest.java:546)
    at Principal.main(Principal.java:74)

我的服务声明为以下形式:

    @PUT
    @Path("gravarBoletos")
    @Consumes("multipart/mixed")
    @Produces(MediaType.TEXT_PLAIN)
    public Integer gravarBoletos(List<TituloTO> tituloTOs) throws ExcecaoSistema, ExcecaoNegocio;

我打电话给我的客户:

    ClientRequest request = new ClientRequest(urlWebService + "/mFinanceiroService/gravarBoletos");

    request.accept("multipart/mixed");
    request.body("multipart/mixed", tituloImport.getTituloTOs());

    ClientResponse<Integer> response = request.put(Integer.class);

    System.out.println(response.getEntity());

有人帮帮我???? 谢谢!

1 个答案:

答案 0 :(得分:0)

使用@Wrapped注释。

@GET
@Path("list")
@Produces("application/xml")
@Wrapped(element="list", namespace="http://foo.org", prefix="foo")
public List<Customer> getCustomerSet(){
    List<Customer> list = new ArrayList<Customer>();
    list.add(new Customer("bill"));
    list.add(new Customer("monica"));

    return list;
}

将返回此xml:

 <foo:list xmlns:foo="http://foo.org">
      <customer><name>bill</name></customer>
      <customer><name>monica</name></customer>
 </foo:list>