1.5 Visualizers - jmstoolbox/jmstoolbox GitHub Wiki
Visualizers are used to "process" the payload of a message. The most common use case is to let the OS display the payload in its "native" form. For example, to show a ByteMessage holding a png file, to unzip the payload or show the payload as PDF. Visualizers can also be implemented as JavaScript/GraalVM scripts (See below)
Visualizers may be associated with the following types of JMS Messages :
- TextMessage
- BytesMessage
- MapMessage
On the "View Message" dialog, on the payload tab, the "Show As" button displays the visualizers available for the type of JMS message viewed. A click on the magnifier will launch the visualizer. The payload is then passed to the visualizer that will "process" the payload. Visualizer are also available from the "Open Payload as..." contextual menu on a message from the Message browser
JMSToolBox is bundled with a few "system" visualizers: ZIP, PDF, Text, xml. Json..
Visualizers are managed via the "Visualizers" top level menu.
The type of visualizers are
- OS file extension
- External Commands
- Inline Scripts
- External Scripts
This kind of visualizer is associates with a "file extension". When selected, JMSToolBox asks the OS to open the tool associated to the file extension and process the payload. For example if a visualizer is associated with the ".zip" extension, and the user selects this visualizer, JMSTololBox will asks the OS to open the payload with the tool associated to the .zip extension in the OS
This kind of visualizer is associated with an external OS command. When selected, the command will be executed on the OS. Two placeholders may be used on the command to execute:
-
${p}
: Will be replaced by the name of a temporary file containing the payload -
${t}
: Will be replaced by the type of JMS Message, either'TEXT'
,'BYTES'
or'MAP'
Example of an external command definition: C:\Windows\notepad.exe ${p}
It is possible to define a script that will be called when the visualizer is chosen on a message Scripts are useful to process unusual payloads (base64 decoding, complex bytes/text structure analysis..). Currently the only language supported by JMSToolBox for scripts is JavaScript/GraalVM. Future versions of JMSToolBox may propose other languages (Groovy. rhino...) Scripts can be defined inline (ie stored in JMSToolBox config files) or externally with a reference to a script file external to JMSToolBox.
When called, scripts have access to the following global objects:
Global Object | Description |
---|---|
String jtb_jmsMessageType |
Type of JMS Message : TEXT, BYTES or MAP |
Object jtb_visualizer |
Exposes some utility method (See below) |
String jtb_payloadText |
The payload of a JMS TextMessage |
byte[] jtb_payloadBytes |
The payload of a JMS BytesMessage |
Map<String, Object> jtb_payloadMap |
The payload of a JMS MapMessage |
Method | Role |
---|---|
void showContent(String ext, String payload) |
Show the content as for the 'OS Extension' visualizer |
void showContent(String ext, byte[] payload) |
Show the content as for the 'OS Extension' visualizer |
void showContent(String ext,Map) |
Show the content as for the 'OS Extension' visualizer |
byte[] decodeBase64(byte [] bytes) |
Decodes base64 encoded bytes |
byte[] decodeBase64(String string) |
Decodes base64 encoded String |
byte[] encodeBase64(byte [] bytes) |
Encodes bytes to base64 encoded bytes |
String encodeBase64ToString(byte[] bytes) |
Encodes bytes to a base64 encoded String |
byte[] compressGzip(byte[] bytes) |
Compress the bytes using the gzip format |
byte[] compressGzip(String string) |
Compress the String using the gzip format |
byte[] decompressGzip(byte[] bytes) |
Uses the gzip algorithm to decompress the bytes |
String decompressGzipToString(byte[] bytes) |
Uses the gzip algorithm to decompress the bytes to a String |
byte[] compressZlib(byte[] bytes) |
Uses the Java 'Deflater' class (zlib) to compress the bytes |
byte[] compressZlib(String string) |
Uses the Java 'Deflater' class (zlib) to compress the String |
byte[] decompressZlib(byte[] bytes) |
Uses the Java 'Inflater' class to decompress the bytes |
String decompressZlibToString(byte[] bytes) |
Uses the Java 'Inflater' class to decompress the bytes to a String |
The output logs of a "Script visualizer" can be managed in two ways
- if the visualizer is defined with "
show logs on execution
", output logs will be displayed in a modeless dialog - if not, scripts logs are written to JMSToolBox standard logs :
<user>\.jtb\JMSToolBox\jmstoolbox.log
Official GraalVM documentation can be found here
Sample script that displays the global objects and calls back JMSToolBox to let it show the payload as for an "OS Extension" visualizer
print('jtb_jmsMessageType=' + jtb_jmsMessageType);
if (typeof jtb_payloadText != "undefined") {
print('jtb_payloadText=' + jtb_payloadText);
jtb_visualizer.showContent(".txt","abcd" + jtb_payloadText);
}
if (typeof jtb_payloadBytes != "undefined") {
print('jtb_payloadBytes=' + jtb_payloadBytes);
jtb_visualizer.showContent(".zip",jtb_payloadBytes);
}
if (typeof jtb_payloadMap != "undefined") {
print('jtb_payloadMap=' + jtb_payloadMap);
jtb_visualizer.showContent(".txt",jtb_payloadMap);
}