Sample 856: Introduction to Synapse Dynamic Router eip function template

<!-- Introduction to Synapse Dynamic Router eip function template --> <definitions xmlns="http://ws.apache.org/ns/synapse"> <import xmlns="http://ws.apache.org/ns/synapse" name="EipLibrary" package="synapse.lang.eip" /> <proxy name="StockQuoteProxy" transports="https http" startOnLoad="true" trace="disable"> <target> <inSequence> <call-template target="synapse.lang.eip.dynamic_router"> <with-param name="conditions" value="header=foo:bar.*{AND}url=/services/StockQuoteProxy.*;seq=cnd1_seq,header=custom_header1:bar.*{OR}header=custom_header1:foo.*;seq=cnd2_seq,header=custom_header2:foo.*;seq=cnd3_seq"/> </call-template> </inSequence> <outSequence> <send/> </outSequence> </target> </proxy> <sequence name="send_seq"> <log level="custom"> <property name="DEBUG" value="Condition Satisfied"/> </log> <send> <endpoint name="simple"> <address uri="http://localhost:9000/services/SimpleStockQuoteService"/> </endpoint> </send> </sequence> <sequence name="cnd1_seq"> <log level="custom"> <property name="MSG_FLOW" value="Condition (I) Satisfied"/> </log> <sequence key="send_seq"/> </sequence> <sequence name="cnd2_seq"> <log level="custom"> <property name="MSG_FLOW" value="Condition (II) Satisfied"/> </log> <sequence key="send_seq"/> </sequence> <sequence name="cnd3_seq"> <log level="custom"> <property name="MSG_FLOW" value="Condition (III) Satisfied"/> </log> <sequence key="send_seq"/> </sequence> </definitions>

Objective

This sample is an introduction to Synapse Dynamic Router eip function template.

Pre-requisites

  • Deploy the SimpleStockQuoteService in the sample Axis2 server and start Axis2
  • Start Synapse using the configuration numbered 856 (repository/conf/sample/synapse_sample_856.xml)
    Unix/Linux: sh synapse.sh -sample 856
    Windows: synapse.bat -sample 856

Executing the Client

In this sample, it checks whether the route condition based on HTTP url,HTTP headers evaluates to true and mediates using the given sequence. We will be using 'curl' as the client in this scenario.

Invoke curl commands as follows to see dynamic routing in action.

curl -d @stockQuoteReq.xml -H "Content-Type: application/soap+xml;charset=UTF-8" -H "foo:bar" "http://localhost:8280/services/StockQuoteProxy

You will see logs according to cnd1_seq in console.

curl -d @stockQuoteReq.xml -H "Content-Type: application/soap+xml;charset=UTF-8" -H "custom_header1:foo" "http://localhost:8280/services/StockQuoteProxy"

or

curl -d @stockQuoteReq.xml -H "Content-Type: application/soap+xml;charset=UTF-8" -H "custom_header1:bar" "http://localhost:8280/services/StockQuoteProxy"

You will see logs according to cnd2_seq in console.

curl -d @stockQuoteReq.xml -H "Content-Type: application/soap+xml;charset=UTF-8" -H "custom_header2:foo" "http://localhost:8280/services/StockQuoteProxy"

You will see logs according to cnd3_seq in console.

Back to Catalog