Rules as Pre and Post Processors

Quantum Fabric provides the ability to write custom code as pre and post processors to modify request and response parameters to service calls. Historically custom code can be implemented either in Java or JavaScript. To simplify implementing custom logic in pre and post processors, a new Rules option is introduced from Quantum Fabric V8 SP4. You can use the Rules option to define your custom logic as a set of rules. This option makes defining pre and post processor custom logic closer to human language and is built using MVEL.

NOTE: The Rules functionality is supported only for the pre and post processor of integration services.

  • Why Use Rules:
    • Quick and easy to write custom logic.
    • Easy to understand and change as per your business logic.
    • No maintenance overhead. For example, No need to maintain separate jars or library and export them to various environments while publishing the updated app.
  • What is the Structure of rules: Rules have a structure in the form of statements, as shown in the following table:
    Sample Rules Structure
    name: "<Name of the rule>"
    description: "<Description of the rule>"
    priority: <Priority of the rule>
    condition: "<Condition to evaluate>"
    actions:
       - "<Set of actions to execute>"
    Description of Rules Structure
    • Name: A unique name of the rule. This is a mandatory field.
    • Description: A description for the rule.
    • Priority: An integer value that represents the order to execute the rule. The bigger the value, the higher the priority.
    • Condition: An expression that is evaluated by the Rules engine. When the condition evaluates to True, the engine executes a set of actions. This is a mandatory field.
      For example, response != null can be used to check whether the back-end response is empty.
    • Action: A set of statements that are executed when the condition evaluates to True. This is a mandatory field.
      For example, statusCode = 200 sets status code to 200.
  • How to Write rules:
    1. When you are configuring an operation, in the Advanced > Custom Code Invocation for pre-processor or post-processor, click the Rules option.

Built-in Objects

The following objects help you to write rules in Quantum Fabric.

Objects Description
"configurationParameters"

Used to access the Server and Client App parameters that are set by the developer in the App Services console. This is equivalent to using ConfigurableParameters in Java.

"continueExecution"

Used in the Pre-processor to terminate back-end calls.

Set the value to false if you want to terminate the back-end call. By default, the value is set to true.

"customMetrics"

This is used to access custom metrics.

For more details to create custom reports and Metrics, refer Custom Reporting – Metrics, Reports, and Dashboard Guide

“deviceHeadersMap”

Used to set headers that are passed to the client and is equivalent to using setDeviceHeaders in Java.

"headerMap"

Used to access the header map of a request. A client can directly access the header map or the individual key-value pairs of the header map.

“identityHandler"

Used to access the identity attributes when a service is protected by an identity service.

"inputMap"

Used to access the input map of a request. A client can directly access the input map or the individual key-value pairs of the input map.

"logger" Used to add a log statement with the appropriate level.
"response"

Used to modify the response body and is equivalent to using setResponse in Java.

"results"

Used to modify the results. A Result is an abstraction of a back-end response. The Result is a collection of Params, Data-sets, and Records. For more details, refer Result.

"resultCache"

Used to access the cache in pre-processor and post-processor. This is equivalent to using ResultCache in Java.

"servicesManager"

Used to invoke an integration service with the specified service id, operation id and version.

"session"

Used to modify the session that is associated with the request.

For more details, refer Session

A client can access values from the session and the individual attributes of the session.

“statusCode” Used to set the status code of the response and is equivalent to using setStatusCode in Java.
"ua"

Used to access the User Agent Header of the request.

Built-in Functions

The following functions help you to write rules in Quantum Fabric.

Functions Description
"Check.isWithin"

Checks if an element is in a specified range. It will return true if the element present in the specified range, otherwise false.

  • Signature: isWithin(double fromInclusive, double toInclusive, double elementToFind)
  • Example
    Check.isWithin(100, 300, 250) = true
    Check.isWithin(100, 300, 350) = false
"Check.isEmpty"

Checks if a CharSequence is empty ("") or null.

  • Signature: isEmpty(final CharSequence cs)
  • Example
    Check.isEmpty(null)      = true
    Check.isEmpty("") = true Check.isEmpty(" ") = false Check.isEmpty("xyz") = false Check.isEmpty(" abc ") = false
"Check.isNotEmpty"

Checks if a CharSequence is not empty ("") and not null.

  • Signature: isNotEmpty(final CharSequence cs)
  • Example
    Check.isNotEmpty(null)      = false
    Check.isNotEmpty("") = false Check.isNotEmpty(" ") = true Check.isNotEmpty("xyz") = true Check.isNotEmpty(" abc ") = true
"Check.isBlank"

Checks if a CharSequence is empty (""), null or white-space only.

  • Signature: isBlank(final CharSequence cs)
  • Example
    Check.isBlank(null)      = true
    Check.isBlank("")        = true
    Check.isBlank(" ")       = true
    Check.isBlank("xyz")     = false
    Check.isBlank("  abc  ") = false
    
"Check.isNotBlank"

Checks if a CharSequence is not empty (""), not null and not white-space only.

  • Signature: isNotBlank(final CharSequence cs)
  • Example
    Check.isNotBlank(null)      = false
    Check.isNotBlank("")        = false
    Check.isNotBlank(" ")       = false
    Check.isNotBlank("xyz")     = true
    Check.isNotBlank("  abc  ") = true
    
"Check.isEqualTo"

Compares two CharSequences, returning true if they represent equal sequences of characters.

  • Signature: isEqualTo(final CharSequence cs1, final CharSequence cs2)
  • Example
    Check.isEqualTo(null, null)   = true
    Check.isEqualTo(null, "abc")  = false
    Check.isEqualTo("abc", null)  = false
    Check.isEqualTo("abc", "abc") = true
    Check.isEqualTo("abc", "ABC") = false
    
"Check.isEqualToIgnoringCase"

Compares two CharSequences, returning true if they represent equal sequences of characters, ignoring case.

  • Signature: isEqualToIgnoringCase(final CharSequence str1, final CharSequence str2)
  • Example
    Check.isEqualToIgnoringCase(null, null)   = true
    Check.isEqualToIgnoringCase(null, "abc")  = false
    Check.isEqualToIgnoringCase("abc", null)  = false
    Check.isEqualToIgnoringCase("abc", "abc") = true
    Check.isEqualToIgnoringCase("abc", "ABC") = true
    

Sample Rules