Topic
7 replies Latest Post - ‏2013-01-08T15:27:30Z by HermannSW
SystemAdmin
SystemAdmin
6772 Posts
ACCEPTED ANSWER

Pinned topic Binary Transformation Not working

‏2012-12-14T01:04:23Z |
Hi,

I have some HTML error coming from backend and want to send that to client. I am using 'Binary Transform' action and using the following XSL that I got from the forum.. I couldn't get an output.. can somebody help me with this.. ?

<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>

Thanks.
Updated on 2013-01-08T15:27:30Z at 2013-01-08T15:27:30Z by HermannSW
  • Liv2luv
    Liv2luv
    573 Posts
    ACCEPTED ANSWER

    Re: Binary Transformation Not working

    ‏2012-12-14T11:23:09Z  in response to SystemAdmin
    A copy of the correct XSLT you're looking for can be found in this thread:

    https://www.ibm.com/developerworks/forums/thread.jspa?messageID=14676613 (search for ampify.xsl)

    Also, a condensed version is pasted below:

    {code}
    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:dp="http://www.datapower.com/extensions"
    xmlns:regexp="http://exslt.org/regular-expressions"
    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:output omit-xml-declaration="yes" />

    <xsl:template match="/">
    <xsl:variable name="html"
    select="dp:decode(dp:binary-encode(/object/message/node()),'base-64')"/>

    <xsl:variable name="htmlwodt">
    <xsl:choose>
    <xsl:when test="starts-with($html,'&lt;!DOCTYPE')">
    <xsl:value-of select="substring-after($html,'>')" />
    </xsl:when>
    <xsl:otherwise>
    <xsl:value-of select="$html"/>
    </xsl:otherwise>
    </xsl:choose>
    </xsl:variable>

    <xsl:variable name="xml"
    select="regexp:replace($htmlwodt,'&amp;','g','&amp;amp;')"/>

    <object>
    <message>
    <xsl:copy-of
    select="dp:binary-decode(dp:encode($xml,'base-64'))"/>
    </message>
    </object>
    </xsl:template>

    </xsl:stylesheet>
    (code}
    • Liv2luv
      Liv2luv
      573 Posts
      ACCEPTED ANSWER

      Re: Binary Transformation Not working

      ‏2012-12-14T11:24:49Z  in response to Liv2luv
      Oops, posted the wrong XSLT, also incorrect code tags. Plz see below:

      <xsl:stylesheet version="1.0"
          xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
          xmlns:dp="http://www.datapower.com/extensions"
          xmlns:regexp="http://exslt.org/regular-expressions"
          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:output omit-xml-declaration="yes" />
          
          <xsl:template match="/">
              <xsl:variable name="html"
                  select="dp:decode(dp:binary-encode(/object/message/node()),'base-64')"/>
       
              <object>
                  <message>
                      <xsl:copy-of 
                          select="dp:binary-decode(dp:encode($html,'base-64'))"/>
                  </message>
              </object>
          </xsl:template>
          
      </xsl:stylesheet>
      
      Updated on 2014-03-25T02:44:40Z at 2014-03-25T02:44:40Z by iron-man
      • SystemAdmin
        SystemAdmin
        6772 Posts
        ACCEPTED ANSWER

        Re: Binary Transformation Not working

        ‏2012-12-14T18:26:36Z  in response to Liv2luv
        Hi Liv2Luv,

        I tried the below xsl but no luck... I have two inputs that are coming one is some text , the other is HTML none of them are coming back to SOAP UI....

        1) The exact string as below
        There is no resource for path info "/View". SOA-1900200
        at com.tsyssw.server.ws.RestfulDispatcher.dispatch(RestfulDispatcher.java:112)

        2) <html>
        <head/>
        <body>
        <hr style="border-style: groove;"/>
        Error:
        401 Unauthorized
        Description:
        No description available.
        </body>
        </html>
        I have my error rule with a Match-all and binary transform.... binary transform containing the same xsl posted below...

        Thanks
        • Liv2luv
          Liv2luv
          573 Posts
          ACCEPTED ANSWER

          Re: Binary Transformation Not working

          ‏2012-12-14T19:19:28Z  in response to SystemAdmin
          Is the error rule being invoked ?

          What is the setting for 'Process Backend Errors' in the advanced tab.
          • SystemAdmin
            SystemAdmin
            6772 Posts
            ACCEPTED ANSWER

            Re: Binary Transformation Not working

            ‏2012-12-14T20:04:49Z  in response to Liv2luv
            Hi Liv2Luv,

            Thanks a lot for your responses.....

            I am using WS-Proxy . I only see 'Process HTTP Headers' option but not 'Process Backend errors'. As you expected it is going to response rule first, failing there and then going to error rule, however to answer your question yes, response rule is triggered.

            Thanks.
            • SystemAdmin
              SystemAdmin
              6772 Posts
              ACCEPTED ANSWER

              Re: Binary Transformation Not working

              ‏2013-01-04T17:42:15Z  in response to SystemAdmin
              Hi,

              Can somebody help me here please ? I couldn't figure out how to parse the binary response yet.

              Thanks,
              Venky.
              • HermannSW
                HermannSW
                4128 Posts
                ACCEPTED ANSWER

                Re: Binary Transformation Not working

                ‏2013-01-08T15:27:30Z  in response to SystemAdmin
                > I have some HTML error coming from backend and want to send that to client.
                > I am using 'Binary Transform' action and using the following XSL that I got from the forum.
                >
                So what do you want to do on response rule?
                If you just want backend response pass thru the box unmodified, please use "passthru" response type.

                Or do you want to get and process XML responses normally, and only handle HTML error responses differently?

                 
                Hermann<myXsltBlog/> <myXsltTweets/>