[英]How to get Request payload content at Response path class mediator using OMElement - WSO2 APIM ver 3.2.0
I am using WSO2 APIM version 3.2.0.我正在使用 WSO2 APIM 版本 3.2.0。
I have a POST request with the request payload.我有一个带有请求负载的 POST 请求。 In the response message mediation of WSO2 APIM I have added the policy that contains the class mediator that tries to get the payload sent during the request.在 WSO2 APIM 的响应消息中介中,我添加了包含类中介的策略,该中介试图获取在请求期间发送的有效负载。
OMElement element = (OMElement) mc.getEnvelope().getBody().getFirstOMChild(); OMElement 元素 = (OMElement) mc.getEnvelope().getBody().getFirstOMChild(); log.info("payload: " + element.toString()); log.info("payload:" + element.toString());
The above code snippet prints the response payload content but I need the request payload content at the response path.上面的代码片段打印了响应负载内容,但我需要响应路径中的请求负载内容。
Response message mediation with a policy added添加了策略的响应消息中介
Below is the sequence with class mediator下面是带有类中介器的序列
sequence with class mediator带有类中介器的序列
Code snippet inside class mediator类中介器中的代码片段
OMElement element = (OMElement) mc.getEnvelope().getBody().getFirstOMChild(); OMElement 元素 = (OMElement) mc.getEnvelope().getBody().getFirstOMChild(); log.info("payload: " + element.toString()); log.info("payload:" + element.toString());
Pls let me know what changes to be done, to get the request payload content.请让我知道要进行哪些更改,以获取请求有效负载内容。
First, we have to store the request payload in a custom property in the Message Context.首先,我们必须将请求负载存储在消息上下文的自定义属性中。 Then, we can use that property to retrieve the Request Payload in the Response path of the execution.然后,我们可以使用该属性在执行的响应路径中检索请求有效负载。
For example: You are invoking an API with JSON Payload.例如:您正在使用 JSON Payload 调用 API。 So, we have to first capture the sent payload and store it in a custom property in the Message Context.因此,我们必须首先捕获发送的有效负载并将其存储在消息上下文中的自定义属性中。 Given below is a sample sequence to perform the same下面给出的是执行相同操作的示例序列
<?xml version="1.0" encoding="UTF-8"?>
<sequence xmlns="http://ws.apache.org/ns/synapse" name="admin--MockAPI:v1.0.0--In">
<property name="RequestPayload" expression="json-eval($)" />
<log level="custom">
<property name="RequestPayload" expression="$ctx:RequestPayload" />
</log>
</sequence>
Then, in the Response path, inside your custom class mediator, you have to access the RequestPayload
property from the MessageContext
to extract the stored payload.然后,在 Response 路径中,在您的自定义类介体中,您必须从MessageContext
访问RequestPayload
属性以提取存储的有效负载。 You can achieve this by using the following snippet您可以使用以下代码段来实现此目的
synapseContext.getProperty("RequestPayload");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.