json - 在 WSO2 ESB 中聚合后无法获得 JSON 格式的响应

标签 json wso2 response esb wso2-esb

我有一个代理服务可以在多个系统中搜索用户,并且应该返回 JSON 格式的组合响应。我得到了组合的响应,但我得到的不是 JSON 格式的响应,而是 XML 格式的响应。 我可以在 WSO2 服务器日志中看到 JSON 响应,如下所示:

[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
llo@companyb.com","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":"Kevin.Mollo@companyb.com","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>Kevin.Mollo@companyb.com</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>Kevin.Mollo@companyb.com</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 响应。 任何帮助将不胜感激。

最佳答案

可以在outSequence中设置messageType为application/json而不是application/xacml+json试试。

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

此外,默认情况下,WSO2 ESB 不附带 application/xacml+json 消息格式化程序和消息构建器。如果您需要使用这些格式,您必须编写自己的格式化程序和构建器,并在 axis2.xml 文件中配置它们。

关于json - 在 WSO2 ESB 中聚合后无法获得 JSON 格式的响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38457557/

相关文章:

java - ExtJs 不会将数据加载到表单

json - 在 Postgres 中解析 JSON

jms - WS02 Websphere MQ 的 JMS 传输

linux - Carbon 4.0.1 (BAM 2.0) 作为 Linux 守护进程

client-server - 请求,响应和服务器之间有什么区别?

jquery - 为什么这个jquery不会触发.ajax()请求?

node.js - NodeJS console.log 可以工作,但 response.write 不能

java - 如何用Java从txt文件中读取JSON数据?

python - 如何接受python json字典中的任何键?

tomcat - 如何通过 WSO2 将 JAVA_HOME 传递给 Tomcat