找不到JAX-RS Chunked Response MessageBodyWriter

时间:2017-01-25 10:02:17

标签: java rest jersey jax-rs

我刚开始使用JAX-RS中的分块输出。当我发送各种不同类型的数据(不同块的字符串和文件)时,想要将分块的“响应”对象发送到输出。但是当我尝试将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;
}

0 个答案:

没有答案