如何从WSO2 ESB Synapse处理程序中的REST请求的JSON正文中提取数据 [英] Howto extract data from the JSON body of REST request inside a WSO2 ESB Synapse handler
本文介绍了如何从WSO2 ESB Synapse处理程序中的REST请求的JSON正文中提取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在为WSO2 ESB编写一个自定义处理程序,以根据输入请求内容构造身份验证凭据.现在我所拥有的是这样的:
I'm writing a custom Handler for WSO2 ESB to construct authentication credentials based on input request content. Right now what I have is something like this:
public boolean handleRequest(MessageContext context) {
// TODO: extract relevant information (clientId) from JSON request body
String clientId;
Map<String, String> headers = (Map<String, String>) ((Axis2MessageContext) context).getAxis2MessageContext().getProperty(
org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS);
setAuthorization(headers, clientId);
return true;
}
我找不到有关如何访问Synapse处理程序中的REST JSON请求正文的文档.有任何想法吗?是否可以在处理程序运行之前定义属性,并使用类似String clientId = (String)context.getProperty("clientId")
的方法捕获它?
I can't find documentation regarding howto access REST JSON request body inside the Synapse handler. Any ideas? Is possible to define a property before the handler runs and capture it with something like String clientId = (String)context.getProperty("clientId")
?
推荐答案
您可以尝试关注;
// Getting the json payload to string
String jsonPayloadToString = JsonUtil.jsonPayloadToString(((Axis2MessageContext) context).getAxis2MessageContext());
// Make a json object
JSONObject jsonBody = new JSONObject(jsonPayloadToString);
这篇关于如何从WSO2 ESB Synapse处理程序中的REST请求的JSON正文中提取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文