From 32e8cc4e387b79bf0b4a94d5bdcf1906bd5758a5 Mon Sep 17 00:00:00 2001 From: Nick Coblentz Date: Thu, 18 Jan 2024 14:39:39 -0600 Subject: [PATCH 1/2] Initial Code to Extract JSON data from WebSocket message --- Proxy/Websocket/ExtractPayloadToNotes.bambda | 25 ++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 Proxy/Websocket/ExtractPayloadToNotes.bambda diff --git a/Proxy/Websocket/ExtractPayloadToNotes.bambda b/Proxy/Websocket/ExtractPayloadToNotes.bambda new file mode 100644 index 0000000..db8e748 --- /dev/null +++ b/Proxy/Websocket/ExtractPayloadToNotes.bambda @@ -0,0 +1,25 @@ +/** + * Extracts JSON elements from the WebSocket message and displays it in the "Notes" column of the WebSocket History tab + * + * @author Nick Coblentz (https://github.com/ncoblentz) + * + **/ + +//The bambda will search for json elements with the following keys. The keys below are just examples. Add the keys you want to include here: +List terms = List.of("target","error"); + +if (!message.annotations().hasNotes()) { + StringBuilder builder = new StringBuilder(); + String payload = utilities().byteUtils().convertToString(message.payload().getBytes()); + terms.forEach(term -> { + Matcher m = Pattern.compile("\"" + term + "\":\"([^\"]+)\"", Pattern.CASE_INSENSITIVE).matcher(payload); + while (m.find() && m.groupCount() > 0) { + for (int i = 1; i <= m.groupCount(); i++) { + if (m.group(i) != null) + builder.append(term + ": " + m.group(i) + " "); + } + } + }); + message.annotations().setNotes(builder.toString()); +} +return true; \ No newline at end of file From c05e888c3ff43c2ae900b77c567569005ef7cbdc Mon Sep 17 00:00:00 2001 From: ps-porpoise <152162390+ps-porpoise@users.noreply.github.com> Date: Fri, 19 Jan 2024 09:22:23 +0000 Subject: [PATCH 2/2] Move bambda to Proxy/WS directory for README.md generation --- Proxy/{Websocket => WS}/ExtractPayloadToNotes.bambda | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Proxy/{Websocket => WS}/ExtractPayloadToNotes.bambda (100%) diff --git a/Proxy/Websocket/ExtractPayloadToNotes.bambda b/Proxy/WS/ExtractPayloadToNotes.bambda similarity index 100% rename from Proxy/Websocket/ExtractPayloadToNotes.bambda rename to Proxy/WS/ExtractPayloadToNotes.bambda