WSO2 中的过滤

发布于 2024-12-26 07:03:57 字数 2650 浏览 0 评论 0原文

我想构建一个代理:
1. 调用授权服务并给出结果“OK”或“Fail”(第一个服务)
2. 如果结果“OK”,则调用服务

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

<?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>

我在输出序列处给出“过滤”。下面是 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

似乎过滤条件始终为 false。
过滤器中 XPath 的正确语句是什么?

I want to build one proxy that:
1. Call Service that do Authorize and give result OK or Fail (1st Service)
2. If Result ‘OK’ then call a Service

The Problem is, when The 1st Service give back the Message :

<?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>

And I give “filtering” at Out Sequence. Here is the 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>

When I run my Application, the ESB always give the message :

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

Seems like the condition of the filtering is always false.
What is the correct statement for the XPath in the filter?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

桃气十足 2025-01-02 07:03:57

您的代理配置应如下所示

<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 source="/result/status" regex="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>
               <send/>
            </else>
         </filter>
       </outSequence>
   </target>
   <description></description>
</proxy>

Your proxy configuration should be look as follows

<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 source="/result/status" regex="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>
               <send/>
            </else>
         </filter>
       </outSequence>
   </target>
   <description></description>
</proxy>
此刻的回忆 2025-01-02 07:03:57

您似乎给出了错误的 xpath 表达式。您不能同时为 xpath 值提供 xpath 和布尔表达式,即它不能是“/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>

It seems that you may have given a wrong xpath expression. You can't give an xpath and a boolean expression both for the xpath value, i.e. it can't be "/result/status='OK'", but has to be "/result/status". Then, according to your sequence, it would fire the section after then, if this element is present. Since, you need to evaluate a boolean condition as well based on the xpath, I'll present an alternative based on the switch mediator (Same can be done for the filter by setting a property):

<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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文