From e07ca6cde47467093d9924b12777920209a68ea5 Mon Sep 17 00:00:00 2001 From: akobor Date: Sat, 29 Aug 2020 17:33:08 +0200 Subject: [PATCH] Fix duplicated netty pipeline handler error --- .../services/HttpCommunicationLogger.kt | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/main/kotlin/com/kuvaszuptime/kuvasz/services/HttpCommunicationLogger.kt b/src/main/kotlin/com/kuvaszuptime/kuvasz/services/HttpCommunicationLogger.kt index b1be5c1..741a5eb 100644 --- a/src/main/kotlin/com/kuvaszuptime/kuvasz/services/HttpCommunicationLogger.kt +++ b/src/main/kotlin/com/kuvaszuptime/kuvasz/services/HttpCommunicationLogger.kt @@ -16,22 +16,27 @@ class HttpCommunicationLogger(private val logbook: Logbook) : BeanCreatedEventLi override fun onCreated(event: BeanCreatedEvent): ChannelPipelineCustomizer { val customizer = event.bean + val handlerName = "logbook" if (customizer.isServerChannel) { customizer.doOnConnect { pipeline: ChannelPipeline -> - pipeline.addAfter( - ChannelPipelineCustomizer.HANDLER_HTTP_SERVER_CODEC, - "logbook", - LogbookServerHandler(logbook) - ) + if (pipeline.get(handlerName) == null) { + pipeline.addAfter( + ChannelPipelineCustomizer.HANDLER_HTTP_SERVER_CODEC, + handlerName, + LogbookServerHandler(logbook) + ) + } pipeline } } else { customizer.doOnConnect { pipeline: ChannelPipeline -> - pipeline.addAfter( - ChannelPipelineCustomizer.HANDLER_HTTP_CLIENT_CODEC, - "logbook", - LogbookClientHandler(logbook) - ) + if (pipeline.get(handlerName) == null) { + pipeline.addAfter( + ChannelPipelineCustomizer.HANDLER_HTTP_CLIENT_CODEC, + handlerName, + LogbookClientHandler(logbook) + ) + } pipeline } }