问题
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