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.controller.netconf.impl.util;
11 import com.google.common.collect.Maps;
12 import io.netty.channel.ChannelHandler;
13 import io.netty.channel.ChannelHandlerContext;
14 import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
15 import org.opendaylight.controller.netconf.util.messages.SendErrorExceptionUtil;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
22 DeserializerExceptionHandler implements ChannelHandler {
24 private static final Logger logger = LoggerFactory.getLogger(DeserializerExceptionHandler.class);
28 public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
33 public void handlerRemoved(ChannelHandlerContext ctx) throws Exception {
38 public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
39 logger.warn("An exception occurred during message handling", cause);
40 handleDeserializerException(ctx, cause);
43 private void handleDeserializerException(ChannelHandlerContext ctx, Throwable cause) {
45 Map<String, String> info = Maps.newHashMap();
46 info.put("cause", cause.getMessage());
47 NetconfDocumentedException ex = new NetconfDocumentedException(cause.getMessage(),
48 NetconfDocumentedException.ErrorType.rpc, NetconfDocumentedException.ErrorTag.malformed_message,
49 NetconfDocumentedException.ErrorSeverity.error, info);
51 SendErrorExceptionUtil.sendErrorMessage(ctx.channel(), ex);