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 { ...@@ -427,7 +427,7 @@ public class NetconfSessionImpl implements NetconfSession {
427 rpc.append(EDIT_CONFIG_CLOSE).append("\n"); 427 rpc.append(EDIT_CONFIG_CLOSE).append("\n");
428 rpc.append(RPC_CLOSE); 428 rpc.append(RPC_CLOSE);
429 rpc.append(ENDPATTERN); 429 rpc.append(ENDPATTERN);
430 - log.info(rpc.toString()); 430 + log.debug(rpc.toString());
431 String reply = sendRequest(rpc.toString()); 431 String reply = sendRequest(rpc.toString());
432 return checkReply(reply); 432 return checkReply(reply);
433 } 433 }
......
...@@ -34,6 +34,8 @@ import java.io.PrintWriter; ...@@ -34,6 +34,8 @@ import java.io.PrintWriter;
34 import java.util.List; 34 import java.util.List;
35 import java.util.Optional; 35 import java.util.Optional;
36 import java.util.concurrent.CompletableFuture; 36 import java.util.concurrent.CompletableFuture;
37 +import java.util.regex.Matcher;
38 +import java.util.regex.Pattern;
37 39
38 /** 40 /**
39 * Thread that gets spawned each time a session is established and handles all the input 41 * 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 ...@@ -50,6 +52,7 @@ public class NetconfStreamThread extends Thread implements NetconfStreamHandler
50 private static final String RPC_ERROR = "rpc-error"; 52 private static final String RPC_ERROR = "rpc-error";
51 private static final String NOTIFICATION_LABEL = "<notification"; 53 private static final String NOTIFICATION_LABEL = "<notification";
52 private static final String MESSAGE_ID = "message-id="; 54 private static final String MESSAGE_ID = "message-id=";
55 + private static final Pattern MSGID_PATTERN = Pattern.compile(MESSAGE_ID + "\"(\\d+)\"");
53 56
54 private PrintWriter outputStream; 57 private PrintWriter outputStream;
55 private final InputStream err; 58 private final InputStream err;
...@@ -220,15 +223,13 @@ public class NetconfStreamThread extends Thread implements NetconfStreamHandler ...@@ -220,15 +223,13 @@ public class NetconfStreamThread extends Thread implements NetconfStreamHandler
220 } 223 }
221 224
222 private static Optional<Integer> getMsgId(String reply) { 225 private static Optional<Integer> getMsgId(String reply) {
223 - if (reply.contains(MESSAGE_ID)) { 226 + Matcher matcher = MSGID_PATTERN.matcher(reply);
224 - String[] outer = reply.split(MESSAGE_ID); 227 + if (matcher.find()) {
225 - Preconditions.checkArgument(outer.length != 1, 228 + Integer messageId = Integer.parseInt(matcher.group(1));
226 - "Error in retrieving the message id"); 229 + Preconditions.checkNotNull(messageId, "Error in retrieving the message id");
227 - String messageID = outer[1].substring(0, 3).replace("\"", ""); 230 + return Optional.of(messageId);
228 - Preconditions.checkNotNull(Integer.parseInt(messageID), 231 + }
229 - "Error in retrieving the message id"); 232 + if (reply.contains(HELLO)) {
230 - return Optional.of(Integer.parseInt(messageID));
231 - } else if (reply.contains(HELLO)) {
232 return Optional.of(0); 233 return Optional.of(0);
233 } 234 }
234 return Optional.empty(); 235 return Optional.empty();
......