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
9 package org.opendaylight.netconf.impl.util;
11 import com.google.common.collect.Maps;
12 import io.netty.channel.ChannelHandler;
13 import io.netty.channel.ChannelHandlerContext;
15 import org.opendaylight.netconf.api.DocumentedException;
16 import org.opendaylight.netconf.util.messages.SendErrorExceptionUtil;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
20 public final class DeserializerExceptionHandler implements ChannelHandler {
22 private static final Logger LOG = LoggerFactory.getLogger(DeserializerExceptionHandler.class);
25 public void handlerAdded(final ChannelHandlerContext ctx) {
30 public void handlerRemoved(final ChannelHandlerContext ctx) {
35 public void exceptionCaught(final ChannelHandlerContext ctx, final Throwable cause) {
36 LOG.warn("An exception occurred during message handling", cause);
37 handleDeserializerException(ctx, cause);
40 private static void handleDeserializerException(final ChannelHandlerContext ctx, final Throwable cause) {
42 final Map<String, String> info = Maps.newHashMap();
43 info.put("cause", cause.getMessage());
44 final DocumentedException ex = new DocumentedException(cause.getMessage(),
45 DocumentedException.ErrorType.RPC, DocumentedException.ErrorTag.MALFORMED_MESSAGE,
46 DocumentedException.ErrorSeverity.ERROR, info);
48 SendErrorExceptionUtil.sendErrorMessage(ctx.channel(), ex);