Skip to content

Commit

Permalink
Fix duplicated netty pipeline handler error
Browse files Browse the repository at this point in the history
  • Loading branch information
akobor committed Aug 29, 2020
1 parent 52303f0 commit e07ca6c
Showing 1 changed file with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,27 @@ class HttpCommunicationLogger(private val logbook: Logbook) : BeanCreatedEventLi

override fun onCreated(event: BeanCreatedEvent<ChannelPipelineCustomizer>): 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
}
}
Expand Down

0 comments on commit e07ca6c

Please sign in to comment.