import java.util.Arrays;
import java.util.List;
import org.opendaylight.controller.config.util.xml.XmlUtil;
-import org.opendaylight.netconf.api.messages.NetconfHelloMessage;
-import org.opendaylight.netconf.api.messages.NetconfHelloMessageAdditionalHeader;
import org.opendaylight.netconf.api.NetconfDocumentedException;
import org.opendaylight.netconf.api.NetconfMessage;
+import org.opendaylight.netconf.api.messages.NetconfHelloMessage;
+import org.opendaylight.netconf.api.messages.NetconfHelloMessageAdditionalHeader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
/**
* Customized NetconfXMLToMessageDecoder that reads additional header with
* session metadata from
- * {@link NetconfHelloMessage}
- *
- *
+ * {@link NetconfHelloMessage}*
* This handler should be replaced in pipeline by regular message handler as last step of negotiation.
* It serves as a message barrier and halts all non-hello netconf messages.
* Netconf messages after hello should be processed once the negotiation succeeded.
@Override
@VisibleForTesting
- public void decode(final ChannelHandlerContext ctx, final ByteBuf in, final List<Object> out) throws IOException, SAXException, NetconfDocumentedException {
+ public void decode(final ChannelHandlerContext ctx, final ByteBuf in, final List<Object> out)
+ throws IOException, SAXException, NetconfDocumentedException {
if (in.readableBytes() == 0) {
LOG.debug("No more content in incoming buffer.");
return;
}
}
- private static NetconfMessage getNetconfMessage(final String additionalHeader, final Document doc) throws NetconfDocumentedException {
+ private static NetconfMessage getNetconfMessage(final String additionalHeader, final Document doc)
+ throws NetconfDocumentedException {
NetconfMessage msg = new NetconfMessage(doc);
- if(NetconfHelloMessage.isHelloMessage(msg)) {
+ if (NetconfHelloMessage.isHelloMessage(msg)) {
if (additionalHeader != null) {
return new NetconfHelloMessage(doc, NetconfHelloMessageAdditionalHeader.fromString(additionalHeader));
} else {
return -1;
}
}
- int j = 0;
+ int index = 0;
for (int i = 0; i < bytes.length; i++) {
- if (bytes[i] == sequence[j]) {
- j++;
- if (j == sequence.length) {
- return i - j + 1;
+ if (bytes[i] == sequence[index]) {
+ index++;
+ if (index == sequence.length) {
+ return i - index + 1;
}
} else {
- j = 0;
+ index = 0;
}
}
return -1;
private static void logMessage(final byte[] bytes) {
if (LOG.isDebugEnabled()) {
- String s = StandardCharsets.UTF_8.decode(ByteBuffer.wrap(bytes)).toString();
- LOG.debug("Parsing message \n{}", s);
+ String string = StandardCharsets.UTF_8.decode(ByteBuffer.wrap(bytes)).toString();
+ LOG.debug("Parsing message \n{}", string);
}
}
private static boolean startsWithAdditionalHeader(final byte[] bytes) {
for (byte[] possibleStart : POSSIBLE_STARTS) {
- int i = 0;
+ int index = 0;
for (byte b : possibleStart) {
- if(bytes[i++] != b) {
+ if (bytes[index++] != b) {
break;
}
- if(i == possibleStart.length) {
+ if (index == possibleStart.length) {
return true;
}
}
}
/**
- * @return Collection of NetconfMessages that were not hello, but were received during negotiation
+ * Get netconf messages received during negotiation.
+ *
+ * @return Collection of NetconfMessages that were not hello, but were received during negotiation.
*/
public Iterable<NetconfMessage> getPostHelloNetconfMessages() {
return nonHelloMessages;