如何从 WSO2 APIM 1.9 中的自定义处理程序访问响应负载内容 [英] How to access response payload content from custom handler in WSO2 APIM 1.9

查看:23
本文介绍了如何从 WSO2 APIM 1.9 中的自定义处理程序访问响应负载内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从 WSO2 APIM 中的自定义处理程序访问响应负载内容?我试着从 org.apache.synapse.MessageContext 或从 org.apache.synapse.core.axis2.Axis2MessageContext 得到这个;但我无法获得响应负载.任何人都可以帮忙吗?

How to access response payload content from custom handler in WSO2 APIM? I tried get this from org.apache.synapse.MessageContext or from org.apache.synapse.core.axis2.Axis2MessageContext; but I am not able get the response payload. Can anyone please help?

推荐答案

在读取有效负载之前,您需要在处理程序中构建消息,如下所示.

You need to build the message inside you handler before reading the payload, as shown below.

    public boolean handleResponse(MessageContext messageContext) {
        try {
            RelayUtils.buildMessage(((Axis2MessageContext) messageContext).getAxis2MessageContext());
        } catch (IOException e) {
            e.printStackTrace();
        } catch (XMLStreamException e) {
            e.printStackTrace();
        }

        // read the body
        log.info(messageContext.getEnvelope().getBody());
        return true;
    }

请参阅 [1] 以获取完整示例,以在 API Manager 1.8.0 的处理程序中构建消息.您需要在 pom.xml 中为 API Manager 1.9.0 放置正确的依赖项(将 synapse-core 和 synapse-nhttp-transport 版本都更新为 2.1.2-wso2v7)

Refer [1] for a complete sample to build the message inside handler for API Manager 1.8.0. You need to put the correct dependencies in pom.xml for API Manager 1.9.0 (update both synapse-core & synapse-nhttp-transport version to 2.1.2-wso2v7)

[1] https://github.com/R-Rajkumar/samples/tree/master/message-builder-handler

这篇关于如何从 WSO2 APIM 1.9 中的自定义处理程序访问响应负载内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆