Layer7 API Management

  • 1.  Translating unpredictable length String to JSON

    Posted Nov 06, 2018 05:17 AM

    Hi,

    I'm creating a policy for sending a string through RAW assertion to the backend server and receiving a response from the server.

    The request string is fixed length but the length of response string is unpredictable.

    I need to get each value from the response string's different part and transfer it to JSON format.

    For example:

    Response String = AA9567BS33411002AAGF1FFG

    AA9567 = Company ID

    BS33411 = Customer ID

    002 = The amount of Txn

    AAGF = First Txn amount 

    1FFG =  Second Txn amount

     

    I'll know the number of Txn from the position 13-15(started from 0) of the string, but I'll never know the number before receiving the string.

     

    I have no idea how to design the policies.

    Is there any suggestion or any assertion suit to do this?

     

    Best Regards,



  • 2.  Re: Translating unpredictable length String to JSON

    Broadcom Employee
    Posted Nov 06, 2018 08:51 AM

    Hi Gary,

     

    Are the positions consistent for the Txn always in the same position in the response? or are the length of the values always consistent? Meaning, is the company ID always 6 characters, the customer ID always 7 characters, etc..

     

    If so you can use the Xpath assertion substring function

     

    https://communities.ca.com/message/242149526-re-substring-function?commentID=242149526&et=watches.email.outcome#comment-… 

     

    The string can be parsed based on any consistent value, i.e: Txn start at position 13-15.

     

    Regards,

    Joe



  • 3.  Re: Translating unpredictable length String to JSON

    Posted Nov 06, 2018 09:36 AM

    Hi Joe,

    Yes. The position and length of every element are fixed.

    So the assertion you mentioned is good for this case but they'is still one question.

    If I can only know the whole string length after I received this string, that means it may contain few or so many Txn. 

    How do I design the XPath assertion for the loop?

     

    Best Regards,



  • 4.  Re: Translating unpredictable length String to JSON
    Best Answer

    Broadcom Employee
    Posted Nov 08, 2018 08:24 AM

    Hi Gary,

     

    Do you mean that there could be multiple Txn values in the string? If that is the case you may be able to nest the Xpath statements inside of the 'Run Assertions for Each Item' assertion. This can iterate through a multivalue context variable.

     

    Run Assertions for Each Item Assertion - CA API Gateway - 9.3 - CA Technologies Documentation 

     

    Regards,

    Joe



  • 5.  Re: Translating unpredictable length String to JSON

    Broadcom Employee
    Posted Nov 28, 2018 11:32 AM

    Hi

    Did the answers on this thread answered your question? If it did please mark it as the right answer.
    When your question is not answered or you still have additional questions please let us know.

    With Kind Regards
    Dirk