事件源挂起-Jersey Java服务器

事件源挂起-Jersey Java服务器,java,jersey,jersey-2.0,server-sent-events,Java,Jersey,Jersey 2.0,Server Sent Events,先了解一下上下文。在服务器端,我使用Jersey 2.28,并将Jersey media sse作为依赖项包含在内 服务器端代码如下所示 @GET @Path("{id}") @Produces(MediaType.SERVER_SENT_EVENTS) public void orderUpdates(@PathParam("id") String id, @Context SseEventSink sink) { service.subscribe(id, sink, sse);

先了解一下上下文。在服务器端,我使用Jersey 2.28,并将Jersey media sse作为依赖项包含在内

服务器端代码如下所示

@GET
@Path("{id}")
@Produces(MediaType.SERVER_SENT_EVENTS)
public void orderUpdates(@PathParam("id") String id, @Context SseEventSink sink) {
    service.subscribe(id, sink, sse);
    OutboundSseEvent initialMessage = sse.newEventBuilder().comment("Connection initiated").build();
    sink.send(initialMessage);
}
客户端代码是-在js中

this.eventSource = new EventSource(URL);
this.eventSource.onmessage = e => console.log(JSON.stringify(e));
但是连接始终处于(挂起)状态,即使通过附加调试程序,我看到服务器代码已执行

调试另一个成功使用sse的项目(具有相同的依赖项),断点位于
sink.send(..)
我发现在我的示例中没有填充SSEventSink的以下字段

  • 请求范围
  • 请求上下文
  • 响应文本
  • 连接回拨


但我仍然没有弄清楚原因,或者即使这是请求被挂起的原因。

结果表明问题是由servlet上启用的GZip筛选器引起的,该筛选器与SSE端点匹配

禁用过滤器可修复问题,其行为符合预期