【问题标题】:How to combine two queries in wso2 esb如何在 wso2 esb 中组合两个查询
【发布时间】:2019-09-26 05:42:52
【问题描述】:

我是 wso2 的新手,可能我的问题很简单,但我已经为此奋斗了一周。问题是我必须在 ESB 4.9.0 中组合两个有效负载。

我已经尝试丰富,使用之前查询的参数创建新的 payloadFactory,但这一切都没有按照我想要的方式实现。问题是我必须从 DS 获取学生数据并从 API 生成密码(基于学生 ID)。所有这些都必须组合在一个有效负载中并转发到 xslt 转换。从 DS 我得到例如这个:

<student>
  <try>
    <st_id>123456</st_id>
    <name>Michael</name>
    <surname>Smith</surname>
    <email>email@email.com</email>
    <ssn>123456789</ssn>
    <faculty name="IT">
      <field>Programming</field>
      <f_code>IT-1234-19</f_code>
    </faculty>
  </try>
</student>

有时学生只能在一个研究领域学习一门学科,但其中一些学生可以学习两个不同的学科:

<student>
  <try>
    <st_id>121234</st_id>
    <name>John</name>
    <surname>Doe</surname>
    <email>jd@email.com</email>
    <ssn>764896536</ssn>
    <faculty name="Management">
      <field>Production engineering</field>
      <f_code>MN-1234-19</f_code>
    </faculty>
  </try>
  <try>
    <st_id>121234</st_id>
    <name>John</name>
    <surname>Doe</surname>
    <email>jd@email.com</email>
    <ssn>764896536</ssn>
    <faculty name="IT">
      <field>Electronics</field>
      <f_code>IT-4321-19</f_code>
    </faculty>
  </try>
</student>

API 告诉我:

{"HASH":"{SSHA}PTFOuvF/20MrSGbTkQTkeBUC8A/0mfKF"}

预期结果: 在学生节点 f ex 内的任意位置添加 HASH:

<student>
  <try>
    <st_id>123456</st_id>
    <name>Michael</name>
    <surname>Smith</surname>
    <email>email@email.com</email>
    <ssn>123456789</ssn>
    <faculty name="IT">
      <field>Programming</field>
      <f_code>IT-1234-19</f_code>
    </faculty>
  </try>
  <hash>{SSHA}PTFOuvF/20MrSGbTkQTkeBUC8A/0mfKF</hash>
</student>

我的代码是:

  <inSequence>

  <property expression="json-eval($.Numb)" name="Numb" scope="default" type="STRING"/>
  <payloadFactory media-type="xml">
    <format>
      <v1:getStudentRequest xmlns:v1="http://localhost/contract/ldap/v1">
        <v1:Numb>$1</v1:Numb>
      </v1:getStudentRequest>
    </format>
    <args>
      <arg evaluator="xml" expression="get-property('uri.var.Numb')"/>
    </args>
  </payloadFactory>
  <header name="Action" scope="default" value="urn:getStudentRequest"/>
  <call>
    <endpoint>
      <address uri="http://localhost:9769/services/LdapDS.SOAP11Endpoint" format="soap11"/>
    </endpoint>
  </call>
  <enrich>
    <source type="body" clone="true"/>
    <target type="property" property="Student"/>
  </enrich> 

  <property name="DISABLE_CHUNKING" value="true" scope="axis2"/>
  <call xmlns:v1="http://localhost/contract/ldap/v1">    
    <endpoint xmlns:v1="http://localhost/contract/ldap/v1"> 
      <http uri-template="http://localhost:39080/ldap/passgen/{uri.var.Numb}" method="GET" format="pox"></http>
    </endpoint>
  </call>
  <property evaluator="json" name="password" scope="default" expression="json-eval($.HASH)"/>
  <filter source="get-property('password')" regex="^$">
    <then>
      <log level="custom">
        <property expression="get-property('Numb')" name="Numb"/>
      </log>
    </then>
    <else>
      <property evaluator="json" name="pass" scope="default" expression="json-eval($.HASH)"/>
    </else>
  </filter>
  <!--
  <payloadFactory media-type="xml">
          <format>
            <m0:password xmlns:m0="http://localhost/contract/ldap/v1">$1</m0:password>
          </format>
          <args>
            <arg evaluator="xml" expression="get-property('pass')"/>
          </args>
  </payloadFactory>
  -->
  <enrich>
    <source xpath="$body" clone="true"/>
    <target action="child" type="custom" xpath="$Student//student/try"/>
  </enrich> 

  <enrich>
    <source type="property" clone="true" property="Student"/>
    <target action="replace" type="body"/>
  </enrich> 


  <xslt key="ldapXSL"/>

  <respond/>
</inSequence>

结果我只得到了一个 HASH :(

【问题讨论】:

    标签: wso2 esb payload


    【解决方案1】:

    以下内容包含满足您要求的示例中介。请参考以下内容并发展您的调解。分析提供的配置,似乎突触工件中存在错误配置(例如:-xpath="$Student//student/try"),但您实现的逻辑是正确的。

    <?xml version="1.0" encoding="UTF-8"?>
    <proxy xmlns="http://ws.apache.org/ns/synapse"
           name="testProxy"
           startOnLoad="true"
           statistics="disable"
           trace="disable"
           transports="http,https">
       <target>
          <inSequence>
             <log level="full"/>
             <call>
                <endpoint>
                   <http uri-template="http://www.mocky.io/v2/5dc6d3963800001c35cdec56"/>
                </endpoint>
             </call>
             <enrich>
                <source clone="true" type="body"/>
                <target property="property1" type="property"/>
             </enrich>
             <call>
                <endpoint>
                   <http uri-template="http://www.mocky.io/v2/5dc6d4723800004a00cdec59"/>
                </endpoint>
             </call>
             <property name="messageType" scope="axis2" value="application/xml"/>
             <enrich>
                <source clone="true" xpath="$body//HASH"/>
                <target action="child" xpath="$ctx:property1"/>
             </enrich>
             <enrich>
                <source clone="true" property="property1" type="property"/>
                <target type="body"/>
             </enrich>
             <log level="custom">
                <property expression="$ctx:property1" name="**-----**"/>
             </log>
             <respond/>
          </inSequence>
       </target>
       <description/>
    </proxy>
    

    上述代理由与您提到的类似的模拟后端响应组成。希望这会有所帮助

    【讨论】:

      猜你喜欢
      • 2017-06-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-12
      • 2015-06-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多