Try WSO2 Cloud for Free
Sign in

All docs This doc

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Manually added ToC

...

Info
titleAlternate Method

You can do the same using a dynamic sequence as well. For that you will need to make the below changes to the sequence explained in Resource-based routing. However all the versions needs to be defined and handled separately whereas the above sequence will dynamically populate any version which you pass in the header.

Expand
titleExpand to see the sample sequence...
Code Block
<sequence name="dynamic_ep" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
    <!-- The property which is retrieved as get-property('To')" stores the request URI for the API. Based on this value we will determine the endpoint which the request needs to be routed to.-->
	<switch source="get-property('transport','Version')">
    	<case regex="1.0.0.*">
           <!-- We are then assigning the endpoint which we need to route to in a property named service_ep in this step -->
        	<property name="service_ep" value="https//first.backend.url/1.0.0/customers/>
    	</case>
    	<case regex="2.0.0">
        	<property name="service_ep" value="https//first.backend.url/2.0.0/customers/"/>
    	</case>
    	<!– add endpoints as needed –>
    	<default>
        	<property name="service_ep" value="https//first.backend.url/1.0.0/customers/"/>
        	<!–default endpoint if required. However there should be a matching resource–>
    	</default>
	</switch>
    <!-- Next we need to store this endpoint in a header named To as shown below -->
	<header name="To" expression="get-property('service_ep')"></header>
	<property expression="get-property('service_ep')" name="ENDPOINT_ADDRESS"></property>
	<!–Please note that "ENDPOINT_ADDRESS" (additional) property is defined here in order to populate
    destination address for statistics (API Usage by Destination). –>
</sequence>



Working with properties

The Property Mediator has no direct impact on the message, but rather on the message context flowing through Synapse.

Code Block
titleSyntax
<property name="string" [action=set|remove] [type="string"] (value="literal" | expression="xpath") [scope=default|transport|axis2|axis2-client] [pattern="regex" [group="integer"]]>
    <xml-element/>?
</property>

Setting properties within your custom mediation 
Anchor
mediation
mediation

For a list of the types of properties which you are able to work with, see Properties Reference. All properties which need to be set follow the same basic syntax. The following are some examples of setting properties.

Table of Contents
maxLevel5
minLevel5
excludeDebugging

Setting a content type
Code Block
titleSyntax
<sequence xmlns="http://ws.apache.org/ns/synapse" name="property_sequence"> 
           <property name="ContentType" value="text/xml" scope="axis2"/>                   
</sequence>

...