private static NetconfMessage getNetconfMessage(final String additionalHeader, final Document doc) throws NetconfDocumentedException { NetconfMessage msg = new NetconfMessage(doc); if(NetconfHelloMessage.isHelloMessage(msg)) { if (additionalHeader != null) { return new NetconfHelloMessage(doc, NetconfHelloMessageAdditionalHeader.fromString(additionalHeader)); } else { return new NetconfHelloMessage(doc); } } return msg; }
@Override @VisibleForTesting public void encode(ChannelHandlerContext ctx, NetconfMessage msg, ByteBuf out) throws IOException, TransformerException { Preconditions.checkState(msg instanceof NetconfHelloMessage, "Netconf message of type %s expected, was %s", NetconfHelloMessage.class, msg.getClass()); Optional<NetconfHelloMessageAdditionalHeader> headerOptional = ((NetconfHelloMessage) msg) .getAdditionalHeader(); // If additional header present, serialize it along with netconf hello message if (headerOptional.isPresent()) { out.writeBytes(headerOptional.get().toFormattedString().getBytes(StandardCharsets.UTF_8)); } super.encode(ctx, msg, out); } }
protected final S getSessionForHelloMessage(final NetconfHelloMessage netconfMessage) throws NetconfDocumentedException { Preconditions.checkNotNull(netconfMessage, "netconfMessage"); final Document doc = netconfMessage.getDocument(); if (shouldUseChunkFraming(doc)) { insertChunkFramingToPipeline(); } changeState(State.ESTABLISHED); return getSession(sessionListener, channel, netconfMessage); }
private boolean shouldUseChunkFraming(final Document doc) { return containsBase11Capability(doc) && containsBase11Capability(sessionPreferences.getHelloMessage().getDocument()); }