Export Variables from Fragment Assertion

The Export Variable from Fragment assertion is used to flag context variables created within a policy fragment as being "in use". This will make the variables available to whichever policy includes the fragment. For example, if XPath-based assertions (Evaluate Request XPath or Evaluate Response XPath) are used in a fragment and the XPath context variables are referenced in the including policy, the Export Variables from Fragment assertion ensures that the variables are created and made available.
gateway90
The Export Variable from Fragment assertion is used to flag context variables created within a policy fragment as being "in use". This will make the variables available to whichever policy includes the fragment. For example, if XPath-based assertions (Evaluate Request XPath or Evaluate Response XPath) are used in a fragment and the XPath context variables are referenced in the including policy, the Export Variables from Fragment assertion ensures that the variables are created and made available.
Why do the context variables need to be "made available"?
For maximum performance, the
API Gateway
creates custom context variables only when it detects that the variables will be used by another assertion. In a policy fragment, it is not possible to determine ahead of time whether the variables within the fragment will be used in a policy that includes the fragment, so they are not created. The Export Variables from Fragment assertion allows you to flag specific variables as being "in use".
Add this assertion to a policy fragment, after the assertion that creates the context variables.
The Export Variable from Fragment assertion is only used in a policy fragment and only when an XPath-based assertion is also present. It provides no additional functionality if used outside of a fragment because XPath context variables are available automatically in that scenario.
When Used in a Global Policy Fragment
When the Export Variables from Fragment assertion is used in a global policy fragment, it will automatically copy the values of the designated variable(s) up to the parent policy, prefixed with "request.shared". This will make it easier to use the values in (for example) the audit sink policy.
Using the following example, the values from the two selected variables would be copied over to these new context variables if this assertion was used in a global policy fragment:
${request.shared.requestXpath.element}
${request.shared.requestXpath.result}
Example: Accessing variables from global policy fragment in audit sink policy
The following example illustrates how to access the "message-received" variable from the audit sink policy:
  1. Create a "message-received" global policy fragment containing these assertions:
    Audit Messages in Policy
    (WARNING)
    Set Context Variable
    varMessageReceived as String to: Hello from message-received global policy
    Export Variables from Fragment: varMessageReceived
  2. Create a custom audit sink policy with this assertion:
    Add Audit Details: log, custom logger "audit": "varMessageReceived=${request.shared.varMessageReceived}"
  3. Consume any service.
  4. The
    API Gateway
    log will contain this line:
    varMessageReceived=Hello from message-received global policy
Using the Assertion
  1. Do one of the following:
    • To add the assertion, create a policy fragment or edit an existing policy fragment and then add the assertion to the policy development window.
    • To change the configuration of an existing assertion, proceed to step 2 below.
  2. Right-click
    Export Variables from Fragment
    in the policy window and select
    Export Variables from Fragment Properties
    . The assertion properties are displayed. 
  3. Select each variable to be made available to policies outside of the fragment.
  4. For more information about the variables, see Evaluate Request XPath Assertion or Evaluate Response XPath Assertion.
    If the variable prefix is modified in the XPath assertions, the new names are reflected in the properties. However, variables that were previously selected will still appear under the old variable names. This will cause validation warnings about variables not being defined. Should this happen, return to the Export Variables from Fragment Properties and re-select the correct updated variables.
  5. Click [
    OK
    ] when done.