DataPower

DataPower

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.

 View Only
  • 1.  How to decode response content type as application/zip?

    Posted Wed March 19, 2025 04:20 AM

    Dear All,

    I have a scenario where the server response is in the application/zip format. Could you please advise on how to read and extract the data from it?

    Any suggestions using GatewayScript or XSLT would be greatly appreciated.

    Thanks!



    ------------------------------
    Mahender Batta
    ------------------------------


  • 2.  RE: How to decode response content type as application/zip?

    Posted Wed March 19, 2025 09:32 AM

    Is it just compressed for network speed or is the back end explicitly compressing as an attachment or other means?

    Check to see if your "Enable pass through of compressed payload" is "on".  If so, you won't be able to process it.

    Also check your User Agent Allow Compression Policy, as it might affect such things.



    ------------------------------
    Joseph Morgan
    CEO - Independent
    ------------------------------



  • 3.  RE: How to decode response content type as application/zip?

    Posted Thu March 20, 2025 05:43 AM

    Dear @Joseph Morgan,

    Thank you for your response, Yes it just compressed for network speed. Backend team had provided some java sample code to read/decode it. However it is not relevant but to get some idea I'm posting  below, 

             InputStream gzipStream = new GZIPInputStream(backendResponseStream);
             Reader decoder = new InputStreamReader(gzipStream, "UTF-8");
             BufferedReader bufferServerReader = new BufferedReader(decoder); 


    Now, my requirement is to o it DataPower gateway, decode the response and return as JSON.



    ------------------------------
    Mahender Batta
    ------------------------------



  • 4.  RE: How to decode response content type as application/zip?
    Best Answer

    Posted Thu March 20, 2025 06:17 AM
    Edited by Mahender Batta Tue March 25, 2025 06:14 AM

    That is a completely different story, in initial posting you wrote "application/zip" which is wrong for gzip as in your code, should be "application/gzip".
    For that you just need to enable "Compression" for MultiProtocolGateway:



    ------------------------------
    Hermann Stamm-Wilbrandt
    Compiler Level 3 support, IBM DataPower Gateways
    IBM
    Boeblingen
    ------------------------------



  • 5.  RE: How to decode response content type as application/zip?

    Posted Thu March 20, 2025 08:49 AM
    Edited by Mahender Batta Thu March 20, 2025 08:49 AM

    Dear @Hermann Stamm-Wilbrandt,

    Thank you so much!

    I'm able to achieve it by dp:inflate DataPower extension and below is my XSLT code:

                  <xsl:variable name="response">
                         <dp:url-open target="{$url}" response="responsecode-binary" content-type="text/xml" http-method="POST" ssl-proxy="client:cert">
                                    <xsl:copy-of select="dp:parse($inputxml)"/>
                         </dp:url-open>
                   </xsl:variable>
                   <xsl:variable name="resultXml">
                               <xsl:copy-of select="dp:parse(dp:inflate(dp:binary-encode($response/result/binary/node()),'gzip'))"/>
                   </xsl:variable>



    ------------------------------
    Mahender Batta
    ------------------------------



  • 6.  RE: How to decode response content type as application/zip?

    Posted Thu March 20, 2025 09:09 AM
    Edited by Hermann Stamm-Wilbrandt Thu March 20, 2025 09:10 AM

    That is a second "by hand" way of dealing with "gzip"ed backend response.
    You don't need to use "dp:inflate()" when you set "Compression" to "on" as I showed in my previous posting.

    Then DataPower will do the inflate and your service will get inflated data as input.

    ------------------------------
    Hermann Stamm-Wilbrandt
    Compiler Level 3 support, IBM DataPower Gateways
    IBM
    Boeblingen
    ------------------------------



  • 7.  RE: How to decode response content type as application/zip?

    Posted Tue March 25, 2025 06:15 AM

    Thank you @Hermann Stamm-Wilbrandt, I got your point. I will try using enabling compression option as well.



    ------------------------------
    Mahender Batta
    ------------------------------



  • 8.  RE: How to decode response content type as application/zip?

    Posted Sun April 20, 2025 03:07 AM

    Hi @Hermann Stamm-Wilbrandt,

    Now, I have similar case to send xml gzip compressed data to backend server.

    Based on suggestion I have tried by enabling the compression on MPG but it is not compressing the payload.
    I have also tried using  dp:deflate it compressing but server responding as Internal Error (from client)

     <xsl:variable name="response">
          <dp:url-open target="{$url}" response="responsecode" content-type="application/gzip"  http-method="POST" ssl-proxy="client:ClientProfile">
                  <xsl:value-of select="dp:deflate($xmlinput,'gzip')"/>
           </dp:url-open>
     </xsl:variable>


    Any suggestion please.



    ------------------------------
    Mahender Batta
    ------------------------------



  • 9.  RE: How to decode response content type as application/zip?

    Posted Thu March 20, 2025 03:13 AM
    Edited by Hermann Stamm-Wilbrandt Thu March 20, 2025 03:17 AM

    In case the .zip file is received as an attachment, you can access with "Archive=zip" from attachment protocol:
    https://www.ibm.com/docs/en/datapower-gateway/10.6.0?topic=servers-attachment-protocol

    If you get only the .zip in response, you need to attach it to some context, and then you can process the .zip.

    The example fetch and results actions show how to extract/add a file from/to the .zip,
    The naming  for fetch example is not good, better:

      fetch
        http://zoostation/some.zip
        file-to-extract

     

    You have to do .zip access with fetch/results actions in DataPower, GatewayScript cannot do that directly.



    ------------------------------
    Hermann Stamm-Wilbrandt
    Compiler Level 3 support, IBM DataPower Gateways
    IBM
    Boeblingen
    ------------------------------