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;
13 import org.opendaylight.controller.netconf.api.NetconfDeserializerException;
14 import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
15 import org.opendaylight.controller.netconf.util.messages.SendErrorExceptionUtil;
17 import com.google.common.collect.Maps;
19 import io.netty.channel.ChannelHandler;
20 import io.netty.channel.ChannelHandlerContext;
22 public final class DeserializerExceptionHandler implements ChannelHandler {
25 public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
30 public void handlerRemoved(ChannelHandlerContext ctx) throws Exception {
35 public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
36 if (cause instanceof NetconfDeserializerException) {
37 handleDeserializerException(ctx, cause);
41 private void handleDeserializerException(ChannelHandlerContext ctx, Throwable cause) {
43 Map<String, String> info = Maps.newHashMap();
44 info.put("cause", cause.getMessage());
45 NetconfDocumentedException ex = new NetconfDocumentedException(cause.getMessage(),
46 NetconfDocumentedException.ErrorType.rpc, NetconfDocumentedException.ErrorTag.malformed_message,
47 NetconfDocumentedException.ErrorSeverity.error, info);
49 SendErrorExceptionUtil.sendErrorMessage(ctx.channel(), ex);