From 5244112b00941ea58f07485d9289d576741d1f66 Mon Sep 17 00:00:00 2001 From: Mathieu Viossat Date: Sat, 19 Aug 2017 15:03:25 +0100 Subject: [PATCH] Fix IXI command selection --- src/main/java/com/iota/iri/IXI.java | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/iota/iri/IXI.java b/src/main/java/com/iota/iri/IXI.java index 296b62fedd..53e2d5af18 100644 --- a/src/main/java/com/iota/iri/IXI.java +++ b/src/main/java/com/iota/iri/IXI.java @@ -22,6 +22,8 @@ import java.time.Instant; import java.util.*; import java.util.concurrent.TimeUnit; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import static com.sun.jmx.mbeanserver.Util.cast; import static java.nio.file.StandardWatchEventKinds.*; @@ -182,16 +184,13 @@ private Path getPackagePath(Path modulePath) { } public AbstractResponse processCommand(final String command, Map request) { - Map> ixiMap; - AbstractResponse res; - String substring; - for (String key: ixiAPI.keySet()) { - substring = command.substring(0, key.length()); - if(substring.equals(key)) { - String subCmd = command.substring(key.length()+1); - ixiMap = ixiAPI.get(key); - res = ixiMap.get(subCmd).call(request); - if(res != null) return res; + Pattern pattern = Pattern.compile("^(.*)\\.(.*)$"); + Matcher matcher = pattern.matcher(command); + + if (matcher.find()) { + Map> ixiMap = ixiAPI.get(matcher.group(1)); + if (ixiMap != null) { + return ixiMap.get(matcher.group(2)).call(request); } } return null;