2016-07-19 58 views
3

我有一個代理服務來搜索多個系統用戶,應該返回JSON format.I結合反應得到的答覆合併而是獲得它以JSON格式我收到了XML格式的回覆。 我可以看到在WSO2服務器日誌JSON迴應如下:無法獲得響應JSON格式彙總後WSO2 ESB

[2016-07-19 07:26:58,249] INFO - LogMediator To: http://www.w3.org/2005/08/addr 
essing/anonymous, WSAction: , SOAPAction: , MessageID: urn:uuid:895c4303-6de5-49 
88-a4d1-c06275582841, Direction: response, Component = Application2, Payload: { 
"findUsers":[ 
{"id":"20","add_state":"0","remove_state":"0","supervisor_id_name":"","idc_id":" 
3","backup_supervisor_name":"","backup_supervisor":"","business_unit_id":"","com 
pany":"companyb","creation_date":"2016-05-11 18:02:42.0","deletion_date":"","dep 
artment":"922","display_name":"Kevin Mollo (companyb)","email_address":"Kevin.Mo 
[email protected]","exception_count":"","first_name":"Kevin","is_terminated":"Fal 
se","job_status":"Active","last_name":"Mollo","legacy_employee_id":"171352","sup 
ervisor_id":"","termination_date":"","title":"Broadband Technician","unique_id": 
"9000070","user_id":"user71","violation_count":""} 
] 
} 
[2016-07-19 07:26:58,888] INFO - LogMediator To: http://www.w3.org/2005/08/addr 
essing/anonymous, WSAction: , SOAPAction: , MessageID: urn:uuid:0cee9dc3-b6e6-48 
81-9bdd-a89ec22999a7, Direction: response, Component = Application1, Payload: {"vi 
ewableIdentityAttributes":{"Email":"[email protected]","cn":"Kevin Mollo" 
,"Last Name":"Mollo","First Name":"Kevin"},"assignedRoles":[],"listAttributes":[ 
"First Name","Last Name","Email","cn"]} 

不過,我不叫代理URL後獲得JSON格式的響應。 下面是我的ESB配置:

<?xml version="1.0" encoding="UTF-8"?> 
<proxy xmlns="http://ws.apache.org/ns/synapse" 
     name="SPRSAPproxy" 
     transports="http,https" 
     statistics="disable" 
     trace="disable" 
     startOnLoad="true"> 
    <target> 
     <inSequence> 
     <log/> 
     <clone> 
      <target> 
       <sequence> 
        <property name="Application" value="Application1"/> 
        <property name="messageType" 
          value="application/xacml+json" 
          scope="axis2" 
          type="STRING"/> 
        <property name="Authorization" 
          expression="fn:concat('Basic ', base64Encode('username:password'))" 
          scope="transport"/> 
        <send> 
        <endpoint> 
         <address uri="http://hostname1:8080/identityiq/rest/identities/9000070"/> 
        </endpoint> 
        </send> 
       </sequence> 
      </target> 
      <target> 
       <sequence> 
        <property name="Application" value="Application2"/> 
        <property name="messageType" 
          value="application/json" 
          scope="axis2" 
          type="STRING"/> 
        <send> 
        <endpoint> 
         <address uri="http://hostname2:8080/aveksa/command.submit?cmd=findUsers&amp;format=json&amp;unique_id=9000070"/> 
        </endpoint> 
        </send> 
       </sequence> 
      </target> 
     </clone> 
     </inSequence> 
     <outSequence> 
     <log level="full" description=""> 
      <property name="Component" expression="get-property('Application')"/> 
     </log> 
     <aggregate> 
      <completeCondition> 
       <messageCount min="2"/> 
      </completeCondition> 
      <onComplete expression="/"> 
       <property name="messageType" 
         value="application/xacml+json" 
         scope="axis2" 
         type="STRING" 
         description="messageType"/> 
       <enrich> 
        <source clone="true" xpath="/"/> 
        <target type="body"/> 
       </enrich> 
       <send/> 
      </onComplete> 
     </aggregate> 
     </outSequence> 
     <faultSequence> 
     <log level="full" category="WARN"/> 
     </faultSequence> 
    </target> 
    <description/> 
</proxy> 

我得到如下回應:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Header/><soapenv:Body><jsonObject><findUsers><id>20</id><add_state>0</add_state><remove_state>0</remove_state><supervisor_id_name></supervisor_id_name><idc_id>3</idc_id><backup_supervisor_name></backup_supervisor_name><backup_supervisor></backup_supervisor><business_unit_id></business_unit_id><company>companyb</company><creation_date>2016-05-11 18:02:42.0</creation_date><deletion_date></deletion_date><department>922</department><display_name>Kevin Mollo (companyb)</display_name><email_address>[email protected]</email_address><exception_count></exception_count><first_name>Kevin</first_name><is_terminated>False</is_terminated><job_status>Active</job_status><last_name>Mollo</last_name><legacy_employee_id>171352</legacy_employee_id><supervisor_id></supervisor_id><termination_date></termination_date><title>Broadband Technician</title><unique_id>9000070</unique_id><user_id>user71</user_id><violation_count></violation_count></findUsers></jsonObject><soapenv:Envelope><soapenv:Header/><soapenv:Body><jsonObject><viewableIdentityAttributes><Email>[email protected]</Email><cn>Kevin Mollo</cn><Last Name>Mollo</Last Name><First Name>Kevin</First Name></viewableIdentityAttributes><listAttributes>First Name</listAttributes><listAttributes>Last Name</listAttributes><listAttributes>Email</listAttributes><listAttributes>cn</listAttributes></jsonObject></soapenv:Body></soapenv:Envelope></soapenv:Body></soapenv:Envelope> 

請讓我知道我怎樣才能得到JSON響應。 任何幫助將不勝感激。

回答

2

您可以設置爲messageType應用/ JSON,而不是應用程序/ XACML + JSON在outSequence和嘗試。

<property name="messageType" value="application/json" scope="axis2" type="STRING" description="messageType"/> 

還沒有應用/ XACML + JSON消息格式化和消息建設者默認使用WSO2 ESB發貨。如果您需要使用這些格式,則必須編寫自己的格式化程序和構建程序,並將它們配置爲axis2.xml文件。

+0

謝謝。我已經嘗試了這一點,但我得到了我的服務器錯誤,並沒有得到任何迴應:錯誤是: [2016-07-20 13:33:06,363]錯誤 - JsonUtil #writeAsJson。無法將OMEle 轉換爲JSON。無效的XML負載。錯誤>>>意外字符 '>'(代碼62)在線 xpected '=' 在[行,列{未知源}]:[1147] [二零一六年七月二十零日13:33:06363] ERROR - PassThroughHttpSender無法提交資源org.apache.axis2.AxisFault:無法寫入JSON流。 在org.apache.synapse.commons.json.JsonUtil.writeAsJson(JsonUtil.java:22 1) – Alka

+0

好像該消息不能被確認爲的OMElement。您可以嘗試啓用線路日誌並在此處發佈以驗證從後端接收到的有效負載是什麼。要啓用wirelogs如下:http://mytecheye.blogspot.com/2013/09/wso2-esb-all-about-wire-logs.html – maheeka

+0

請點擊下面的鏈接查看服務器響應: [服務器響應( http://imgur.com/a/zzyLm) – Alka