Mathematical functions within Policy
search cancel

Mathematical functions within Policy


Article ID: 42952


Updated On:


STARTER PACK-7 CA Rapid App Security CA API Gateway



Use case:Executing mathematical functions within Policy.

Description:Sometimes in policy the need arises to do some basic mathematical functions in order to facilitate a use case. While this can be facilitated through custom assertions to manage this, the Gateway can also do it with the standard core assertion set.

Setup:In order to do XPath math, drag a Response XPath over into our Gateway's policy workspace. In the 'XPath:' window enter the mathematical function to be executed. This field supports a very flexible array of functions as demonstrated in the attached policies. To access the result of the equation, use the *.results context variable that is created by this assertion. The prefix to *.results will depend upon what is used as the variable prefix in the lower left hand corner of the Response XPath Assertion. For example, in the use case pictured below, the result would be '2.0' and accessed via the 'math.results' context variable:


<Please see attached file for image>

XPath Math Sample

To get a bit more complex, use context variables in the XPath field. The variables used should be saved as a string, and invoked in the 'XPath:' field in the format $variableName. Note the lack of curly brackets around the variable [ {} ]. The policy below shows how this could be utilized to ensure there is an attachment on a message by taking the total request size, subtracting the size of the main body of the message, and seeing if there is a remainder.

<Please see attached file for image>


There are plenty of other ways to use this functionality as well. Attached to this article are two stripped down policies showing how we can use XPath for both simple and more complex math. The XPath*Sample policy shows very basic +/- math. Also attached is a sample policy that will do XPath Math to round up, down, to decimal place or to do the mround function.



Component: APIGTW


Please Update This Required Field


1558688556073000042952_sktwi1f5rjvs16fmu.jpeg get_app
1558688554225000042952_sktwi1f5rjvs16fmt.jpeg get_app
1558688552431000042952_sktwi1f5rjvs16fms.jpeg get_app
1558688549688000042952_sktwi1f5rjvs16fmr.jpeg get_app get_app