import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.List;
+import org.opendaylight.controller.config.util.xml.XmlUtil;
import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
import org.opendaylight.controller.netconf.api.NetconfMessage;
import org.opendaylight.controller.netconf.util.messages.NetconfHelloMessage;
import org.opendaylight.controller.netconf.util.messages.NetconfHelloMessageAdditionalHeader;
-import org.opendaylight.controller.netconf.util.xml.XmlUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
// Auth information containing username, ip address... extracted for monitoring
int endOfAuthHeader = getAdditionalHeaderEndIndex(bytes);
if (endOfAuthHeader > -1) {
- byte[] additionalHeaderBytes = Arrays.copyOfRange(bytes, 0, endOfAuthHeader + 2);
+ byte[] additionalHeaderBytes = Arrays.copyOfRange(bytes, 0, endOfAuthHeader);
additionalHeader = additionalHeaderToString(additionalHeaderBytes);
- bytes = Arrays.copyOfRange(bytes, endOfAuthHeader + 2, bytes.length);
+ bytes = Arrays.copyOfRange(bytes, endOfAuthHeader, bytes.length);
}
}
}
}
- private 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 (additionalHeader != null) {
return msg;
}
- private int getAdditionalHeaderEndIndex(final byte[] bytes) {
+ private static int getAdditionalHeaderEndIndex(final byte[] bytes) {
for (byte[] possibleEnd : POSSIBLE_ENDS) {
int idx = findByteSequence(bytes, possibleEnd);
if (idx != -1) {
- return idx;
+ return idx + possibleEnd.length;
}
}
return -1;
}
-
- private void logMessage(final byte[] bytes) {
- String s = Charsets.UTF_8.decode(ByteBuffer.wrap(bytes)).toString();
- LOG.debug("Parsing message \n{}", s);
+ private static void logMessage(final byte[] bytes) {
+ if (LOG.isDebugEnabled()) {
+ String s = Charsets.UTF_8.decode(ByteBuffer.wrap(bytes)).toString();
+ LOG.debug("Parsing message \n{}", s);
+ }
}
- private boolean startsWithAdditionalHeader(final byte[] bytes) {
+ private static boolean startsWithAdditionalHeader(final byte[] bytes) {
for (byte[] possibleStart : POSSIBLE_STARTS) {
int i = 0;
for (byte b : possibleStart) {
return false;
}
- private String additionalHeaderToString(final byte[] bytes) {
+ private static String additionalHeaderToString(final byte[] bytes) {
return Charsets.UTF_8.decode(ByteBuffer.wrap(bytes)).toString();
}