繁体   English   中英

在WSO2 ESB中进行聚合后,无法以JSON格式获得响应

[英]Unable to get response in JSON format after aggregation in 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文件中进行配置。

暂无
暂无

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

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