开发者

NoMessageBodyWriterFoundFailure at sending ByteArrayOutputStream through REST service

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜