简体   繁体   English

如何从WSO2 ESB Synapse处理程序内的REST请求的JSON正文中提取数据

[英]Howto extract data from the JSON body of REST request inside a WSO2 ESB Synapse handler

I'm writing a custom Handler for WSO2 ESB to construct authentication credentials based on input request content. 我正在为WSO2 ESB编写自定义处理程序,以根据输入请求内容构造身份验证凭据。 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;
}

I can't find documentation regarding howto access REST JSON request body inside the Synapse handler. 我找不到有关如何访问Synapse处理程序中的REST JSON请求主体的文档。 Any ideas? 有任何想法吗? Is possible to define a property before the handler runs and capture it with something like String clientId = (String)context.getProperty("clientId") ? 可以在处理程序运行之前定义一个属性,并使用String clientId = (String)context.getProperty("clientId")类的内容来捕获它吗?

You can try following; 您可以尝试跟随;

// Getting the json payload to string
String jsonPayloadToString = JsonUtil.jsonPayloadToString(((Axis2MessageContext) context).getAxis2MessageContext());
// Make a json object
JSONObject jsonBody = new JSONObject(jsonPayloadToString);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM