简体   繁体   English

如何使用 OMElement - WSO2 APIM ver 3.2.0 在响应路径类调解器处获取请求有效负载内容

[英]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.

相关问题 在 WSO2 APIM 3.2.0 中修改/删除 wso2 类中介或 xml 序列中的请求有效负载内容 - Modify/Remove request payload content in wso2 class mediator or xml sequence in WSO2 APIM 3.2.0 无法在 class mediator 和 xml wso2 apim 3.2.0 中设置自定义响应码 - Unable to set the custom response code in class mediator and xml wso2 apim 3.2.0 在 wso2 apim 4.1.0 中提取请求响应中介的信息 - Extract information of request in response mediator in wso2 apim 4.1.0 如何从WSO2 APIM 1.9中的自定义处理程序访问响应有效内容 - How to access response payload content from custom handler in WSO2 APIM 1.9 WSO2 EI,如何从自定义 Class 调解器获取有效负载作为字符串 - WSO2 EI, How to get payload as String from Custom Class mediator 如何在 WSO2 APIM 中的“脚本中介”javascript 语言中发送 http 请求? - How to send http request in "script mediator" javascript language in WSO2 APIM? 如何更改 WSO2 3.2.0 APIM 的默认端口? - How to change the default ports of WSO2 3.2.0 APIM? 如何在 WSO2 3.2.0 APIM 中启用隐式授权? - How can I enable Implicit Grant in WSO2 3.2.0 APIM? 如何将XML模拟的有效负载放入由WSO2 ESB发送介体发送的POST请求有效负载中? - How can I put an XML mocked payload into a POST request payload sended by a WSO2 ESB send mediator? WSO2 APIM 3.2.0 管理门户无法访问 - WSO2 APIM 3.2.0 Admin Portal not accessible
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM