Skip to content

Latest commit

 

History

History
90 lines (61 loc) · 4.13 KB

File metadata and controls

90 lines (61 loc) · 4.13 KB
description
This page provides the technical details of the Assign Content policy

Assign Content

Overview

You can use the assign-content policy to change or transform the content of the request body or response body.

This policy is compatible with the Freemarker template engine, which allows you to apply complex transformations, such as transforming from XML to JSON and vice versa.

By default, you can access multiple objects from the template context: request and response bodies, dictionaries, context attributes and more.

Functional and implementation information for the assign-content policy is organized into the following sections:

Examples

{% hint style="warning" %} This policy can be applied to all Gravitee APIs: v2 APIs, v4 proxy APIs, and v4 message APIs. {% endhint %}

{% tabs %} {% tab title="Proxy API example" %} You could use the Assign Content policy to inject a dictionary value and application into the request payload:

{
  "example": "${context.dictionaries['my-dictionary']['my-value']}",
  "application": "${context.attributes['application']}"
}

{% endtab %}

{% tab title="Message API example" %} You could use the Assign Content policy to inject a dictionary value and metadata into the message:

{
  "example": "${message.dictionaries['my-dictionary']['my-value']}",
  "metadata": "${message.attributes['metadata']}"
}

{% endtab %} {% endtabs %}

Configuration

Sample policy configuration:

{% code title="Sample Configuration" %}

"policy-assign-content": {
    "scope":"REQUEST",
    "body":"Put your content here"
}

{% endcode %}

Phases

The phases checked below are supported by the assign-content policy:

v2 PhasesCompatible?v4 PhasesCompatible?
onRequestfalseonRequestfalse
onResponsefalseonResponsefalse
onRequestContenttrueonMessageRequesttrue
onResponseContenttrueonMessageResponsetrue

Options

You can configure the assign-content policy with the following options:

PropertyRequiredDescriptionTypeDefault
scopetrueThe execution scope of the policyscopeREQUEST
bodytrueThe data to push as request or response body contentstring-

Compatibility matrix

The following is the compatibility matrix for APIM and the assign-content policy:

Plugin VersionSupported APIM versions
Up to 1.6.xUp to 3.9.x
1.7.x3.10.x to 3.20.x
2.x4.0+

Errors

PhaseHTTP status codeError template key
onRequestContent500The body content cannot be transformed.
onResponseContent500The body content cannot be transformed.
onMessageRequest400The body content cannot be transformed.
onMessageResponse500The body content cannot be transformed.

Changelogs

{% @github-files/github-code-block url="https://github.com/gravitee-io/gravitee-policy-assign-content/blob/master/CHANGELOG.md" %}