I have to send a ByteArrayOutputStream through a rest service, and I got this exception:
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
I don't understand why and I have to make it work.
Here is my rest service:
@POST
@Path("/exported")
@Consumes(MediaType.APPLICATION_XML)
public ByteArray开发者_如何学运维OutputStream getExported(Wrapper wrapper) {
ByteArrayOutputStream os = null;
os = new ByteArrayOutputStream();
try {
os.write("TTT".getBytes());
} catch (IOException e) {
e.printStackTrace();
}
return os;
}
Here is my client:
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";
Everything in the class containing this method works, except this method.
RestEasy doesn't know who to convert your ByteArrayOutputStream into something that can be sent over HTTP. Read up on RESTEasy Content Marshalling and then either use a different content type and/or use a different data type that is automatically handled and/or write a content marshalling provider to handle your ByteArrayOutStream.
精彩评论