Layer7 API Management

  • 1.  How to split an XML and process each node?

    Posted Aug 10, 2016 11:00 AM


    Hi

    I am receiving XML files containing multiple "documents". I want to split the whole XML into documents and then process each document.

    Example:

    <?xml version="1.0" encoding="UTF-8"?>
    <Export>
        <Header></Header>
        <Documents>
            <Document>...</Document>
            <Document>...</Document>
            <Document>...</Document>
            <Document>...</Document>
            <Document>...</Document>
        </Documents>
    </Export>
    

     

    When I understand the documentation of the the "Run Assertions for Each Item Assertion" correct, I can run into problems when I use it:

    If any of the POST requests fail to reach the target server, the Run Assertions for Each Item assertion will fail and the remaining POSTS will not be attempted.

    I understand this as: the iteration can break after 2 documents. What happens then to the rest of the documents? How can I process them since the iteration will always break at the same point no matter how often I retry?

     

    What I am looking for is way to process EACH document, no matter if one or some documents are not processable. If a processing error occurs, I would like to define an "exception handling" for the erroneous document. But the iteration must continue. 

     

    Thanks for any hints

    Stephan



  • 2.  Re: How to split an XML and process each node?
    Best Answer

    Posted Aug 11, 2016 04:55 AM

    To provide the answer to my own question: the "Handle errors" assertion is your friend when you want to do this. Combined with the "Raise error" assertion to abort the current cycle, but not the iteration itself.

     

    Example:

    l7-iteration-handleerrors.png

    • Line 4 splits the XML
    • Line 6 iterates over the parts
    • Line 7 encapsulates the content of the iteration
    • Line 10 is a placeholder for whatever processing
    • Line 11 is only reached if processing fails
    • Line 13 aborts the current cycle if processing was failed
    • Line 14 is only reached if processing was successful
    • Line 15 is reached no matter if there were processing errors or not in the iteration

     

    This example produces the following log output:

    l7-iteration-handleerrors-log.png

     

    Stephan



  • 3.  Re: How to split an XML and process each node?

    Broadcom Employee
    Posted Aug 11, 2016 01:50 PM
      |   view attached

    Hi Stephan

     

    I’ve attached a policy to this email showing you a basic run through of this scenario.  I created the request message within the policy that looks like this:

     

     

     

    CA API Management Community: https://communities.ca.com/community/ca-api-management-community

    Attachment(s)

    zip
    xml_splitting.xml.zip   1 KB 1 version