Monday, May 8, 2017

How to read query parameter from the WSO2 ESB?

You can read the HTTP query parameter as below.

For this example, I assumed that proxy received the request with the firstName value and lastName value as query parameter.
http://tharanga:8280/services/Proxy4?firstName=tharanga&lastName=wijeweera

Now you can read the query parameter as below
  <property name="param_a" expression="$url:firstName"/>
  <property name="param_b" expression="$url:lastName"/>

Here, firstName and lastName values will assign to the properties.

How to read HTTP headers in WSO2 ESB?

You can read the HTTP headers as below.

For this example, I assumed that proxy received the request with the firstName as a HTTP header. In the ESB we can get the value as below
<property name="firstNameValue" expression="$trp:firstName"/>

Here firstName header value will assign to the firstNamevalue property.

How to get String size in WSO2 ESB?

You can get the String size using Xpath expression. Find the blow steps:

1. Assign the string value to the property.
2. Get the value using Xpath expression.
 fn:string-length(get-property('StringValue'))

Find the below sample proxy.
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
       name="Proxy1"
       startOnLoad="true"
       statistics="disable"
       trace="disable"
       transports="https,http">
   <target>
      <inSequence>
         <property name="stringvalue" value="Colombo"/>
         <property expression="fn:string-length(get-property('stringvalue'))" name="string_length"/>
         <log level="custom">
            <property expression="get-property('string_length')" name="Length"/>
         </log>
      </inSequence>
   </target>
   <description/>
</proxy>

 After executing this proxy, you can see the length value in console:
[2017-05-09 00:08:10,153]  INFO - LogMediator Lenght = 7.0