Resteasy Service 中的类似参数列表

发布于 2024-12-01 08:18:42 字数 2043 浏览 1 评论 0原文

各位哀悼者好!

如何将像参数这样的列表发送到 Resteasy 服务?

当我执行时抛出异常如下:

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

有人帮助我吗??? 谢谢!

Good mournig guys!

How to send a List like param to a Resteasy service?

When I'll execute throws the exception follow:

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)

My service is declared this form:

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

I call in my client this form:

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

Anybody help me????
Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

简单 2024-12-08 08:18:42

使用@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>

Use the @Wrapped annotation.

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

Would return this xml:

 <foo:list xmlns:foo="http://foo.org">
      <customer><name>bill</name></customer>
      <customer><name>monica</name></customer>
 </foo:list>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文