From 85f4d1c58aaa113fd75084cc953f880c2f7f6496 Mon Sep 17 00:00:00 2001 From: Jin Date: Thu, 9 Jan 2025 23:27:52 +0800 Subject: [PATCH] Fix channel name split issue in JPOS 3 --- jpos/src/main/java/org/jpos/iso/ISOServer.java | 2 +- jpos/src/main/java/org/jpos/q2/iso/QServer.java | 15 +++++---------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/jpos/src/main/java/org/jpos/iso/ISOServer.java b/jpos/src/main/java/org/jpos/iso/ISOServer.java index dd8a2db25b..8ba21d06af 100644 --- a/jpos/src/main/java/org/jpos/iso/ISOServer.java +++ b/jpos/src/main/java/org/jpos/iso/ISOServer.java @@ -653,7 +653,7 @@ public String getISOChannelNames () { WeakReference ref = (WeakReference) entry.getValue(); ISOChannel c = (ISOChannel) ref.get (); if (c != null && !LAST.equals (entry.getKey()) && c.isConnected()) { - if (i > 0) { + if (i > 0 && !sb.isEmpty()) { sb.append (' '); } sb.append (entry.getKey()); diff --git a/jpos/src/main/java/org/jpos/q2/iso/QServer.java b/jpos/src/main/java/org/jpos/q2/iso/QServer.java index f7aee026d4..abe4018563 100644 --- a/jpos/src/main/java/org/jpos/q2/iso/QServer.java +++ b/jpos/src/main/java/org/jpos/q2/iso/QServer.java @@ -348,11 +348,12 @@ public void notify(Object key, Object value) { } else if ("ALL".equals(sendMethod)) { String channelNames = getISOChannelNames(); + String[] channelName; if (channelNames != null) { - StringTokenizer tok = new StringTokenizer(channelNames, " "); - while (tok.hasMoreTokens()) { + channelName = channelNames.split(" (?=\\d+ \\S+:\\S+)"); + for (String s : channelName) { try { - ISOChannel c = server.getISOChannel(tok.nextToken()); + ISOChannel c = server.getISOChannel(s); if (c == null) { throw new ISOException("Server has no active connections"); } @@ -368,15 +369,9 @@ else if ("ALL".equals(sendMethod)) { } else if ("RR".equals(sendMethod)) { String channelNames = getISOChannelNames(); - int i =0; String[] channelName; if (channelNames != null) { - StringTokenizer tok = new StringTokenizer(channelNames, " "); - channelName = new String[tok.countTokens()]; - while (tok.hasMoreTokens()) { - channelName[i] = tok.nextToken(); - i++; - } + channelName = channelNames.split(" (?=\\d+ \\S+:\\S+)"); try { ISOChannel c = server.getISOChannel(channelName[msgn.incrementAndGet() % channelName.length]); if (c == null) {