泽西岛2.25.1服务器发送的事件导致ERR_INCOMPLETE_CHUNKED_ENCODING

时间:2020-02-03 12:46:35

标签: jersey jersey-2.0 server-sent-events

这是我的JAX-RS资源

@Singleton
@Path("priceTaskEvents")
public class PlainPriceTaskEventResource implements PlainPriceTaskEventService.PriceTaskEventCallback {

    private SseBroadcaster broadcaster = new SseBroadcaster();

    @Inject
    private PlainPriceTaskEventService priceTaskEventService;

    @GET
    @Produces(SseFeature.SERVER_SENT_EVENTS)
    public EventOutput listenToPriceTaskEvents() {

        if (priceTaskEventService.getCallback() == null) {
            priceTaskEventService.setCallback(this);
        }

        final EventOutput eventOutput = new EventOutput() {
            @Override
            public void write(OutboundEvent chunk) throws IOException {
                super.write(chunk);
                System.out.println(chunk.getData());
            }
        };
        this.broadcaster.add(eventOutput);
        return eventOutput;
    }

    @Override
    public void onSupplierUpdated(PlainSupplier supplier) {
        System.out.println("Supplier updated : " + supplier.getId());
        broadcaster.broadcast(new OutboundEvent.Builder()
                .mediaType(MediaType.TEXT_PLAIN_TYPE)
                .name("supplier-updated")
                .data(String.valueOf(supplier.getId())).build());
    }
}

代码是根据Jersey文档(https://eclipse-ee4j.github.io/jersey.github.io/documentation/2.25.1/sse.html#d0e11862

建模的

这里的想法是我的Javascript UI将使用URL /.../priceTaskEvents注册一个EventSource,然后当服务器需要报告某些内容时,系统的其他部分将调用onSupplierUpdated方法。

当我尝试直接使用浏览器(在地址栏中输入URL)或创建一个EventSource对象从事件中读取数据时,尝试从Chrome测试此问题。我收到错误代码net :: ERR_INCOMPLETE_CHUNKED_ENCODING200。似乎我只获得了响应头,并且发生了错误。

这是我从请求中获得的响应头: The response headers I get

有人知道吗?

0 个答案:

没有答案