From dfb15c6adaa52b55f95a311d0cfd851b9c6a358c Mon Sep 17 00:00:00 2001 From: junaidkhan Date: Tue, 14 Jan 2025 16:10:47 +0500 Subject: [PATCH] NMS-15717 : DeviceConfig via Minion fails if sshScript output contains control characters.(upgrade library - draft). --- .../opennms/netmgt/poller/DeviceConfig.java | 1 - .../netmgt/poller/EscapeSequenceAdapter.java | 71 -------------- .../poller/EscapeSequenceAdapterTest.java | 95 ------------------- pom.xml | 2 +- 4 files changed, 1 insertion(+), 168 deletions(-) delete mode 100755 features/poller/api/src/main/java/org/opennms/netmgt/poller/EscapeSequenceAdapter.java delete mode 100755 features/poller/api/src/test/java/org/opennms/netmgt/poller/EscapeSequenceAdapterTest.java diff --git a/features/poller/api/src/main/java/org/opennms/netmgt/poller/DeviceConfig.java b/features/poller/api/src/main/java/org/opennms/netmgt/poller/DeviceConfig.java index ae1a644fc3fc..5e96664651ef 100755 --- a/features/poller/api/src/main/java/org/opennms/netmgt/poller/DeviceConfig.java +++ b/features/poller/api/src/main/java/org/opennms/netmgt/poller/DeviceConfig.java @@ -45,7 +45,6 @@ public class DeviceConfig { private String filename; @XmlAttribute(name="scriptOutput") - @XmlJavaTypeAdapter(EscapeSequenceAdapter.class) private String scriptOutput; public DeviceConfig(String scriptOutput) { diff --git a/features/poller/api/src/main/java/org/opennms/netmgt/poller/EscapeSequenceAdapter.java b/features/poller/api/src/main/java/org/opennms/netmgt/poller/EscapeSequenceAdapter.java deleted file mode 100755 index a810457fc67c..000000000000 --- a/features/poller/api/src/main/java/org/opennms/netmgt/poller/EscapeSequenceAdapter.java +++ /dev/null @@ -1,71 +0,0 @@ -/******************************************************************************* - * This file is part of OpenNMS(R). - * - * Copyright (C) 2023 The OpenNMS Group, Inc. - * OpenNMS(R) is Copyright (C) 1999-2023 The OpenNMS Group, Inc. - * - * OpenNMS(R) is a registered trademark of The OpenNMS Group, Inc. - * - * OpenNMS(R) is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published - * by the Free Software Foundation, either version 3 of the License, - * or (at your option) any later version. - * - * OpenNMS(R) is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with OpenNMS(R). If not, see: - * http://www.gnu.org/licenses/ - * - * For more information contact: - * OpenNMS(R) Licensing - * http://www.opennms.org/ - * http://www.opennms.com/ - *******************************************************************************/ - -package org.opennms.netmgt.poller; - -import org.eclipse.persistence.exceptions.XMLMarshalException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.xml.bind.annotation.adapters.XmlAdapter; - -public class EscapeSequenceAdapter extends XmlAdapter { - private static final Logger LOG = LoggerFactory.getLogger(EscapeSequenceAdapter.class); - - public EscapeSequenceAdapter() { - - } - - @Override - public String unmarshal(String v) throws Exception { - if (v != null) { - v = v.replace(" ", "\r") - .replace(" ", "\n"); - } - try { - return v; - } catch (XMLMarshalException e) { - LOG.warn("Unable to unmarshal escape sequences value '{}' to a script output. Returning null instead.", v); - return null; - } - } - - @Override - public String marshal(String v) throws Exception { - if (v != null) { - v = v.replace("\r", " ") - .replace("\n", " "); - } - try { - return v; - } catch (XMLMarshalException e) { - LOG.warn("Unable to marshal escape sequences value '{}' to a script output. Returning null instead.", v); - return null; - } - } -} diff --git a/features/poller/api/src/test/java/org/opennms/netmgt/poller/EscapeSequenceAdapterTest.java b/features/poller/api/src/test/java/org/opennms/netmgt/poller/EscapeSequenceAdapterTest.java deleted file mode 100755 index 7228c69a4b03..000000000000 --- a/features/poller/api/src/test/java/org/opennms/netmgt/poller/EscapeSequenceAdapterTest.java +++ /dev/null @@ -1,95 +0,0 @@ -/******************************************************************************* - * This file is part of OpenNMS(R). - * - * Copyright (C) 2023 The OpenNMS Group, Inc. - * OpenNMS(R) is Copyright (C) 1999-2023 The OpenNMS Group, Inc. - * - * OpenNMS(R) is a registered trademark of The OpenNMS Group, Inc. - * - * OpenNMS(R) is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published - * by the Free Software Foundation, either version 3 of the License, - * or (at your option) any later version. - * - * OpenNMS(R) is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with OpenNMS(R). If not, see: - * http://www.gnu.org/licenses/ - * - * For more information contact: - * OpenNMS(R) Licensing - * http://www.opennms.org/ - * http://www.opennms.com/ - *******************************************************************************/ - -package org.opennms.netmgt.poller; - - -import org.junit.Before; -import org.junit.Test; - -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertEquals; - - -public class EscapeSequenceAdapterTest { - - private EscapeSequenceAdapter adapter; - - @Before - public void setUp() { - adapter = new EscapeSequenceAdapter(); - } - - @Test - public void testUnmarshalWithEscapeSequences() throws Exception { - String input = "Hello World Test"; - String expected = "Hello\rWorld\nTest"; - String result = adapter.unmarshal(input); - assertNotNull(result, "Result should not be null"); - assertEquals("Escape sequences should be replaced correctly", expected, result); - } - - @Test - public void testUnmarshalWithNullValue() throws Exception { - String result = adapter.unmarshal(null); - assertNull("Null input should return null", result); - } - - @Test - public void testMarshalWithSpecialCharacters() throws Exception { - String input = "Hello\rWorld\nTest"; - String expected = "Hello World Test"; - String result = adapter.marshal(input); - assertNotNull(result,"Result should not be null"); - assertEquals("Special characters should be converted to escape sequences",expected, result); - } - @Test - public void testMarshalWithNullValue() throws Exception { - String result = adapter.marshal(null); - assertNull("Null input should return null",result); - } - - @Test - public void testUnmarshalWithNoEscapeSequences() throws Exception { - String input = "NoEscapeSequenceHere"; - String expected = "NoEscapeSequenceHere"; - String result = adapter.unmarshal(input); - assertNotNull( "Result should not be null",result); - assertEquals("Input without escape sequences should remain unchanged",expected, result); - } - - @Test - public void testMarshalWithNoSpecialCharacters() throws Exception { - String input = "NormalString"; - String expected = "NormalString"; - String result = adapter.marshal(input); - assertNotNull( "Result should not be null",result); - assertEquals( "Input without special characters should remain unchanged",expected, result); - } -} diff --git a/pom.xml b/pom.xml index 5c5dffc14580..b8a1d8cacce1 100644 --- a/pom.xml +++ b/pom.xml @@ -1658,7 +1658,7 @@ 3.1.2 4.4.2 2.1.0.RELEASE - 2.5.1 + 2.7.6 0.3.0 4.1.69.Final 7.6.2