Contact Us 1-800-596-4880

DataWeave Request Filter Policy

Policy name

DataWeave Request Filter

Summary

Filters requests by using a DataWeave script

Category

Transformation

First Omni Gateway version available

1.12

Release Notes

DataWeave Request Filter

Returned Status Codes

400 - The DataWeave script failed to execute or returned an invalid result

Summary

The DataWeave Request Filter policy evaluates a DataWeave script on the request, including headers and the body, to allow or block the message. The script returns an object with a Boolean success value. If success is false, the script can return a response object with statusCode, body, and headers. The gateway sends that as the immediate HTTP response to the client and stops processing. If success is true, the message continues.

Result format:

  • Success: { "success": true }

  • Error: { "success": false, "response": { "body": "…​", "headers": {}, "statusCode": 400 } }

Payload Handling

The DataWeave Request Filter policy processes only requests. Responses pass through unchanged.

How the policy handles the request body depends on requiresPayload:

  • false (the default): The policy reads headers only and doesn’t buffer the body.

  • true: The policy buffers the full request body so that the script can read payload. If the request has no body, the policy returns a 400 error.

Buffered payloads count toward the Omni Gateway payload limit, which is 1 MB by default. To change the limit on a self-managed Omni Gateway, set the FLEX_DOWNSTREAM_CONNECTION_BUFFER_LIMIT_BYTES environment variable. In Connected Mode, you can also set Global connection buffer limit in Runtime Manager. For more information, see Configure Global and Routing Settings in Runtime Manager. For more information about the limit, see Omni Gateway Limits and Performance Metrics.

To avoid buffering, keep requiresPayload set to false and write the script to use only the request headers.

Configure Policy Parameters

Omni Gateway Local Mode

- policyRef:
    name: dataweave-request-filter-flex
  config:
    script: <string>           // REQUIRED - DataWeave script
    requiresPayload: <boolean> // OPTIONAL, default: false
Parameter Required Default Value Description

script

Required

—

A DataWeave script that returns an object with a boolean success field. If success is false, the optional response is: { "body": string, "headers": object, "statusCode": number }.

requiresPayload

Optional

false

If true, the script receives the message body in the payload binding. If true and the body is missing, the gateway returns an error.

Resource Configuration Example

  policies:
    - policyRef:
        name: dataweave-request-filter-flex
      config:
        script: |
          %dw 2.0
          output application/java
          ---
          if (attributes.headers["x-api-key"] != null) { success: true }
          else { success: false, response: { statusCode: 401, body: "Missing API key", headers: {} } }
        requiresPayload: false

Managed Omni Gateway and Omni Gateway Connected Mode

When you apply the policy from the UI, the following parameters are displayed:

Parameter Description

Policy type

DataWeave Request Filter

Script

The DataWeave script that returns a success or error result

Requires payload

Whether the script requires the message body