use of org.opendaylight.netconf.nettyutil.handler.NetconfXMLToMessageDecoder in project netconf by opendaylight.
the class NetconfServerSessionTest method testAddExiHandlers.
@Test
public void testAddExiHandlers() throws Exception {
channel.pipeline().addLast(AbstractChannelInitializer.NETCONF_MESSAGE_DECODER, new NetconfXMLToMessageDecoder());
channel.pipeline().addLast(AbstractChannelInitializer.NETCONF_MESSAGE_ENCODER, new NetconfMessageToXMLEncoder());
final NetconfEXICodec codec = NetconfEXICodec.forParameters(EXIParameters.empty());
session.addExiHandlers(NetconfEXIToMessageDecoder.create(codec), NetconfMessageToEXIEncoder.create(codec));
}
use of org.opendaylight.netconf.nettyutil.handler.NetconfXMLToMessageDecoder in project netconf by opendaylight.
the class MessageParserTest method testEOMFramingMechanismOnPipeline.
@Test
public void testEOMFramingMechanismOnPipeline() throws Exception {
EmbeddedChannel testChunkChannel = new EmbeddedChannel(FramingMechanismHandlerFactory.createHandler(FramingMechanism.EOM), new NetconfMessageToXMLEncoder(), new NetconfEOMAggregator(), new NetconfXMLToMessageDecoder());
testChunkChannel.writeOutbound(this.msg);
ByteBuf recievedOutbound = testChunkChannel.readOutbound();
byte[] endOfMsgBytes = NetconfMessageConstants.END_OF_MESSAGE.getBytes(StandardCharsets.UTF_8);
byte[] eom = new byte[endOfMsgBytes.length];
recievedOutbound.getBytes(recievedOutbound.readableBytes() - endOfMsgBytes.length, eom);
assertArrayEquals(endOfMsgBytes, eom);
testChunkChannel.writeInbound(recievedOutbound);
NetconfMessage receivedMessage = testChunkChannel.readInbound();
assertNotNull(receivedMessage);
XMLUnit.setIgnoreWhitespace(true);
assertXMLEqual(this.msg.getDocument(), receivedMessage.getDocument());
}
use of org.opendaylight.netconf.nettyutil.handler.NetconfXMLToMessageDecoder in project netconf by opendaylight.
the class MessageParserTest method testChunkedFramingMechanismOnPipeline.
@Test
public void testChunkedFramingMechanismOnPipeline() throws Exception {
EmbeddedChannel testChunkChannel = new EmbeddedChannel(FramingMechanismHandlerFactory.createHandler(FramingMechanism.CHUNK), new NetconfMessageToXMLEncoder(), new NetconfChunkAggregator(), new NetconfXMLToMessageDecoder());
testChunkChannel.writeOutbound(this.msg);
Queue<Object> messages = testChunkChannel.outboundMessages();
assertFalse(messages.isEmpty());
final NetconfMessageToXMLEncoder enc = new NetconfMessageToXMLEncoder();
final ByteBuf out = Unpooled.buffer();
enc.encode(null, msg, out);
int msgLength = out.readableBytes();
int chunkCount = msgLength / ChunkedFramingMechanismEncoder.DEFAULT_CHUNK_SIZE;
if (msgLength % ChunkedFramingMechanismEncoder.DEFAULT_CHUNK_SIZE != 0) {
chunkCount++;
}
byte[] endOfChunkBytes = NetconfMessageConstants.END_OF_CHUNK.getBytes(StandardCharsets.UTF_8);
for (int i = 1; i <= chunkCount; i++) {
ByteBuf recievedOutbound = (ByteBuf) messages.poll();
int exptHeaderLength = ChunkedFramingMechanismEncoder.DEFAULT_CHUNK_SIZE;
if (i == chunkCount) {
exptHeaderLength = msgLength - ChunkedFramingMechanismEncoder.DEFAULT_CHUNK_SIZE * (i - 1);
byte[] eom = new byte[endOfChunkBytes.length];
recievedOutbound.getBytes(recievedOutbound.readableBytes() - endOfChunkBytes.length, eom);
assertArrayEquals(endOfChunkBytes, eom);
}
byte[] header = new byte[String.valueOf(exptHeaderLength).length() + NetconfMessageConstants.MIN_HEADER_LENGTH - 1];
recievedOutbound.getBytes(0, header);
assertEquals(exptHeaderLength, getHeaderLength(header));
testChunkChannel.writeInbound(recievedOutbound);
}
assertTrue(messages.isEmpty());
NetconfMessage receivedMessage = testChunkChannel.readInbound();
assertNotNull(receivedMessage);
XMLUnit.setIgnoreWhitespace(true);
assertXMLEqual(this.msg.getDocument(), receivedMessage.getDocument());
}
use of org.opendaylight.netconf.nettyutil.handler.NetconfXMLToMessageDecoder in project netconf by opendaylight.
the class NetconfClientSession method stopExiCommunication.
@Override
public void stopExiCommunication() {
// TODO never used, Netconf client does not support stop-exi
replaceMessageDecoder(new NetconfXMLToMessageDecoder());
replaceMessageEncoder(new NetconfMessageToXMLEncoder());
}
use of org.opendaylight.netconf.nettyutil.handler.NetconfXMLToMessageDecoder in project netconf by opendaylight.
the class NetconfServerSession method stopExiCommunication.
@Override
public void stopExiCommunication() {
replaceMessageDecoder(new NetconfXMLToMessageDecoder());
replaceMessageEncoderAfterNextMessage(new NetconfMessageToXMLEncoder());
}
Aggregations