Messaging
Use the Messaging policy to trigger a messaging extension based on the specified conditions to enable request and response transformations.
In IBM API Studio, this policy
is identified by the kind InvokeMessagingExtension.
Example of a Messaging policy in code view.
kind: InvokeMessagingExtension
apiVersion: api.ibm.com/v1
metadata:
name: messaging-extension
version: 1
namespace: sample
tags:
- invoke
- messaging
- extension
- policy
spec:
condition: (${request.httpMethod} equals POST) or (${request.headers.name} notEquals ${request.payload.jsonPath[$.customer.name]})
# other operators include Equals, Equals ignore case, Not equals, Not equals ignore case, Contains, Not Contains, Exists, Not Exists, IP Range, Greater Than, Lesser Than
messageConfig:
$ref: sample:MessageConfig:1.0 # refer 28-message-config.yml
request_processing:
transformations:
set:
- key: ${request.headers.h2}
value: test4
- key: ${request.query.q2}
value: ${request.payload.jsonPath[$.customer.name]}
setPayload:
content-types:
- application/json: |
{"empid" : "1"}
- application/xml: |
<a>a<a>
- text/plain: |
sample text
default-ContentType: application/json
xsl:
- feature:
- name: http://javax.xml.XMLConstants/feature/secure-processing
value: true
$path: ./a/a.xsl
content: sdsd
remove:
response_processing:
transformations:
set:
- key: ${request.headers.h2}
value: test4
- key: ${request.query.q2}
value: ${request.payload.jsonPath[$.customer.name]}
copyEntireResponse: true
abortAPIExecutionForFailure: true
namespaces:
- prefix: ps1
URI: http://test.com
- prefix: ps2
URI: http://test2.com
| Code view | Form view | Description |
|---|---|---|
condition |
Conditions |
Conditions are used to specify when the policy is run. You can add multiple conditions with logical operators. Provide the condition in the format: {set} operator {value} condition {set} operator {value} You can configure the following conditions in the Conditions section:
You can use the following operators in the code view and in the form view by using the Add condition button, which is optional.
|
messageConfig |
Messaging |
Configures the messaging system details such as connection, destination, and message format. In
the form view, click Create new message config and define these message configurations:
|
request_processing |
Request transformation |
Specifies the request processing parameters. You can configure the following
|
response_processing |
Response transformation |
Specifies the response processing parameters.
|
namespaces |
Namespace |
Configure the metadata for the message configuration request. In the code view, under In the form view, use the Custom metadata extension tab to configure the metadata. Click the Add namespace button and specify the optional Namespace prefix and Namespace URL fields. |