From 92b0b8f418f245bdde8996721e4ba422cf7b142e 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 734c7e4359..bd4f6c8c7a 100644 --- a/jpos/src/main/java/org/jpos/iso/ISOMsg.java +++ b/jpos/src/main/java/org/jpos/iso/ISOMsg.java @@ -847,10 +847,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)) @@ -859,10 +860,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 69a78b0f58..da383ab37f 100644 --- a/jpos/src/test/java/org/jpos/iso/ISOMsg2Test.java +++ b/jpos/src/test/java/org/jpos/iso/ISOMsg2Test.java @@ -636,6 +636,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()); }