2017-02-03 23 views
0

我寫了一個定製的Axis模塊來嗅探我的WSO2 ESB中的所有通信。我有它的所有階段註冊 - 一切都按預期工作,當涉及到SOAP通信。WSO2 ESB定製軸模塊​​JSON消息在MessageContext

但是,我無法檢索在WSO2 ESB中定義和調用的REST API的JSON負載。 MessageContext.getEnvelope返回一個空的正文,即使我可以看到在我的REST客戶端中返回的JSON負載。

基本上我的代碼如下所示:

public InvocationResponse invoke(MessageContext msgContext) throws AxisFault { 
      String logId = msgContext.getLogCorrelationID(); 
      long currentTimestamp = System.currentTimeMillis(); 

      logEntry.setId(logId); 

      if(msgContext.isDoingREST()) { 
       logEntry.setFormat(ILogEntry.FORMAT_REST); 
       logEntry.setPayload(String.valueOf(msgContext.getEnvelope())); 
      } else if(msgContext.isDoingMTOM()) { 
       logEntry.setFormat(ILogEntry.FORMAT_MTOM); 
      } else if(msgContext.isDoingSwA()) { 
       logEntry.setFormat(ILogEntry.FORMAT_SWA); 
      } else { 
       logEntry.setFormat(ILogEntry.FORMAT_SOAP); 
       JSONObject json = XML.toJSONObject(String.valueOf(msgContext.getEnvelope())); 
       logEntry.setPayload(String.valueOf(json)); 
      } 
    } 

距離org.apache.axis2.context.MessageContext的JSON有效載荷以不同的方式比SOAP管理?

我該如何檢索它?

彼得

回答

0

看起來像你面臨的問題與此處所述的相同。

Will JSON based REST - ESB - REST communication build AXIS 2 XML MessageContext

+0

嗨 - 感謝您的回覆。在發佈這個問題之前,我確實考慮過了。嘗試解析getProperty(「JSON_STREAM」)時,我得到NULL。我也遇到了一個提到「JSON_STRING」作爲屬性來看,但這並沒有這樣做......( –

+0

也許下面的幫助,但我不知道。/ /獲得json有效載荷字符串 String jsonPayloadToString =(JsonUtil.jsonPayloadToString(((Axis2MessageContext)context).getAxis2MessageContext()); //創建一個json對象 JSONObject jsonBody = new JSONObject(jsonPayloadToString); –