• 2 replies
  • Latest Post - ‏2013-01-11T20:16:07Z by K8E0_Andy_Zevenhuizen
94 Posts

Pinned topic how to Capture Binary data in a file or log?

‏2012-08-28T18:46:56Z |
I would like to know about capturing binary data or non xml data to be copied to log, i.e binary request message sent should be copied in to the log.
Is there any precise way to do it
Updated on 2013-01-11T20:16:07Z at 2013-01-11T20:16:07Z by K8E0_Andy_Zevenhuizen
  • HermannSW
    7405 Posts

    Re: how to Capture Binary data in a file or log?


    the utility stylesheet dump-nodes.xsl from this posting

    does the following:
    • it dumps the base64-encoded binary input data into a file in "temporary:" folder
    • it returns the binary input data unchanged to the output

    So you can plug in this stylesheet as "Tansform Binary Action" into an existing flow.
    dump-nodes.xsl uses "dp:dump-nodes()" extension function to write a node-set to a file.
    That is the reason why the binary input has to be base64 encoded.
    The same is true for log messages, they cannot contain binary or Non-XML data.
    Now replacing
    ... <!-- create a node set 
    for dump-nodes, data base64 encoded --> <xsl:variable name=
    "dump"> <b64><xsl:value-of select=
    "$input64"/></b64> </xsl:variable> <!-- dump it --> <dp:dump-nodes file=
    "'abc.txt'" nodes=
    "$dump"/> ...

    ... <!-- log data base64 encoded --> <xsl:message dp:priority=
    "error"> <xsl:value-of select=
    "$input64"/> </xsl:message> ...

    will log the (binary) input data as requested by you.
    I use "error" log level to make sure I can "see" it in the logs -- you may want to adapt the log level.

    Be aware that log message length is restricted, see technote
    "DataPower log event message truncated when using xsl:message to output a custom log message"

    In case you want to be able to directly "read" the binary data logged and your "brain-base64-decoder"
    is not that good (like mine :-) ), you may want to log the binary data hexadecimally encoded
    (although that increases log message length 50% compared to base64-encoded):
    <xsl:value-of select=

    Hermann<myXsltBlog/> <myXsltTweets/>
  • K8E0_Andy_Zevenhuizen
    23 Posts

    Re: how to Capture Binary data in a file or log?

    We had the same need. Being new to xsl and DataPower, I laboured long and hard and came up code that takes a Base64 encoded string in either UTF8 or EBCDIC characters and returns a string like this:

    Offset  ------------------------ Hex Bytes ------------------------   ------ Display------
    00000:  C1 D4 C7 F9 F1 C2 D9 40 F0 F1 FD C2 40 40 40 C5 D9 40 40 F0   AMG91BR 01.B   ER  0
    00020:  F0 F0 F1 FD FD 40 C5 A3 83 85 A7 84 F1 F0 F9 40 40 40 F7 F1   001.. Etcexd109   71
    00040:  F5 F0 F6 F4 F1 F1 F4 F1 F1 F2 F0 F1 F3 F0 F1 F1 F1 F0 D6 40   506411411201301110O 
    00060:  D5 F2 F0 F1 F3 F0 F1 F1 F1 F1 F5 F0 F0 F5 F2 F2 F0 F1 F3 F0   N2013011115005220130
    00080:  F1 F1 F1 F1 F5 F0 F6 F3 F7 FD F0 F0 C9 D5 D8 40 40 40 F0 F1   111150637.00INQ   01
    00100:  F0 F1 FD F0 F0 F1 F0 F0 F0 F0 F0 F0 F2 F0 F1 F3 60 F0 F3 60   01.0010000002013-03-
    00120:  F2 F8 FD                                                      28.

    Another callable template dealt with chunking the Base64 data in 400 bytes chunks and wrote out repeated log messages (linked by the DataPower transaction ID) to deal with longer messages. Due to company policy I cannot post the code directly but I could outline the steps. Note that little consideration was given to efficiency since this logging is only turned on in our case in test environments.
    Updated on 2014-03-25T02:41:54Z at 2014-03-25T02:41:54Z by iron-man