2011-08-26 68 views
1

发送ByteArrayOutputStream我有过一个休息服务发送一个ByteArrayOutputStream,我得到这个异常:NoMessageBodyWriterFoundFailure在通过REST服务

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"; 

一切都在包含此方法的类的作品,除了这个方法。

回答

2

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