esb – 在WSO2中过滤

我想构建一个代理:

1.致电授权服务并给出结果正常或失败(第一服务)

2.如果结果为“确定”,则调用服务

问题是,当第一服务回馈消息时:

<?xml version='1.0' encoding='utf-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
       <soapenv:Body>
              <result>
                     <status>OK</status>
                     <message></message>
              </result>
       </soapenv:Body>
</soapenv:Envelope>

我在Out Sequence给出了“过滤”.这是XML:

<proxy xmlns="http://ws.apache.org/ns/synapse" name="TestProxy" transports="https,http" statistics="disable" trace="enable" startOnLoad="true">
   <target endpoint="AuthorizationService">
      <outSequence>
         <log level="full" />
         <filter xpath="/result/status='OK'">
            <then>
               <send>
                  <endpoint>
                     <address uri="http://192.168.1.140:8080/axis2/services/TaskService.TaskServiceHttpEndpoint/getTask" />
                  </endpoint>
               </send>
            </then>
            <else>
               <makefault version="soap11">
                  <code xmlns:soap11Env="http://schemas.xmlsoap.org/soap/envelope/" value="soap11Env:VersionMismatch" />
                  <reason value="1" />
                  <role>2</role>
                  <detail>3</detail>
               </makefault>
            </else>
         </filter>
         <log level="full" />
      </outSequence>
   </target>
</proxy>

当我运行我的应用程序时,ESB总是给出消息:

16:08:59,358 [-] [HttpClientWorker-4] INFO Start : Log mediator 
16:08:59,361 [-] [HttpClientWorker-4] INFO To: http://www.w3.org/2005/08/addressing/anonymous, WSAction: , SOAPAction: , MessageID: urn:uuid:0bc33821-c4f1-448e-a7dc-be4194be8e99, Direction: response, Envelope: <?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><result><status>OK</status><message></message></result></soapenv:Body></soapenv:Envelope> 
16:08:59,361 [-] [HttpClientWorker-4] INFO End : Log mediator 
16:08:59,361 [-] [HttpClientWorker-4] INFO Start : Filter mediator 
16:08:59,361 [-] [HttpClientWorker-4] INFO XPath expression : /result/status='OK' evaluates to false - executing the else path child mediators

似乎过滤的条件总是假的.过滤器中XPath的正确语句是什么?

最佳答案 您似乎可能已经给出了错误的xpath表达式.你不能为xpath值赋予xpath和boolean表达式,即它不能是“/ result / status =’OK’”,但必须是“/ result / status”.然后,根据你的顺序,如果这个元素存在,那么它将在那之后触发该部分.因为,你需要根据xpath计算一个布尔条件,我将提供一个基于switch中介的替代方法(可以通过设置属性为过滤器做同样的事情):

<proxy xmlns="http://ws.apache.org/ns/synapse" name="TestProxy" transports="https,http" statistics="disable" trace="enable" startOnLoad="true">
   <target endpoint="AuthorizationService">
      <outSequence>
         <log level="full" />
         <switch source="//result/status">
            <case regex="OK">
               <send>
                  <endpoint>
                     <address uri="http://192.168.1.140:8080/axis2/services/TaskService.TaskServiceHttpEndpoint/getTask" />
                  </endpoint>
               </send>
            </case>
            <default>
               <makefault version="soap11">
                  <code xmlns:soap11Env="http://schemas.xmlsoap.org/soap/envelope/" value="soap11Env:VersionMismatch" />
                  <reason value="1" />
                  <role>2</role>
                  <detail>3</detail>
               </makefault>
            </default>
         </switch>
         <log level="full" />
      </outSequence>
   </target>
</proxy>
点赞