From: Robert Varga Date: Mon, 23 Aug 2021 23:28:01 +0000 (+0200) Subject: Improve DeserializerExceptionHandler X-Git-Tag: v2.0.3~3 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F03%2F97303%2F4;p=netconf.git Improve DeserializerExceptionHandler We are getting a deprecation warning, as there exceptionCaught() really makes sense only on inbound side. This happens to be what we actually are doing with DeserializerExceptionHandler anyway, so just pick up ChannelInboundHandlerAdapter and use that as the superclass. Change-Id: Ic661e4e85f4442a395c820463abf00e71c52543e Signed-off-by: Robert Varga --- diff --git a/netconf/netconf-impl/src/main/java/org/opendaylight/netconf/impl/util/DeserializerExceptionHandler.java b/netconf/netconf-impl/src/main/java/org/opendaylight/netconf/impl/util/DeserializerExceptionHandler.java index 55631ef0eb..bd2561d3ed 100644 --- a/netconf/netconf-impl/src/main/java/org/opendaylight/netconf/impl/util/DeserializerExceptionHandler.java +++ b/netconf/netconf-impl/src/main/java/org/opendaylight/netconf/impl/util/DeserializerExceptionHandler.java @@ -7,9 +7,8 @@ */ package org.opendaylight.netconf.impl.util; -import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandlerContext; -import java.util.HashMap; +import io.netty.channel.ChannelInboundHandlerAdapter; import java.util.Map; import org.opendaylight.netconf.api.DocumentedException; import org.opendaylight.netconf.util.messages.SendErrorExceptionUtil; @@ -18,19 +17,9 @@ import org.opendaylight.yangtools.yang.common.ErrorType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public final class DeserializerExceptionHandler implements ChannelHandler { +public final class DeserializerExceptionHandler extends ChannelInboundHandlerAdapter { private static final Logger LOG = LoggerFactory.getLogger(DeserializerExceptionHandler.class); - @Override - public void handlerAdded(final ChannelHandlerContext ctx) { - // NOOP - } - - @Override - public void handlerRemoved(final ChannelHandlerContext ctx) { - // NOOP - } - @Override public void exceptionCaught(final ChannelHandlerContext ctx, final Throwable cause) { LOG.warn("An exception occurred during message handling", cause); @@ -38,11 +27,9 @@ public final class DeserializerExceptionHandler implements ChannelHandler { } private static void handleDeserializerException(final ChannelHandlerContext ctx, final Throwable cause) { - final Map info = new HashMap<>(); - info.put("cause", cause.getMessage()); - final DocumentedException ex = new DocumentedException(cause.getMessage(), - ErrorType.RPC, DocumentedException.MALFORMED_MESSAGE, ErrorSeverity.ERROR, info); - - SendErrorExceptionUtil.sendErrorMessage(ctx.channel(), ex); + final String message = cause.getMessage(); + SendErrorExceptionUtil.sendErrorMessage(ctx.channel(), new DocumentedException(message, + ErrorType.RPC, DocumentedException.MALFORMED_MESSAGE, ErrorSeverity.ERROR, + message != null ? Map.of("cause", message) : Map.of())); } }