Filtering in WSO2

I want to create one proxy that:
1. A call service that performs authorization and gives the result OK or Fail (1st Service)
2. If Result is "OK", call the service

The problem is that when the 1st service returns a 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" in 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 launch my application, the ESB always displays a 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 

It seems that the filter condition is always wrong.
What is the correct instruction for XPath in the filter?

+4
source share
2 answers

It seems that you made the wrong xpath expression. You cannot give xpath and boolean expression as for xpath value, i.e. It cannot be β€œ/ result / status =β€œ OK, ”but it must beβ€œ / result / status. ”Then, according to your sequence, it will light up section after that if this element is present. Since you also need to evaluate the logical condition based on xpath, I will present an alternative based on the switch broker (this can be done for the filter by setting the 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> 
0
source

The proxy configuration should look like this

 <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> 
+2
source

Source: https://habr.com/ru/post/1390196/


All Articles