2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.netconf.impl.util;
10 import io.netty.channel.ChannelHandlerContext;
11 import io.netty.channel.ChannelInboundHandlerAdapter;
13 import org.opendaylight.netconf.api.DocumentedException;
14 import org.opendaylight.netconf.impl.SendErrorExceptionUtil;
15 import org.opendaylight.yangtools.yang.common.ErrorSeverity;
16 import org.opendaylight.yangtools.yang.common.ErrorTag;
17 import org.opendaylight.yangtools.yang.common.ErrorType;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
21 public final class DeserializerExceptionHandler extends ChannelInboundHandlerAdapter {
22 private static final Logger LOG = LoggerFactory.getLogger(DeserializerExceptionHandler.class);
25 public void exceptionCaught(final ChannelHandlerContext ctx, final Throwable cause) {
26 LOG.warn("An exception occurred during message handling", cause);
27 handleDeserializerException(ctx, cause);
30 private static void handleDeserializerException(final ChannelHandlerContext ctx, final Throwable cause) {
31 final String message = cause.getMessage();
32 SendErrorExceptionUtil.sendErrorMessage(ctx.channel(), new DocumentedException(message,
33 ErrorType.RPC, ErrorTag.MALFORMED_MESSAGE, ErrorSeverity.ERROR,
34 message != null ? Map.of("cause", message) : Map.of()));