问题描述
我目前正在使用 Wildfly 中的 RESTEasy 处理服务器发送的事件。到目前为止一切正常,除了有时 SSE 实现无法以某种方式识别侦听事件的客户端已经关闭(也是客户端的 SseEventSource
的 close() 方法被称为)。在程序逻辑方面,这根本不是问题。
但不幸的是,用于发送事件的 org.jboss.resteasy.plugins.providers.sse.SseEventOutputImpl
类确实 - 除了将异常报告回 org.jboss.resteasy.plugins.providers.sse.SsebroadcasterImpl
- 不仅报告异常,而且还使用 {{1 FailedToWriteSseEvent(String,Throwable)
的 }} 方法(后面的类基于 JBoss 日志)。因此,我不时收到 ERROR 级别的不必要的日志消息,告诉我连接已被客户端关闭。除了我从 org.jboss.resteasy.resteasy_jaxrs.i18n.LogMessages
获得的 onClose 事件之外,它还在日志中获得了该条目。
配置 JBoss 日志似乎是不可能的,因为日志名称是 Ssebroadcaster
,它也用于记录其他错误(意味着仅在部署的 log4j.xml 中配置记录器将不起作用/也关闭其他错误)。
org.jboss.resteasy.resteasy_jaxrs.i18n
有没有办法控制 RESTEasy 中的日志记录并禁用 2021-06-22 12:59:27 [ERROR] [org.jboss.resteasy.resteasy_jaxrs.i18n:272] - RESTEASY002030: Failed to write event org.jboss.resteasy.plugins.providers.sse.OutboundSseEventImpl@fd79b33
java.io.IOException: An existing connection was forcibly closed by the remote host
at sun.nio.ch.socketdispatcher.writev0(Native Method)
at sun.nio.ch.socketdispatcher.writev(UnkNown Source)
at sun.nio.ch.IoUtil.write(UnkNown Source)
at sun.nio.ch.socketChannelImpl.write(UnkNown Source)
at org.xnio.nio.NioSocketConduit.write(NioSocketConduit.java:162)
at io.undertow.server.protocol.http.HttpResponseConduit.write(HttpResponseConduit.java:647)
at io.undertow.conduits.ChunkedStreamSinkConduit.doWrite(ChunkedStreamSinkConduit.java:166)
at io.undertow.conduits.ChunkedStreamSinkConduit.write(ChunkedStreamSinkConduit.java:128)
at org.xnio.conduits.ConduitStreamSinkChannel.write(ConduitStreamSinkChannel.java:150)
at io.undertow.channels.DetachableStreamSinkChannel.write(DetachableStreamSinkChannel.java:240)
at io.undertow.server.HttpServerExchange$WritedispatchChannel.write(HttpServerExchange.java:2103)
at io.undertow.servlet.spec.ServletoutputStreamImpl.writeBufferBlocking(ServletoutputStreamImpl.java:574)
at io.undertow.servlet.spec.ServletoutputStreamImpl.flushInternal(ServletoutputStreamImpl.java:489)
at io.undertow.servlet.spec.ServletoutputStreamImpl.flush(ServletoutputStreamImpl.java:476)
at io.undertow.servlet.spec.HttpServletResponseImpl.flushBuffer(HttpServletResponseImpl.java:468)
at javax.servlet.ServletResponseWrapper.flushBuffer(ServletResponseWrapper.java:221)
at org.jboss.resteasy.plugins.server.servlet.HttpServletResponseWrapper.flushBuffer(HttpServletResponseWrapper.java:124)
at org.jboss.resteasy.plugins.providers.sse.SseEventOutputImpl.writeEvent(SseEventOutputImpl.java:264)
at org.jboss.resteasy.plugins.providers.sse.SseEventOutputImpl.send(SseEventOutputImpl.java:199)
at org.jboss.resteasy.plugins.providers.sse.SsebroadcasterImpl.lambda$null$4(SsebroadcasterImpl.java:150)
at java.lang.Iterable.forEach(UnkNown Source)
at org.jboss.resteasy.plugins.providers.sse.SsebroadcasterImpl.lambda$broadcast$5(SsebroadcasterImpl.java:146)
at java.util.concurrent.CompletableFuture$AsyncRun.run(UnkNown Source)
at java.util.concurrent.CompletableFuture$AsyncRun.exec(UnkNown Source)
at java.util.concurrent.ForkJoinTask.doExec(UnkNown Source)
at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(UnkNown Source)
at java.util.concurrent.ForkJoinPool.runWorker(UnkNown Source)
at java.util.concurrent.ForkJoinWorkerThread.run(UnkNown Source)
的日志记录?就像引入/注入自己的 FailedToWriteSseEvent(String,Throwable)
实现(但据我所知,该接口用作代理,所以...)?
解决方法
您可能会点击RESTEASY-1986。不过,您可以使用日志过滤器过滤掉这些。在 CLI 中类似:
/subsystem=logging/logger=org.jboss.resteasy.resteasy_jaxrs.i18n:add(filter-spec=not(match(".*RESTEASY002030.*")),level=INFO)