Topic
11 replies Latest Post - ‏2013-06-18T08:48:48Z by HermannSW
Developer11
Developer11
75 Posts
ACCEPTED ANSWER

Pinned topic base64 encoding

‏2013-06-13T14:09:57Z |

Hi All,

How do we deal with embedded messages in DP?

If we get a pdf file embedded in a SOAP message as 'base64' encoded, is it possible to capture the pdf file from the message and store it remotely? Please advise.

 

Thanks

  • JoeMorganNTST
    JoeMorganNTST
    427 Posts
    ACCEPTED ANSWER

    Re: base64 encoding

    ‏2013-06-13T16:00:49Z  in response to Developer11

    Try using an "Extract" action to get the PDF out of the message into a DP variable.  Then you can use a results Asynch to send that content anywhere you want.

  • HermannSW
    HermannSW
    4369 Posts
    ACCEPTED ANSWER

    Re: base64 encoding

    ‏2013-06-13T21:05:16Z  in response to Developer11

    Please see how you can use <dp:url-open> to send base64 endoded data to a backend (decoded):

    https://www.ibm.com/developerworks/community/forums/html/topic?id=bd76be0a-1dee-4e2f-8861-739378aedb9f#a0342be2-b5f0-4cfa-bbc9-ca19efc5c870


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

     

    • Developer11
      Developer11
      75 Posts
      ACCEPTED ANSWER

      Re: base64 encoding

      ‏2013-06-14T05:05:20Z  in response to HermannSW

      Thanks for the response

       

      The variable which contains the "pdf embedded in it" contains the value as "JVBERi0xLjIgCiXi48/TCjEgMCBvYmoKPDwgCi9UeXBlIC........".

      Is it possible to transform this into a ".pdf"?

      • HermannSW
        HermannSW
        4369 Posts
        ACCEPTED ANSWER

        Re: base64 encoding

        ‏2013-06-14T06:19:43Z  in response to Developer11

        Sorry that I did not make that clear.

        The  data-type="base64"  in <dp:url-open> does first base64-decode the input and then sends it to backend.
        This way the PDF file gets send, not its base64 encoding.

        PDF files contain typically binary data. In XSLT only XML Characters can be processed.
        This is the reason why you cannot have the PDF file itself in XLST, only its base64 encoding.

         


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

         

        • Developer11
          Developer11
          75 Posts
          ACCEPTED ANSWER

          Re: base64 encoding

          ‏2013-06-17T06:28:58Z  in response to HermannSW

          Thanks for the clarification Hermann!

          We are currently getting the "pdf" encoded in the "base64binary" format in one of the SOAP parameters of the message.

          When I tried to decode it, only the first few lines are getting decoded, but the actual content in the pdf is not getting decoded. They are being displayed as "special" characters.

          %PDF-1.2
          %âãÏÓ
          1 0 obj
          <<
          /Type /Catalog
          /Pages 3 0 R
          >>
          endobj
          2 0 obj
          <<
          /CreationDate (D:20130614173453)
          /ModDate (D:20130614173453)
          /Producer (libtiff / tiff2pdf - 2.3.606.0)
          >>
          endobj
          3 0 obj
          <<
          /Type /Pages
          /Kids [ 4 0 R 9 0 R ]
          /Count 2
          >>
          endobj
          4 0 obj
          <<
          /Type /Page
          /Parent 3 0 R
          /MediaBox [0.0000 0.0000 3441.0000 4870.5000]
          /Contents 5 0 R
          /Resources <<
          /XObject <<
          /Im1 7 0 R >>
          /ProcSet [ /ImageB ]
          >>
          >>
          endobj
          5 0 obj
          <<
          /Length 6 0 R
           >>
          stream
          q  1111.0000 0.0000 0.0000 1112.5000 0.0000 0.0000 cm /Im1 Do Q

          endstream
          endobj
          6 0 obj
          64
          endobj
          7 0 obj
          <<
          /Length 8 0 R
          /Type /XObject
          /Subtype /Image
          /Name /Im1
          /Width 4588
          /Height 6494
          /BitsPerComponent 1
          /ColorSpace /DeviceGray
          /Filter /CCITTFaxDecode /DecodeParms << /K -1 /Columns 6588 /Rows 8494>>
           >>
          stream
          ò¾á ¹Ó`¹ƒ09°k0%ÀðR0
          äGc"2+¼B£#XÎ%±'Îd[ã;®;œc2ˆéÿÿÿÿÿÿÿ ðC28‰œƒÁ O$G4ÏàƒÁãA8 bŠä Î'''#î%¹'
          NJ    Áœ·Aœ‰àöx‹'vpÌG³c=šGLÄb/g#TQÍæ#-ŒD6O"ñAļbô^8ËÆ3

           

          • HermannSW
            HermannSW
            4369 Posts
            ACCEPTED ANSWER

            Re: base64 encoding

            ‏2013-06-17T09:25:29Z  in response to Developer11

            > When I tried to decode it,
            >
            you cannot do that, because XSLT/XML cannot handle binary data (XML Characters do not contain most control characters).

            And you do not need to do that:

            • just pass the base64 string if using <dp:url-open>
              <dp:url-open target="..." data-type="base64">
                <xsl:value-of select="//base64Data"/>
              </dp:url-open>

               
            • or pass binary-decoded value for sending to service backend

            <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-request-header
                  name="'Content-Type'"
                  value="'application/pdf'"
                />
                <!-- <dp:freeze-headers/> -->

                <object>
                  <message>
                    <xsl:copy-of select="dp:binary-decode(//yourBase64PDFdata)"/>
                  </message>
                </object>

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

             

            You can find more information on the second approach in these two WSTE webcasts:
            http://www-01.ibm.com/support/docview.wss?uid=swg27022977
            http://www-01.ibm.com/support/docview.wss?uid=swg27022979


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

             

            • Developer11
              Developer11
              75 Posts
              ACCEPTED ANSWER

              Re: base64 encoding

              ‏2013-06-18T07:52:31Z  in response to HermannSW

              Hermann,

               

              Service provider sends DP, the SOAP response message.

              One of the parameters in the response message contains the "base64binary" encoded text.

              Dp should extract this "base64binary" content and place it in a PDF file.

               

              If I understand correctly, we can't transform these contents (in base64binary) into ASCII format and store them in the PDF?

              Please confirm

              • HermannSW
                HermannSW
                4369 Posts
                ACCEPTED ANSWER

                Re: base64 encoding

                ‏2013-06-18T08:02:29Z  in response to Developer11

                store where?

                Store remotely by <dp:url-open target="..." data-type="base64">base64data</dp:url-open> yes.
                Send to backend as stated above, yes.

                There are only two options to "store" data on appliance:<

                • <dp:dump-nodes> allows to store XML only, in temporary: folder, not applicable in your case
                • storeing via <dp:set-file> XML Managemnt Interface command


                So please clarify "where" you want to "store the PDF".


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

                • Developer11
                  Developer11
                  75 Posts
                  ACCEPTED ANSWER

                  Re: base64 encoding

                  ‏2013-06-18T08:10:19Z  in response to HermannSW

                  Hermann,

                   

                  We need to store the contents in "ASCII" format on a remote FTP server.

                  I am able to do that now. But as stated earlier, the contents are not in the readable format. We are getting special characters in the message content.

                • Developer11
                  Developer11
                  75 Posts
                  ACCEPTED ANSWER

                  Re: base64 encoding

                  ‏2013-06-18T08:21:53Z  in response to HermannSW

                  Hermann,

                   

                  Forgot to mention in my pervious post.

                  I've used the url-open option. But still getting the special characters in the output file

                  <dp:url-open target="..." data-type="base64">
                    <xsl:value-of select="//base64Data"/>
                  </dp:url-open>

                  • HermannSW
                    HermannSW
                    4369 Posts
                    ACCEPTED ANSWER

                    Re: base64 encoding

                    ‏2013-06-18T08:48:48Z  in response to Developer11

                    > We are getting special characters in the message content.
                    >
                    There is a simple reason for this -- PDF is a mixed ASCII/BINARY format.

                    Nothing is wrong with that -- PDF is not intended to be opened by an editor program, but by a PDF reader ...

                    Since PDF version 1.2:
                    http://en.wikipedia.org/wiki/Portable_Document_Format#Adobe.27s_versions

                    "... zlib/deflate compression of text or binary data; ..."


                    I attached the PDF printed version of you previous posting.
                    Opening this in "vi" editor you can see binary data.
                    Binary data is always framed by "...stream binaryData endstrem..."

                    %PDF-1.4
                    %Çì<8f>¢
                    5 0 obj
                    <</Length 6 0 R/Filter /FlateDecode>>
                    stream
                    x<9c>Õ< x^TEÖ<92><99>I&Ã<98>0<84>^P<92>^Phî<8e><98>NWõQÝ®"<87>^RAD@TÀ°ê<86>K<99>^D^S@Deu^QQñ^@  ¬ú<83> â<85><80>
                    ...

                     

                     

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

                    Attachments