This site contains the documentation that is relevant to older WSO2 product versions and offerings.
For the latest WSO2 documentation, visit https://wso2.com/documentation/.
Sample 452: Conditional URL Rewriting with Multiple Rules
Note that WSO2 EI is shipped with the following changes to what is mentioned in this documentation:
<PRODUCT_HOME>/
repository/samples/
directory that includes all Integration profile samples is changed to<EI_HOME>/
samples/service-bus/
.<PRODUCT_HOME>/
repository/samples/resources/
directory that includes all artifacts related to the Integration profile samples is changed to<EI_HOME>/
samples/service-bus/resources/
.
Objective: Demonstrate the ability of the URL Rewrite mediator to perform rewrites based on multiple rules.
<definitions xmlns="http://ws.apache.org/ns/synapse"> <sequence name="main"> <in> <property name="http.port" value="9000"/> <property name="https.port" value="9002"/> <rewrite> <rewriterule> <action fragment="host" value="localhost"/> <action fragment="path" type="prepend" value="/services"/> </rewriterule> <rewriterule> <condition> <equal type="url" source="protocol" value="http"/> </condition> <action fragment="port" xpath="get-property('http.port')"/> </rewriterule> <rewriterule> <condition> <equal type="url" source="protocol" value="https"/> </condition> <action fragment="port" xpath="get-property('https.port')"/> </rewriterule> </rewrite> <log level="full"/> <send/> </in> <out> <send/> </out> </sequence> </definitions>
Prerequisites:
- Deploy the SimpleStockQuoteService in sample Axis2 server and start it on port 9000.
- Start ESB with the sample configuration 452 (i.e. wso2esb-samples -sn 452).
Invoke the Axis2 client as follows.
ant stockquote -Dtrpurl=http://localhost:8280 -Daddurl=http://test.com/SimpleStockQuoteService
The provided address URL does not contain a port number and the context. The URL rewrite mediator will replace the hostname to be 'localhost' and add the context '/services' to the path. Then it will add the appropriate port number to the URL by looking at the protocol prefix. Ultimately the service request will be routed the sample Axis2 server and the client will receive a valid response. Note that the Synapse configuration does not specify any endpoints explicitly. So the messages are sent to the rewritten To header.
Another important aspect shown by this sample is the ability of the URL rewrite mediator to obtain the necessary values by executing XPath expressions. The port numbers are calculated by executing an XPath on the messages.
Publishing Events to Topics Using the Event Mediator
WSO2 ESB can be used as an event broker. It comes with a built-in eventing implementation and a lightweight event broker based on Apache Qpid. You can use the ESB management console to create event topics and clients can subscribe to those topics by sending WS-Eventing subscription requests. The management console also allows creating static subscription.
WSO2 ESB is also equipped with an event mediator which can be used to publish messages to predefined topics. With this mediator it is possible for a sequence or a proxy service to directly publish a received request or a response to a topic as an event.