2 * Copyright (c) 2014 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.controller.netconf.util.handler;
10 import io.netty.buffer.ByteBuf;
11 import io.netty.buffer.ByteBufInputStream;
12 import io.netty.buffer.ByteBufUtil;
13 import io.netty.channel.ChannelHandlerContext;
14 import io.netty.handler.codec.ByteToMessageDecoder;
16 import java.io.IOException;
17 import java.util.List;
19 import org.opendaylight.controller.netconf.api.NetconfMessage;
20 import org.opendaylight.controller.netconf.util.xml.XmlUtil;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
24 import com.google.common.annotations.VisibleForTesting;
25 import org.xml.sax.SAXException;
27 public final class NetconfXMLToMessageDecoder extends ByteToMessageDecoder {
28 private static final Logger LOG = LoggerFactory.getLogger(NetconfXMLToMessageDecoder.class);
32 public void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws IOException, SAXException {
33 if (in.readableBytes() != 0) {
34 LOG.trace("Received to decode: {}", ByteBufUtil.hexDump(in));
35 out.add(new NetconfMessage(XmlUtil.readXmlToDocument(new ByteBufInputStream(in))));
37 LOG.debug("No more content in incoming buffer.");