【问题标题】:NoMessageBodyWriterFoundFailure at sending ByteArrayOutputStream through REST serviceNoMessageBodyWriterFoundFailure 在通过 REST 服务发送 ByteArrayOutputStream
【发布时间】:2011-08-26 11:36:33
【问题描述】:

我必须通过休息服务发送一个 ByteArrayOutputStream,我得到了这个异常:

org.jboss.resteasy.client.ClientResponseFailure: Unable to find a MessageBodyReader of content-type text/html;charset="iso-8859-1" and type class java.io.ByteArrayOutputStream

我不明白为什么,我必须让它发挥作用。

这是我的休息服务:

@POST
@Path("/exported")
@Consumes(MediaType.APPLICATION_XML)
public ByteArrayOutputStream getExported(Wrapper wrapper) {

    ByteArrayOutputStream os = null;

    os = new ByteArrayOutputStream();
    try {
        os.write("TTT".getBytes());
    } catch (IOException e) {
        e.printStackTrace();
    }

    return os;

}

这是我的客户:

    ClientRequest request = new ClientRequest("http://localhost:8081/restws/rest/rrr/exported");
    request.accept(MediaType.APPLICATION_XML);

    request.body(MediaType.APPLICATION_XML, new Wrapper(
            listOf Objects));

    ClientResponse<ByteArrayOutputStream> response = request
            .post(ByteArrayOutputStream.class);

    ByteArrayOutputStream os = response.getEntity();

    return "success";

类中包含这个方法的所有东西都可以工作,除了这个方法。

【问题讨论】:

    标签: java web-services rest resteasy


    【解决方案1】:

    RestEasy 不知道谁将您的 ByteArrayOutputStream 转换为可以通过 HTTP 发送的东西。阅读RESTEasy Content Marshalling,然后使用不同的内容类型和/或使用自动处理的不同数据类型和/或编写内容编组提供程序来处理您的 ByteArrayOutStream。

    【讨论】:

      猜你喜欢
      • 2012-10-22
      • 1970-01-01
      • 2016-01-30
      • 1970-01-01
      • 1970-01-01
      • 2019-10-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多