Topic
37 replies Latest Post - ‏2014-04-28T15:39:20Z by Kumar_Y
HermannSW
HermannSW
3145 Posts
ACCEPTED ANSWER

Pinned topic DataPower "binary" node type (binaryNode)

‏2011-01-18T20:40:13Z |

DataPower "binary" node type (binaryNode)


DataPower node types

DataPower does support the 7 node types from XPath 1.0 data model [1]:
  • root, element
  • text
  • attribute, namespace
  • processing instruction, comment

In addition DataPower provides a proprietary node type called binaryNode.
This node type is used for containing binary data while processing XML files, eg. for crypto purposes.

binaryNode is not a first class member of the DataPower node types.
You may not do everything with it and expect it to work.
For example passing a binaryNode as argument to a user defined func:function or a template might not give the results you expect.
This is working as designed as binaryNode is intended for specific uses only.

Examples of how a binaryNode can be created

  • dp:binary-decode('VGVzdA==')
  • <dp:url-open target="..." response="binaryNode" .../>
  • <dp:input-mapping href="store:///pkcs7-convert-input.ffd" type="ffd"/>
  • ...

xsl:copy-of and dp:binary-encode

binaryNode nodes can be copied by xsl:copy-of.
And they can be encoded by dp:binary-encode() which base64 encodes the binary data and therefore returns a xs:string.

xsl:value-of for binaryNode

Trying to access the value of a binaryNode by

<xsl:value-of select=
"dp:binary-decode('VGVzdA==')"/>

you will not get "Test" as you might expect ("VGVzdA==" is base64 encoding of "Test") but get "***BINARY NODE***" instead.
Since a binaryNode may contain arbitrary binary data this is the designed behaviour.

how to get the "real" value

As part of the "hex-to-text" template on this [2] slide of last years WSTE presentation a method was shown how to get the "real" value out of a binaryNode:
1) store the binaryNode into a xsl:variable ($raw)
2) do <xsl:value-of select="$raw"/> then

Security considerations -- validation

If you have the contents of the binary data under control you may just use above method.
But some binary data may affect the stability of the DataPower appliance if accessed that way.
Therefore eg. getting a HTML page which you do not have unter control via

<dp:url-open target=
"http://..." response=
"binaryNode" .../>

is not a good idea since getting the value of the binaryNode return by above method bypassed the input validation of DataPower
(UTF-8 validation is the default validation if no other encoding is specified in the input XML file).

Therefore below two functions dp:value-base64() and dp:value-hex() allow to pass the request for
validation against an encoding as 2nd argument (either "ascii" or "utf-8").
The validation is done by regular expression matching against the hex representation string.

dp:value-base64(base64string, encoding)

The three stylesheets and binary input files (41, c3a4, c080) are contained in attached .zip file.

The binary input files just contain the binary data indicated by their name, eg:

$ od -Ax -tx1 c3a4 000000 c3 a4 000002 $


These are the different outputs generated by dp:value-base64(), with no validation or validation against UTF-8 or ASCII:
. 41 c3a4 c080
value-base64.xsl "A" "&#228;" "&#0;"
value-base64-utf-8.xsl "A" "&#228;" ""
value-base64-ascii.xsl "A" "" ""


Btw, c080 is an overlong representation of the 0x00 byte and therefore not valid UTF-8, but valid modified UTF-8 [3].

This is the stylesheet demonstrating UTF-8 validation as part of dp:value-base64() -- if validation fails an empty string is returned:

$ cat value-base64_utf-8.xsl <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" > <xsl:output omit-xml-declaration=
"yes" />   <xsl:include href=
"binaryNode.xsl"/>   <dp:input-mapping   href=
"store:///pkcs7-convert-input.ffd" type=
"ffd"/>   <xsl:template match=
"/"> <xsl:value-of select=
"dp:value-base64( dp:binary-encode(/object/message/child::node()),
'utf-8')
"/> </xsl:template> </xsl:stylesheet> $


dp:value-hex(hexString, encoding)

The three stylesheets and input files (41.xml, c3a4.xml, c080.xml) are contained in attached .zip file.

The input files just contain the hex representation indicated by their name, eg:

$ cat c3a4.xml <y>c 3 A 4 </y> $


These are the different outputs generated by dp:value-hex(), with no validation or validation against UTF-8 or ASCII:
. 41.xml c3a4.xml c080.xml
value-hex.xsl "A" "&#228;" "&#0;"
value-hex-utf-8.xsl "A" "&#228;" ""
value-hex-ascii.xsl "A" "" ""


This is the stylesheet demonstrating UTF-8 validation as part of dp:value-hex() -- if validation fails an empty string is returned:

$ cat value-hex_utf-8.xsl <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" > <xsl:output omit-xml-declaration=
"yes" />   <xsl:include href=
"binaryNode.xsl"/>   <xsl:template match=
"/"> <xsl:value-of select=
"dp:value-hex(dp:normalize-hex(.),'utf-8')"/> </xsl:template> </xsl:stylesheet> $


Magnifying glass -- DataPower internal data representation is UTF-8


Input data sample for German Umlaute, UTF-8 encoded:

$ cat umlaute-u.xml <?xml version=
"1.0" encoding=
"UTF-8"?> <umlaute>äöüÄÖÜß</umlaute> $


Input data sample for German Umlaute, ISO-8859-1 encoded:

$ cat umlaute-i.xml <?xml version=
"1.0" encoding=
"ISO-8859-1"?> <umlaute>�������</umlaute> $


The output of magnifyingGlass.xsl (the internal representation of DataPower for both input files) is the same -- it is UTF-8 encoded:

$ od -Ax -tx1 umlaute-u.xml.out 000000 c3 a4 c3 b6 c3 bc c3 84 c3 96 c3 9c c3 9f 00000e $ $ od -Ax -tx1 umlaute-i.xml.out 000000 c3 a4 c3 b6 c3 bc c3 84 c3 96 c3 9c c3 9f 00000e $


magnifyingGlass.xsl -- wrap input into a binary node and then output it "as is" by using
"store:///pkcs7-convert-input.ffd" as dp:output-mapping (just put into <object><mesage>...</message></object>):

$ cat magnifyingGlass.xsl <xsl:stylesheet version=
"1.0" xmlns:xsl=
"http://www.w3.org/1999/XSL/Transform" xmlns:dp=
"http://www.datapower.com/extensions" xmlns:func=
"http://exslt.org/functions" xmlns:exslt=
"http://exslt.org/common" extension-element-prefixes=
"dp" > <xsl:output omit-xml-declaration=
"yes" />   <dp:output-mapping  href=
"store:///pkcs7-convert-input.ffd" type=
"ffd"/>   <xsl:template match=
"/"> <object> <message> <xsl:variable name=
"inputAsBinaryNode" select=
"dp:binary-decode(dp:binary-encode(.))"/>   <xsl:copy-of select=
"$inputAsBinaryNode"/> </message> </object> </xsl:template> </xsl:stylesheet> $


Termination at first 0x00 byte

dp:value-base64() and dp:value-hex() both terminate the output at the first 0x00 byte (&#0;) of the data.
For example the result of "dp:value-hex('41424300313233')" is "ABC".

As you have seen in previous magnifyingGlass.xsl stylesheet you may use dp:output-mapping to deal with 0x00 bytes without termination:

$ od -Ax -tcx1 zero.xsl.out 000000   A   B   C  \0   1   2   3 41 42 43 00 31 32 33 000007 $


This is the stylesheet generating above output, has to be referenced by a binary transform action:

$ cat zero.xsl <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" > <xsl:output omit-xml-declaration=
"yes" />   <dp:output-mapping  href=
"store:///pkcs7-convert-input.ffd" type=
"ffd"/>   <xsl:template match=
"/"> <object> <message> <xsl:variable name=
"withZero" select=
"dp:radix-convert('41424300313233',16,64)"/>   <xsl:copy-of select=
"dp:binary-decode($withZero)"/> </message> </object> </xsl:template> </xsl:stylesheet> $


store:///pkcs7-convert-input.ffd


You may use this file in dp:input-mapping as in value-base64.xsl, value-base64_ascii.xsl or value-base64_utf-8.xsl above.

... <!-- This FFD converts the input into an XML tree like 

this:   <object> <message>***binary data***</message> </object> --> ...


But you may also use it as dp:output-mapping like in magnifyingGlass.xsl or zero.xsl above.

store:///pkcs7-convert-input.ffd is used by five strore:///pkcs7... stylesheets.

binaryNode.xsl


You may include binaryNode.xsl to have access to this functionality:
  • dp:value-base64(string, encoding) --> provide "value" of base64 encoded string, validate against encoding (utf-8/ascii) if requested
  • dp:value-hex(string, encoding) --> provide "value" of hex encoded string, validate against encoding (utf-8/ascii) if requested
  • dp:normalize-hex(hexStringWithWhiteSpace) --> normalize
  • dp:validate-hex(hexString) --> UTF-8 validate the input string
  • dp:validate-base64(base64string) --> UTF-8 validate the input string

These are the steps to get the value of a binary node,
  • access it by ".../child::node()"
  • then dp:binary-encode() it
  • and then use dp:value-base64()
like this:

... <xsl:variable name=
"binaryNode" select=
"/object/message/child::node()"/>   <xsl:value-of select=
"dp:value-base64( dp:binary-encode($binaryNode),
'utf-8')
"/> ...


binaryNode.xsl:

<xsl:stylesheet version=
"1.0" xmlns:xsl=
"http://www.w3.org/1999/XSL/Transform" xmlns:dp=
"http://www.datapower.com/extensions" xmlns:func=
"http://exslt.org/functions" xmlns:regexp=
"http://exslt.org/regular-expressions" extension-element-prefixes=
"dp" > <xsl:output omit-xml-declaration=
"yes" />   <!-- dp:radix-convert(_,64,16) generates upper 

case characters. Therefore normalize hex string to upper 

case characters and additionally eliminate all white space. --> <func:function name=
"dp:normalize-hex"> <xsl:param name=
"str"/>   <func:result select=
"translate(normalize-space($str),'abcdef ','ABCDEF')" /> </func:function>   <!-- from http:
//www.w3.org/International/questions/qa-forms-utf-8.en.php   $field =~ m/\A( [\x09\x0A\x0D\x20-\x7E]            # ASCII | [\xC2-\xDF][\x80-\xBF]             # non-overlong 2-

byte |  \xE0[\xA0-\xBF][\x80-\xBF]        # excluding overlongs | [\xE1-\xEC\xEE\xEF][\x80-\xBF]
{2
}  # straight 3-

byte |  \xED[\x80-\x9F][\x80-\xBF]        # excluding surrogates |  \xF0[\x90-\xBF][\x80-\xBF]
{2
}     # planes 1-3 | [\xF1-\xF3][\x80-\xBF]
{3
}          # planes 4-15 |  \xF4[\x80-\x8F][\x80-\xBF]
{2
}     # plane 16 )*\z/x; -->   <!-- 

this excludes most of the ASCII control characters --> <xsl:variable name=
"ASCII_char" select=
"'09|0A|0D|[2-6][0-9A-F]|7[0-9A-E]'" />   <xsl:variable name=
"UTF-8_char" select=
"concat( $ASCII_char, 
'|C[2-9A-F][89AB][0-9A-F]|D[0-9A-F][89AB][0-9A-F]', 
'|E[AB][0-9A-F][89AB][0-9A-F]', 
'|E[1-9A-CEF][89AB][0-9A-F][89AB][0-9A-F]', 
'|ED[89][0-9A-F][89AB][0-9A-F]', 
'|F0[9AB][0-9A-F][89AB][0-9A-F][89AB][0-9A-F]', 
'|F[1-3][89AB][0-9A-F][89AB][0-9A-F][89AB][0-9A-F]', 
'|F48[0-9A-F][89AB][0-9A-F][89AB][0-9A-F]' )
" />     <!-- validate that $hexString is a valid UTF-8 string --> <func:function name=
"dp:validate-hex"> <xsl:variable name=
"hexString" />   <func:result select=
"regexp:test(dp:normalize-hex($hexString), concat(
'^(',$UTF-8_char,
')*$'), 
'')
"/> </func:function> <!-- validate that $base64string is a valid UTF-8 string --> <func:function name=
"dp:validate-base64"> <xsl:variable name=
"base64string" />   <func:result select=
"regexp:test(dp:radix-convert($base64string,64,16), concat(
'^(',$UTF-8_char,
')*$'), 
'')
"/> </func:function>     <func:function name=
"dp:value"> <xsl:param name=
"base64string"/> <xsl:param name=
"hexString" select=
"''"/> <xsl:param name=
"validateString" select=
"''"/>   <xsl:variable name=
"raw" select=
"dp:binary-decode($base64string)"/>   <func:result> <xsl:choose> <xsl:when test=
"$validateString"> <xsl:

if test=
"regexp:test($hexString, $validateString, 
'')
"> <xsl:value-of select=
"$raw"/> </xsl:if> </xsl:when>   <!-- no validation --> <xsl:otherwise> <xsl:value-of select=
"$raw"/> </xsl:otherwise> </xsl:choose> </func:result> </func:function>     <func:function name=
"dp:value-base64"> <xsl:param name=
"base64string"/> <xsl:param name=
"validate" select=
"''"/>   <func:result> <xsl:choose> <xsl:when test=
"$validate"> <xsl:variable name=
"hexString" select=
"dp:radix-convert($base64string,64,16)"/>   <xsl:choose> <xsl:when test=
"$validate = 'ascii'"> <xsl:value-of select=
"dp:value($base64string, $hexString, concat(
'^(',$ASCII_char,
')*$'))
"/> </xsl:when>   <xsl:when test=
"$validate = 'utf-8'"> <xsl:value-of select=
"dp:value($base64string, $hexString, concat(
'^(',$UTF-8_char,
')*$'))
"/> </xsl:when> </xsl:choose> </xsl:when>   <!-- no validation --> <xsl:otherwise> <xsl:value-of select=
"dp:value($base64string)"/> </xsl:otherwise> </xsl:choose> </func:result> </func:function>   <func:function name=
"dp:value-hex"> <xsl:param name=
"hexString"/> <xsl:param name=
"validate" select=
"''"/>   <xsl:variable name=
"base64string" select=
"dp:radix-convert($hexString,16,64)"/>   <func:result> <xsl:choose> <xsl:when test=
"$validate"> <xsl:choose> <xsl:when test=
"$validate = 'ascii'"> <xsl:value-of select=
"dp:value($base64string, $hexString, concat(
'^(',$ASCII_char,
')*$'))
"/> </xsl:when>   <xsl:when test=
"$validate = 'utf-8'"> <xsl:value-of select=
"dp:value($base64string, $hexString, concat(
'^(',$UTF-8_char,
')*$'))
"/> </xsl:when> </xsl:choose> </xsl:when>   <!-- no validation --> <xsl:otherwise> <xsl:value-of select=
"dp:value($base64string)"/> </xsl:otherwise> </xsl:choose> </func:result> </func:function>   </xsl:stylesheet>

Appendix


[1] http://www.w3.org/TR/xpath/#data-model
[2] http://www-01.ibm.com/support/docview.wss?uid=swg27019118&aid=1#page=5
[3] http://en.wikipedia.org/wiki/Utf-8#Modified_UTF-8

Hermann.
Updated on 2012-11-21T10:16:13Z at 2012-11-21T10:16:13Z by HermannSW
  • cltnc28269
    cltnc28269
    2 Posts
    ACCEPTED ANSWER

    Re: DataPower "binary" node type (binaryNode)

    ‏2011-05-29T01:28:15Z  in response to HermannSW
    Hi there!

    I am working on an urgent requirement to convert a SOAP Response with MTOM attachment to a REST/HTTP response with MIME attachment.

    The following XSLT returns only half of the entire PDF/binary content. I noticed "Transfer-Encoding: chunked" in the HTTP header. Not sure at this point what could be wrong. I need to return the pdf.

    <xsl:stylesheet xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:dp="http://www.datapower.com/extensions" xmlns:dpquery="http://www.datapower.com/param/query" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" extension-element-prefixes="dp" exclude-result-prefixes="dp" version="1.1">
    <xsl:output encoding="utf-8" omit-xml-declaration="yes" method="html" indent="no"/>
    <xsl:template match="/">
    <dp:set-http-response-header name="'Content-Type'" value="'application/pdf' "/>
    <dp:set-http-response-header name="'Content-Transfer-Encoding'" value="'binary' "/>
    <xsl:variable name="manifest" select="dp:variable('var://context/INPUT/attachment-manifest')"/>
    <xsl:variable name="pdf">
    <xsl:for-each select="$manifest/*/
    /">
    <xsl:variable name="filename" select="./uri/text()"/>
    <xsl:variable name="cid" select="concat($filename,'?Encode=base64')"/>
    <xsl:variable name="base64">
    <dp:url-open target="{$cid}"/>
    </xsl:variable>
    <xsl:message dp:priority="debug">****(base64)****: <xsl:value-of select="$base64"/>
    </xsl:message>
    <xsl:variable name="raw" select="dp:binary-decode($base64)"/>
    <xsl:message dp:priority="debug">****(raw)****: <xsl:value-of select="$raw"/>
    </xsl:message>
    <xsl:value-of select="$raw"/>
    </xsl:for-each>
    </xsl:variable>
    <xsl:value-of select="$pdf"/>
    </xsl:template>
    </xsl:stylesheet>
    • HermannSW
      HermannSW
      3145 Posts
      ACCEPTED ANSWER

      Re: DataPower "binary" node type (binaryNode)

      ‏2011-05-30T20:27:54Z  in response to cltnc28269
      Hello,

      > ...
      > The following XSLT returns only half of the entire PDF/binary
      > content. ...
      > Not sure at this point what could be wrong. I need to return the pdf.
      >

      please read section "Termination at first 0x00 byte" in my previous posting.
      Whenever a 0x00 byte gets introduced somehow in the data (0x00 of &​#0; is not a valid XML character,
      can only be introduced by the $raw trick from above posting) the first occurence is interpreted as end of data as described in that section.

      Please take this PDF document as a sample:
      http://publib.boulder.ibm.com/infocenter/wsdatap/v3r8m1/topic/xi50/optimizingThroughStreaming.pdf

      It contains many 0x00 bytes, the first one at offset 2395:
      
      $ head --bytes 2400 optimizingThroughStreaming.pdf | od -tcx1 | tail -7 0004460   h       1   5   4       0       R       >   >      \r   s   t 68 20 31 35 34 20 30 20 52 20 3e 3e 20 0d 73 74 0004500   r   e   a   m  \r  \n   H 211   b   `   `   `   f   ` 340   x 72 65 61 6d 0d 0a 48 89 62 60 60 60 66 60 e0 78 0004520 303 300 016   $ 347   2  \b   0     200  \0 003   +   P 224 205 c3 c0 0e 24 e7 32 08 30 20 80 00 03 2b 50 94 85 0004540 $
      


      This setting of Content-Type matches what you state above -- return one PDF file:
      
      ... <xsl:template match=
      "/"> <dp:set-http-response-header name=
      "'Content-Type'" value=
      "'application/pdf' "/> <dp:set-http-response-header name=
      "'Content-Transfer-Encoding'" value=
      "'binary' "/>
      


      But here you iterate over all attachments and just copy them together for the output.
      Are you sure that just copying all attachments will result in a valid PDF file?!?
      
      <xsl:for-each select=
      "$manifest/*/ /
      "> <xsl:variable name=
      "filename" select=
      "./uri/text()"/> <xsl:variable name=
      "cid" select=
      "concat($filename,'?Encode=base64')"/> <xsl:variable name=
      "base64"> <dp:url-open target=
      "{$cid}"/> </xsl:variable> <xsl:message dp:priority=
      "debug">****(base64)****: <xsl:value-of select=
      "$base64"/> </xsl:message> <xsl:variable name=
      "raw" select=
      "dp:binary-decode($base64)"/> <xsl:message dp:priority=
      "debug">****(raw)****: <xsl:value-of select=
      "$raw"/> </xsl:message> <xsl:value-of select=
      "$raw"/> </xsl:for-each>
      


      As said above, '<xsl:value-of select="$pdf"/>' will stop output at first 0x00 byte:
      
      <xsl:variable name=
      "manifest" select=
      "dp:variable('var://context/INPUT/attachment-manifest')"/> <xsl:variable name=
      "pdf"> ... </xsl:variable> <xsl:value-of select=
      "$pdf"/> </xsl:template> </xsl:stylesheet>
      


      Please see stylesheet "zero.xsl" in above posting on how to do the output you want to do (complete).

       
      Hermann<myXsltBlog/>
  • HermannSW
    HermannSW
    3145 Posts
    ACCEPTED ANSWER

    Re: DataPower "binary" node type (binaryNode)

    ‏2011-06-11T07:17:41Z  in response to HermannSW
    > These are the steps to get the value of a binary node,
    > *access it by ".../child::node()"
    > *then dp:binary-encode() it
    > *and then use dp:value-base64()
    like this:
    > ...

    there is a simpler and more efficient way to get the value of a binary node with validation for UTF-8:
    have dp:decode(_,'base-64') as 3rd step !
    • Jaango
      Jaango
      249 Posts
      ACCEPTED ANSWER

      Re: DataPower "binary" node type (binaryNode)

      ‏2011-12-08T11:12:31Z  in response to HermannSW
      Hi Hermann,
      Recently we had to play around with binary data.:).

      Is there a way i can preserve the input binary to output. The attached is my input.txt. However the generated output doesnt have the input characters as it is. At the end there are @ characters(4 in output and 5 in input at the end). I have used dp:value-base64() as the third step. If I use dp:decode(_,'base-64') as the third step, getting "Transforming (possibly binary) INPUT with xsl results stored in OUTPUT' failed: Valid base64 passed to dp:decode resulted in non UTF8: "

      Attached here with is the inputfile. Here is the xsl file, same as base-64.xsl.

      
      # java coproc2 value-base64.xsl input.txt http:
      //dp:server:2224; echo DŽׇţיքمذเ@řٖـ&#3 41;Ö䕣řń@@ǵ㠙ţ䙕`Öą@~@&#20 3830;@ԁトɕǀDŽ♀ŕ㙨@Ֆ〆&#14 44;Մ@Ɩـ@DŽׇţיքمذ&# 265264;῀@@@@
      


      Here is the xsl file

      
      <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" > <xsl:output omit-xml-declaration=
      "yes" />   <xsl:include href=
      "local:///binaryNode.xsl"/>   <dp:input-mapping   href=
      "store:///pkcs7-convert-input.ffd" type=
      "ffd"/>   <xsl:template match=
      "/"> <xsl:value-of select=
      "dp:value-base64( dp:binary-encode(/object/message/child::node()))
      "/> </xsl:template> </xsl:stylesheet>
      
      • HermannSW
        HermannSW
        3145 Posts
        ACCEPTED ANSWER

        Re: DataPower "binary" node type (binaryNode)

        ‏2011-12-09T00:10:39Z  in response to Jaango
        Hi Maneesh,

        it is good that you ask in this thread.

        In October I gave two complete webcasts on Non-XML data processing and forgot to add the references here.
        The webcasts contain the presentation .pdf, the recording .mp3 as well as a .zip containing all sample stylesheets and files.

        Webcast replay: Non-XML Data Processing in WebSphere DataPower SOA Appliances Stylesheets (1/2) - Basics and Encodings
        http://www-01.ibm.com/support/docview.wss?uid=swg27022977

        Webcast replay: Non-XML Data Processing in WebSphere DataPower SOA Appliances Stylesheets (2/2) - Advanced
        http://www-01.ibm.com/support/docview.wss?uid=swg27022979

         
        Related to this current thread, you may find details on DataPower XML node type extension binaryNode on this slide:
        http://www-01.ibm.com/support/docview.wss?uid=swg27022977&aid=3#page=8

        And the answer to your question, how to output binary data unchanged, is by using a dp:output-mapping, see this slide for a complete example:
        http://www-01.ibm.com/support/docview.wss?uid=swg27022977&aid=3#page=9

        Please see also slide "Return GIF image for Browser display" on how to retrieve binary data via <dp:url-open ...>
        (animated .gif file from my website in the sample stylesheet) and output it unchanged by dp:output-mapping:
        http://www-01.ibm.com/support/docview.wss?uid=swg27022977&aid=3#page=9

         
        If you do not need to deal with encoding conversions, then you may use these two slides as DataPower Non-XML cheat sheet :-)
        http://www-01.ibm.com/support/docview.wss?uid=swg27022977&aid=3#page=13
        http://www-01.ibm.com/support/docview.wss?uid=swg27022977&aid=3#page=5

         
        Hermann<myXsltBlog/>
        • HermannSW
          HermannSW
          3145 Posts
          ACCEPTED ANSWER

          Re: DataPower "binary" node type (binaryNode)

          ‏2011-12-09T00:12:39Z  in response to HermannSW
          Ups, sent too quick, the "Return GIF image for Browser display" link is wrong, here is the correct one:
          http://www-01.ibm.com/support/docview.wss?uid=swg27022979&aid=3#page=18

          Hermann.
          • Jaango
            Jaango
            249 Posts
            ACCEPTED ANSWER

            Re: DataPower "binary" node type (binaryNode)

            ‏2011-12-09T06:41:50Z  in response to HermannSW
            Perfect,
            Thanks Hermann
            • Jaango
              Jaango
              249 Posts
              ACCEPTED ANSWER

              Re: DataPower "binary" node type (binaryNode)

              ‏2011-12-09T12:06:22Z  in response to Jaango
              Hermann,
              I was able to generate the ouput, like the way you explained. However, if I use the below xsl to store the binary contents in a file, under temp(again by your guidance in another post), getting
              *****binary node**** as the contents of file.

              Is this possible, to generate the text file with the actual contents of the input. As always your guidance helps a lot

              <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                  xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl" xmlns:dp="http://www.datapower.com/extensions" extension-element-prefixes="dp"
              >
                <xsl:output omit-xml-declaration="yes"/>
                <dp:input-mapping href="local:///binaryNode.ffd" type="ffd"/>
                <dp:output-mapping href="local:///binaryNode.ffd" type="ffd"/>
               
                  <xsl:template match="/">
                    <object>
                      <message>
                        <dp:dump-nodes file="'abc.txt'" nodes="/object/message/node()"/>
                        <dp:url-open target="temporary:///abc.txt"/>
                      </message>
                    </object>
                  </xsl:template>
              </xsl:stylesheet>
              
              Updated on 2014-03-25T03:05:45Z at 2014-03-25T03:05:45Z by iron-man
              • Liv2luv
                Liv2luv
                573 Posts
                ACCEPTED ANSWER

                Re: DataPower "binary" node type (binaryNode)

                ‏2011-12-09T14:49:36Z  in response to Jaango
                dp:dump-nodes outputs a node-set into the temporary:/// directory. therefore there is no need of a url-open extension function.

                Also if the output text is not a node-set; that needs to be converted into a nodeset - probably like below:

                <xsl:variable name="someText"
                      select="dp:decode(dp:binary-encode(/object/message/node()),'base-64')"/>
                          
                 <xsl:variable name="nodeSet">
                         <x>
                                <xsl:copy-of select="$someText"/>
                         </x>
                 </xsl:variable>
                 
                <dp:dump-nodes file="'someFile.txt'" nodes="$nodeSet" />
                


                Finally, dp:output-mapping is not needed in this case.
                Updated on 2014-03-25T03:05:41Z at 2014-03-25T03:05:41Z by iron-man
                • HermannSW
                  HermannSW
                  3145 Posts
                  ACCEPTED ANSWER

                  Re: DataPower "binary" node type (binaryNode)

                  ‏2011-12-09T18:59:20Z  in response to Liv2luv
                  > Liv2luv wrote:
                  > dp:dump-nodes outputs a node-set into the temporary:/// directory. therefore there is no need of a url-open extension function.
                  >
                  Maneesh said "Is there a way i can preserve the input binary to output".
                  He wants to dump the data AND pass it unmodified.
                  So the dp:url-open is needed.

                  > Also if the output text is not a node-set; that needs to be converted into a nodeset - probably like below:
                  >
                  >
                  
                  > >  <xsl:variable name=
                  "someText" >       select=
                  "dp:decode(dp:binary-encode(/object/message/node()),'base-64')"/> > >  <xsl:variable name=
                  "nodeSet"> >         <x> >                 <xsl:copy-of select=
                  "$someText"/> >          </x> >  </xsl:variable> > > <dp:dump-nodes file=
                  "'someFile.txt'" nodes=
                  "$nodeSet" /> >
                  

                  >
                  > Finally, dp:output-mapping is not needed in this case.
                  >
                  again, it is needed as he wants to pass data back.

                  Also Maneesh's data seems to be binary data, not UTF-8 encoded text.
                  So dp:decode() as used in your sample will complain on Non-UTF8 data.

                  What I think Maneesh wants is dump-nodes.xsl below.
                  It does an identity copy of his backend response data to the client.
                  In addition, it dumps the binary data base64 encoded in temporary folder.

                  This is a simple demo only.
                  What is missing is incorporation transaction ID into dump file name,
                  otherwise each transaction just overwrites the previous dump.
                  AND being careful to make sure not running out of temp space.
                  This should be used for development or debugging situations only.
                  
                  [stammw@oc4482023428 xslt]$ od -tcx1 te0t 0000000   t   e  \0   t 74  65  00  74 0000004 [stammw@oc4482023428 xslt]$ coproc2 dump-nodes.xsl te0t http:
                  //dp5-l3:2224; echo tet [stammw@oc4482023428 xslt]$   (downloaded 
                  'abc.txt' from temporary: folder)   [stammw@oc4482023428 xslt]$ cat abc.txt; echo <b64>dGUAdA==</b64> [stammw@oc4482023428 xslt]$ cat dump-nodes.xsl <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"/> <dp:output-mapping href=
                  "store:///pkcs7-convert-input.ffd" type=
                  "ffd"/> <xsl:variable name=
                  "input64" select=
                  "dp:binary-encode(/object/message/node())"/>   <xsl:template match=
                  "/"> <object> <message> <!-- 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"/>   <!-- 
                  "binary" identity transform --> <xsl:copy-of select=
                  "dp:binary-decode($input64)"/> </message> </object> </xsl:template> </xsl:stylesheet> [stammw@oc4482023428 xslt]$
                  


                   
                  Hermann<myXsltBlog/>
                  • HermannSW
                    HermannSW
                    3145 Posts
                    ACCEPTED ANSWER

                    Re: DataPower "binary" node type (binaryNode)

                    ‏2011-12-10T17:38:17Z  in response to HermannSW
                    This is nicer:
                    <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"/>
                      <dp:output-mapping href="store:///pkcs7-convert-input.ffd" type="ffd"/>
                     
                     
                      <xsl:variable name="input64" 
                        select="dp:binary-encode(/object/message/node())"/>
                     
                     
                      <!-- create a node set for dump-nodes, binary data base64 encoded -->
                      <xsl:variable name="dump">
                        <b64><xsl:value-of select="$input64"/></b64>
                      </xsl:variable>
                     
                      <!-- and dump it -->
                      <dp:dump-nodes file="'abc.txt'" nodes="$dump"/>
                     
                     
                      <xsl:template match="/"> 
                     
                        <!-- "binary" identity transform -->
                        <object>
                          <message>
                            <xsl:copy-of select="dp:binary-decode($input64)"/>
                          </message>
                        </object>
                      </xsl:template>
                    </xsl:stylesheet>
                    


                    Hermann.
                    Updated on 2014-03-25T03:05:37Z at 2014-03-25T03:05:37Z by iron-man
                    • HermannSW
                      HermannSW
                      3145 Posts
                      ACCEPTED ANSWER

                      Re: DataPower "binary" node type (binaryNode)

                      ‏2011-12-11T00:40:30Z  in response to HermannSW
                      Sorry, I should have tested the 2nd stylesheet.
                      It is nicer but does not work (does not dump).

                      This is nicer and works:
                      
                      $ cat dump-nodes.3.xsl <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"/> <dp:output-mapping href=
                      "store:///pkcs7-convert-input.ffd" type=
                      "ffd"/> <xsl:variable name=
                      "input64" select=
                      "dp:binary-encode(/object/message/node())"/> <!-- create a node set 
                      
                      for dump-nodes, binary data base64 encoded --> <xsl:variable name=
                      "dump"> <b64><xsl:value-of select=
                      "$input64"/></b64> </xsl:variable> <xsl:template match=
                      "/"> <!-- and dump it --> <dp:dump-nodes file=
                      "'abc.txt'" nodes=
                      "$dump"/> <!-- 
                      "binary" identity transform --> <object> <message> <xsl:copy-of select=
                      "dp:binary-decode($input64)"/> </message> </object> </xsl:template>   </xsl:stylesheet>   $
                      


                       
                      Hermann<myXsltBlog/>
                      • Jaango
                        Jaango
                        249 Posts
                        ACCEPTED ANSWER

                        Re: DataPower "binary" node type (binaryNode)

                        ‏2011-12-12T09:01:16Z  in response to HermannSW
                        Suresh and Hermann,

                        Thanks for your inputs and solutions :)
                        • Jaango
                          Jaango
                          249 Posts
                          ACCEPTED ANSWER

                          Re: DataPower "binary" node type (binaryNode)

                          ‏2012-02-22T10:49:47Z  in response to Jaango
                          Hi Hermann,

                          I have a context variable with binary value set. Just wanted to print in my logs. However the below code does not seem to work

                          <xsl:message dp:priority="error">
                            Test: 
                            <xsl:copy-of select="dp:binary-encode(dp:variable('var://context/MyBinaryvalue'))" /> 
                            </xsl:message>
                          


                          The error is

                          "Cannot convert this value to binary data" and the xsl, where the above code is there, fails
                          Updated on 2014-03-25T03:02:08Z at 2014-03-25T03:02:08Z by iron-man
                          • HermannSW
                            HermannSW
                            3145 Posts
                            ACCEPTED ANSWER

                            Re: DataPower "binary" node type (binaryNode)

                            ‏2012-02-23T15:36:22Z  in response to Jaango
                            Hi,
                            >
                            > I have a context variable with binary value set. Just wanted to print in my logs. However the below code does not seem to work
                            >
                            >
                            
                            > <xsl:message dp:priority=
                            "error"> >   Test: >   <xsl:copy-of select=
                            "dp:binary-encode(dp:variable('var://context/MyBinaryvalue'))" /> >   </xsl:message> >
                            

                            >
                            > The error is
                            >
                            > "Cannot convert this value to binary data" and the xsl, where the above code is there, fails
                            >
                            sorry, binary contexts are different, their binary content cannot be accessed that way.

                            For logging above you did choose dp:binary-encode() which is fine.

                            You can do what you want in a binary transform action like toBase64b.xsl.
                            I tested this and it works, Input context of binary transform actions is "MyBinaryvalue":
                            
                            $ cat toBase64b.xsl <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 omit-xml-declaration=
                            "yes" /> <xsl:template match=
                            "/"> <xsl:copy-of select=
                            "dp:binary-encode(/object/message/node())"/> </xsl:template> </xsl:stylesheet> $
                            

                            Hermann<myXsltBlog/>
                  • This reply was deleted by Kumar_Y 2014-04-24T14:53:35Z. Reason for deletion: duplicate thread
                  • Kumar_Y
                    Kumar_Y
                    83 Posts
                    ACCEPTED ANSWER

                    Re: DataPower "binary" node type (binaryNode)

                    ‏2014-04-24T14:24:28Z  in response to HermannSW

                    Hi Hermann,

                     

                    I am using the above xslt for creating some file in the temp:/// folder, however nothing is being created. I am not sure what I am doing wrong.

                     

                    <?xml version="1.0" encoding="UTF-8"?>
                    <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">
                            <xsl:variable name="someText" select="dp:decode(dp:binary-encode(/object/message/node()),'base-64')"/>
                            <xsl:variable name="nodeSet">
                                    <x>
                                            <xsl:copy-of select="$someText"/>
                                    </x>
                            </xsl:variable>
                            <dp:dump-nodes file=" 'someFile.txt' " nodes="$nodeSet"/>
                    </xsl:stylesheet>
                    

                    Also this code is not working.

                    <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"/>
                            <dp:output-mapping href="store:///pkcs7-convert-input.ffd" type="ffd"/>
                            <xsl:variable name="input64" select="dp:binary-encode(/object/message/node())"/>
                            <xsl:template match="/">
                                    <object>
                                            <message>
                                                    <!-- 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"/>
                                                    <!-- 
                    "binary" identity transform -->
                                                    <xsl:copy-of select="dp:binary-decode($input64)"/>
                                            </message>
                                    </object>
                            </xsl:template>
                    </xsl:stylesheet>
                    
                    • HermannSW
                      HermannSW
                      3145 Posts
                      ACCEPTED ANSWER

                      Re: DataPower "binary" node type (binaryNode)

                      ‏2014-04-25T08:51:59Z  in response to Kumar_Y

                      Your 1st stylesheet misses <xsl:template>.

                      I did add that, executed it

                      $ coproc2 tmp.xsl tmp.xsl http://dp2-l3:2223
                      $
                      

                      and it worked:
                      "someFile.txt" gets created in temporary: folder ot dp2-l3 box, with content "<x/>".

                      The dp:binary-encode does nothing because input did not contain "/object/message".

                      You cannot just copy script, use and expect to do what you want.
                      In case you do want to deal with Non-XML data you will have to at least go through 1st WSTE webcast:
                      http://www-01.ibm.com/support/docview.wss?uid=swg27022977
                      http://www-01.ibm.com/support/docview.wss?uid=swg27022979


                      Hermann<myBlog/> <myTweets/> | <GraphvizFiddle/> | <xqib/> | <myCE/> <myFrameless/>
                       

                      Attachments

                      Updated on 2014-04-25T08:52:32Z at 2014-04-25T08:52:32Z by HermannSW
                      • Kumar_Y
                        Kumar_Y
                        83 Posts
                        ACCEPTED ANSWER

                        Re: DataPower "binary" node type (binaryNode)

                        ‏2014-04-25T15:23:01Z  in response to HermannSW

                        Thanks for the correction Hermann. I was able to create the file in temp:/// folder, however when I saw the .txt file it always start with something like this 

                        &lt;?xml version="1.0" encoding="UTF-8"?>
                        

                        Is there any way to remove &lt; from the starting? I was wondering if the dp:serialize will work for this?

                         

                        • HermannSW
                          HermannSW
                          3145 Posts
                          ACCEPTED ANSWER

                          Re: DataPower "binary" node type (binaryNode)

                          ‏2014-04-27T14:48:11Z  in response to Kumar_Y

                          Hi,

                          not sure what you are doing.

                          When I use below stylesheet the file (temporary:///abc.txt) content does not have an XML declaration:

                          <answer>42</answer>
                          


                          Please try with this stylesheet:

                          $ coproc2 tmp.2.xsl ab.xml http://dp2-l3:2223
                          $ 
                          $ cat tmp.2.xsl 
                          <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"
                          >
                            <xsl:output omit-xml-declaration="no" />
                            
                            <xsl:variable name="x"><answer>42</answer></xsl:variable>
                          
                            <xsl:template match="/">
                              <dp:dump-nodes file=" 'abc.txt' " nodes="$x"/>
                            </xsl:template>
                            
                          </xsl:stylesheet>
                          $
                          

                           

                          Hermann<myBlog/> <myTweets/> | <GraphvizFiddle/> | <xqib/> | <myCE/> <myFrameless/>

                          • Kumar_Y
                            Kumar_Y
                            83 Posts
                            ACCEPTED ANSWER

                            Re: DataPower "binary" node type (binaryNode)

                            ‏2014-04-28T14:47:15Z  in response to HermannSW

                            Hi Hermann,

                            Thanks for replying. I am using MPGW and in processing policy using the binary action to dump the value as you explained. However while sending the request everytime I am getting 415 error code in the log and when I used check the temp:/// file it always has &lt; at the starting of each line.

                            For some reason I am not able to see anything in the probe, that's why going through this trouble. I have changed the XML declaration, still I am getting the same problem.

                            <?xml version="1.0" encoding="UTF-8"?>
                            <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">
                                    <xsl:output omit-xml-declaration="no"/>
                              <dp:input-mapping  href="store:///pkcs7-convert-input.ffd" type="ffd"/>
                              <dp:output-mapping href="store:///pkcs7-convert-input.ffd" type="ffd"/>
                                    <xsl:template match="/">
                                            <xsl:variable name="someText" select="dp:decode(dp:binary-encode(/object/message/node()),'base-64')"/>
                                            <xsl:variable name="nodeSet">
                                                    <x>
                                                            <xsl:copy-of select="$someText"/>
                                                    </x>
                                            </xsl:variable>
                                            <dp:dump-nodes file=" 'someFile.txt' " nodes="$nodeSet"/>
                                    </xsl:template>
                            </xsl:stylesheet>
                            

                             

                            The error in the log.

                             

                            mpgw (DP-MPGW): HTTP response code 415 for 'http://xxxx/service/TestService'

                            Please let me know if I am missing anything.

                            • HermannSW
                              HermannSW
                              3145 Posts
                              ACCEPTED ANSWER

                              Re: DataPower "binary" node type (binaryNode)

                              ‏2014-04-28T15:17:14Z  in response to Kumar_Y

                              Hi,


                              I just use your stylesheet against Non-XML endpoint of coproc2 service (port 2224).

                              No error returned,

                              $ echo -n "test123" | coproc2 Kumar.xsl - 
                              http://firestar:2224
                              $ 
                              $ echo -n "test123" | coproc2 Kumar.xsl - 
                              http://firestar:2224 -vs 2>&1 | grep "^< H"
                              < HTTP/1.1 200 OK
                              $
                              

                               


                              and the file gets created correctly and without xml declaration:

                              <x>test123</x>
                              

                               

                               

                              Please either attach a sample service export with instructions on how to send sample request here to investigate, or create your service from scratch again.

                              I have not seen HTTP 415 sofar, but my favorite status code is HTTP 418 ... ;-)
                               


                              Hermann.

                              Updated on 2014-04-28T15:21:14Z at 2014-04-28T15:21:14Z by HermannSW
                              • This reply was deleted by Kumar_Y 2014-04-28T15:38:23Z.
                                • This reply was deleted by Kumar_Y 2014-04-28T15:38:10Z.
                              • Kumar_Y
                                Kumar_Y
                                83 Posts
                                ACCEPTED ANSWER

                                Re: DataPower "binary" node type (binaryNode)

                                ‏2014-04-28T15:39:20Z  in response to HermannSW

                                Hi Hermann,

                                If you want I can send you whole export to your email. This what is happening right now.

                                We have Xb62 appliance from which I am sending ebMS messsage to the  ebMS app, in the processing policy I am wrapping the soap message using XSLT and sending to the MPGW ( I have WSDL file, but for reason I am getting soap action error)

                                The above XSLT I am using only for logging purpose just to the request and response.

                                I am attaching the export as well as temp:/// file

                                Attachments

  • SystemAdmin
    SystemAdmin
    6772 Posts
    ACCEPTED ANSWER

    Re: DataPower "binary" node type (binaryNode)

    ‏2012-05-04T09:46:53Z  in response to HermannSW
    Hi Hermann,

    I am just trying to output the string representation of response .

    Below is my xsl

    <xsl:stylesheet version="1.0" extension-element-prefixes="dp"
    exclude-result-prefixes="dp dpconfig date" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:dp="http://www.datapower.com/extensions" xmlns:date="http://exslt.org/dates-and-times"
    xmlns:dpconfig="http://www.datapower.com/param/config">

    <dp:output-mapping href="local:///simple.ffd" type="ffd"/>
    <xsl:template match="/">

    <xsl:variable name="resp">
    <dp:url-open target="http://http-server-ip:port/test-text-file" response="binaryNode"/>
    </xsl:variable>
    <MyFile>
    <Payload><xsl:value-of select="$resp/result/binary/child::node()"/></Payload>
    </MyFile>

    </xsl:template>
    </xsl:stylesheet>

    • FFD FIle****
    <File version="1.0" name="MyFile">
    <Field name="Payload" minOccurs="1" type="String"/>
    </File>
    *************

    Above code is giving me blank output

    Now if i use

    <xsl:variable name="base64">
    <xsl:value-of select="dp:binary-encode($resp/result/binary/child::node())"/>
    </xsl:variable>

    <xsl:variable name="raw" select="dp:decode($base64,'base-64')"/>

    and then use value-of $raw It works fine.
    • Another weird thing is happening is that if use <xsl:value-of select="$resp/result/binary/child::node()"/> line of code before encode and decode , Then even after encode and decode my Result is blank.

    Could you please suggest , I just some how wanted to skip encode n decode , and want to use the string representaion of binaryData
    Thanks
    Pradeep
    • Liv2luv
      Liv2luv
      573 Posts
      ACCEPTED ANSWER

      Re: DataPower "binary" node type (binaryNode)

      ‏2012-05-04T11:27:39Z  in response to SystemAdmin
      First in the XSL:

      it is input-mapping instead of output-mapping

      FFD file looks like:

      <?xml version="1.0" encoding="UTF-8" ?>
      <File version="2.1" name="MyFile">
      <Field name="Payload" type="String" />
      </File>
      • HermannSW
        HermannSW
        3145 Posts
        ACCEPTED ANSWER

        Re: DataPower "binary" node type (binaryNode)

        ‏2012-05-07T13:40:48Z  in response to Liv2luv
        > First in the XSL:
        >
        > it is input-mapping instead of output-mapping
        >
        Hi Suresh, it is output-mapping since he wants to output text data received by dp:url-open (binaryNode).
        Pradeep, please see "getgif.xsl" on slide 18 of this WSTE webcast (you do not need your own FFD as long as your test-text-file is UTF-8 encoded):
        http://www-01.ibm.com/support/docview.wss?uid=swg27022979

        You can find all sample files in "Samples File" attachment.
        Just try out "getgif.xsl" as it is -- it will get you a small animated .gif file from my private web server ...

         
        Hermann<myXsltBlog/> <myXsltTweets/>
        • SystemAdmin
          SystemAdmin
          6772 Posts
          ACCEPTED ANSWER

          Re: DataPower "binary" node type (binaryNode)

          ‏2012-05-08T06:41:14Z  in response to HermannSW
          Hi Hermann,

          Thanks a lot for your Inputs.

          I tried and it is working as expected.

          But my requirement is slightly different. i need to add to string fields at the end of text file and the concatenated string should go to the backend server

          Content of test-text-file is
          hello world

          trail1 ="string1" and trail2="string2"

          Final output would be hello world string1 string2
          As i am unable to hold the binary output into xsl variable therefore i am unable to achieve this string concatenation.

          But if i do dp:binary-encode and dp:decode then xsl variable is holding the content of test-text-file.
          My only objective is skip the encode and decode because my file is already having UTF-8 encoded content.

          I believe , i am still missing some thing in binaryNode as i am getting some weird outputs ( If i use simple.ffd)

          Could you please provide your inputs on this.

          Thanks
          Pradeep
      • SystemAdmin
        SystemAdmin
        6772 Posts
        ACCEPTED ANSWER

        Re: DataPower "binary" node type (binaryNode)

        ‏2012-05-08T03:48:59Z  in response to Liv2luv
        Hi ,

        As my input to the Transform Action is a XML , therefore i am not using input mapping.

        I only want to send the non-xml data back to the client/Backend
  • HermannSW
    HermannSW
    3145 Posts
    ACCEPTED ANSWER

    Re: DataPower "binary" node type (binaryNode)

    ‏2012-05-08T10:41:02Z  in response to HermannSW
    Hi Pradeep,

    > But if i do dp:binary-encode and dp:decode then xsl variable is holding the content of test-text-file.
    that is correct.

    > My only objective is skip the encode and decode because my file is already having UTF-8 encoded content.
    You cannot, because you need to convert the "binaryNode" response you get to String.

    AND you should not, because the decode does UTF-8 validation for you, see slide 16 of this WSTE webcast:
    http://www-01.ibm.com/support/docview.wss?uid=swg27022977

    You should not rely on that someone promises to send UTF-8 data -- such a contract will always fail at some point in time.
    See slide 5 of this webcast what can go wrong if you do not validate:
    http://www-01.ibm.com/support/docview.wss?uid=swg27022979

    And that is not the worst what can happen.
    Regarding your requirement of appending strings to what you read, please see binary-append.xsl posting:
    https://www.ibm.com/developerworks/mydeveloperworks/blogs/HermannSW/entry/binary_append_xsl7

    It demonstrates how to append arbitrary binary data, but of course you can do the same with text strings.
    In your case you can use this approach of getting yout trail strings appended:
    
    ... <xsl:variable name=
    "str" select=
    "dp:decode(dp:binary-encode($resp/result/binary/node()),'base-64')"/> ... <object> <message> <xsl:copy-of select=
    "dp:binary-decode(dp:encode(concat($str,$trail1,$trail2),'base-64'))"/> </message> </object> ...
    


     
    Hermann<myXsltBlog/> <myXsltTweets/>
    • SystemAdmin
      SystemAdmin
      6772 Posts
      ACCEPTED ANSWER

      Re: DataPower "binary" node type (binaryNode)

      ‏2012-05-08T17:24:48Z  in response to HermannSW
      Thanks a lot Hermann for your Inputs.

      I got this working now.
  • HermannSW
    HermannSW
    3145 Posts
    ACCEPTED ANSWER

    Re: DataPower "binary" node type (binaryNode)

    ‏2012-07-27T07:58:28Z  in response to HermannSW
    A colleague needed to use "dp:validate-hex()" and found a problem end of June.
    I fixed that, sent the fixed version to him -- and forgot to update this thread.

    Yesterday another colleague did run into the same -- this time I do the update.

    The problem is that I mistakenly used a <xsl:variable> instead of a <xsl:param> in <func:function name="dp:validate-hex"> ...
    (if you want to use that function, please correct)

    $ diff -C1 binaryNode.xsl.old binaryNode.xsl
    *** binaryNode.xsl.old  2012-06-28 14:40:02.000000000 +0200
    --- binaryNode.xsl      2012-06-28 14:41:34.000000000 +0200
    ***************
    *** 65,67 ****
        <func:function name="dp:validate-hex">
    !     <xsl:variable name="hexString" />
      
    --- 65,67 ----
        <func:function name="dp:validate-hex">
    !     <xsl:param name="hexString" />
      
    $
    


     
    Hermann <myXsltBlog/> <myXsltTweets/>
    Updated on 2014-03-25T02:50:42Z at 2014-03-25T02:50:42Z by iron-man
    • HermannSW
      HermannSW
      3145 Posts
      ACCEPTED ANSWER

      Re: DataPower "binary" node type (binaryNode)

      ‏2012-10-11T12:18:58Z  in response to HermannSW
      There were still some function parameters declared as <xsl:variable> instead of <xsl:param> in some <func:function>s.
      Find attached the corrected stylesheet binaryNode.xsl.

      These are the functions provided ("dp:...")
      $ xpath++ "str:split(str:concat(//func:function/@name),'dp:')[.!='']" binaryNode.xsl 
      <token>normalize-hex</token><token>validate-hex</token><token>validate-base64</token><token>value</token><token>value-base64</token><token>value-hex</token>
      $
      


      More current information on binaryNode and Non-XML processing inside stylesheets can be found in these two webcasts:
      http://www-01.ibm.com/support/docview.wss?uid=swg27022977
      http://www-01.ibm.com/support/docview.wss?uid=swg27022979

       
      Hermann <myXsltBlog/> <myXsltTweets/>
      Updated on 2014-03-25T02:47:28Z at 2014-03-25T02:47:28Z by iron-man
  • SystemAdmin
    SystemAdmin
    6772 Posts
    ACCEPTED ANSWER

    Re: DataPower "binary" node type (binaryNode)

    ‏2012-11-20T15:56:53Z  in response to HermannSW
    Hi Hermann

    I'm trying to set up a somewhat unusual HTTP GET "proxy" which takes a GET request them retrieves an XML-wrapped base64 encoded binary from a backend WebService, decodes it & returns the binary. Actual content will be a PDF, but initially I'm just trying to test with a GIF. I'm running into the issue you describe here regarding binary zero values embedded in the data, but I can't seem to get the output-mapping fix to work. I'm using the following stylesheet in an MPG - currently it returns just the "GIF89a*" header from the binary, which is the section before the first binary zero:
    <?xml version="1.0"?>
    <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">
    <xsl:output omit-xml-declaration="yes"/>
    <dp:output-mapping href="store:///pkcs7-convert-input.ffd" type="ffd"/>
    <xsl:template match="/">
    <xsl:variable name="binContent" select="dp:binary-decode(/image/imagebase64)" disable-output-escaping="yes"/>
    <xsl:message dp:priority="debug">****(binContent)****: <xsl:value-of select="$binContent"/>
    </xsl:message>
    <dp:set-variable name="'var://context/bin/data'" value='$binContent'/>
    <xsl:value-of select="dp:variable('var://context/bin/data')"/>
    <dp:set-http-response-header name="'Content-Type'" value="'image/gif'"/>
    <dp:set-http-response-header name="'Content-Transfer-Encoding'" value="'binary'"/>
    </xsl:template>
    </xsl:stylesheet>

    XML response from the backend looks like this:

    <image><title>An Image></title><imagebase64>base64data</imagebase64></image>

    Any idea what I'm doing wrong here?

    Thanks
    Chris
    • HermannSW
      HermannSW
      3145 Posts
      ACCEPTED ANSWER

      Re: DataPower "binary" node type (binaryNode)

      ‏2012-11-21T10:16:13Z  in response to SystemAdmin
      I gave two WSTE webcasts on Non-XML data processing in DataPower stylesheets.
      These links give you the presentation .pdf, the audio recording .mp3 AND all samples and stylesheets in Samples.zip:
      http://www-01.ibm.com/support/docview.wss?uid=swg27022977
      http://www-01.ibm.com/support/docview.wss?uid=swg27022979

      How to return of a .gif file from <dp:url-open ... response="binaryNode"> to client is shown on slide 18 of the 2nd webcast above.

      And a sample application export for your real problem (returning base64 encoded PDF files) is attached to this posting:
      https://www.ibm.com/developerworks/forums/thread.jspa?messageID=14479355#14482399

      That solution retrieves a base64 string which is the encoded PDF from the backend.

      I modified your stylesheet to do exactly what you requested, see a sample execution:
      
      $ coproc2 Chris.xsl bqw.gif.xml  http:
      //dp5-l3:2224 -s | od -tcx1 | head -4 0000000   G   I   F   8   9   a  \f  \0  \f  \0 306   A  \0  \0  \0  \0 47  49  46  38  39  61  0c  00  0c  00  c6  41  00  00  00  00 0000020  \v  \v  \v 016 016 016 020 020 020 021 021 021 024 024 024 025 0b  0b  0b  0e  0e  0e  10  10  10  11  11  11  14  14  14  15 $
      


      This is your modified stylesheet, also attached:
      
      <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:output-mapping href=
      "store:///pkcs7-convert-input.ffd" type=
      "ffd"/>   <xsl:template match=
      "/"> <dp:set-http-response-header name=
      "'Content-Type'" value=
      "'image/gif'"/> <dp:set-http-response-header name=
      "'Content-Transfer-Encoding'" value=
      "'binary'"/>   <object> <message> <xsl:copy-of select=
      "dp:binary-decode(/image/imagebase64)"/> </message> </object> </xsl:template> </xsl:stylesheet>
      


      As can be seen, you just have to copy the "binaryNode" returned by "dp:binary-decode()" into <object><message>...</message></object>.
      The <dp:output-mapping> strips the <object> and <message> tags and returns the binary data, including any 0x00 or other Non-XML bytes.

      For completeness, this is the sample image I used:
      
      $ cat bqw.gif.xml <image> <imagebase64> R0lGODlhDAAMAMZBAAAAAAsLCw4ODhAQEBERERQUFBUVFRsbGx0dHR4eHiQkJDg4OD4+PkFBQUhI SExMTFBQUFJSUlNTU1ZWVlhYWFlZWVxcXF1dXWZmZnBwcHR0dHx8fH5+fn9/f4WFhYeHh4+Pj5KS kpaWlpeXl5+fn6CgoKKioqampqmpqaurq7KysrOzs7a2tre3t8XFxcvLy9XV1djY2N7e3uDg4OHh 4eLi4+Tk5Obm5+fn5+jo6Ovr6+3t7fj4+Pr6+vv7+/z8/P39/f
      ////////////////////////// 
      //////////////////////////////////////////////////////////////////////////// 
      //////////////////////////////////////////////////////////////////////////// 
      /////////////////////////////////////////////////////////////////////////yH+ EUNyZWF0ZWQgd2l0aCBHSU1QACwAAAAADAAMAAAHcYA3goOENzVBiCkzISYwLIg+QCE6EioiKCQY NiM+PQ0uIS8lKy0nKhA+QS4fIRkbIBYnGjGpOAYeCQwOBSABPalBCgIAxAACC0HAFwgUzRADGcmI NBUe1h4TO9JBPA/XHhE/2zIdBAEBBxw524jt7j6BADs= </imagebase64> </image> $
      


      It is taken from this "nice" application (find it at bottom of "View Page Source"), "click" and enjoy what you see ...
      http://stamm-wilbrandt.de/en/xsl-list/n-queens/n-queens.internalImages.xsl.xml
      ... after your browser's XSLT processor has computed all different solutions for the n-queens problem with n∈{4,…,9}.
      (for more information see this posting, math character entities from previous line are &​isin; and &​hellip;)

       
      Hermann<myXsltBlog/> <myXsltTweets/>

      Attachments

      • This reply was deleted by UtjalMajumder 2013-05-03T05:56:01Z. Reason for deletion: Resolved
        • HermannSW
          HermannSW
          3145 Posts
          ACCEPTED ANSWER

          Re: DataPower "binary" node type (binaryNode)

          ‏2013-05-02T09:59:29Z  in response to UtjalMajumder

          Hi Utjal,

          can your client process the response when directly accessing the AIS system?
          If so, then response type "Pass-Thru" should do.

          Or do you need to do some processing on response rule (you did not mention that)?

          Or, if client cannot access directly because eg. of missing Content-Type header entry in AIS response,
          do you want to add thet header by DataPower?
           

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

          • UtjalMajumder
            UtjalMajumder
            2 Posts
            ACCEPTED ANSWER

            Re: DataPower "binary" node type (binaryNode)

            ‏2013-05-02T12:37:11Z  in response to HermannSW

            Hi Hermann,

            Thanks for your quick response.

            I am sending some input parameter, which is basically a XML string to AIS. AIS perform some processing and generate the pdf bytestream. AIS than send the pdf bytestream as a response/output to IBM BPM Process. Now I have to take that and create a PDF.

            Now I know that iTEXT can be used to generate PDF, but in my case I have pdf bytestream which I want to convert in PDF and dispay as output and than later I can print it with local printer.

            I searched but I am not able to figure out how to perform such conversion, if you have any sample code or you have implemented such functionality than it would be great.

             

            Thanks and Regards,

            Utjal