2012-01-10 46 views
4

我想建立一個代理,該代理:
那些授權,給結果OK或失敗(1處)
2. 1.呼叫服務如果結果「OK」然後調用一個服務過濾在WSO2

問題是,當第一個服務返回消息:

<?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序列中給出「過濾」。下面是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的正確聲明是什麼?

回答

0

看來你可能已經給出了錯誤的xpath表達式。你不能爲xpath值給出xpath和布爾表達式,即它不能是「/ result/status ='OK'」,但必須是「/ result/status」。然後,根據您的順序,如果此元素存在,則會在此之後觸發該部分。因爲,你需要評估以及基於XPath一個布爾條件,我將(同可以過濾器來完成通過設置一個屬性)提出了一種基於開關調解一種替代方案:

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