我've just started working with chunked output in JAX-RS. Wanted to send chunked '响应' objects to the output as I'm发送各种不同类型的数据(不同块的字符串和文件) . 但是当我尝试将Response对象写入 ChunkedOutput 对象时,我得到以下异常: org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException: MessageBodyWriter not found for media type=text/html, type=class org.glassfish.jersey.message.internal.OutboundJaxrsResponse, genericType=class javax.ws.rs.core.Response.

以下是我的代码:

@GET
public ChunkedOutput<Response> getChunkedResponse() {
    final ChunkedOutput<Response> output2 = new ChunkedOutput<Response>(Response.class);

    new Thread() {
        public void run() {
            try {
                String chunk;
                while ((chunk = getNextString()) != null) {
                    ResponseBuilder responseBuilder = Response.ok()
                                              .type(MediaType.TEXT_XML)
                                              .entity(chunk);
                    output2.write(responseBuilder.build());   //Exception thrown here
                    System.out.println(chunk);
                }
                output2.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }.start();
    return output2;
}