Moon Mysterious
Moon Mysterious

Reputation: 174

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

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?

Upvotes: 1

Views: 1269

Answers (1)

Rajkumar Rajaratnam
Rajkumar Rajaratnam

Reputation: 925

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

Upvotes: 1

Related Questions