Layer7 API Management

Expand all | Collapse all

Set/used variables from custom assertion not refreshed by gateway

  • 1.  Set/used variables from custom assertion not refreshed by gateway

    Posted 11-22-2018 10:36 AM

    Hi, I'm developing custom assertion and there's one problem that I can't solve.

    I want to dynamically set what variables are used/set by my assertion, but it doesn't seem to be refreshed in gateway, there are only properties visible that are set when assertion class is constructed, so I assume that these methods are only called once on assertion creation.

    How can I force gateway to refresh this?

     

    Here's my code in Kotlin:

     

    class JsonTransformationAssertion : CustomAssertion, UsesVariables, SetsVariables {

        var source: String? = null
        var destination: String? = null
        var isFormatOutput: Boolean = true
        var isOmitQuotesFromNumbers: Boolean = true
        var isOmitQuotesFromBoolean: Boolean = true
        private val fields = DEFAULT
        override fun getName(): String {
            return "Json Transformation"
        }

        override fun getVariablesUsed(): Array<String> {
            var computedFields = fields;
            if(!source.isNullOrEmpty() && source != "Request" && source != "Response"){
                computedFields += " $source"
            }
            return ContextVariablesUtils.getReferencedNames(computedFields)
        }

        override fun getVariablesSet(): Array<VariableMetadata> {
            val array = arrayOf(
                    VariableMetadata("source", false, false, null, true, DataType.STRING),
                    VariableMetadata("destination", false, false, null, true, DataType.STRING),
                    VariableMetadata("formatOutput", false, false, null, true, DataType.BOOLEAN),
                    VariableMetadata("omitQuotesFromNumbers", false, false, null, true, DataType.BOOLEAN),
                    VariableMetadata("omitQuotesFromBoolean", false, false, null, true, DataType.BOOLEAN))
            if(!destination.isNullOrEmpty() && destination != "Request" && destination != "Response"){
                array.plus(VariableMetadata(destination, false, false, null, true, DataType.STRING))
            }
            return array
        }

        companion object {
            private val DEFAULT = "\${source} \${destination} " +
                    "\${formatOutput} \${omitQuotesFromNumbers} " +
                    "\${omitQuotesFromBoolean}"
        }
    }


  • 2.  Re: Set/used variables from custom assertion not refreshed by gateway

    Broadcom Employee
    Posted 12-10-2018 03:21 PM

    Good afternoon,

     

    Were you able to resolve the issue? What was the final result?

     

    Sincerely,


    Stephen Hughes
    Broadcom Support



  • 3.  Re: Set/used variables from custom assertion not refreshed by gateway

    Broadcom Employee
    Posted 11-27-2018 08:42 PM

    Hi Adrian,

     

    I think you need to implement the checkRequest method in the ServiceInvocation class which is invoked every time on the evaluation of your custom assertion.

     

    Best regards,

    Seiji



  • 4.  Re: Set/used variables from custom assertion not refreshed by gateway

    Broadcom Employee
    Posted 11-23-2018 10:26 AM

    Hi Adrian 

     

    I don;t think you can make the variables you use dynamic , i will ask around to make sure this is the case 

    and will let you know .

     

    Dirk 



  • 5.  Re: Set/used variables from custom assertion not refreshed by gateway

    Posted 11-23-2018 04:56 PM

    Hi Dirk,

     

    Thank you for answer. I know that it's possible in some way in built-in JSON transformation assertion, would be great to have some way to do it in custom assertion as well. Maybe it could be implemented in the future, if not possible right now.