*/
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;
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);
}
private static void handleDeserializerException(final ChannelHandlerContext ctx, final Throwable cause) {
- final Map<String, String> 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()));
}
}