Konstantinos Kanonakis
Committed by Gerrit Code Review

Allowing message-id > 99 in NETCONF rcp-reply

Change-Id: If6fbc0c3ea432e8d33f6d790491342312333cee4
......@@ -427,7 +427,7 @@ public class NetconfSessionImpl implements NetconfSession {
rpc.append(EDIT_CONFIG_CLOSE).append("\n");
rpc.append(RPC_CLOSE);
rpc.append(ENDPATTERN);
log.info(rpc.toString());
log.debug(rpc.toString());
String reply = sendRequest(rpc.toString());
return checkReply(reply);
}
......
......@@ -34,6 +34,8 @@ import java.io.PrintWriter;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Thread that gets spawned each time a session is established and handles all the input
......@@ -50,6 +52,7 @@ public class NetconfStreamThread extends Thread implements NetconfStreamHandler
private static final String RPC_ERROR = "rpc-error";
private static final String NOTIFICATION_LABEL = "<notification";
private static final String MESSAGE_ID = "message-id=";
private static final Pattern MSGID_PATTERN = Pattern.compile(MESSAGE_ID + "\"(\\d+)\"");
private PrintWriter outputStream;
private final InputStream err;
......@@ -220,15 +223,13 @@ public class NetconfStreamThread extends Thread implements NetconfStreamHandler
}
private static Optional<Integer> getMsgId(String reply) {
if (reply.contains(MESSAGE_ID)) {
String[] outer = reply.split(MESSAGE_ID);
Preconditions.checkArgument(outer.length != 1,
"Error in retrieving the message id");
String messageID = outer[1].substring(0, 3).replace("\"", "");
Preconditions.checkNotNull(Integer.parseInt(messageID),
"Error in retrieving the message id");
return Optional.of(Integer.parseInt(messageID));
} else if (reply.contains(HELLO)) {
Matcher matcher = MSGID_PATTERN.matcher(reply);
if (matcher.find()) {
Integer messageId = Integer.parseInt(matcher.group(1));
Preconditions.checkNotNull(messageId, "Error in retrieving the message id");
return Optional.of(messageId);
}
if (reply.contains(HELLO)) {
return Optional.of(0);
}
return Optional.empty();
......