Contact Free trial Login

HTTP Policy Transform Extension

In Mule 4.1.0 and later, the HTTP Policy Transform Extension is available to use in policies. This extension simplifies the modification of HTTP requests and responses that go through the different policies. This extension is valid for Mule 3.0.0 and later.

Namespace

<mule
xmlns:http-transform="http://www.mulesoft.org/schema/mule/http-policy-transform"

xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/http-policy-transform http://www.mulesoft.org/schema/mule/http-policy-transform/current/mule-http-policy-transform.xsd">

Operations

  • Add Headers Operations

    • Add Request Headers

    • Add Response Headers

  • Remove Headers

  • Set Response

  • Set Request

Add Headers Operations

This operations depends on its correlation with the Mule message:

  • Correlated—​Adds headers in requests and responses of the HTTP Listener and Requester.

  • Not correlated—​Creates a new request and response with the specified headers.

The operation and Mule message are not correlated if the specified outputType is response, but the Mule Message contains the HTTP Request. When the operation executes, it overwrites the entire value, creating a new response with the specified headers. If the Mule Message contains a HTTP response, it just adds the headers to the request.

Add Request Headers

This operation is used to inject headers in the request. To use this operation, you must initiate a call from:

  • Source Policy, before the execute-next is invoked.

  • Operation Policy, before the execute-next is invoked.

Parameters
  • headers

    A DataWeave expression that resolves to the Map of the headers to be added to present message attributes.

    Example

    <http-transform:add-request-headers outputType="response">
    <http-transform:headers>#[
    {
      'FirstHeader': 'FirstHeaderValue',
      'SecondHeader': 'SecondHeaderValue',
      'ThirdHeader': 'ThirdHeaderValue'
    }
    ]</http-transform:headers>
    </http-transform:add-request-headers>

Add Response Headers

This operation is used to inject headers in the response. To use this operation, you must initiate a call from:

  • Source Policy, after the execute-next is invoked.

  • Operation Policy, after the execute-next is invoked.

Parameters
  • headers

    A DataWeave expression that resolves to the Map of headers to be added to present message attributes.

    Example

    <http-transform:add-response-headers>
    <http-transform:headers>#[
    {
      'FirstHeader': 'FirstHeaderValue',
      'SecondHeader': 'SecondHeaderValue',
      'ThirdHeader': 'ThirdHeaderValue'
    }
    ]</http-transform:headers>
    </http-transform:add-response-headers>

Remove Headers

This operation removes the headers from both requests and responses of the the HTTP Listener and Requester. The returned attributes are of the same type as that of the input attributes. This operation is case-insensitive.

Parameters

  • header-names

    A Data-Weave expression that resolves to an array of header names to be removed.

    Example

    <http-transform:remove-headers>
        <http-transform:header-names>#[['FirstHeader', 'SecondHeader']]</http-transform:header-names>
    </http-transform:remove-headers>

Set Response

This operation sets a complete HTTP response. You use this operation when the policy prevents the flow from being executed, thereby resulting in no HTTP response being set.

Parameters

  • statusCode-- An integer representing the HTTP status code of the response.

  • reasonPhrase-- A string representing the HTTP reason phrase of the response.

  • body-- The content of the HTTP response.

  • headers-- A DataWeave expression that resolves to the map of headers of the HTTP response

    Example

    <http-transform:set-response statusCode="203" reasonPhrase="policyReasonPhrase">
        <http-transform:body>#['policyPayload']</http-transform:body>
        <http-transform:headers>#[
            {
                'FirstHeader': 'FirstHeaderValue',
                'SecondHeader': 'SecondHeaderValue',
                'ThirdHeader': 'ThirdHeaderValue'
            }
        ]</http-transform:headers>
    </http-transform:set-response>

Set Request

This operation sets a complete HTTP request that the HTTP Requester executes.

Parameters

  • requestPath: The path where the HTTP Request is being sent.

  • body: The content of the HTTP Request.

  • headers: A DataWeave expression that resolves to the map of headers of the HTTP request.

  • uriParams: A DataWeave expression that resolves to the map of URI params of the HTTP request.

  • queryParams: A DataWeave expression that resolves to the map of query params of the HTTP request.

    Example

    <http-transform:set-requester-request requestPath="/backend/policy/{policyUriParam}">
        <http-transform:body>#['policyPayload']</http-transform:body>
        <http-transform:headers>#[
            {
                'FirstHeader': 'FirstHeaderValue',
                'SecondHeader': 'SecondHeaderValue',
                'ThirdHeader': 'ThirdHeaderValue'
            }
        ]</http-transform:headers>
        <http-transform:uri-params>#[
            {
                'FirstUriParam': 'FirstUriParamValue',
                'SecondUriParam': 'SecondUriParamValue'
            }
        ]</http-transform:uri-params>
        <http-transform:query-params>#[
            {
                'FirstQueryParam': 'FirstQueryParamValue',
                'SecondQueryParam': 'SecondQueryParamValue'
            }
        ]</http-transform:query-params>
    </http-transform:set-requester-request>

Upgrading to Mule 3.0.0 and above

If you are upgrading from previous Mule versions, for example 1.0.0 and 2.0.0, to 3.0.0, you must add the following instructions.

When a policy using the HTTP Policy Transform Extension is packaged, the Mule HTTP Connector is unnecessarily added to the policy JAR file.

To avoid this issue, add the corresponding exclusion in the extension’s dependency declaration of the policy’s POM file:

  <dependency>
      <groupId>com.mulesoft.anypoint</groupId>
      <artifactId>mule-http-policy-transform-extension</artifactId>
      <version>${httpPolicyTransformVersion}</version>
      <classifier>mule-plugin</classifier>
      <exclusions>
          <exclusion>
              <groupId>org.mule.connectors</groupId>
              <artifactId>mule-http-connector</artifactId>
          </exclusion>
      </exclusions>
  </dependency>

We use cookies to make interactions with our websites and services easy and meaningful, to better understand how they are used and to tailor advertising. You can read more and make your cookie choices here. By continuing to use this site you are giving us your consent to do this.