4

我想构建一个代理:
1. 调用授权服务并给出结果 OK 或失败(第一个服务)
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>

我在 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 的正确语句是什么?

4

2 回答 2

2

您的代理配置应如下所示

<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>
于 2013-05-05T03:21:20.697 回答
0

看来您可能给出了错误的 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>
于 2012-01-10T18:07:40.607 回答