Topic
3 replies Latest Post - ‏2014-03-13T17:56:47Z by XKW0_Murat_Üre
JoeMorganNTST
JoeMorganNTST
427 Posts
ACCEPTED ANSWER

Pinned topic Example of how to use xsl:message to log json content

‏2013-06-20T16:16:42Z |

I want to log actual json content (not the jsonX version of it) to a log.  Does anyone have an example xsl I can steal?

I keep getting invalid char '{'.... maybe I'm doing something stupid.

 

 

  • swlinn
    swlinn
    1344 Posts
    ACCEPTED ANSWER

    Re: Example of how to use xsl:message to log json content

    ‏2013-06-20T17:48:01Z  in response to JoeMorganNTST

    The JSON message is invalid XML, so you'll need to run your INPUT context thru a binary transformation algorithm using a .ffd.  Hermann has examples in this forum on using the .ffds from the store directory.  A simple case I've used is to use the follow .ffd

    <File name="input">
        <Field name="wrapper"/>
    </File>

    and an xsl that references that file

    <?xml version="1.0" encoding="utf-8"?>

    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
                    xmlns:dp="http://www.datapower.com/extensions"
                    extension-element-prefixes="dp"
                    exclude-result-prefixes="dp">

        <!-- This stylesheet simply copies the binary input to XML output -->
        <dp:input-mapping href="wrapper.ffd" type="ffd"/>
        <xsl:output method="xml"/>

        <xsl:template match="/">
            <xsl:choose>
               <xsl:when test=".">
                   <xsl:copy-of select="."/>
               </xsl:when>
               <xsl:otherwise>
                   <emptyinput/>
               </xsl:otherwise>
            </xsl:choose>
        </xsl:template>

    </xsl:stylesheet>
     

    Now the now xml content will be in the output context of this binary xform in /input/wrapper.  The .ffds Hermann has handles non utf chars I believe that can get you into trouble, but you then have more work to do other than the copy-of.

    Regards,

    Steve

    • HermannSW
      HermannSW
      4156 Posts
      ACCEPTED ANSWER

      Re: Example of how to use xsl:message to log json content

      ‏2013-06-20T20:27:05Z  in response to swlinn

      Hi Steve,

      yes, this works, but it is unsecure.

      Although JSON expressions are a subset of Char*, the strings build of XML characters, see
      https://www.ibm.com/developerworks/community/blogs/HermannSW/entry/datapower_transformations

      an (invalid) JSON input may be sent to DataPower containing Non-UTF-8 encoded binary data.

      The String-type wrapper FFD does not do UTF-8 validation, and the log system assumes UTF-8 encoded data.
      See slide 5 of this WSTE presentation on what can happen:
      http://www-01.ibm.com/support/docview.wss?uid=swg27022979

      And that is not the worst that can happen.
      Therefore UTF-8 validation is a best (and needed) practice, see slide 16 of this WSTE webcast:
      http://www-01.ibm.com/support/docview.wss?uid=swg27022977

      Because of that I would prefer this version of your stylesheet:

      <xsl:stylesheet  version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:dp="http://www.datapower.com/extensions"
        extension-element-prefixes="dp"
      >
        <dp:input-mapping href="store:///pkcs7-convert-input.ffd" type="ffd"/>
        <xsl:output method="xml"/>

        <xsl:template match="/">
          <xsl:variable name="input64"
            select="dp:binary-encode(/object/message/node())"
          />

          <xsl:choose>
            <xsl:when test="$input64">
              <xsl:copy-of select="dp:decode($input64, 'base-64')"/>
            </xsl:when>
            <xsl:otherwise>
              <emptyinput/>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:template>

      </xsl:stylesheet>

       



      Hermann<myXsltBlog/> <myXsltTweets/> <myCE/>

       

      Attachments

    • XKW0_Murat_Üre
      XKW0_Murat_Üre
      1 Post
      ACCEPTED ANSWER

      Re: Example of how to use xsl:message to log json content

      ‏2014-03-13T17:56:47Z  in response to swlinn

      Hi Steve,

      I have similar requirement and followed your recommendations and it's worked. But I have a problem regarding logging the input to the destination mainframe MQ queue. The problem is , even though using log action, the log message somehow truncated and there are some "full stop" chars in the message and also ">" chars converted as &gt;.  I added all artifacts as an attachment. Could you please help me on this issue ?

       

      ps: since xsl:message have limitations around 2K I prefered to use log action to achieve off-box logging.

      Best Regards,

      Onder

       

       

      Attachments