Set Context Variable Assertion

The Set Context Variable assertion allows you to create custom context variables. These custom variables behave the same as the system predefined ones, except that you can control the contents of the variables. You can even define complete messages with a custom context variable. These messages can be used later in the policy by the  as the request message source, and by the  as the XML message source.
The Set Context Variable assertion allows you to create custom context variables. These custom variables behave the same as the system predefined ones, except that you can control the contents of the variables. You can even define complete messages with a custom context variable. These messages can be used later in the policy by the Route via HTTP(S) Assertion as the request message source, and by the Evaluate Response XPath Assertion as the XML message source.
 The Set Context Variable assertion can be used to map one of the predefined context variables to a different name. This is necessary in instances where the predefined context variable name is incompatible with a specific subsystem.
Using the Assertion
  1. Do one of the following:
    • To add the assertion to the Policy Development window, see Add an Assertion.
    • To change the configuration of an existing assertion, proceed to step 2 below.
  2. When adding the assertion, the 
    Context Variable Properties
     automatically appear; when modifying the assertion, right-click 
    Set Context Variable
     in the policy window and select 
    Context Variable Properties
     or double-click the assertion in the policy window. The assertion properties are displayed.
  3. Configure the properties as follows:
    Variable Name
    Enter a name for the context variable. This name can include letters or number, but do not include the ${ } delimiter characters. For example, use  "gatewayTime" and not "${gatewayTime}".
    You can also enter a request or response to set the request message or response message, respectively. A validation message provides instant feedback on the context variable name entered. For an explanation of the validation messages , see "Context Variable Validation" under Context Variables.
    Data Type
    If the variable name is not built-in, specify the data type from the drop-down list:
      : The variable will contain a string of characters.
      : The variable will contain integers.
      : The variable will contain a message. Enter the message body into the Expression box below. Message type variables can be used for later routing or XPath assertions.
      : The variable will contain date/time information. For more information, see "Context Variable Data Types" under Context Variables.
     Creating a new variable of type "Date/Time" and accepting the defaults in all the other fields produce a variable that is identical to the built-in variable ${gateway.time}. The default value is an UTC formatted ISO-8601 string of 
    . For more information,
    see Date and Time Variables.
    Select "Message" if setting a request or response variable.
    (Date/Time only)
    Choose a format from the drop-down list. The assertion uses this format to interpret the value in the Expression field. The default is "<
    o>", which means the assertion tries to determine the format automatically. You may reference a context variable, which is evaluated as part of an expression and must resolve to a single format string.
     The formats 
    <Millisecond Timestamp>
     (13 digits), and 
    <Second Timestamp>
     (10 digits) can be used for finer control in parsing the Expression field:  
    • A timestamp entered in the Expression field successfully matches the formats: <auto> and <Timestamp> and <Millisecond Timestamp> if it is a millisecond timestamp and <Second Timestamp> if it is a seconds timestamp.
    • A timestamp in milliseconds entered successfully matches the formats: <auto>, <Timestamp>, and <Milliseconds Timestamp>
    • A timestamp in seconds entered successfully matches the formats: <auto>, <Timestamp>, and <Seconds Timestamp>
     You can customize the options shown in the drop-down list by editing the cluster property 
    . You can customize the formats attempted by the "<
    >" selection by editing the cluster property 
    Time Offset 
    (Date/Time only)
    Enter a time offset. The value can be negative or positive and can reference variables. The unit of time applied is determined by the drop-down beside the field.
    : seconds
    Choose the offset unit from the drop-down list if necessary.
    You may reference context variables.
    (Date/Time only)
    Displays a preview of the date format based on date expression entered. The preview includes any time offset entered, except when a context variable has been specified.  
    The preview of the parsed date expression can be used to troubleshoot formats based on sample inputs.
     (1) The format used for the preview is ISO 8601, in the W3C format yyyy-MM-dd'T'HH:mm:ss.SSS'Z'. The date format is shown in GMT. (2) A preview is displayed only when it is possible to parse the format entered. If a preview is not possible, "No preview is available" is displayed.
    (Message only)
    If the Data Type is "Message", select a Content-Type from the drop-down list for the message. The character set (charset) from the Content-Type is used for message encoding.
     The Content-Types list contains the character encodings that are compatible with the default XML encoding, but you can manually type in another compatible encoding (no context variables). For example, the utf-8 charset is shown by default, but you can enter other charsets such as 'sjis' or 'euc' as necessary.
    Enter the string value or message body here, or leave empty. You can use existing context variables within the expression by enclosing them within the standard "${ }" variable reference syntax. For example: "${gateway.time}".
    The expression for variables of type Message can be a simple text document, an XML document, a MIME multi-part document, or other valid textual data for the content type entered. For example, the expression can be a SOAP request message. You can modify the Route via HTTP(S) Assertion to use this expression referencing its variable as the "request message source", rather than using the default request.  
     For variables of type Message, you can specify a single context variable, in the form 
    , to initialize the target variable with the content of the specified message or part. This applies even if the message or part being copied is not text (for example, images or random binary files).
    Syntax Highlighting
    The Expression box displays syntax highlighting for Message variables of Content -Type "text/xml" or "application/json". This helps you identify errors more easily.
    XML Highlighting
    • non-XML values are not highlighted
    • for invalid XML values, only the correctly formatted XML elements are highlighted
    • for valid XML elements, the opening and closing tags are highlighted
     Closing tag for an XML element are auto-completed for your convenience. For example, typing "<xml> test </" results in the closing tag "</xml>" being auto completed
    JSON Highlighting
    • non-JSON values are not highlighted
    • characters that surround JSON elements (whether valid or invalid) are highlighted
    • placing the cursor after one of the JSON characters highlights its paired character
  4. Click [
    ] when done. The new variable name is available to subsequent assertions in the policy. The [
     button is unavailable if there are errors identified by any of the instant validators.