Layer7 API Management

Expand all | Collapse all

Integer operations in policy assertion?

Jump to Best Answer
  • 1.  Integer operations in policy assertion?

    Posted 11-02-2015 10:57 AM

    I'm writing a new policy assertion that requires integer manipulation. None of my attempts have yielded any success. Here's what I'm trying to do:


    Screen Shot 2015-11-02 at 09.53.05.png


    If either assertion 2 or 3 are set to Integer, then I get an error along the lines of "Unable to parse integer string" (I'm assuming because in assertion 2, the gateway.time.millis exceeds Integer.MAX_VALUE)


    I can have integer values that are smaller, but still can't make integer math work

    Screen Shot 2015-11-02 at 09.55.54.png

    Assertion 3 still gives me the Unable to parse integer string.


    So is there a way to get integer math to work in a policy through stock assertions? If so, how?



  • 2.  Re: Integer operations in policy assertion?
    Best Answer

    Posted 11-02-2015 11:20 AM

    Hello chou_abc,


    That won't work . We have kind of a 'Work Around' that you can use, but with the knowledge that mathematical computations may add load to the host.


    with that acceptance, you can leverage our response Xpath assertion to do simple mathematical computations.



    Take this Policy:



    take a look at the xpath assertion.


    Here it is working.



    hope this helped.

  • 3.  Re: Integer operations in policy assertion?

    Posted 11-02-2015 11:26 AM

    Hi Doyle_Reece


    Do you recommend Custom assertion for these type of scenarios and is there an added load of using custom assertion as compared to Xpath or for that matter existing assertions?



    Ganesh Reddy

  • 4.  Re: Integer operations in policy assertion?

    Posted 11-02-2015 11:31 AM

    i don't think a custom assertion will give you anymore benefit, I just wanted to mention that some people really 'run away' with doing lots of unnecessary mathematical computations on the gateway, and i would try to limit them if necessary.

  • 5.  Re: Integer operations in policy assertion?

    Posted 11-02-2015 12:13 PM

    Hi Doyle,

       First of all, that answer works and seems like a sneaky use of XPath transform ;-)

    The use case here is that I'm generating a web token from the gateway and wanted to compute an expiration. Thus, I get gateway.time.millis and add say 60000 to that in get a one-minute token expiration time. Should this have been done outside of the gateway?


    One other question, the XPath expression creates a decimal result (e.g. 3.0 instead of 3), I'm using split variable to parse out everything before the decimal, this is expected and the right way to do this? I couldn't get the format-number() Xpath function to work for this.

  • 6.  Re: Integer operations in policy assertion?

    Posted 11-02-2015 01:33 PM

    If all you're looking to do is create a token expiry date you can use the Set Variable assertion with the Date/Time data type: Set Context Variable Assertion - CA API Gateway - 8.4 - CA Technologies Documentation .  There is an offset field that allows you to create a time offset from a specified time.

    Screen Shot 2015-11-02 at 10.31.41 AM.png


    And yes, this is a good use of the Gateway.

  • 7.  Re: Integer operations in policy assertion?

    Posted 11-02-2015 02:25 PM

    Well, that almost feels like cheating it's so easy! Thanks...

  • 8.  Re: Integer operations in policy assertion?

    Posted 01-17-2018 04:59 AM

    Hi Julian, 


    I just developing the same solution. I'm trying to add an offset to the current time. But I'm facing problems during the time conversion to milliseconds. I just added the same assertion with the same offset.  

    But in the Debugger I can only see the normal time and not the millisecond time. 


    I'm using the API Gateway 9.2.

    Do you have a hint for me? 



  • 9.  Re: Integer operations in policy assertion?

    Posted 03-23-2018 09:39 AM

    There is a 'millis' suffix that can be used to get the time in milliseconds ( ${gateway.time.millis} )

    Date and Time Variables - CA API Gateway - 9.2 - CA Technologies Documentation