How to access response payload content from custom handler in WSO2 APIM 1.9

倖福魔咒の 提交于 2019-12-23 03:12:44

问题


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?


回答1:


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;
    }

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



来源:https://stackoverflow.com/questions/31697415/how-to-access-response-payload-content-from-custom-handler-in-wso2-apim-1-9

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!