Layer7 API Management

  • 1.  Javascript Assertion

    Posted Jan 23, 2019 04:07 AM

    I have created a context variable using execute javascript assertion as context.setVariable("url",value). But am unable to access the variable in the following assertions. Say for example, i am trying to access the context variable url in return template response to the requestor assertion which is after the javascript assertion. Do i need to use any prefix to access context variables created in execute javascript assertion? 



  • 2.  Re: Javascript Assertion

    Broadcom Employee
    Posted Jan 23, 2019 10:02 AM
      |   view attached

    Hi Giridharan,

     

    I have attached a sample of what I believe you are trying to accomplish. Please take a look and let me know if this helps. Feel free to ping me with any questions, thank you.

     

    Regards,

    Joe

    Attachment(s)



  • 3.  Re: Javascript Assertion

    Broadcom Employee
    Posted Jan 23, 2019 10:06 AM

    Just to add on here, if value is not defined in your policy as a variable it would return blank/error. If you are meaning to use the literal string value you can simply enclose it in quotes

     

    ie:

    context.setVariable("url","value");



  • 4.  Re: Javascript Assertion

    Posted Jan 24, 2019 02:42 AM

    Thanks Joe. Exactly what am trying.

    But a warning is appearing when i tried to access the context variable url. is there a way to suppress the warning?



  • 5.  Re: Javascript Assertion

    Broadcom Employee
    Posted Jan 24, 2019 08:45 AM

    Is this the message you see?

     

     

    If so, the 2 options I can think of, 1) turn off policy validation or 2) define the variable ahead of it's use in the return template response. Meaning, use a set context variable assertion to set 'url' to nothing. 

     

    It does not appear that the validation takes into account a variable declaration in the assertion, so even setting it explicitly in the JS assertion will not suppress the message.

     

    var url = "";

    or 

    var url = null;



  • 6.  Re: Javascript Assertion

    Posted Jan 25, 2019 01:47 AM

    Yes. I am seeing the same warning. I would like to know more about option 1. can i turn off policy validation for specific policy? If so, please let me know the procedure?



  • 7.  Re: Javascript Assertion
    Best Answer

    Broadcom Employee
    Posted Jan 25, 2019 07:39 AM

    Policy validation is a global setting, it cannot be turned off on a per policy basis.

    If you would like to turn off validation for all policies:

     

    In Policy Manager

     

    1) File -> Preferences

    2) Uncheck 'Policy Validation Feedback'

     

     

    Regards,

    Joe



  • 8.  Re: Javascript Assertion

    Posted Jan 25, 2019 08:45 AM

    Thanks so much Joe