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 catch the response of type text/xml in the DataPower XSLT using dp:url-open?

    Posted Wed November 15, 2023 08:06 AM
      |   view attached

    Dear All,

    I have a case where the backed server is responding with the Content-Type="text/xml".

    How to read the response data in the XSLT?



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


  • 2.  RE: How to catch the response of type text/xml in the DataPower XSLT using dp:url-open?

    Posted Wed November 15, 2023 08:55 AM

    This looks like base64 encoding to me.  Have you tried dp:decode?

    https://www.ibm.com/docs/en/datapower-gateway/10.0.x?topic=functions-dpdecode



    ------------------------------
    Joseph Morgan
    ------------------------------



  • 3.  RE: How to catch the response of type text/xml in the DataPower XSLT using dp:url-open?

    Posted Wed November 15, 2023 09:04 AM
    Edited by Mahender Batta Wed November 15, 2023 09:05 AM

    Thank you @Joseph Morgan,

    I'm using following xslt code to read the response, 

                          <xsl:variable name="callServeurl">
                            <dp:url-open target="{$url}" response="responsecode-binary" content-type="application/json" http-headers="$httpHeaders"
                                         http-method="POST">
                                <xsl:copy-of select="$requestBody"/>
                            </dp:url-open>
                        </xsl:variable>
                        <xsl:variable name="Response">
                            <xsl:copy-of select="dp:stringToJSONx(dp:decode(dp:binary-encode($callServeurl/result/binary/node()),'base-64'))"/>
                        </xsl:variable>

    Could you please advise? 



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



  • 4.  RE: How to catch the response of type text/xml in the DataPower XSLT using dp:url-open?

    Posted Wed November 15, 2023 09:25 AM

    So at this point, I'm a bit lost.  What is the content-type of $callServeurl/result/binary/node()?   If the response is, in fact, XML, would it not already be base64 encoded?

    It seems to me if the server is responding with XML, you simply need to:

    dp:stringToJSONx(dp:decode($callServeurl/result/binary/node()), 'base-64'))

    Have you tried this?



    ------------------------------
    Joseph Morgan
    ------------------------------



  • 5.  RE: How to catch the response of type text/xml in the DataPower XSLT using dp:url-open?

    Posted Thu November 16, 2023 01:39 AM

    Dear @Joseph Morgan,

    Response Content-Type is text/plain; charset=utf-8.



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



  • 6.  RE: How to catch the response of type text/xml in the DataPower XSLT using dp:url-open?

    Posted Thu November 16, 2023 10:27 AM

    I don't want to get too caught up in your screenshot there, but, I'm seeing a 500 error.  What would you expect to see in the binary node there, or is this just an intentional example?

    I also think I have a parenthesis out of order in by code snippet above:  apologies for that.

    Going from the original example posted, it appears the content of the binary node is already base64 encoded.  You will first need to decode from base64.  If that, then, contains a string parsable to JSONx, then you should be good to go.  It seems strange to me you'd binary-encode a binary node if that node is already base64 encoded.



    ------------------------------
    Joseph Morgan
    ------------------------------



  • 7.  RE: How to catch the response of type text/xml in the DataPower XSLT using dp:url-open?

    Posted Fri November 17, 2023 09:16 AM

    Hi Mahender,
    Just to add to what Joseph has posted, you are correct in using the response="responsecode-binary" attribute for a non-XML response.  That is why your response result is a binary node in $callServeurl/result/binary.  Since your content type response header is plain text, you can get the actual plain text from the binary node by using
    <xsl:variable name="textResponse" select="dp:binaryNodeToString($callServeurl/result/binary)" />

    Now if your response is not text/plain but is actually an XML response, then on the url-open extension element you should use response="xml" or ="responsecode" which I believe will provide a similar result set if you also want to get the response code, headers, etc, in addition to the XML response which will be parsed and available in the  returned urlopen xml response.

    Your screenshot above doesn't appear to be xml though, perhaps base64 plain/text? If so you should base64 decode the string into an xml string, and if you need to look  inside the xml, dp:parse the string to get a nodeset.


    Best Regards,
    Steve



    ------------------------------
    Steve Linn
    Senior Consulting I/T Specialist
    IBM
    ------------------------------