开发者

NoMessageBodyWriterFoundFailure at sending ByteArrayOutputStream through REST service

开发者 https://www.devze.com 2023-03-31 04:05 出处:网络
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

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

精彩评论

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