From 2cb2bbc6a5e69fbafd0fc2f6605d301b96376ca9 Mon Sep 17 00:00:00 2001 From: Daniel McCoy Stephenson Date: Wed, 29 Mar 2023 09:03:37 -0600 Subject: [PATCH 1/4] Added a unit test for depositing a tim with extra properties. --- .../dot/its/jpo/ode/traveler/TimDepositControllerTest.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/jpo-ode-svcs/src/test/java/us/dot/its/jpo/ode/traveler/TimDepositControllerTest.java b/jpo-ode-svcs/src/test/java/us/dot/its/jpo/ode/traveler/TimDepositControllerTest.java index e76cd0ced..7bf56b99a 100644 --- a/jpo-ode-svcs/src/test/java/us/dot/its/jpo/ode/traveler/TimDepositControllerTest.java +++ b/jpo-ode-svcs/src/test/java/us/dot/its/jpo/ode/traveler/TimDepositControllerTest.java @@ -160,4 +160,11 @@ public void testSuccessfulMessageReturnsSuccessMessagePut(@Capturing TimTransmog assertEquals("{\"success\":\"true\"}", actualResponse.getBody()); } + @Test + public void testDepositingTimWithExtraProperties(@Capturing TimTransmogrifier capturingTimTransmogrifier, @Capturing XmlUtils capturingXmlUtils) { + String timToSubmit = "{\"request\":{\"rsus\":[],\"snmp\":{},\"randomProp1\":true,\"randomProp2\":\"hello world\"},\"tim\":{\"msgCnt\":\"13\",\"timeStamp\":\"2017-03-13T01:07:11-05:00\",\"randomProp3\":123,\"randomProp4\":{\"nestedProp1\":\"foo\",\"nestedProp2\":\"bar\"}}}"; + ResponseEntity actualResponse = testTimDepositController.postTim(timToSubmit); + assertEquals("{\"success\":\"true\"}", actualResponse.getBody()); + } + } From 9daaf0ff825fe5f5e0aca77608ba9a0138580823 Mon Sep 17 00:00:00 2001 From: Daniel McCoy Stephenson Date: Wed, 29 Mar 2023 10:12:56 -0600 Subject: [PATCH 2/4] Fixed input to invalid syntax test not being invalid. --- .../us/dot/its/jpo/ode/traveler/TimDepositControllerTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jpo-ode-svcs/src/test/java/us/dot/its/jpo/ode/traveler/TimDepositControllerTest.java b/jpo-ode-svcs/src/test/java/us/dot/its/jpo/ode/traveler/TimDepositControllerTest.java index 7bf56b99a..5c61a856b 100644 --- a/jpo-ode-svcs/src/test/java/us/dot/its/jpo/ode/traveler/TimDepositControllerTest.java +++ b/jpo-ode-svcs/src/test/java/us/dot/its/jpo/ode/traveler/TimDepositControllerTest.java @@ -63,7 +63,7 @@ public void emptyRequestShouldReturnEmptyError() { @Test public void invalidJsonSyntaxShouldReturnJsonSyntaxError() { - ResponseEntity actualResponse = testTimDepositController.postTim("{\"invalid\":\"json\"}}"); + ResponseEntity actualResponse = testTimDepositController.postTim("{\"in\"va}}}on\"}}"); assertEquals("{\"error\":\"Malformed or non-compliant JSON syntax.\"}", actualResponse.getBody()); } From bb1a64144caca0e7430a462d4aa18ff5148efcc9 Mon Sep 17 00:00:00 2001 From: Daniel McCoy Stephenson Date: Mon, 22 May 2023 13:34:55 -0600 Subject: [PATCH 3/4] Reviewed specified log levels for each log statement. --- .../src/main/java/us/dot/its/jpo/ode/dds/CASClient.java | 6 +++--- .../java/us/dot/its/jpo/ode/plugin/OdePluginImpl.java | 2 +- .../builders/TravelerMessageFromHumanToAsnConverter.java | 4 ++-- .../src/main/java/us/dot/its/jpo/ode/OdeProperties.java | 4 ++-- .../main/java/us/dot/its/jpo/ode/heartbeat/RsuSnmp.java | 8 ++++---- .../dot/its/jpo/ode/storage/FileSystemStorageService.java | 2 +- .../main/java/us/dot/its/jpo/ode/udp/bsm/BsmReceiver.java | 3 --- .../main/java/us/dot/its/jpo/ode/udp/map/MapReceiver.java | 2 -- .../java/us/dot/its/jpo/ode/udp/spat/SpatReceiver.java | 2 -- .../main/java/us/dot/its/jpo/ode/udp/srm/SrmReceiver.java | 2 -- .../main/java/us/dot/its/jpo/ode/udp/ssm/SsmReceiver.java | 2 -- .../main/java/us/dot/its/jpo/ode/udp/tim/TimReceiver.java | 2 -- 12 files changed, 13 insertions(+), 26 deletions(-) diff --git a/jpo-ode-core/src/main/java/us/dot/its/jpo/ode/dds/CASClient.java b/jpo-ode-core/src/main/java/us/dot/its/jpo/ode/dds/CASClient.java index 07239439d..80d07bc70 100644 --- a/jpo-ode-core/src/main/java/us/dot/its/jpo/ode/dds/CASClient.java +++ b/jpo-ode-core/src/main/java/us/dot/its/jpo/ode/dds/CASClient.java @@ -142,7 +142,7 @@ private String getTicketGrantingTicket(String server, String username, try { httpClient.close(); } catch (HttpException e) { - logger.warn(http, e); + logger.error(http, e); } } } @@ -175,7 +175,7 @@ private String getServiceTicket(String server, String ticketGrantingTicket, try { httpClient.close(); } catch (HttpException e) { - logger.warn(http, e); + logger.error(http, e); } } } @@ -208,7 +208,7 @@ private String getServiceCall(String service, String serviceTicket) try { httpClient.close(); } catch (HttpException e) { - logger.warn(http, e); + logger.error(http, e); } } } diff --git a/jpo-ode-plugins/src/main/java/us/dot/its/jpo/ode/plugin/OdePluginImpl.java b/jpo-ode-plugins/src/main/java/us/dot/its/jpo/ode/plugin/OdePluginImpl.java index b8d809fd0..b15c147ee 100644 --- a/jpo-ode-plugins/src/main/java/us/dot/its/jpo/ode/plugin/OdePluginImpl.java +++ b/jpo-ode-plugins/src/main/java/us/dot/its/jpo/ode/plugin/OdePluginImpl.java @@ -92,7 +92,7 @@ private void loadAllClasses(File file) throws OdePluginException { try { loader.close(); } catch (IOException e) { - logger.debug("Error closing URLClassLoader: {}", e); + logger.error("Error closing URLClassLoader: {}", e); } } } diff --git a/jpo-ode-plugins/src/main/java/us/dot/its/jpo/ode/plugin/j2735/builders/TravelerMessageFromHumanToAsnConverter.java b/jpo-ode-plugins/src/main/java/us/dot/its/jpo/ode/plugin/j2735/builders/TravelerMessageFromHumanToAsnConverter.java index 03035ccef..9ea156a6f 100644 --- a/jpo-ode-plugins/src/main/java/us/dot/its/jpo/ode/plugin/j2735/builders/TravelerMessageFromHumanToAsnConverter.java +++ b/jpo-ode-plugins/src/main/java/us/dot/its/jpo/ode/plugin/j2735/builders/TravelerMessageFromHumanToAsnConverter.java @@ -251,7 +251,7 @@ public static long translateISOTimeStampToMinuteOfYear(String isoTime) { startMinute = (int) Duration.between(DateTimeUtils.isoDateTime(startYear, 1, 1, 0, 0, 0, 0), zDateTime) .toMinutes(); } catch (Exception e) { // NOSONAR - logger.warn("Failed to parse datetime {}, defaulting to unknown value {}", isoTime, startMinute); + logger.error("Failed to parse datetime {}, defaulting to unknown value {}", isoTime, startMinute); } return startMinute; @@ -277,7 +277,7 @@ public static void replaceDataFrameTimestamp(ObjectNode dataFrame) { startMinute = (int) ChronoUnit.MINUTES.between(DateTimeUtils.isoDateTime(startYear, 1, 1, 0, 0, 0, 0), zDateTime); } catch (Exception e) { - logger.warn("Failed to startDateTime {}, defaulting to unknown value {}.", startDateTime, startMinute); + logger.error("Failed to startDateTime {}, defaulting to unknown value {}.", startDateTime, startMinute); } dataFrame.put("startYear", startYear); diff --git a/jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/OdeProperties.java b/jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/OdeProperties.java index 917c2087b..4bf1b5adf 100644 --- a/jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/OdeProperties.java +++ b/jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/OdeProperties.java @@ -216,7 +216,7 @@ void initialize() { } catch (UnknownHostException e) { // Let's just use a random hostname hostname = UUID.randomUUID().toString(); - logger.info("Unknown host error: {}, using random", e); + logger.warn("Unknown host error: {}, using random", e); } hostId = hostname; logger.info("Host ID: {}", hostId); @@ -224,7 +224,7 @@ void initialize() { if (kafkaBrokers == null) { - logger.info("ode.kafkaBrokers property not defined. Will try DOCKER_HOST_IP => {}", kafkaBrokers); + logger.warn("ode.kafkaBrokers property not defined. Will try DOCKER_HOST_IP => {}", kafkaBrokers); String dockerIp = CommonUtils.getEnvironmentVariable("DOCKER_HOST_IP"); diff --git a/jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/heartbeat/RsuSnmp.java b/jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/heartbeat/RsuSnmp.java index f0b11e8c0..53340343c 100644 --- a/jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/heartbeat/RsuSnmp.java +++ b/jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/heartbeat/RsuSnmp.java @@ -40,7 +40,7 @@ private RsuSnmp() { public static String sendSnmpV3Request(String ip, String oid, Snmp snmp, String username) { if (ip == null || oid == null || snmp == null) { - logger.debug("Invalid SNMP request parameter"); + logger.warn("Invalid SNMP request parameter"); throw new IllegalArgumentException("Invalid SNMP request parameter"); } @@ -68,16 +68,16 @@ public static String sendSnmpV3Request(String ip, String oid, Snmp snmp, String snmp.close(); } catch (Exception e) { responseEvent = null; - logger.debug("SNMP4J library exception", e); + logger.warn("SNMP4J library exception", e); } // Interpret snmp response String stringResponse; if (responseEvent == null) { - logger.debug("SNMP connection error"); + logger.error("SNMP connection error"); stringResponse = "[ERROR] SNMP connection error"; } else if (responseEvent.getResponse() == null) { - logger.debug("Empty SNMP response"); + logger.error("Empty SNMP response"); stringResponse = "[ERROR] Empty SNMP response"; } else { stringResponse = responseEvent.getResponse().getVariableBindings().toString(); diff --git a/jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/storage/FileSystemStorageService.java b/jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/storage/FileSystemStorageService.java index fa309a5cb..4299b0075 100644 --- a/jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/storage/FileSystemStorageService.java +++ b/jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/storage/FileSystemStorageService.java @@ -124,7 +124,7 @@ public Resource loadAsResource(String filename) { @Override public void deleteAll() { FileSystemUtils.deleteRecursively(rootLocation.toFile()); - EventLogger.logger.error("Deleting {}", this.rootLocation); + EventLogger.logger.info("Deleting {}", this.rootLocation); } @Override diff --git a/jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/udp/bsm/BsmReceiver.java b/jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/udp/bsm/BsmReceiver.java index 1962e130a..a61cfff3a 100644 --- a/jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/udp/bsm/BsmReceiver.java +++ b/jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/udp/bsm/BsmReceiver.java @@ -104,9 +104,6 @@ public void run() { public byte[] removeHeader(byte[] packet) { String hexPacket = HexUtils.toHexString(packet); - // logger.debug("BSM packet length: {}, start index: {}", - // hexPacket.length(), startIndex); - int startIndex = hexPacket.indexOf(BSM_START_FLAG); if (startIndex == 0) { logger.debug("Message is raw BSM with no headers."); diff --git a/jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/udp/map/MapReceiver.java b/jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/udp/map/MapReceiver.java index 2aae95fec..d72089eb8 100644 --- a/jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/udp/map/MapReceiver.java +++ b/jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/udp/map/MapReceiver.java @@ -105,8 +105,6 @@ public void run() { public byte[] removeHeader(byte[] packet) { String hexPacket = HexUtils.toHexString(packet); - // logger.debug("MAP packet: {}", hexPacket); - int startIndex = hexPacket.indexOf(MAP_START_FLAG); if (startIndex == 0) { logger.debug("Message is raw MAP with no headers."); diff --git a/jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/udp/spat/SpatReceiver.java b/jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/udp/spat/SpatReceiver.java index b8455de6a..c57c28188 100644 --- a/jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/udp/spat/SpatReceiver.java +++ b/jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/udp/spat/SpatReceiver.java @@ -104,8 +104,6 @@ public void run() { public byte[] removeHeader(byte[] packet) { String hexPacket = HexUtils.toHexString(packet); - //logger.debug("SPAT packet: {}", hexPacket); - int startIndex = hexPacket.indexOf(SPAT_START_FLAG); if (startIndex == 0) { logger.debug("Message is raw SPAT with no headers."); diff --git a/jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/udp/srm/SrmReceiver.java b/jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/udp/srm/SrmReceiver.java index b5f157d5f..cd57c7172 100644 --- a/jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/udp/srm/SrmReceiver.java +++ b/jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/udp/srm/SrmReceiver.java @@ -105,8 +105,6 @@ public void run() { public byte[] removeHeader(byte[] packet) { String hexPacket = HexUtils.toHexString(packet); - //logger.debug("SRM packet: {}", hexPacket); - int startIndex = hexPacket.indexOf(SRM_START_FLAG); if (startIndex == 0) { logger.debug("Message is raw SRM with no headers."); diff --git a/jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/udp/ssm/SsmReceiver.java b/jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/udp/ssm/SsmReceiver.java index 755b8a988..05169b12a 100644 --- a/jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/udp/ssm/SsmReceiver.java +++ b/jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/udp/ssm/SsmReceiver.java @@ -105,8 +105,6 @@ public void run() { public byte[] removeHeader(byte[] packet) { String hexPacket = HexUtils.toHexString(packet); - //logger.debug("SSM packet: {}", hexPacket); - int startIndex = hexPacket.indexOf(SSM_START_FLAG); if (startIndex == 0) { logger.debug("Message is raw SSM with no headers."); diff --git a/jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/udp/tim/TimReceiver.java b/jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/udp/tim/TimReceiver.java index 664a5c661..7bc086bca 100644 --- a/jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/udp/tim/TimReceiver.java +++ b/jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/udp/tim/TimReceiver.java @@ -114,8 +114,6 @@ public void run() { public byte[] removeHeader(byte[] packet) { String hexPacket = HexUtils.toHexString(packet); - //logger.debug("TIM packet: {}", hexPacket); - int startIndex = hexPacket.indexOf(TIM_START_FLAG); if (startIndex == 0) { logger.info("Message is raw TIM with no headers."); From 5908b6f2876a2e453e2309c356ec29c714f6ad09 Mon Sep 17 00:00:00 2001 From: Daniel McCoy Stephenson Date: Fri, 16 Jun 2023 11:16:55 -0600 Subject: [PATCH 4/4] Changed logging level in exception catch blocks to `error` in 'RsuSnmp.java' and 'OdeProperties.java' --- .../src/main/java/us/dot/its/jpo/ode/OdeProperties.java | 2 +- .../src/main/java/us/dot/its/jpo/ode/heartbeat/RsuSnmp.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/OdeProperties.java b/jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/OdeProperties.java index 4bf1b5adf..1058a22f5 100644 --- a/jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/OdeProperties.java +++ b/jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/OdeProperties.java @@ -216,7 +216,7 @@ void initialize() { } catch (UnknownHostException e) { // Let's just use a random hostname hostname = UUID.randomUUID().toString(); - logger.warn("Unknown host error: {}, using random", e); + logger.error("Unknown host error: {}, using random", e); } hostId = hostname; logger.info("Host ID: {}", hostId); diff --git a/jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/heartbeat/RsuSnmp.java b/jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/heartbeat/RsuSnmp.java index 53340343c..0c7a54579 100644 --- a/jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/heartbeat/RsuSnmp.java +++ b/jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/heartbeat/RsuSnmp.java @@ -68,7 +68,7 @@ public static String sendSnmpV3Request(String ip, String oid, Snmp snmp, String snmp.close(); } catch (Exception e) { responseEvent = null; - logger.warn("SNMP4J library exception", e); + logger.error("SNMP4J library exception", e); } // Interpret snmp response