DataPower

 View Only
  • 1.  XML-declaration is missing.

    Posted Tue May 04, 2021 05:36 AM
    Edited by Joacim Dahlblom Wed May 05, 2021 04:55 AM

    Hello,
    We have a Multi-Protocol Gateway where we need to log the incoming request to be able to use it later for calculating checksum.
    The problem is that the XML-declaration is missing in the log.
    We don't do any transformation or anything before logging.
    Also when I look at the request input in the probe the XML-declaration is missing.

    Start of request:
    <?xml version="1.0" encoding="UTF-8"?>
    <Document xmlns=...

    Start of log:
    <Document xmlns=...

    I did a packet capture to make sure that the XML-declaration is OK when the request arrives at DP.

    Is the any way to make the XML-declaration visible?


    Edit:

    If I set Request Type to Non XML I can see the declaration in the probe.

    As soon as it is parsed to XML, the declaration disappears.


    Regards
    Jocke D

    ------------------------------
    Joacim Dahlblom
    ------------------------------



  • 2.  RE: XML-declaration is missing.

    Posted Wed May 05, 2021 04:01 PM

    Jocke,

    Thanks for the question!


    Explanation of the behavior

    For Request Type of "XML", the MGPW will usually automatically parse the input as XML, so it is then an XML Infoset and not XML serialized as bytes anymore.
    The XML Infoset specification is here:  http://www.w3.org/TR/xml-infoset

    The Document Information Item in the XML Infoset has a property [character encoding scheme] but it does not have an XML Declaration per-se.

    For Request Type of "Non XML", the MPGW is not parsing it by default, so you still have the input XML serialized as bytes, including your XML Declaration.

    Options you can choose

    There are many options of what you can do, all around what behavior you want and how much performance you're willing to "spend" on parts of that behavior.

    (Option 1) In an MPGW, you can use XSLT via an XForm Action to serialize your XML however you like, including with an XML Decl, and then log that.

    (Option 2) MPGW also supports the Parse policy so you could parse it as XML after you log it.

    (Option 3) Or you can decide that it's ok to not have an XML declaration in the log as long as the XML you see is spec-compliant as the same XML infoset.
    For example, UTF-8 data does not require an XML declaration to identify it as UTF-8 according to the XML specification, since it is automatically inferred.
    So it could be ok for your log to be the same Infoset, which means the same semantic data from an XML perspective, while not being the exact same bytes.
    The XML specification is here:  https://www.w3.org/TR/xml/

    That's three options of how to proceed.  As you can see they are all depending on what your real requirements are.
    Hopefully at least the explanation helps for why you're seeing the behavior that you get.



    ------------------------------
    Morris Matsa
    ------------------------------



  • 3.  RE: XML-declaration is missing.

    Posted Thu May 06, 2021 07:45 AM

    Thanks for the answer Morris Matsa.

    Yes now I understand the behavior but I can't really solve my problem.

    I have to forward the request looking exactly as it came in.

    Need to work on that. :)

    Thanks

    /Jocke D



    ------------------------------
    Joacim Dahlblom
    ------------------------------



  • 4.  RE: XML-declaration is missing.

    Posted Thu May 06, 2021 10:32 AM
    Sure.  If you need the identical byte-for-byte document, then you can either log it before you parse it, or you can save a copy of it and use that copy even after you parse it.

    ------------------------------
    Morris Matsa
    ------------------------------



  • 5.  RE: XML-declaration is missing.

    Posted Tue June 22, 2021 03:43 AM

    > I have to forward the request looking exactly as it came in.

    >

    DataPower log has default XML encoding UTF-8.
    So if your request comes with a different encoding, it will be logged UTF-8 encoded.

    "exactly as it came in" is a Non-XML requirement, so you need Non-XML procedures.
    Even then you cannot get non-UTF8 encoding in DataPower log.
    The best you have is to log the original unparsed message base64 or hex encoded.



    ------------------------------
    Hermann Stamm-Wilbrandt
    Compiler Level 3 support & Fixpack team lead
    IBM DataPower Gateways (⬚ᵈᵃᵗᵃ / ⣏⠆⡮⡆⢹⠁⡮⡆⡯⠂⢎⠆⡧⡇⣟⡃⡿⡃)
    https://stamm-wilbrandt.de/en/blog/
    ------------------------------