From dbe14687f393d3d74f7d16b54542101d0fafbce6 Mon Sep 17 00:00:00 2001 From: Alejandro Revilla Date: Fri, 29 Mar 2024 16:25:28 -0500 Subject: [PATCH] Add ISOMsg.merge(ISOMsg m, boolean mergeHeader) option rolled back change from the previous commit to avoid rocking the boat with a non backward compatible (@barspi raised a very reasonable concern). --- jpos/src/main/java/org/jpos/iso/ISOMsg.java | 15 +++++++++++++-- jpos/src/test/java/org/jpos/iso/ISOMsg2Test.java | 2 ++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/jpos/src/main/java/org/jpos/iso/ISOMsg.java b/jpos/src/main/java/org/jpos/iso/ISOMsg.java index 2dc2ba1d7d..b9c48a1143 100644 --- a/jpos/src/main/java/org/jpos/iso/ISOMsg.java +++ b/jpos/src/main/java/org/jpos/iso/ISOMsg.java @@ -848,10 +848,11 @@ public ISOMsg clone(String ... fpaths) { * * @param m The ISOMsg to merge into this ISOMsg. It must not be {@code null}. * The method does nothing if {@code m} is {@code null}. + * @param mergeHeader A boolean flag indicating whether to merge the header of the input message into this message. * */ @SuppressWarnings("PMD.EmptyCatchBlock") - public void merge (ISOMsg m) { + public void merge (ISOMsg m, boolean mergeHeader) { for (int i : m.fields.keySet()) { try { if (i >= 0 && m.hasField(i)) @@ -860,10 +861,20 @@ public void merge (ISOMsg m) { // should never happen } } - if (m.header != null) + if (mergeHeader && m.header != null) header = (ISOHeader) m.header.clone(); } + /* + * Merges the content of the specified ISOMsg into this ISOMsg instance, excluding the header. + * This method is a convenience wrapper around {@link #merge(ISOMsg, boolean)} with the {@code mergeHeader} + * parameter set to {@code false} for backward compatibility, indicating that the header of the input message + * will not be merged. + */ + public void merge (ISOMsg m) { + merge (m, false); + } + /** * @return a string suitable for a log */ diff --git a/jpos/src/test/java/org/jpos/iso/ISOMsg2Test.java b/jpos/src/test/java/org/jpos/iso/ISOMsg2Test.java index c7e215c382..4b0d3dcfb6 100644 --- a/jpos/src/test/java/org/jpos/iso/ISOMsg2Test.java +++ b/jpos/src/test/java/org/jpos/iso/ISOMsg2Test.java @@ -642,6 +642,8 @@ public void testMerge1() throws Throwable { assertEquals(3, iSOMsg.maxField, "iSOMsg.maxField"); assertTrue(iSOMsg.dirty, "iSOMsg.dirty"); assertEquals("000000", iSOMsg.getString(3)); + assertNull(iSOMsg.getHeader()); + iSOMsg.merge(m, true); assertArrayEquals("ISOHEADER".getBytes(), iSOMsg.getHeader()); }